var isBackend = false;

function calculate(aria, num, width, trimble, hektar, zastapvane, plosht, spestqvane)
{	
	var zast = 100/($(width).value)*($(trimble).value)/100;
		
	var pl = ($(aria).value)*($(num).value)*zast/100;
	
	if (zast) 
		$(zastapvane).innerHTML = zast.toFixed(2);
	else
		$(zastapvane).innerHTML = "0.00";
		
	if (pl) 
		$(plosht).innerHTML = pl.toFixed(2);
	else
		$(plosht).innerHTML = "0.00";
	
	var spest = ($(hektar).value)*pl;
	
	if (spest) 
		$(spestqvane).innerHTML = spest.toFixed(2);
	else
		$(spestqvane).innerHTML = "0.00";
	
	return false;
}

function calculate_example(aria, num, width, trimble, hektar, zastapvane, plosht, spestqvane)
{	
	$(aria).value = "500";
	$(num).value = "1";
	$(width).value = "3.6";
	$(trimble).value = "15";
	$(hektar).value =	"160";
	$(zastapvane).innerHTML = "4.17";
	$(plosht).innerHTML = "20.83";	
	$(spestqvane).innerHTML = "3333.33";	
	return false;
}


displayInProgress = false;
function showPlayer(titleDiv, videoURL, imageURL)
{
	document.getElementById('flashcontent').style.display = 'none';
	
	var title= document.getElementById(titleDiv).innerHTML;
	var prefix = '';
	
	if (!displayInProgress)
	{
		displayInProgress = true;
		
		var divWidth = 660;
		var divHeight = 440;
		
		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.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;
		
		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;	
		//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;
		
		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><div class="clear"></div>';
	
		html += '<div style="margin: 10px 0 0 0; font-family: Verdana; font-size: 10px; color: #666666; float: left;">' + title + '</div>';
		html += '<a href="#" onclick="hidePlayer(); return false;"><img src="images/closelabel.gif" style="margin: 10px 0 0 0; border: 0; float: right;" /></a>';
		
		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", "640", "385", "9.0.115", "expressInstall.swf", flashvars, params, attributes);	
	}			
}

function hidePlayer()
{
	if (!displayInProgress)
	{
		document.getElementById('flashcontent').style.display = '';
		
		obj = document.getElementById('player');
		obj.parentNode.removeChild(obj);		
	 
		new Effect.Appear('overlayPlayer', { duration: 0.4, from: 0.8, to: 0.0, afterFinish: (function(){
		
			var obj = document.getElementById('overlayPlayer');
			obj.parentNode.removeChild(obj);			
		
			displayInProgress = false;
		
		}).bind(this)});
	}		
}

//
//  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];
}
