var isBackend = false;

function popupPlayer(titleDiv, videoURL, imageURL, sitePath)
{
	var title= document.getElementById(titleDiv).innerHTML;
	popup(sitePath+'modules/player_popup.php?title='+title+'&videoPath='+videoURL+'&videoImagePath='+imageURL, 640, 480);
}

function popupAudioPlayer(titleDiv, audioURL, sitePath)
{
	var title= document.getElementById(titleDiv).innerHTML;
	popup(sitePath+'modules/player_popup.php?title='+title+'&audioPath='+audioURL, 640, 480);
}

function popup(url,winWidth,winHeight) 
{
	winTop = (screen.height - winHeight) / 2;
	winLeft = (screen.width - winWidth) / 2;
	window.open(url,"","width=" + winWidth + ",height=" + winHeight + ",top=" + winTop  + ",left=" + winLeft  + ",resizable=no,scrollbars=no,toolbar=no");
}

function inquiryChangeSelected(sender, radioId)
{
	var object = document.getElementById("inquiry");	
	var arr = object.getElementsByTagName('a');	
	for(i=0;i<arr.length;i++) arr[i].className = "";	
	sender.className = "bold";
	
	var arr = object.getElementsByTagName('input');	
	for(i=0;i<arr.length;i++) arr[i].value = 'false';
	
	object = document.getElementById(radioId);	
	object.value = 'true';
}

function showZoomIcon(element)
{
	$(element).setStyle({visibility: 'visible'});
}

function hideZoomIcon(element)
{
	$(element).setStyle({visibility: 'hidden'});
}

displayInProgress = false;
function showPlayer(titleDiv, videoURL, imageURL, fromPopup)
{
	var title= document.getElementById(titleDiv).innerHTML;
	var prefix = '';

	if (!displayInProgress)
	{
		displayInProgress = true;
		
		if (fromPopup) prefix = '../';
		
		var divWidth = 548;
		var divHeight = 383;
		
		var arrayPageSize = getPageSize();
		
		var objBody = document.getElementsByTagName("body").item(0);
		
		if (!fromPopup) 
		{
			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.8, 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;
		
		if (!fromPopup) objBody.insertBefore(objPlayer, objOverlay.nextSibling);
		else objBody.insertBefore(objPlayer, objBody.firstChild);
		
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var playerTop = arrayPageScroll[1] + (document.viewport.getHeight() - divHeight)/2;
		var playerLeft = arrayPageScroll[0] + (document.viewport.getWidth() - divWidth)/2;	
		//var playerTop = (arrayPageSize[1] - document.body.scrollTop  - divHeight) / 2;
		//var playerLeft = (arrayPageSize[0] - document.body.scrollLeft  - divWidth) / 2;
		
		objPlayer.style.top = (playerTop < 0) ? "0px" : playerTop + "px";
		objPlayer.style.left = (playerLeft < 0) ? "0px" : playerLeft + "px";
	
		var html = new String;
		
		if (!fromPopup) 
		{
			html += '<div class="page_title" style="background: url('+prefix+'themes/Main/player_video_title.png); width: 29px; height: 136px;"></div>';
			html += '<div class="player_content_top"></div>';
			html += '<div class="player_content">';
		}
		else
		{ 
			html += '<div class="page_title" style="background: url('+prefix+'themes/Main/video_title.png); width: 29px; height: 136px;"></div>';
			html += '<div class="page_content_top"></div>';
			html += '<div class="player_content" style="background: url('+prefix+'themes/Main/semi_transparent_bg.png);">';
		}		
	
		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 style="margin: 10px 0px 0px 0px; float: left; font-weight: bold;">' + title + '</div>';
		if (!fromPopup) html += '<a href="javascript:void(0);" onclick="hidePlayer();" style="color: #4c4c4c; margin: 10px 0px 0px 0px; float: right;">затвори</a>';
		else html += '<a href="javascript:void(0);" onclick="window.close();" style="color: #4c4c4c; margin: 10px 0px 0px 0px; float: right;">затвори</a>';
		html += '<div class="clear"></div>';
		
		html += '</div>';
		html += '</div>';
		if (!fromPopup) html += '<div class="player_content_bottom"></div>';
		else html += '<div class="page_content_bottom"></div>';
		html += '<div class="clear"></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", "508", "315", "9.0.115", "expressInstall.swf", flashvars, params, attributes);
	}			
}

function showAudioPlayer(titleDiv, audioFile, fromPopup)
{
	var title= document.getElementById(titleDiv).innerHTML;
	var prefix = '';
	
	if (!displayInProgress)
	{
		displayInProgress = true;
		
		if (fromPopup) prefix = '../';
		
		var divWidth = 548;
		var divHeight = 130;
		
		var arrayPageSize = getPageSize();
		
		var objBody = document.getElementsByTagName("body").item(0);

		if (!fromPopup) 
		{		
			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.8, 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;
		
		if (!fromPopup) objBody.insertBefore(objPlayer, objOverlay.nextSibling);
		else objBody.insertBefore(objPlayer, objBody.firstChild);
	
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var playerTop = arrayPageScroll[1] + (document.viewport.getHeight() - divHeight)/2;
		var playerLeft = arrayPageScroll[0] + (document.viewport.getWidth() - divWidth)/2;	
		//var playerTop = (arrayPageSize[1] - document.body.scrollTop  - divHeight) / 2;
		//var playerLeft = (arrayPageSize[0] - document.body.scrollLeft  - divWidth) / 2;
			
		objPlayer.style.top = (playerTop < 0) ? "0px" : playerTop + "px";
		objPlayer.style.left = (playerLeft < 0) ? "0px" : playerLeft + "px";
	
		var html = new String;

		if (!fromPopup) 
		{
			html += '<div class="page_title" style="background: url('+prefix+'themes/Main/player_audio_title.png); width: 29px; height: 136px;"></div>';
			html += '<div class="player_content_top"></div>';
			html += '<div class="player_content" style="height: 130px;">';
		}
		else
		{ 
			html += '<div class="page_title" style="background: url('+prefix+'themes/Main/discography_title.png); width: 29px; height: 136px;"></div>';
			html += '<div class="page_content_top"></div>';
			html += '<div class="player_content" style="height: 130px; background: url('+prefix+'themes/Main/semi_transparent_bg.png);">';
		}
	
		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 style="margin: 10px 0px 0px 0px; float: left; font-weight: bold;">' + title + '</div>';
		if (!fromPopup) html += '<a href="javascript:void(0);" onclick="hidePlayer();" style="color: #4c4c4c; margin: 10px 0px 0px 0px; float: right;">затвори</a>';
		else html += '<a href="javascript:void(0);" onclick="window.close();" style="color: #4c4c4c; margin: 10px 0px 0px 0px; float: right;">затвори</a>';
		html += '<div class="clear"></div>';
		
		html += '</div>';
		html += '</div>';
		if (!fromPopup) html += '<div class="player_content_bottom"></div>';
		else html += '<div class="page_content_bottom"></div>';
		html += '<div class="clear"></div>';
		objPlayer.innerHTML = html;
		
		var flashvars = {};
		flashvars.audioFile = audioFile;
		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_audio.swf", "player-holder", "508", "30", "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];
}
