


function isGecko()
{
	return (-1 != navigator.userAgent.toLowerCase().indexOf( "gecko"));	
}

function isOpera()
{
	return (-1 != navigator.userAgent.toLowerCase().indexOf( "opera/"));	
}

function isIE7()
{
	
	isIE7 = false;
	ieStrPos = navigator.userAgent.toLowerCase().indexOf( "msie");
	if (ieStrPos != -1)
	{
	    ieVer = parseFloat(navigator.userAgent.substr(ieStrPos + "msie".length));
	    if (ieVer >= 7)
	    {
	        isIE7 = true;
	    }
	}
	
	return isIE7;
}







/*******************************************************************************
* GET ELEMENT BY ID SHORTCUT                                                   *
*******************************************************************************/
function gE( id)
{
	var el;
	if(document.getElementById) {
		el = document.getElementById(id);
	} else if(document.all) {
		el = document.all[id];
	} else {
		return null;
	}
	return el;
}
/*******************************************************************************
* END: GET ELEMENT BY ID SHORTCUT                                              *
*******************************************************************************/


/*******************************************************************************
* FUNKCE PRO WEB TV                                                            *
*******************************************************************************/
function showVideo( link, w, h, autoPlay, loop)
{
	document.write(getVideo( link, w, h, autoPlay, loop));
}

/*
function getVideo ( link, w, h, autoPlay)
{
	var video = "<object "
	+ " width=\"" + w + "\""
	+ " height=\"" + h + "\" "
	+ " classid=\"clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6\" id=\"videoObjectJs\">"
	+ "<param name=\"URL\" value=\"" + link + "\" />"
	+ "<param name=\"AutoStart\" value=\"" + autoPlay + "\" />"
	+ "<param name=\"ShowDisplay\" value=\"1\" />"
	+ "<param name=\"ShowTracker\" value=\"1\" />"
	+ "<param name=\"ShowControls\" value=\"1\" />"
	+ "<param name=\"EnableTracker\" value=\"1\" />"
	+ "<param name=\"AllowChangeDisplayMode\" value=\"1\" />"
	+ "<param name=\"EnablePositionControls\" value=\"1\" />"
	+ "<param name=\"stretchToFit\" value=\"1\" />"
	
	+ "<embed type=\"application/x-mplayer2\" src=\"" + link + "\" name=\"mediaplayer\" id=\"videoEmbedJs\" "
	+ " width=\"" + w + "\" "
	+ " height=\"" + h + "\" "
	+ " scale=\"tofit\""
	+ " autostart=\"" + autoPlay + "\" showcontrols=\"1\" showstatusbar=\"1\" pluginspage=\"http://www.microsoft.com/windows/mediaplayer/\">"
	+ "</embed>"
	
	+ "</object>"
	
	return video;
}
*/



function getVideo ( link, w, h, autoPlay, loop)
{

	if (isGecko())
	{

		var video = '<object width="' + w + '" height="' + h + '" data="' + link + '" type="video/x-ms-wmv" id="videoObjectJs">'
					+ '<param name="Filename" value="' + link + '" \/>'
					+ '<param name="AutoStart" value="' + autoPlay + '" \/>'
					+ '<param name="ShowDisplay" value="1" \/>'
					+ '<param name="ShowTracker" value="1" \/>'
					+ '<param name="ShowControls" value="1" \/>'
					+ '<param name="EnableTracker" value="1" \/>'
					+ '<param name="MovieWindowWidth" value="' + w + '" \/>'
					+ '<param name="MovieWindowHeight" value="' + h + '" \/>'
					+ '<param name="AllowChangeDisplayMode" value="0" \/>'
					+ '<param name="EnablePositionControls" value="1" \/>'
					+ '<param name="StretchToFit" value="0" \/>'
					+ '<param name="scale" value="noScale" />'
					+ (loop ? '<param name="PlayCount" value="9999" \/>' : '')
					
					+ '<\/object>';	
	}
	else
	{
		var video = "<object "
					+ " width=\"" + w + "\""
					+ " height=\"" + h + "\" "
					+ " classid=\"clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6\" id=\"videoObjectJs\">"
					+ "<param name=\"URL\" value=\"" + link + "\" />"
					+ "<param name=\"AutoStart\" value=\"" + autoPlay + "\" />"
					+ "<param name=\"ShowDisplay\" value=\"1\" />"
					+ "<param name=\"ShowTracker\" value=\"1\" />"
					+ "<param name=\"ShowControls\" value=\"1\" />"
					+ "<param name=\"EnableTracker\" value=\"1\" />"
					+ "<param name=\"AllowChangeDisplayMode\" value=\"1\" />"
					+ "<param name=\"EnablePositionControls\" value=\"1\" />"
					+ "<param name=\"stretchToFit\" value=\"1\" />"
					+ (loop ? '<param name="PlayCount" value="9999" \/>' : '')
				/*	
					+ "<embed type=\"application/x-mplayer2\" src=\"" + link + "\" name=\"mediaplayer\" id=\"videoEmbedJs\" "
					+ " width=\"" + w + "\" "
					+ " height=\"" + h + "\" "
					+ " scale=\"noscale\""
					+ " autostart=\"" + autoPlay + "\" showcontrols=\"1\" showstatusbar=\"1\" pluginspage=\"http://www.microsoft.com/windows/mediaplayer/\">"
					+ "</embed>"
				*/	
					+ "</object>"
	
	}
	

	

	return video;
}




function stopVideo ()
{
	
	if (window.ActiveXObject)
	{
		try
		{
			videoObjectJs.controls.stop();
			return true;
		}
		catch (e)
		{
			// nedaří se
		}		
	}
	
	
	var videoO = document.getElementById('videoObjectJs');	
	var videoParams = videoO.getElementsByTagName( 'param');	
	//var link = videoParams.namedItem('URL').value;
	var link = videoO.getAttribute('data');

	var largePlayer = document.getElementById('tvPlayerLarge');

	largePlayer.removeChild(videoO);
	largePlayer.innerHTML = getVideo( "", videoO.width, videoO.height, 0);
	
	var videoO = document.getElementById('videoObjectJs');	
	largePlayer.removeChild(videoO);
	largePlayer.innerHTML = getVideo( link, videoO.width, videoO.height, 0);	
	
}

function stopVideoSmall ()
{
	
	if (window.ActiveXObject)
	{
		try
		{
			videoObjectJs.controls.stop();
			return true;
		}
		catch (e)
		{
			// nedaří se
		}		
	}
	
	
	var videoO = document.getElementById('videoObjectJs');	
	var videoParams = videoO.getElementsByTagName( 'param');	
	//var link = videoParams.namedItem('URL').value;
	var link = videoO.getAttribute('data');

	var largePlayer = document.getElementById('tvPlayerSmallFrame');

	largePlayer.removeChild(videoO);
	largePlayer.innerHTML = getVideo( "", videoO.width, videoO.height, 0);
	
	var videoO = document.getElementById('videoObjectJs');	
	largePlayer.removeChild(videoO);
	largePlayer.innerHTML = getVideo( link, videoO.width, videoO.height, 0);	
	
}

function centerVideo ()
{

	
	if (window.ActiveXObject)
	{
		return true;
	}
	
	var emb = document.getElementById('videoEmbedJs');
	
	if (!emb)
	{
		return true;
	}
	
	var tvPlayer = document.getElementById('tvPlayerLarge');
	var playerW = tvPlayer.offsetWidth;
	var playerH = tvPlayer.offsetHeight;
	var embW = emb.offsetWidth;
	var newH = parseInt(emb.offsetHeight) + 100;
	
	if (embW > playerW)
	{
		var leftA = 0;
	}
	else
	{
		var leftA = Math.floor((playerW - embW) / 2);
	}
	
	if (newH > playerH)
	{
		var topA = 0;
	}
	else
	{
		var topA = Math.floor((playerH - newH) / 2);		
	}
	
	emb.style.display = "block";
	emb.style.height = newH + "px";
	emb.style.marginLeft = leftA+"px";
	emb.style.marginTop = topA+"px";
	
	return true;
}


/*******************************************************************************
* END: FUNKCE PRO WEB TV                                                       *
*******************************************************************************/


function switchVis ( id)
{
	var el = document.getElementById('sub_'+id);
	var vis = el.style.display;
	
	if ('none' == vis)
	{
		el.style.display = 'block';
		if (nodes_with_children)
		{
			var my_level = nodes_levels[ id];
			for (var i = 0; i < nodes_with_children.length; i++)
			{
				var oid = nodes_with_children[ i];
				var olevel = nodes_levels[ oid];
				
				if (olevel != my_level)
				{
					continue;
				}
				
				if (oid == id)
				{
					continue;
				}
				
				oel = document.getElementById( 'sub_'+oid);
				oel.style.display = 'none';
			}
		}
		
	}
	else
	{
		el.style.display = 'none';
	}
}

function redraw_menu ()
{
	for (var i = 0 ; i < init_hide.length; i++)
	{
		switchVis( init_hide[ i]);
	}
}

/**
 * Trida starajici se o rotovani novinek ve smeru dolu->nahoru
 * 
 * @author Miroslav Oujesky <oujesky@westcom.cz>
 * 
 */
function NewsTickerDownUp() {
			
	this.step = 1;
	this.speed = 150;
	this.delay = 5000;	
	
	// aktualni novinka
	this.current = 0;
	
	/**
	 * Startuje posun novinek
	 * 
	 * @param string tickerId ID tickeru
	 */
	this.start = function(tickerId)
	{			
		// element tickeru
		this.tickerEl = document.getElementById(tickerId);
		// elementy novinek
		this.newsEls = this.tickerEl.getElementsByTagName('li');
	
		// nastavime kazde novince atributy
		for (var i = 0; i < this.newsEls.length; i++)
		{
			this.newsEls[i].style.position = 'absolute';
			this.newsEls[i].style.width = this.tickerEl.offsetWidth + 'px';
			this.newsEls[i].style.top = this.tickerEl.offsetHeight + 'px';
		}
		
		if (this.newsEls.length > 0)
		{
			this.roll();
		}
	}
	

	/**
	 * Ridi posun novinek, po dojeti novinky na konec tickeru
	 * vola ceka a vola reset().
	 * 
	 */
	this.roll = function() 
	{
		// pretekli jsme v seznamu novinek?
		if (this.current >= this.newsEls.length)
		{
			this.current = 0;
		}
		
		// zobrazime novinku
		this.newsEls[this.current].style.display = 'block';
		
		// novinka je nizsi nez ticker tudiz se tam vejde cela => konec bude
		// az se bude cela uplne nahore v tickeru
		if (this.newsEls[this.current].offsetHeight <= this.tickerEl.offsetHeight)
		{
			// vrsek novinky by uz pretekl pres horni okraj tickeru, koncime
			if (this.newsEls[this.current].offsetTop - this.step < 0)
			{				
				window.setTimeout('newsTickerDownUp.fade(100, 0, 500);', this.delay);	
			} 
			// novinka jeste neni v konecne pozici, jedeme dale
			else
			{
				this.newsEls[this.current].style.top = (parseInt(this.newsEls[this.current].style.top) - this.step) + 'px';
				window.setTimeout('newsTickerDownUp.roll();', this.speed);
			}
		
		}
		// novinka je vyssi nez ticker => konec bude az se jeji spodek dostane
		// do spodku tickeru
		else
		{
			// spodek novinky by pretekl pres dolni okraj tickeru, koncime
			if ((this.newsEls[this.current].offsetTop + this.newsEls[this.current].offsetHeight - this.step) < this.tickerEl.offsetHeight)
			{
				window.setTimeout('newsTickerDownUp.fade(100, 0, 500);', this.delay);
			}
			// novinka jeste neni v konecne pozici, jedeme dale
			else
			{
				this.newsEls[this.current].style.top = (parseInt(this.newsEls[this.current].style.top) - this.step) + 'px';
				window.setTimeout('newsTickerDownUp.roll();', this.speed);
			}
		}					
	}
	
	/*
	 * Fade in / fade out efekt
	 * 
	 * @param integer opacStart Pocatecni pruhlednost
	 * @param integer opacEnd Cilova pruhlednost
	 * @param integer millisec Trvani efektu
	 */
	this.fade = function (opacStart, opacEnd, millisec) 
	{			 
			
	    //speed for each frame 
	    var speed = Math.round(millisec / 100); 
	    var timer = 0; 
	
	    //determine the direction for the blending, if start and end are the same nothing happens 
	    if(opacStart > opacEnd) { 
	        for(i = opacStart; i >= opacEnd; i--) { 
	            setTimeout("newsTickerDownUp.changeOpacity(" + i + ")", (timer * speed)); 
	            timer++;
	        } 
	    } else if(opacStart < opacEnd) { 
	        for(i = opacStart; i <= opacEnd; i++) 
	            { 
	            setTimeout("newsTickerDownUp.changeOpacity(" + i + ")", (timer * speed)); 
	            timer++;
	        } 
	    } 
	    
	    setTimeout('newsTickerDownUp.reset()', (timer * speed));
	} 

	/*
	 * Nastavuje pruhlednost pro vsechny prohlizece
	 * 
	 * @param integer opacity Pruhlednost
	 */
	this.changeOpacity = function(opacity) 
	{ 
	    this.newsEls[this.current].style.opacity = (opacity / 100); 
	    this.newsEls[this.current].style.MozOpacity = (opacity / 100); 
	    this.newsEls[this.current].style.KhtmlOpacity = (opacity / 100); 
	    this.newsEls[this.current].style.filter = "alpha(opacity=" + opacity + ")"; 
	}	
	
	/**
	 * Resetuje pozici novinky, nastavuje dalsi novinku a predava 
	 * rizeni zpet roll().
	 */
	this.reset = function()
	{
		// ukryjeme novinku a vratime ji do puvodni polohy
		this.newsEls[this.current].style.display = 'none';
		this.changeOpacity(100);
		this.newsEls[this.current].style.top = this.tickerEl.offsetHeight + 'px';
		
		// prejdeme na dalsi novinku
		this.current++;
		
		this.roll();
	}

	
}
// instance
var newsTickerDownUp = new NewsTickerDownUp();


/**
 * Trida starajici se o rotovani novinek ve smeru pravo->levo
 * 
 * @author Miroslav Oujesky <oujesky@westcom.cz>
 * 
 */
function NewsTickerRightLeft() {
			
	this.step = 2;
	this.speed = 75;	
	
	// aktualni novinka
	this.current = 0;
	
	/**
	 * Startuje posun novinek
	 * 
	 * @param string tickerId ID tickeru
	 */
	this.start = function(tickerId)
	{			
		// element tickeru
		this.tickerEl = document.getElementById(tickerId);
		// elementy novinek
		this.newsEls = this.tickerEl.getElementsByTagName('li');
	
		// nastavime kazde novince atributy
		for (var i = 0; i < this.newsEls.length; i++)
		{
			this.newsEls[i].style.position = 'absolute';
			this.newsEls[i].style.height = '1em'; 
			this.newsEls[i].style.left = this.tickerEl.offsetWidth + 'px';
		}
		
		if (this.newsEls.length > 0)
		{
			this.roll();
		}
	}
	

	/**
	 * Ridi posun novinek, po dojeti novinky na konec tickeru
	 * vola ceka a vola reset().
	 * 
	 */
	this.roll = function() 
	{
		// pretekli jsme v seznamu novinek?
		if (this.current >= this.newsEls.length)
		{
			this.current = 0;
		}
		
		// zobrazime novinku
		this.newsEls[this.current].style.display = 'block';
						
		// spodek novinky by pretekl pres dolni okraj tickeru, koncime
		if ((this.newsEls[this.current].offsetLeft + this.newsEls[this.current].offsetWidth - this.step) < 0)
		{
			this.reset();
		}
		// novinka jeste neni v konecne pozici, jedeme dale
		else
		{
			this.newsEls[this.current].style.left = (parseInt(this.newsEls[this.current].style.left) - this.step) + 'px';
			window.setTimeout('newsTickerRightLeft.roll();', this.speed);
		}
							
	}
		
	
	/**
	 * Resetuje pozici novinky, nastavuje dalsi novinku a predava 
	 * rizeni zpet roll().
	 */
	this.reset = function()
	{
		// ukryjeme novinku a vratime ji do puvodni polohy
		this.newsEls[this.current].style.display = 'none';
		this.newsEls[this.current].style.left = this.tickerEl.offsetWidth + 'px';
		
		// prejdeme na dalsi novinku
		this.current++;		
		this.roll();
	}

	
}
// instance
var newsTickerRightLeft = new NewsTickerRightLeft();


/**
 * Otevira/zavira blok
 * 
 * @param {string} id ID bloku
 * @param {bool} open True pro otevreni bloku, false pro zavreni bloku 
 * 
 * @author Miroslav Oujesky <oujesky@westcom.cz>
 * 
 * @version 1
 */
function collapse(id, open)
{
    var hId = document.getElementById('h-' + id); // hlavicka s ikonou
    var sId = document.getElementById('s-' + id); // span se zaviratkem/oteviratkem
    var dId = document.getElementById('d-' + id); // div s blokem
    var fId = document.getElementById('f-' + id); // spodek bloku

    // otevirame blok
    if (true == open)
    {
        hId.className = 'open';
        sId.onclick = function () { collapse(id , false); };
        sId.title = select_portal ? icon_close_portal_title : icon_close_spot_title;
        dId.style.display = 'block';
        fId.style.display = 'block';
    }
    // zavirame blok
    else
    {
        hId.className = 'close';
        sId.onclick = function () { collapse(id , true); };
        sId.title = select_portal ? icon_open_portal_title : icon_open_spot_title;
        dId.style.display = 'none';
        fId.style.display = 'none';
    }
    
    
}

/**
 * Odstrani bile znaky z retezce
 * 
 * @param str Retezec
 */

function trim(str)
{
    return str.replace(/^\s+|\s+$/g, '');
}    

/**
 * Vraci true a tim padem umoznuje odeslat formular pokud je neco zadano v search inputu
 *
 * @param string iId ID inputu
 * @parma string fId ID formulare
 * @param string defaultText Vychozi hodnota inputu, pokud je '', nic se s ni neprovadi
 * 
 * @return bool
 *
 * @author Miroslav Oujesky <oujesky@westcom.cz>
 */
function search_onSubmit(iId, fId, defaultText)
{
    var searchField = document.getElementById(iId); 
    
    if('' == trim(searchField.value) || defaultText == trim(searchField.value))
    {
        searchField.focus();
        return false;
    }
    else
    {
        return true;
    } 
}

/**
 * Po kliknuti vymaze vychozi obsah formulare, nebo necha stavajici
 *
 * @param bool empty True pokud se ma zobrazit defaultni text
 * @param string defaultText Vychozi hodnota inputu, pokud je '', nic se s ni neprovadi
 *
 * @author Miroslav Oujesky <oujesky@westcom.cz>
 */
function search_onFocus(iId, fId, empty, defaultText)
{
    var searchField = document.getElementById(iId);
    var searchForm = document.getElementById(fId);
    
    //hack pro fulltext
    if ('i1' == iId) 
    {    
        frameShow(1);
    }
       
    if (true == empty)
    {        
        searchField.style.color = '#333333';    
        searchField.value = '';
    }
    searchForm.onsubmit = function () { return search_onSubmit(iId, fId, defaultText); };
    searchField.onblur = function () { search_onBlur(iId, fId, defaultText); };    
    searchField.onfocus = function () { };
}

/**
 * Nastavi vychozi stav fulltextoveho formulare
 *
 * @param bool empty True pokud se ma zobrazit defaultni text
 * @param string defaultText Vychozi hodnota inputu
 *
 * @author Miroslav Oujesky <oujesky@westcom.cz>
 */
function search_init(iId, fId, empty, defaultText)
{
    var searchField = document.getElementById(iId);  
      
    if (true == empty)
    {        
        searchField.style.color = '#c8c8c8';
        searchField.value = defaultText;
    }
    searchField.onfocus = function () { search_onFocus(iId, fId, empty, defaultText); };
}

/**
 * Po odkliknuti z inputu vrati defaultni obsah nebo necha stavajici
 *
 * @param string defaultText Vychozi hodnota inputu, pokud je '', nic se s ni neprovadi
 *
 * @author Miroslav Oujesky <oujesky@westcom.cz>
 */
function search_onBlur(iId, fId, defaultText)
{
    var searchField = document.getElementById(iId);
    
    //hack pro fulltext
    if ('i1' == iId) 
    {    
        frameHide(1);
    }
    
    if ('' == trim(searchField.value))
    {
        search_init(iId, fId, true, defaultText);
    }
    else
    {
        searchField.onfocus = function () { search_onFocus(iId, fId, false, defaultText ); };
    }
}

/**
 * Zobrazi/zmizi *** ramecek okolo formularoveho prvku
 * 
 * @param int num Cislo formularoveho prvku 
 * 
 * @author Miroslav Oujesky <oujesky@westcom.cz>
 */
function frameShow(num)
{
    var elW = document.getElementById('w' + num);
    var elI = document.getElementById('i' + num);
    elW.className = elW.className + ' selected';
    elI.className = elI.className + ' selected';
}

/**
 * Zobrazi/zmizi *** ramecek okolo formularoveho prvku
 * 
 * @param int num Cislo formularoveho prvku 
 * 
 * @author Miroslav Oujesky <oujesky@westcom.cz>
 */
function frameHide(num)
{
    var elW = document.getElementById('w' + num);
    var elI = document.getElementById('i' + num);    
    elW.className = elW.className.replace(/selected/g, '');
    elI.className = elI.className.replace(/selected/g, '');
}
