var isBackend = false;

function switchPanel(obj, panel)
{
	if (obj.checked)
	{
		$(panel).show();
	}
	else
	{
		$(panel).hide();
	}
}

displayInProgress = false;
function showPlayer(titleDiv, videoURL, imageURL)
{
	//var title= document.getElementById(titleDiv).innerHTML;
	var prefix = '';

	if (!displayInProgress)
	{
		displayInProgress = true;
		
		prefix = '../';
		
		var divWidth = 757;
		var divHeight = 507;
		
		var arrayPageSize = getPageSize();
		
		var windowWidth = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
		var windowHeight = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
		
		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 = '9999';
		 	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 = '9999';	
	 	objPlayer.style.width = divWidth;
		objPlayer.style.height = divHeight;
		
		objBody.insertBefore(objPlayer, objOverlay.nextSibling);
		
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var playerLeft = (windowWidth - divWidth)/2 + arrayPageScroll[0];
		var playerTop = (windowHeight - divHeight)/2 + arrayPageScroll[1];
		
		
		objPlayer.style.top = (playerTop < 0) ? "0px" : playerTop + "px";
		objPlayer.style.left = (playerLeft < 0) ? "0px" : playerLeft + "px";
	
		var html = new String;

		html += '<div id="close" style="background: #4e4e4e;  padding: 8px;" >';	
		
		html += '<div id="player-holder">';
		
		html += '</div>';
		html += '<a id="closeLink" href="javascript:void(0)" onclick="hidePlayer()"></a>';
		html += '</div>';
	
		objPlayer.innerHTML = html;
			
		flash360(videoURL,$('player-holder'));
		
		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+"residentialpark/lib/flash/player.swf", "player-holder", "508", "315", "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;
	}
	
	var windowWidth, windowHeight;
	
	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];
}

function flash360(videoURL, el)
{

	//if ((window.p2q_Version) && (window.p2q_Version>=2.0)) {
		var flashvars="";
		p2q_EmbedFlashElement(el, 'lib/flash/'+videoURL,'757','507','allowFullScreen','true','bgcolor','#ffffff','FlashVars',flashvars);
		
		// Check to see if the version meets the requirements for playback
		if (!DetectFlashVer(9,0,0)) {
			document.write('<p class="warning">This content requires Adobe Flash Player Version 9 or higher. '
						 + '<a href="http://www.adobe.com/go/getflash/">Get Flash<\/a><\/p>');
		}
	//} else {
		//document.writeln('<p class="warning">p2q_embed_object.js is not included or it is too old! Please copy this file into your html directory.<\/p>');
	//}
}

