// SCRIPT KU SKINU "FANTASY BLUE"

Skin = new Object();

Skin.init = function()
{
	IE_PNG_Images.repairAllImages();
	
	// intro
	if (document.getElementById('main').className=='uvod' && document.getElementById('intro'))
	{
		var h = document.getElementById('intro').offsetHeight;
		document.getElementById('content').style.height = (h+24)+'px';
		
		// skopiruje anketu
		var anketa = document.getElementById('anketa').cloneNode(true);
		document.getElementById('anketa_block').appendChild(anketa);
		
		// uprava pre OPERU
		if (navigator.userAgent.toLowerCase().indexOf("opera")>=0 && window.opera)
		{
			document.getElementById('anketa_block').firstChild.firstChild.nextSibling.style.color = 'white';
			document.getElementById('anketa_block').firstChild.style.borderTop = '1px solid white';
		}
	}
	
	// tiene stranky
	if (!browser.isIE || browser.version>5)
	{
		var shadow_static = document.createElement('DIV');
		shadow_static.id  = 'shadow_static';
		
		var h = getDocumentHeight()-25;
		if (h>613) h=613; // 613
		shadow_static.style.height = h+'px';
		document.body.insertBefore(shadow_static, document.getElementById('main'));

		var shadow = document.createElement('DIV');
		shadow.id  = 'shadow';
		var h = getDocumentHeight()-613-26;
		if (h<0) h = 0;
		if (h==0)
			shadow.style.display = 'none';
		shadow.style.height = (h)+'px';
		document.body.insertBefore(shadow, document.getElementById('main'));
		
		var shadow_end = document.createElement('DIV');
		shadow_end.id  = 'shadow_end';
		shadow_end.style.top = (getDocumentHeight()-26)+'px';
		if (browser.isIE && browser.version<6)
			shadow_end.style.marginTop = '-13px';
		document.body.insertBefore(shadow_end, document.getElementById('main'));
		
		var shadow_bottom = document.createElement('DIV');
		shadow_bottom.id  = 'shadow_bottom';	
		shadow_bottom.style.top = (getDocumentHeight())+'px';
		var h = getWindowHeight()-document.getElementById('main').offsetHeight;
		if (h<0) h=0;
		if (h>13) h=13;
		shadow_bottom.style.height = (h)+'px';
		document.body.insertBefore(shadow_bottom, document.getElementById('main'));
	}
	
	if (browser.isIE && browser.version==5)
		document.getElementById('scrolling_banner').style.display = 'none';
		
	if (browser.isIE && browser.version<6)
	{
		//document.getElementById('other_options').style.paddingLeft = '0px';
	}
	
	Skin.popupMenu.init();
	
	Skin.wave.start();
	
	window.onresize = Skin.onDocumentChangeSize;
	
	Skin.onDocumentChangeSize();
	
}


Skin.showCrepy = function()
{
	IE_PNG_Images.repairStyleSheets();

	if (document.getElementById('scrolling_banner'))
		document.getElementById('scrolling_banner').style.display = 'block';	
}

Skin.onDocumentChangeSize = function()
{
	if (!browser.isIE || browser.version>5)
	{
		var h = document.getElementById('main').offsetHeight-25;
		if (h>613) h=613; // 613
		document.getElementById('shadow_static').style.height = h+'px';
		
		var h = document.getElementById('main').offsetHeight-613-26;
		if (h<0) h = 0;
		document.getElementById('shadow').style.display = (h==0 ? 'none' : 'block');
		document.getElementById('shadow').style.height  = (h)+'px';

		document.getElementById('shadow_end').style.top = (document.getElementById('main').offsetHeight-26)+'px';
		
		document.getElementById('shadow_bottom').style.top = (document.getElementById('main').offsetHeight)+'px';
		var h = getWindowHeight()-document.getElementById('main').offsetHeight;
		if (h<0) h=0;
		if (h>13) h=13;
		document.getElementById('shadow_bottom').style.height = (h)+'px';
	}
}

// objekt POPUP Menu
Skin.popupMenu = new Object();

// hlavne menu stranky (IDcka HTML Elementov)
Skin.popupMenu.mainItems = new Array("menu_uvod","menu_nasa_ponuka","menu_o_nas","menu_info","menu_download","menu_forum","menu_sutaze");
Skin.popupMenu.submenuItems = new Array();

Skin.popupMenu.proccess = new Object();
Skin.popupMenu.proccess.id = null;
Skin.popupMenu.proccess.set = function( operation, time ) { this.clear(); this.id = setTimeout( operation, time ); }
Skin.popupMenu.proccess.clear = function() { if (this.id) clearTimeout(this.id); this.id = null; }
Skin.popupMenu.lastItem = null;

Skin.popupMenu.init = function()
{
	this.mainDiv = document.getElementById('menu');
	// toto je tu kvoli medzere medzi jednotlivymi polozkami a ich dalsej ponuky (popup menu), zrusil by sa onmouseover
	this.mainDiv.onmouseover = function() { Skin.popupMenu.proccess.clear(); }
	this.mainDiv.onmouseout  = Skin.popupMenu.hideChildSubMenuTimed;
	var linka;
	
	for (var i=0; i<Skin.popupMenu.mainItems.length; i++)
		if (document.getElementById(Skin.popupMenu.mainItems[i]))
		{
			var menuItem = document.getElementById(Skin.popupMenu.mainItems[i]);
			
			var gizmoContainer = document.createElement('DIV');
			gizmoContainer.id = 'gizmoContainer';
			
			var cloneItem = menuItem.cloneNode(true);
			var item = cloneItem.lastChild;

			if (item.nodeName=='SPAN' && item.firstChild)
			{
				item = item.firstChild;
				while (item.nodeName!='A') item = item.nextSibling;
				var k = 0;
				while (item)
				{
					item.id = menuItem.id+'2_'+k;
					item.onmouseover = Skin.popupMenu.highlightChildSubMenu;
					item.onmouseout  = Skin.popupMenu.normalizeChildSubMenu;
					
					item = item.nextSibling;
					while (item && item.nodeName!='A') item = item.nextSibling;
					k++;
				}
			}
			cloneItem.id = menuItem.id+'2';
			cloneItem.className = menuItem.id;
			gizmoContainer.appendChild(cloneItem);
			
			document.body.appendChild(gizmoContainer);
			
			
			var item = menuItem.lastChild;

			if (item.nodeName=='SPAN' && item.firstChild)
			{
				item = item.firstChild;
				while (item.nodeName!='A') item = item.nextSibling;
				var k = 0;
				while (item)
				{
					item.id = menuItem.id+'_'+k;			
					
					// PRIDAM TIEN
					// vlozim text polozky podmenu do tagu B
					var newItem = document.createElement('B');
					newItem.className = 'text';
					newItem.appendChild(item.firstChild);

					// vytvorim dalsi tag B ktoru bude tienom predchadzajuceho tagu
					var newShadow = document.createElement('B');
					newShadow.innerHTML = newItem.innerHTML;
					newShadow.className = 'shadow';
					item.appendChild(newShadow);
					
					item.appendChild(newItem);
					
					//item.innerHTML
					/*var newItem = item.cloneNode(true);
					item.style.position = 'relative';
					item.style.zIndex = '2';
					newItem.style.position = 'absolute';
					newItem.style.zIndex = '1';
					newItem.style.color = 'red';
					item.parentNode.insertBefore(newItem, item);*/
					
					item = item.nextSibling;
					while (item && item.nodeName!='A') item = item.nextSibling;
					k++;
				}
			}
			
			// prebehne vsetky linky a prazdnym nastavi return_false funkciu, aby so po kliku na ne nic nestalo
			linka = menuItem.firstChild;
			if (linka.href.charAt(linka.href.length-1)=="/") linka.onclick = return_false;
			
			// ak existuje taka polozka a ma aj podmenu
			if (menuItem.lastChild.nodeName=="SPAN")
			{
				var subMenu  = menuItem.lastChild;
				// prebehne vsetky linky a prazdnym nastavi return_false funkciu, aby so po kliku na ne nic nestalo
				linka	 = subMenu.firstChild;
				while (linka)
				{
					if (linka.nodeName=="A" && linka.href.charAt(linka.href.length-1)=="/")
						linka.onclick = return_false;
					linka = linka.nextSibling;	
				}
				
				Skin.popupMenu.submenuItems[Skin.popupMenu.submenuItems.length] = subMenu;
				
				cloneItem.onmouseover =
				menuItem.onmouseover = Skin.popupMenu.showChildSubMenu;
				cloneItem.onmouseout =
				menuItem.onmouseout  = Skin.popupMenu.hideChildSubMenuTimed;
				
				//subMenu.onmouseover  = Skin.popupMenu.showChildSubMenu;
			}
			else
				menuItem.onmouseover = menuItem.onmouseout = Skin.popupMenu.hideOtherSubmenus;
		}
}

// zobrazi submenu (svoje dieta)
Skin.popupMenu.showChildSubMenu = function()
{
	if (this.parentNode.id!='gizmoContainer')
	{
		Skin.popupMenu.lastItem = this;
		this.lastChild.style.display = 'block';
		document.getElementById(this.id+'2').lastChild.style.display = 'block';
		Skin.popupMenu.proccess.clear(); 
		Skin.popupMenu.hideOtherSubmenus(this.id);
	}
	else
	{
		Skin.popupMenu.proccess.clear();
		Skin.popupMenu.hideOtherSubmenus(this.className);
	}	
}

// zobrazi submenu (svoje dieta)
Skin.popupMenu.hideChildSubMenu = function() { this.lastChild.style.display = "none"; }
// skryje submenu (svoje dieta) 
Skin.popupMenu.hideChildSubMenuTimed = function()
{
	if (this.parentNode.id!='gizmoContainer')
	{
		var obj = this;
		if (obj && obj.id=="menu") obj = Skin.popupMenu.lastItem;
		if (obj)
			Skin.popupMenu.proccess.set( 'document.getElementById("'+obj.id+'").lastChild.style.display = "none"; document.getElementById("'+obj.id+'2").lastChild.style.display = "none";', 50); 
	}
	else
		Skin.popupMenu.proccess.set( 'document.getElementById("'+this.className+'").lastChild.style.display = "none"; document.getElementById("'+this.className+'2").lastChild.style.display = "none";', 50); 
}

Skin.popupMenu.hideOtherSubmenus = function( ktoreNie )
{
	for (var i=0; i<Skin.popupMenu.submenuItems.length; i++)
		if (Skin.popupMenu.submenuItems[i].parentNode.id != ktoreNie)
		{
			Skin.popupMenu.submenuItems[i].style.display = "none";
			document.getElementById(Skin.popupMenu.submenuItems[i].parentNode.id+'2').lastChild.style.display = 'none';
		}
}

Skin.popupMenu.highlightChildSubMenu = function()
{
	document.getElementById(this.id.replace('2_','_')).className='hover';
}

Skin.popupMenu.normalizeChildSubMenu = function()
{
	document.getElementById(this.id.replace('2_','_')).className='';
	window.status = 'x '+document.getElementById(this.id.replace('2_','_'));
	return true;
}


Skin.wave = 
{
	elementID: 'water_background',
	element: null,
	phaseStep: 4,
	phaseInterval: 100,
	
	add: 0,
	phase: 0,
	freq: 7,
	lightStrength: 0,
	strength: 3
}

// spusti sa iba v IE 5.5+
Skin.wave.start = function()
{
	this.element = document.getElementById(this.elementID);
	if (navigator.isIE5higher && this.element)
		setInterval('Skin.wave.animate()', this.phaseInterval);
}

Skin.wave.writeFilter = function()
{
	this.element.style.filter = 'Wave(Add='+this.add+', Freq='+this.freq+', LightStrength='+this.lightStrength+', Phase='+this.phase+', Strength='+this.strength+')';
}

Skin.wave.animate = function()
{
	this.phase += this.phaseStep;
	this.writeFilter();
}


// [PROPERTIES]
// ci je to IE 5.0
navigator.isIE5       = document.all && !window.opera && !document.fireEvent;
// ci je to IE verzie vyssej ako 5.0 (nie 5.0)
navigator.isIE5higher = document.all && !window.opera && document.fireEvent;

var IE_PNG_Images = new Object();
var cesta = 'css/broken_glasses/';

// moze sa zavolat az po nahrati css, vyhlada a upravi styl kde najde png v background-image
IE_PNG_Images.repairStyleSheets = function()
{
	if (navigator.isIE5higher)
	{
		var styleShit, style;
		// prejde kazdy externy styl zvlast
		for(var i=0; i<document.styleSheets.length; i++)
		{
			styleShit = document.styleSheets[i];
			// ak je stylesheet urceny pre zobrazovanie na monitore a obsahuje niekde .png ...
			if (!styleShit.disabled && 
			   (styleShit.media=="screen" || styleShit.media=="all" || styleShit.media=="") && 
			    styleShit.cssText.match(/\.png/i))
				// ...tak prebehne vsetky pravidla a ak najde v backgrounde PNG obrazok, nahradi ho filtrom
				for (var k=0; k<styleShit.rules.length; k++)
					if (styleShit.rules[k].style.backgroundImage.match(/crepy\.png/i)||styleShit.rules[k].style.backgroundImage.match(/login_bg\.png/i)||styleShit.rules[k].style.backgroundImage.match(/footer_bg\.png/i)||styleShit.rules[k].style.backgroundImage.match(/oblacik\.png/i)||styleShit.rules[k].style.backgroundImage.match(/slogany3\.png/i)||styleShit.rules[k].style.backgroundImage.match(/shadow_bottom\.png/i))
					{
						style = styleShit.rules[k].style;
						style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+cesta+style.backgroundImage.replace(/url\(|\)$/g,'')+"',sizingMethod='scale')";
						style.backgroundImage = 'none';
					}
		}
	}
}


// vklada sa do elementu IMG do udalosti onload="IE_PNG_Images.repairImage(this)"
IE_PNG_Images.repairImage = function( imageElement )
{
	imageElement.onload = null;
	if (navigator.isIE5higher && !imageElement.style.filter.match(/progid:DXImageTransform/))
	{
		var picture = imageElement.src;
		var width   = imageElement.width;
		var height  = imageElement.height;
		imageElement.src    = "img/s.gif";
		imageElement.width  = width;
		imageElement.height = height;
		// sizingMethod='image' | 'scale' [default] | 'crop'
		// sizingMethod='scale' tato metoda roztiahne obrazok na celu velkost elementu
		imageElement.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+picture+"',sizingMethod='scale');";
	}
}

// po nahrati stranky opravi vsetky elementy IMG, je to vlastne hromadne .repairImage()
IE_PNG_Images.repairAllImages = function()
{
	var count = document.images.length;
	for (var i=0; i<count; i++)
		if (document.images[i].src.match(/\.png$/))
			this.repairImage(document.images[i]);
}


// vracia velkost okna (vnutornu velkost)	
function getWindowHeight()
{
	//Non-IE
	if( typeof( window.innerWidth ) == 'number' ) 
		return window.innerHeight;
	
	//IE 6+ in 'standards compliant mode'
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		return document.documentElement.clientHeight;
		
	//IE 4 compatible
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
		return document.body.clientHeight;
	
	else 
		return 0;
}

function getDocumentHeight()
{
	return document.body.scrollHeight ? document.body.scrollHeight : document.body.offsetHeight;
}