/*
	===============================================================================================
	
		Project: 		Agrofert Holding Corporate Website
		Description:	JavaScript - common functions
	   ----------------------------------------------------------------------------------
		Author:			Michael Zítek
		Version:		1.00
		Created:		July 2010
		Modifications:
					01 - 
	
	===============================================================================================
*/


	// Nalezeni pozice objektu
	
	function getPosX (obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
			while (1) {
				curleft += obj.offsetLeft;
				if (!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}
	
	function getPosY (obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
			while (1) {
				curtop += obj.offsetTop;
				if (!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
		else if (obj.y)
        	curtop += obj.y;
		return curtop;
	}
	
	// Zjisteni velikosti okna (browseru)
	
	function getWindowWidth ()
	{
		if (self.innerWidth)
			ret = self.innerWidth;
		else if (document.documentElement && document.documentElement.clientWidth)
			ret = document.documentElement.clientWidth;
		else if (document.body)
			ret = document.body.clientWidth;
		return ret;
	}
	
	function getWindowHeight ()
	{
		if (self.innerHeight)
			ret = self.innerHeight;
		else if (document.documentElement && document.documentElement.clientHeight)
			ret = document.documentElement.clientHeight;
		else if (document.body)
			ret = document.body.clientHeight;
		return ret;
	}
	
	// Zjisteni velikosti dokumentu (stranky)
	
	function getDocumentWidth ()
	{
		ret = document.body.clientWidth;
		return ret;
	}
	
	function getDocumentHeight ()
	{
		ret = document.body.clientHeight;
		return ret;
	}
	
	// Zjisteni posunuti obsahu okna
	
	function getScrollX ()
	{
		if (document.all)
			return (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft
		else
			return window.pageXOffset
	}
	
	function getScrollY ()
	{
		if (document.all)
			return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop
		else
			return window.pageYOffset
	}
	
	// Uprava velikosti prekryvaciho DIVu pri zmene velikosti okna
	
	function pageCoverResize ()
	{
		if (document.getElementById("pageCover").className.indexOf ("pageCoverOn") != -1) {
			var winWidth = getWindowWidth ();
			var docWidth = getDocumentWidth ();
			var winHeight = getWindowHeight ();
			var docHeight = getDocumentHeight ();
			
			if (winWidth > docWidth) docWidth = winWidth;
			if (winHeight > docHeight) docHeight = winHeight;
			
			document.getElementById("pageCover").style.width = docWidth + "px";
			document.getElementById("pageCover").style.height = docHeight + "px";
		}
	}
	
	// Zobrazeni/skryti prekryvaciho DIVu
	
	function pageCover (action)
	{
		var winWidth = getWindowWidth ();
		var docWidth = getDocumentWidth ();
		var winHeight = getWindowHeight ();
		var docHeight = getDocumentHeight ();
		
		if (winWidth > docWidth) docWidth = winWidth;
		if (winHeight > docHeight) docHeight = winHeight;
		
		if (action) {																				// zobrazeni
			document.getElementById("pageCover").style.width = docWidth + "px";						// resize - sirka
			document.getElementById("pageCover").style.height = docHeight + "px";					// resize - vyska
			document.getElementById("pageCover").className = "pageCoverOn";							// prirazeni CSS tridy
		}
		else {																						// skryti
			parent.frames.document.getElementById("pageCover").className = "pageCover";
		}
	}
	
	// Zobrazeni/skryti obrazku
	
	function imageLoaded ()
	{
		var container = document.getElementById("imageContainer");
		
		if (container.clientWidth < 70)
			setTimeout ("imageLoaded ()", 500);														// cekani na natazeni obrazku
		else
			imagePosition ();																		// pozicovani kontajneru
	}
	
	function imagePosition ()
	{
		var container = document.getElementById("imageContainer");
		
		var scrollY = getScrollY ();																// vertikalni skrolovani
		var browserHeight = getWindowHeight ();														// vyska okna
		var browserWidth = getWindowWidth ();														// sirka okna
		var containerHeight = container.clientHeight;												// vyska kontajneru
		var containerWidth = container.clientWidth;													// sirka kontajneru
		var newTop = ((browserHeight - containerHeight) / 2) + scrollY - 30;						// odsazeni shora
		var newLeft = (browserWidth - containerWidth) / 2;											// odsazeni zleva
		
		container.style.top = newTop + "px";														// nastaveni odsazeni shora
		container.style.left = newLeft + "px";														// nastaveni odsazeni zleva
	}
	
	function imageDisplay (action, imageURL)
	{
		var container = document.getElementById("imageContainer");
		var containerInner = document.getElementById("imageContainerInner");
		
		if (action == "open" || action == "1")														// -=- otevreni nahledu -=-
		{
			var imageHTML = "<img src='" + imageURL + "'>";											// novy obsah kontajneru - odkaz na fotku
			
			containerInner.innerHTML = imageHTML;													// vlozeni fotky do kontajneru
			container.style.display = "block";														// zobrazeni kontajneru s fotkou
			document.body.style.overflow = "hidden";												// skryti posuvniku v hlavnim okne
			pageCover (1);																			// zobrazeni prekryti hlavniho okna
			
			imageLoaded ();																			// cekani na natazeni obrazku
		}
		else																						// -=- zavreni nahledu -=-
		{
			parent.frames.document.body.style.overflow = "";										// zobrazeni posuvniku v hlavnim okne
			container.style.display = "none";														// skryti kontajneru s fotkou
			document.getElementById("pageCover").className = "pageCover";							// zruseni prekryti hlavniho okna
		}
	}
