var baseAddress = 'http://www.got-kali.com/promo/flash/';
var uploadDir = 'upload/';
var bkgdImg = 'bkgdImg.jpg';
var clickHereImg = 'clickHere.jpg';

function deletePlayer(theWrapper, thePlaceholder, thePlayerId) { 
        swfobject.removeSWF(thePlayerId);
        var tmp=document.getElementById(theWrapper);
        if (tmp) { tmp.innerHTML = "<div id=" + thePlaceholder + "></div>"; }
}


function createPlayer(thePlaceholder, thePlayerId, theFile, image, autostart, plugins, skin, displayclick, link, linktarget ) {
        var flashvars = {
                file:theFile, 
                image:image, 
		skin: skin,
                autostart:autostart,
		plugins: plugins,
		displayclick: displayclick,
		link: link,
		linktarget: linktarget 
        }
        var params = {
                allowfullscreen:"true", 
                allowscriptaccess:"always"
        }
        var attributes = {
                id:thePlayerId,  
                name:thePlayerId
        }
        swfobject.embedSWF(baseAddress + "js/player.swf", thePlaceholder, "480", "360", "9.0.115", false, flashvars, params, attributes);
}


function initPlayer(newWrapper, theFile, image, autostart, plugins, skin, displayclick, link, linktarget ) { 
	fullFile = baseAddress + uploadDir + theFile;
	if (image == null) { image = baseAddress + bkgdImg; }
	if (autostart == null) { autostart = 'false'; }
	if (displayclick == null) { displayclick = 'play'; }
        deletePlayer(newWrapper, 'placeholder1', 'ply'); 
        createPlayer('placeholder1', 'ply', fullFile, image, autostart, plugins, skin, displayclick, link, linktarget );
}


var player;
function playerReady(obj) {
	player = document.getElementById('ply');
	player.addModelListener("STATE","updatePlayerState");
}

function updatePlayerState(obj) {
	playerStatus = obj['newstate'];
	playerOldStatus = obj['oldstate'];
	if (playerStatus == "COMPLETED") {
		divJumpText = document.getElementById('jumpText');
		jump = divJumpText.innerHTML;
		if (jump == 'true') {
			openPopup();
		} else {
			theFile = baseAddress + clickHereImg;
			divWrapText = document.getElementById('wrappText');
			wrap = divWrapText.innerHTML;
			divLinkText = document.getElementById('linkText');
			link = divLinkText.innerHTML;
			initPlayer(wrap, theFile, theFile, 'false', null, null , 'link', link, '_self' );
		}
	}
}

function openPopup() {
	divLinkText = document.getElementById('linkText');
	link = divLinkText.innerHTML;
	window.location.replace( link ); 
}
