/**
* set style
*/
window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  initProfile();
  activeTable();
  stuntRotation();
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title); 

/**
* Profile
*/
var activeProfile = 3;
/** change profile */
function switchProfile(profile)	{
	changeClass("prh"+activeProfile,"inactive");
	changeClass("pr"+activeProfile,"inactive");
	changeClass("prh"+profile,"active");
	changeClass("pr"+profile,"active");
	activeProfile=profile;
	return false;
}
/** init profile on load */
function initProfile()	{
	//switchProfile(3);
	switchProfile(2);
	switchProfile(1);
	changeClass("profile","safewidth");
}

/**
* Stylesheet switch (based on ALA code)
*/
function setActiveStyleSheet(title) {
	if ( document.getElementsByTagName && isSafe() )	{
		var i, a, main;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title) a.disabled = false;
			}
		}
		return false;
	}
	else	{
		return true;
	}
}
function getActiveStyleSheet() {
	if ( document.getElementsByTagName )	{
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
		}
	}
	return null;
}
function getPreferredStyleSheet() {
	if ( document.getElementsByTagName )	{
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("rel").indexOf("alt") == -1
			&& a.getAttribute("title")
			) return a.getAttribute("title");
		}
	}
	return null;
}
/**
* Active table (ALA code)
*/
function activeTable(){
	if (document.getElementById && document.createTextNode)  {
		var tables=document.getElementsByTagName('table');
		for (var i=0;i<tables.length;i++)   {
			if (tables[i].className=='activetable') {
				var trs=tables[i].getElementsByTagName('tr');
				for (var j=0;j<trs.length;j++) {
					if(trs[j].parentNode.nodeName=='TBODY' && trs[j].parentNode.nodeName!='TFOOT') {
						trs[j].onmouseover=function(){this.className='active';return false}
						trs[j].onmouseout=function(){this.className='';return false}
					}
				}
			}
		}
	}
}
/**
* Left side stunts rotation
*/
stunts = 0;
currentStunt = 0;
function stuntRotation(){
	if (document.getElementById && document.createTextNode)  {
		var divs=document.getElementsByTagName('div');
		
		for (var i=0;i<divs.length;i++)   {
			if (divs[i].className=='leftstunt') {
				stunts++;
				divs[i].id = "lstunt"+stunts;
				if ( stunts>2 )
					{
				
					divs[i].style.display = "none";
				}
			}
		}
		currentStunt = stunts;
		if ( stunts>2 )
			{
		
			switchStunt();
			setInterval("switchStunt()",5000);
		}
	}
}
function switchStunt(){
	if ( stunts>2 )
		{
	
		var s = getById("lstunt"+currentStunt);
		s.style.display = "none";
		if ( currentStunt<stunts )
			{
		
			currentStunt++;
		}
		else
			{
		
			currentStunt = 2;
		}
		s = getById("lstunt"+currentStunt);
		s.style.display = "block";
	}
}


/**
* Open new win function
*/
function openWin( path, name, width, height ) {
	var win = window.open(path, name,'scrollbars=yes,resizable=yes,resize=no,width='+width+',height='+height+',screenX='+getCenterW(width)+',screenY='+getCenterH(height)+',top='+getCenterH(height)+',left='+getCenterW(width) );
	win.focus();
	return win;
}
function openHardWin( name, path, width, height ) {
	var win = window.open(path, name,'scrollbars=no,resizable=no,resize=no,width='+width+',height='+height+',screenX='+getCenterW(width)+',screenY='+getCenterH(height)+',top='+getCenterH(height)+',left='+getCenterW(width)+',locationbar=no,directories=no' );
	win.focus();
	return win;
}
function getCenterW(width) {
	return parseInt( eval( (screen.availWidth-parseInt(width))/2 ) );
}
function getCenterH(height) {
	return parseInt( eval( (screen.availHeight-parseInt(height))/2 ) );
}
function show(anch)	{
	return popImage(anch.href,"Army.cz - detail obrázku");
}
function popImage( imageURL,imageTitle ){
	var AutoClose = true;
	var PositionX = 10;
	var PositionY = 10;
	var defaultWidth  = 640;
	var defaultHeight = 480;
	var imgWin = window.open('','army_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function resizeWinTo() {\n'+
		'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
		'var oH = document.images[0].height, oW = document.images[0].width;\n'+
		'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
		'window.doneAlready = true;\n'+ //for Safari and Opera
		'var x = window; x.resizeTo( oW + 100, oH + 100 );\n'+
		'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
		'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
		'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
		'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
		'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
		'x.resizeTo( oW = oW + ( ( oW + 100 ) - myW ), oH = oH + ( (oH + 100 ) - myH ) );\n'+
		'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
		'if( !window.opera && screen.width>800 ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
		'}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;">'))+
		'<img src="'+imageURL+'" alt="Otevírám obrázek ..." title="" onload="resizeWinTo();" onclick="window.close();">'+
		(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	return false;
}

/**
* cookies
*/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
/**
* Common
*/
/* Get element */
function getById(e) {
	if(typeof(e)!="string") return e;
	if(document.getElementById) e=document.getElementById(e);
	else if(document.all) e=document.all[e];
	else e=null;
	return e;
}
/* Change class */
function changeClass(e,cl)	{
	var el = getById(e);
	if ( el == null ) return null;
	el.className=cl;
	return el;
}
/* Check dom safe browser */
function isSafe()	{
	var UA=navigator.userAgent.toLowerCase();
	var opera56 = false;
	if(window.opera) {
		opera56=(UA.indexOf('opera 5')!=-1 || UA.indexOf('opera/5')!=-1 || UA.indexOf('opera 6')!=-1 || UA.indexOf('opera/6')!=-1);
	}
	return (!opera56);
}

/**
* Videogallery
*/
function writeVideoPlayer( fileName, ext, name )	{
	document.write( videoPlayer(fileName, ext, name) );
}

pl_name = null;
pl_ext = null;
pl_path = null;
function setVideoPlayer( fileName, ext, name )	{
	if ( ext != "wmv" )	{
		return;	
	}
	pl_name = name;
	pl_ext = ext;
	pl_path = fileName;	
}

function startVideoPlayer( contId )	{
	if ( pl_path!= null )	{
		putVideoPlayer(contId,pl_path,pl_ext,pl_name);
	}
}

function putVideoPlayer( contId, fileName, ext, name )	{
	var el = getById(contId);
	if ( el == null ) return true;
	el.innerHTML = videoPlayer( fileName, ext, name );
	return false;
}

function videoPlayer( fileName, ext, name )	{
	var format = ext.toUpperCase();
	var ico = ext;
	if ( ico == 'rm' )	{
		ico = 'real';	
	}
	
	var result = "<div class='videoPlayer'><div class='ct'>";
	result+="<div class='label'>";
	result+="<img src='../img/"+ico+".gif' alt='"+ext+"' class='datatype'> "+name;
	result+="</div>";
	if ( ext == "wmv" )	{
		result+='<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" type="application/x-oleobject" ';
		result+='codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" ';
		result+='standby="Loading Microsoft Windows Media Player components..."';
		result+='width="320" height="313">';
		result+='<param name="url" value="'+fileName+'">';
		result+='<param name="autostart" value="true">';
		result+='<param name="ShowStatusBar" value="true">';
		result+='<param name="volume" value="100">';
		result+='<param name="stretchToFit" value="true">';
		result+='<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/mediaplayer/" src="'+fileName+'" height="313" width="320" autostart="1" showcontrols="1" showstatusbar="1">';
		result+='</embed>';
		result+='</object>';
    
		/*
		result+='<object id="wmp" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-oleobject">';
		result+='<param name="filename" value="'+fileName+'">';
		result+='<param name="autostart" value="1">';
		result+='<param name="showcontrols" value="1">';
		result+='<param name="showstatusbar" value="1">';

		result+='<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/mediaplayer/" src="'+fileName+'" height="313" width="320" autostart="1" showcontrols="1" showstatusbar="1">';
		result+='</embed>';
		result+='</object>';*/
		
	}
	else if ( ext == "rm" )	{
		result+='<object id="rap" height="241" width="320" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA">';
		result+='<param name="controls" value="ImageWindow"/>';
		result+='<param name="console" value="Clip1"/>';
		result+='<param name="autostart" value="true"/>';
		result+='<param name="src" value="'+fileName+'"/>';
		result+='<embed name="video" src="'+fileName+'" NOJAVA="true" console="Clip1" controls="ImageWindow" height="241" width="320" autostart="true" type="audio/x-pn-realaudio-plugin"/>';
		result+='</object><br>';

		result+='<object id="rap" height="24" width="320" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA">';
		result+='<param name="controls" value="StatusField"/>';
		result+='<param name="console" value="Clip1"/>';
		result+='<embed type="audio/x-pn-realaudio-plugin" NOJAVA="true" console="Clip1" controls="StatusField" height="24" width="320" autostart="true"/>';
		result+='</object><br>';

		result+='<object id="rap" height="30" width="320" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA">';
		result+='<param name="controls" value="ControlPanel"/>';
		result+='<param name="console" value="Clip1"/>';
		result+='<embed type="audio/x-pn-realaudio-plugin" NOJAVA="true" console="Clip1" controls="ControlPanel" height="30" width="320" autostart="true"/>';
		result+='</object>';

	}
	else	{
		result+="Vybraný formát nelze přehrát.";
		result+="</div>";
		result+="<div class='clear'>";
	}
	
	result+="<div class='label'>";
	result+="<a href='"+fileName+"'>Soubor ke sta&#382;ení - formát "+format+"</a> <img src='../img/"+ico+".gif' alt='"+ext+"' class='datatype'>";
	result+="</div>";
	
	result+="</div></div>";
	return result;
} 

/**
* Org chart
*/
function chartShow( id ) {
	changeClass('chart_container_'+id,"cctext");
	changeClass('chart_link_'+id,"linka");
	return false;	
}
function chartHide( id ) {
	changeClass('chart_container_'+id,"cctextd");
	changeClass('chart_link_'+id,"link");
	return false;	
}
function chartStrShow( id ) {
	changeClass('chart_container_'+id,"cctexta");
	changeClass('chart_link_'+id,"linka");
	return false;	
}
function chartLnk( id, more ) {
	var result = "";
	result+="<div class=\"link\" id=\"chart_link_"+id+"\">";
	result+="	<span class=\"mo\"><a href=\"#\" onclick=\"return chartShow('"+id+"');\">Dal&scaron;í informace &raquo;</a></span>";
	result+="	<span class=\"le\"><a href=\"#\" onclick=\"return chartHide('"+id+"');\">&laquo; Skrýt</a>";
	if ( more!='' ) { result+="	 | <a href=\"#\" onclick=\"return chartStrShow('"+id+"');\">Zobrazit celou strukturu &raquo;</a>"; }
	result+="</span></div>";
	document.write(result);
}


