var isBackend = false;

function showPlayIcon(element)
{
	$(element).setStyle({visibility: 'visible'});
	$('video-title').innerHTML = '';
}

function hidePlayIcon(element, titleDiv, personDiv)
{
	$(element).setStyle({visibility: 'hidden'});
	$('video-title').innerHTML = $(personDiv).innerHTML + ' - ' + $(titleDiv).innerHTML;
}

displayInProgress = false;
function showPlayer(titleDiv, videoURL, imageURL, personDiv)
{
	var title = document.getElementById(titleDiv).innerHTML;
	var person = document.getElementById(personDiv).innerHTML;
	var prefix = '';

	if (!displayInProgress)
	{	
		displayInProgress = true;
		
		var divWidth = 690;
		var divHeight = 470;
		
		var arrayPageSize = getPageSize();

		var objBody = document.getElementsByTagName("body").item(0);
		
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlayPlayer');
		objOverlay.style.position = 'absolute';
		objOverlay.style.top = '0';
		objOverlay.style.left = '0';
		objOverlay.style.zIndex = '90';
		objOverlay.style.width = '100%';
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		objOverlay.onclick = hidePlayer;
		objBody.insertBefore(objOverlay, objBody.firstChild);
	
		new Effect.Appear('overlayPlayer', { duration: 0.4, from: 0.0, to: 0.6, afterFinish: (function(){displayInProgress=false;}).bind(this)});
		
		var objPlayer = document.createElement("div");
		objPlayer.setAttribute('id','player');
		objPlayer.style.position = 'absolute';
		objPlayer.style.zIndex = '100';	
	 	objPlayer.style.width = divWidth;
		objPlayer.style.height = divHeight;
		
		objBody.insertBefore(objPlayer, objOverlay.nextSibling);
		
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var playerTop = arrayPageScroll[1] + (document.viewport.getHeight() - divHeight)/2;
		var playerLeft = arrayPageScroll[0] + (document.viewport.getWidth() - divWidth)/2;	
		
		objPlayer.style.top = (playerTop < 0) ? "0px" : playerTop + "px";
		objPlayer.style.left = (playerLeft < 0) ? "0px" : playerLeft + "px";
	
		var html = new String;
		
		html += '<div id="player-border">';
		html += '<div id="player-title"><span style="color: #BCBCBC;">'+person+' - </span>'+title+'</div>';
		html += '<a href="#" onclick="hidePlayer(); return false;" title="Затвори" class="player-close"></a>';
		
		html += '<div id="player-holder">';
		html += '<a href="http://www.adobe.com/go/getflashplayer">';
		html += '<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />';
		html += '</a>';
		html += '</div>';
		
		html += '</div>';	

		objPlayer.innerHTML = html;
		
		var flashvars = {};
		flashvars.videoUrl = videoURL;
		flashvars.imageUrl = imageURL;
		flashvars.autoPlay = 0;
		var params = {};
		params.menu = "false";
		params.quality = "best";
		params.scale = "noscale";
		params.allowfullscreen = "true";
		var attributes = {};
		swfobject.embedSWF(prefix+"lib/flash/player.swf", "player-holder", "570", "350", "9.0.115", "expressInstall.swf", flashvars, params, attributes);

	}
	
}

function hidePlayer()
{
	if (!displayInProgress)
	{ 
		displayInProgress = false;
		
		var obj = document.getElementById('overlayPlayer');
		obj.parentNode.removeChild(obj);
	
		obj = document.getElementById('player');
		obj.parentNode.removeChild(obj);
	}		
}

//
//  getPageSize()
//
var pageWidth,pageHeight;
var windowWidth, windowHeight;
function getPageSize() {
        
    var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}