/*
	Dobra Vila
	dostava hrane Ljubljana
	
	(layout javascript)
*/

var windowResizeTimer;
var objPageArea;
var minPageSize = 0;

function adjustMainframeLayers() {
	clearInterval(windowResizeTimer);
	if (objPageArea != null && minPageSize > 0) {
		var windowHeight = window.size().height;
		var spareHeight = windowHeight - minPageSize - 104 - 30;	// -30px; glih še ok; I guess pride od menuItems (28px)
		
		var newHeigth;
		if (spareHeight > 0) newHeigth = minPageSize + spareHeight;
		 else newHeigth = minPageSize;
		newHeigth -= 100; 	// DIV "dostava_hrana"; padding-bottom: 100px;
		objPageArea.style.height = newHeigth+'px';
		adjustFacebookIcon();
	}
}

function onWindowResize() {
	clearInterval(windowResizeTimer);
	windowResizeTimer = setTimeout('adjustMainframeLayers()', 75);
	adjustFacebookIcon();		// Tale bi sicer morala biti samo v adjustMainframeLayers(); vendar potem vizualno grdo "skače" (ker se adjustMainframeLayers() ne izvede, dokler vlečeš (resize-aš) okno...
}

function adjustFooter() {
	objPageArea = document.getElementById('dostava_hrana');
	if (objPageArea != null) {
		minPageSize = parseInt(objPageArea.offsetHeight) || 0;
		adjustMainframeLayers();
	}
}

window.size = function() {
	var w = 0;
	var h = 0;
	if(window.innerWidth) {										// All Browsers except MS Internet Explorer
		w = window.innerWidth;
		h = window.innerHeight;
	}
	 else if (!(document.documentElement.clientWidth == 0)) {	// MS Internet Explorer (strict mode)
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
	 }
	  else {													// MS Internet Explorer (quirks mode)
			w = document.body.clientWidth;
			h = document.body.clientHeight;
	  }
	return {
		width: w,
		height: h
	};
}

function hideLayer(layerName) {
	var objLayer = document.getElementById(layerName);
	if (!objLayer) return false;
	objLayer.style.display = 'none';
}

//////////////////////////////////////
//	Dobra Vila na Facebooku			//
//////////////////////////////////////

// Preload Icon Images
var imgDobraVilaFacebookIcon_Normal = new Image(93, 20);
	imgDobraVilaFacebookIcon_Normal.src = '/img/footer/dobra_vila-facebook.gif';
var imgDobraVilaFacebookIcon_Active = new Image(93, 20);
	imgDobraVilaFacebookIcon_Active.src = '/img/footer/dobra_vila-facebook-a.gif';

function adjustFacebookIcon() {
	var addressWidth = 135;			// Visual width boxa z naslovom (v footerju, na desni; Dobra Vila, Vodnikova...; 125px) + marginRight (10px)
	var disclamerWidth = 500;		// Aprox. visual width boxa (Cene so v EUR, plačilo s karticami...
	var facebookIconWidth = 100;	// Aprox. width DIVa "[Facebook Icon] - Postani oboževalec"!
	var windowWidth = parseInt(window.size().width) || -1;

	var objFacebookIconContainer = document.getElementById('dobra_vila_facebook');
	if (!objFacebookIconContainer || windowWidth < 0) return false;
	var disclamerRight = Math.round((windowWidth + disclamerWidth) / 2);
	var addressLeft = windowWidth - addressWidth;
	var fbLeft = disclamerRight + Math.round((addressLeft - disclamerRight - facebookIconWidth) / 2);	// Facebook Ikona je pocentrirana med disclamer in address
	if (fbLeft > disclamerRight + 10) {
		objFacebookIconContainer.style.left = fbLeft+'px';
		objFacebookIconContainer.style.display = 'block';
	}
	 else objFacebookIconContainer.style.display = 'none';
}


function hltDobraVilaFacebook(newState) {
	var objFacebookIcon = document.getElementById('img_DobraVila_Facebook');
	if (!objFacebookIcon) return false;
	if (newState == 1) objFacebookIcon.src = imgDobraVilaFacebookIcon_Active.src;
	 else objFacebookIcon.src = imgDobraVilaFacebookIcon_Normal.src;
	
}
