/**
 * VLOŽENÉ SOUBORY:
 * - AC_RunActiveContent.js
 * - command.js
 * - components.js
 * - flashutil.js
 * - webtoolkit.utf8.js
 */



//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;


//!!! POZOR TOTO PRIDAT PRI UPGRADE !!!!!!

function runFlash(flashId,flashFile,flashWidth,flashHeight,flashIdAlternative)
{
    document.getElementById(flashIdAlternative).style.display='none';
       
    var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		
 	if(hasRightVersion)
    {                  
      	AC_FL_RunContent(
      				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0',
      				'width', flashWidth,
      				'height', flashHeight,
      				'src', flashFile,
      				'quality', 'high',
      				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
      				'align', 'middle',
      				'play', 'true',
      				'loop', 'true',
      				'scale', 'showall',
      				'wmode', 'transparent',
      				'devicefont', 'false',
      				'id', flashId ,
      				'bgcolor', '#ffffff',
      				'name', '{flashId}',
      				'menu', 'true',
      				'allowScriptAccess','sameDomain',
      				'movie', flashFile,
      				'salign', ''
      				);		      	    
     }		
	 else 
		{		
			if (!document.getElementById(flashIdAlternative))
			{
				alert('FLASH ALTERNATIVE ERROR!');
				return;
			}
			var html = document.getElementById(flashIdAlternative).innerHTML;
			var o = html.indexOf('<!--');
			if (o < 0)
			{
				alert('FLASH ALTERNATIVE ERROR!');
				return;
			}			
			html = html.replace('<!--','').replace('-->','');			
			var el = document.getElementById(flashIdAlternative);
      		var div = document.createElement('DIV');
      		div.innerHTML = html.replace(/^\s*|\s*$/g, "");
      		el.appendChild(div);				
			document.getElementById(flashIdAlternative).style.display='block';		
    	}					
} 

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}


// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }
  
  document.write(str);
}

function AC_FL_RunContent(){
  
  var ret = 
    AC_GetArgs
    (  arguments, "" /*.swf"*/, "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblclick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}









var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 0;

$(document).ready(function() {
	CreateAndRunFlash();
});

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function onLoadParseCommand()
{
    
    var inputList = document.getElementsByTagName('input'); 
  	var hashList = new Object();
  	
  	//addLoadEvent(ChangeCSSBgImg);
  	
    for(var i=0;i<inputList.length;i++ )
    {
    
      var element = inputList[i];
    
      if(element.id == undefined)
      {
       alert("One or more imput doesn`t have id"+element.className);
       return;
      }
      
      var idstr = element.id.toString();
      
      var pattern = /(Cmd)(.+)/;
      
      var result =  idstr.match(pattern);
      
     if(result != null)
     {
        if(result[1] == "Cmd")
        {
          var resend = result[2].split('_');          
          var argument = "";
          var name = "";
          
          name =  result[2];           
          if(resend.length == 2)
          {
            argument = resend[1];
            name = resend[0];
          }
          
          if(hashList[name] == undefined)   
      		hashList[name] = element;
      	  else
      	  {
      	  	alert("Error: duplicate command :"+name);
      	  	return;
      	  }
          element.cmdargument = argument;
          element.cmdname = "Cmd"+name;                                    
          element.onclick = function()
          {           
             var valid = this.getAttribute('valid')
             var ret = true
             if (valid) ret = eval(valid)
             if (ret) sendCommand(this.cmdname, this.cmdargument);
             return false
          }
                  
        } 
     }
      
     
      
    }
    
    
    
    
}

function sendCommand(commandName , commandArgument, formContainer)
{
	if (!formContainer) formContainer = "mainForm";
    var mainForm = document.getElementById("mainForm");
    
	disableOtherFormFields(formContainer);
    
    var CommandArgumentElement = document.getElementById("CommandArgument");  
    var CommandNameElement = document.getElementById("CommandName");
    var ComponentIdElement = document.getElementById("ComponentId");

    if(commandArgument != undefined)
    	CommandArgumentElement.value = commandArgument;
    	
    CommandNameElement.value = commandName;
    ComponentIdElement.value = formContainer;
    mainForm.submit();
	return;
}

function checkemail(email)
{
	var filter=/^.+@.+\..{2,3}$/;
	if (filter.test(email)) return true
	return false
}

function sendValidateForm(click_button)
{
	// naleznem ID div, ve kterém je form zabalený
	var formId = findContainerFormId(click_button);
		
	//var inputList = document.getElementsByTagName('input');	
	//var areaList = document.getElementsByTagName('textarea');
	//var selectList = document.getElementsByTagName('select');
	
	var inputList = findInputs(formId);	
	var areaList = findTextareas(formId);
	var selectList = findSelects(formId);
	
	var sdata = new Array();
	
	var elementArray = new Array();	
	var button = null;
  	for(var i=0;i<inputList.length;i++)
  	{
        if(inputList[i].name.charAt(1) == "_")
        {
	  		if(inputList[i].type != "button") {
				elementArray.push(inputList[i]);
			}
	  		else {
				button = inputList[i];
				//alert(inputList[i].type);
			}
	  	}
	}
	if (button == null)
	{
		alert('Error')
		return; 
	}
	
	for(var i=0;i<areaList.length;i++) {
	  	if(areaList[i].name.charAt(1) == "_") {
	  		elementArray.push(areaList[i]);
	  	}
	}
	
    for(var i=0;i<selectList.length;i++) {
		if(selectList[i].name.charAt(1) == "_") {
			elementArray.push(selectList[i]);
	  	}
	}

	   		
	for(var i=0;i<elementArray.length;i++)
	{
		var name = elementArray[i].name;
		var value = elementArray[i].value.replace(/^\s*|\s*$/g, "");				
		var pole = name.split("_");
		if (elementArray[i].type == 'text')
		{
			var required = (Number(pole[2])==1) ? true : false;
			if (required)
			{
				if(value == '')
				{
					var desc = Utf8.decode(pole[1]);
					alert(command_js_txt1+desc);
					elementArray[i].focus();
					return
				}
			}
		}

		if (elementArray[i].type == 'text' && pole[3]==4)
		{
			var desc = Utf8.decode(pole[1]);		
			// číslo
			if(pole[3] == 2) {
				var is_int = true;
				var is_float = true;
				if(parseInt(value) != value) {
					is_int = false;
				}
				if(parseFloat(value) != value) {
					is_float = false;
				}
				if(!is_int || !is_float) {
					alert('Chybný formát čísla v položce: '+desc);
				   	elementArray[i].focus();
					return;
				}
			}
			// datum
			else if(pole[3] == 3) {
				var reg_date = new RegExp(/\d{1,2}\.\d{1,2}.\d{4,4}/); // info@systemia.cz
				var reg_res = reg_date.exec(value);
				if (reg_res == null) {
					alert('Chybný formát data v položce: '+desc);
				   	elementArray[i].focus();
					return;
				}
			}
			// email
			else if(pole[3] == 4) {
				if (!checkemail(value)) {
					var desc = Utf8.decode(pole[1]);
					alert(command_js_txt2+desc);
				   	elementArray[i].focus();
					return
				}
			}
			// obecné
			else { }
		}
	}

	if(confirm(command_js_txt3))
	{			
        for(var i=0;i<elementArray.length;i++)
		{
			sdata.push("p"+i+":"+elementArray[i].name);
			elementArray[i].name = "p"+i;
		}
		var psdata = document.getElementById("psdata");
 		if (!psdata)
 		{
			psdata = document.createElement("input");
        	psdata.setAttribute("name","psdata");
        	psdata.setAttribute("id","psdata");
        	psdata.setAttribute("type","hidden");
        	document.getElementById("mainForm").appendChild(psdata);
		}
		var a = ""
		for(var i=0;i<sdata.length;i++) a += "(!^#@]"+sdata[i]
		psdata.value = a
		
		sendCommand("CmdSendForm", button.name, formId);
	}			
}

function resetForm()
{
	var inputList = document.getElementsByTagName('input');	
	var areaList = document.getElementsByTagName('textarea');

  	for(var i=0;i<inputList.length;i++)
  	{
	  	if(inputList[i].name.charAt(1) == "_" && inputList[i].type == "text") inputList[i].value = ""	  
	}
	for(var i=0;i<areaList.length;i++)
	{
	  	if(areaList[i].name.charAt(1) == "_" ) areaList[i].value = ""	 
	}
}

function dweFormRadioClick(elRadio)
{
	var pole = elRadio.name.split("_");
	var group = pole[2];
	if ((!group) || (group == '')) return;
			
	var inputList = document.getElementsByTagName('input');	
  	for(var i=0;i<inputList.length;i++) {
		var name = inputList[i].name;
		if(name.charAt(1) == "_" && inputList[i].type == "radio") {
			pole = name.split("_");
			if (pole[2] == group) inputList[i].checked = false;
	  	}
	}
	elRadio.checked = true;
}
/**
 * Nalezne ID divu, ve kterém je form zabalený
 * @example
 *  ID div = "formId_36091d9c98678eeee0d7f3fe78d391ce" 
 * @param string 
 */
function findContainerFormId(source_el)
{
	try {
		var el = source_el;
		var parent = null;
		var id = '';
		do {
			parent = el.parentNode;
			if(!parent) {
				return "mainForm";
			}
			id = parent.id;
			if(!id) id = '';
			el = parent;
		} while(id.match("^formId_[a-z0-9]+$") == null);
		//alert('id divu je '+id);	
		return id;
	}
	catch(e) { return ''; }
}

function findInputs(form_id) {
	var inputs = null;
	var elements = new Array();
	fields = document.getElementsByTagName('input');
	for(var i = 0; i < fields.length; i++) {
		div_form = findContainerFormId(fields[i]);
		if(div_form == form_id) {
			elements.push(fields[i]);
		}
	}
	return elements;
}

function findTextareas(form_id) {
	var fields = null;
	var elements = new Array();
	fields = document.getElementsByTagName('textarea');
	for(var i = 0; i < fields.length; i++) {
		div_form = findContainerFormId(fields[i]);
		if(div_form == form_id) {
			elements.push(fields[i]);
		}
	}
	return elements;
}

function findSelects(form_id) {
	var fields = null;
	var elements = new Array();
	fields = document.getElementsByTagName('select');
	for(var i = 0; i < fields.length; i++) {
		div_form = findContainerFormId(fields[i]);
		if(div_form == form_id) {
			elements.push(fields[i]);
		}
	}
	return elements;
}
/**
 * Při odeslání formuláře odstraní ty pole, která jsou nežádoucí
 * @param string div|form ID
 */ 
function disableOtherFormFields(form_id) {

	if(form_id == "mainForm") {
		// odešle se všechno
		return;	
	}

	var inputs = null;
	var textareas = null;
	var selects = null;

	var div_form = null;
	// počet zrušených prvků
	var found = 0;
	var removed = 0;
	
	inputs = document.getElementsByTagName('input');
	//alert('inputs = '+inputs.length);
	found += inputs.length;
	for(var i = 0; i < inputs.length; i++) {
		div_form = findContainerFormId(inputs[i]);
		if(div_form != form_id) {
			if(inputs[i].name != "CommandName" && inputs[i].name != "CommandArgument" && inputs[i].name != "psdata" && inputs[i].name != "ComponentId") {
				removed++;
				remove_el = inputs[i];
				//remove_el.setAttribute('name',null);
				remove_el.removeAttribute('name');
			}
		}
	}
	
	textareas = document.getElementsByTagName('textarea');
	//alert('textareas = '+textareas.length);
	found += textareas.length;
	for(var i = 0; i < textareas.length; i++) {
		div_form = findContainerFormId(textareas[i]);
		if(div_form != form_id) {
			if(inputs[i].name != "CommandName" && inputs[i].name != "CommandArgument" && inputs[i].name != "psdata" && inputs[i].name != "ComponentId") {
				removed++;
				remove_el = textareas[i];
				remove_el.removeAttribute('name');
			}
		}
	}
	
	selects = document.getElementsByTagName('select');
	//alert('selects = '+selects.length);
	found += selects.length;
	for(var i = 0; i < selects.length; i++) {
		div_form = findContainerFormId(selects[i]);
		if(div_form != form_id) {
			if(inputs[i].name != "CommandName" && inputs[i].name != "CommandArgument" && inputs[i].name != "psdata" && inputs[i].name != "ComponentId") {
				removed++;
				remove_el = selects[i];
				remove_el.removeAttribute('name');
			}
		}
	}
	//alert('found = '+found+', removed = '+removed);
}
















function switchOffFlash(off) {
	var objectarray = document.getElementsByTagName("object");
	if(objectarray) {
		for(var i in objectarray) {
			//alert(objectarray[i].style);
			if(objectarray[i].style) {
				if(objectarray[i].style.visibility) {
					if(objectarray[i].style.visibility != null) {
						objectarray[i].style.visibility = (off) ? "hidden" : "";
					}
				}
			}
		}
	}
}
/**
 * MainMenu
 */
var tm1=0

function hideShow(id,key)
{
    var element = document.getElementById(id);
if(element != null)
    if(element.className=="makeMenu")
    {
      element.style.display=key;
    }

}

function doMenu(id)
{
    for(var i=1;i != menu_count+1;i++)
    {
        var nameid = "m"+i;
        var key = 'none';
        
        if(nameid==id){
		key='block';        
        hideShow(nameid,key);
        document.getElementById("acko"+i).style.textDecoration='none'; 		// styl pri otevrenem menu
        }
        else {
		document.getElementById("acko"+i).style.textDecoration='none';		// styl pri zavrenem menu
		key='none';
		hideShow(nameid,key);
		}
    }
    if (id != '') cancelOut()    	
}

function cancelOut()
{
	if (tm1 != 0)
	{
		clearTimeout(tm1)
		tm1 = 0
	}
}

function hidemenu()
{
	doMenu('')
} 

function mhide()
{
	cancelOut()
	tm1 =setTimeout("hidemenu()",334);
}

/**
 * Search
 */
function searchKeyEnter(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
   		sendCommand("CmdSearch");
   		return false;
    }
	else
   		return true;
}
/**
 * SearchResult
 */
function searchKeyEnterFromResult(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
   		sendCommand("CmdSearchAgain");
   		return false;
    }
	else
   		return true;
}

/**
 * Login
 */
// odchytavani klavesy ENTER (13) v polích login a password
function loginKeyEnter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13 )
    {
   
   		sendCommand('CmdLogin',null);
   		return false;
    }
	else
   		return true;
}
/**
 * Objekt pro kontrolu hodnot.
 * Každá funkce vrací true nebo false 
 */ 
var Validate = {
	/**
	 *	Kontrolu emailu
	 *	@param  string
	 *	@return boolean
	 */ 	 	
	email : function( value ) {
		//var regexp = new RegExp(/([.a-z0-9_-]{3,251}\@[.a-z0-9_-]{3,251})/i);
		var regexp = new RegExp(/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i);
		return regexp.test(value);
	},
	/**
	 *	Kontrolu PSČ (190000 nebo 190 00)
	 *	@param  string
	 *	@return boolean
	 */
	zipcode : function( value ) {
		var regexp = new RegExp(/^(^[0-9]{5,5}$)|(^[0-9]{3,3}\s{1,1}[0-9]{2,2}$)$/);
		return regexp.test(value);
	},
	/**
	 * Kontrola telefonního čísla
	 *	@param  string
	 *	@param  boolean Jestli je požadována mezinárodní předvolba	 
	 *	@return boolean
	 */
	phone : function( value, internation_required ) {
		//var regexp = new RegExp(/^([+]{0,1}[0-9]{3,3})?([0-9]{9,9})$/);
		if(typeof internation_required == 'undefined') var internation_required = false;
		// musí obsahovat mezinárodní předvolbu
		if(internation_required) {
			var regexp = new RegExp(/^([+]{1,1}[0-9]{3,3}[0-9]{9,9})$/);
		// může obsahovat mezinárodní předvolbu
		} else {
			var regexp = new RegExp(/^([+]{0,1}[0-9]{3,3})?([0-9]{9,9})$/);
		}
		return regexp.test(value);
	},
	/**
	 * Kontrola celého čísla
	 *  @param  mixed
	 *  @param  boolean
	 *	@return boolean
	 */
	intValue : function( value, correct ) {
		if(typeof correct == 'undefined') var correct = false;
		var newVal = parseInt(value);
		if(!correct) {
			return newVal == value;
		}
		var newVal = '';
		for(var i = 0; i < value.length; i++) {
			var letter = value.slice(i,i+1);
			var number = parseInt(letter);
			if(!isNaN(number)) {
				newVal += letter;
			}
		}
		if(newVal == '') newVal = '1';
		if(newVal == '0') newVal = '1';
		return newVal;
	},
	/**
	 * Kontrola desetinného čísla
	 *  @param  mixed
	 *  @param  boolean
	 *	@return boolean
	 */	 
	floatValue : function( value, correct ) {
		if(typeof correct == 'undefined') var correct = false;
		var pvalue = parseFloat(value);
		if(isNaN(pvalue)) {
			return false;
		}
		if(pvalue.toString() != value.toString()) {
			return false;
		}
		return true;
	}
}

/**
 * Objekt pro vypisování chyb ve formuláři
 */ 
var FormAlert = {
	c : 0,
	/**
	 * Přidání zprávy
	 * @param  string
	 * @param  string
	 * @return false 
	 */	 	 	 	
	add : function( id, text ) {
		if($("#form_alerts").has("li#form_each_alert_"+id).length == 0) {
			FormAlert.c++;
			if($("#form_alerts").has("ul").length > 0) {
				$("#form_alerts ul").append('<li id="form_each_alert_'+id+'" style="display: none">'+text+'</li>');
			}
			else {
				$("#form_alerts").append('<ul><li id="form_each_alert_'+id+'" style="display: none">'+text+'</li></ul>');
			}
			$("#form_each_alert_"+id).slideDown(200);
		}
		return false;
	},
	/**
	 * Odstranění zprávy
	 * @param  string
	 * @param  string
	 * @return true	 
	 */	 	 	 	
	remove : function( id ) {
		if($("#form_alerts ul").has("li#form_each_alert_"+id).length > 0) {
			FormAlert.c--;
			$("#form_alerts ul li#form_each_alert_"+id).slideUp(200,function(){
				$(this).remove();
				if(FormAlert.c == 0) {
					$("#form_alerts ul").remove();
				}
			});
		}
		else {
			if(FormAlert.c == 0) {
				$("#form_alerts ul").remove();
			}
		}
		return true;
	},
	/**
	 * Vrácení počtu zobrazených chyb
	 * @return boolean
	 */
	count : function() {
		try {
			// nelze použít kvůli slideDown a slideUp
			// return $("#form_alerts ul").children("li").length;
			if(FormAlert.c < 0) FormAlert.c = 0; 
			return FormAlert.c;
		} catch(e) {
			return 0;
		}
	},
	/**
	 * Zvýraznění chybových hlášek
	 */	 	
	highlight : function(color) {
		var bgcolor1 = $("#form_alerts").css("backgroundColor");
		var bgcolor2 = (typeof color == 'undefined') ? "#FFB87F" : color;
		$("#form_alerts").toggle(function() {
		    $(this).animate({ backgroundColor: "#FFFFFF" }, 1000);
		},function() {
		    $(this).animate({ backgroundColor: "#FFB87F" }, 500);
		});
	}
}

// Inicializace funkcí na formulářové prvky.
$(document).ready(function() {	
	try {
		$("#address1 label.boxtitle").click(function(){
			$("#address1_container").slideToggle(300);
		});
		$("#address2 label.boxtitle").click(function(){
			$("#address2_container").slideToggle(300);
		});
	}
	catch(e) {
		try {
			$("#address1_container").show();
			$("#address2_container").show();
		}
		catch(e) { }
	}
});














var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; 
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; 
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false; 
jsVersion = 1.1; 

function JSGetSwfVer(i){ 
 // NS/Opera version >= 3 check for Flash plugin in plugin array 
 if (navigator.plugins != null && navigator.plugins.length > 0) 
 { 
   if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) 
     { 
       var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; 
       var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; 
       descArray = flashDescription.split(" "); 
       tempArrayMajor = descArray[2].split("."); 
       versionMajor = tempArrayMajor[0]; 
       versionMinor = tempArrayMajor[1]; 
       if ( descArray[3] != "" ) 
       { 
          tempArrayMinor = descArray[3].split("r"); 
        } 
        else 
        { 
          tempArrayMinor = descArray[4].split("r"); 
        } 
        versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0; 
        flashVer = versionMajor + "." + versionMinor + "." + versionRevision; 
     } 
     else 
     { 
      flashVer = -1; 
     } 
 } 
 // MSN/WebTV 2.6 supports Flash 4 
 else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4; 
 // WebTV 2.5 supports Flash 3 
 else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3; 
 // older WebTV supports Flash 2 
 else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2; 
 // Can&apos;t detect in all other cases 
 else { 

  flashVer = -1; 
 } 
 return flashVer; 
}  
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)  
{ 
 reqVer = parseFloat(reqMajorVer + "." + reqRevision); 
 // loop backwards through the versions until we find the newest version 
 for (i=25;i>0;i--) 
 {  
    if (isIE && isWin && !isOpera) 
    { 
      versionStr = VBGetSwfVer(i); 
    } 
    else 
    { 
      versionStr = JSGetSwfVer(i);  
    }
     
    if (versionStr == -1 ) 
    {  
      return false; 
    } 
    else if (versionStr != 0) 
    { 
      if(isIE && isWin && !isOpera) 
      { 
        tempArray = versionStr.split(" "); 
         tempString = tempArray[1]; 
         versionArray = tempString .split(",");  
      } 
      else 
      { 
        versionArray = versionStr.split("."); 
      } 
         versionMajor = versionArray[0]; 
         versionMinor = versionArray[1]; 
         versionRevision = versionArray[2]; 
  
      versionString = versionMajor + "." + versionRevision; // 7.0r24 == 7.24 
      versionNum = parseFloat(versionString); 
   // is the major.revision >= requested major.revision AND the minor version >= requested minor 
        if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) 
        { 
          return true; 
        } 
        else 
        { 
          return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );  
        } 
   } 
 }  
  return (reqVer ? false : 0.0); 
} 



function CreateFlashObject(DivID, URL,WIDTH, HEIGHT,alternatediv,wmode)
{
  var isvalidVersion = DetectFlashVer(requiredMajorVersion,requiredMinorVersion,requiredRevision);
   
  if(isvalidVersion)
  {

    var outer=
    '<!--[if !IE]> --><object type="application/x-shockwave-flash" data="'+URL+'" width="'+WIDTH+'" height="'+HEIGHT+'"><!-- <![endif]-->'+
    '              		<!--[if IE]>'+
                  		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+
                  		  'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+WIDTH+'" height="'+HEIGHT+'">'+
                  		  '<param name="movie" value="'+URL+'" />'+
                  		'<!--><!---->'+
                  		  '<param name="loop" value="true" />'+
                  		  '<param name="menu" value="false" />'+                  		  
                  		  '<param name="wmode" value="'+wmode+'" />'+
                  		  
                		'</object>';
    var fl = document.getElementById(DivID);
     
     if(fl != null)
     {
     
    	fl.innerHTML = outer;
    }
  //vymaze alternative html content
    if(alternatediv != undefined)
    {
    
       var altern = document.getElementById(alternatediv);
       if(altern != undefined)
        altern.parentNode.removeChild(altern);
    }           		
                		
  }
  else
  {
    if(alternatediv != undefined)
    {
		var el = document.getElementById(alternatediv);
		if (el)
		{
			el.style.visibility = 'visible';
		} 
       var fl = document.getElementById(DivID);  
       if(fl != undefined)
       fl.parentNode.removeChild(fl);           
    }   
  }
  
  
  
}

function CreateAndRunFlash()
{
 	
  for(var i=0 ;i< window.FlashObjectsList.length; i++ )
  {
   	 
      var flashElementId = window.FlashObjectsList[i].flashElementId;
      var swfUrl   = window.FlashObjectsList[i].swfUrl;
      var width   = window.FlashObjectsList[i].width;
      var height   = window.FlashObjectsList[i].height;
      var alternativeElementId   = window.FlashObjectsList[i].alternativeElementId;
      var wmode   = window.FlashObjectsList[i].wmode;
     
      CreateFlashObject(
        flashElementId,
        swfUrl,
        width,
        height,
        alternativeElementId,
        wmode
      );
   
    
  }

}




/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/
var Utf8 = {

	// public method for url encoding
	encode : function (string) {
	
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		var ser = "";
		for (var n = 0; n < string.length; n++) 
		{
			var c = string.charCodeAt(n);
			ser += c + "a";	
		}

		return ser;
	},

	// public method for url decoding
	decode : function (utftext) {

		var pole  = utftext.split("a");
		var utftext = "";
		for(var i=0;i<pole.length;i++)
		{
			var charcode = Number(pole[i]); 
			utftext += String.fromCharCode(charcode);
		}
		return utftext;


	}

}

/**
 * Načítání obsahu do stránky
 */
var AjaxContent = {
	/**
	 * jQuery objekt umístění obsahu
	 * @var object jQuery
	 */
	contentContainer : null,
	/**
	 * Odkaz (bez domény) na požadovanou stránky
	 * @var string
	 */
	contentLocation : "",
	/**
	 * Zda-li se právě načítá obsah
	 * @var boolean
	 */
	contentLoading : false,
	/**
	 * Požadované pozadí stránky
	 */
	loadedIndex : 0,
	/**
	 * Adresy směřující na homepage
	 * '/cz/homepage.html','/cz/ooh.html','/cz/instore.html','/cz/kreativita-a-produkce.html','/cz/reference.html'
	 * @var array
	 */
	homepageUrls : ['/cz/homepage.html'],
	/**
	 * Inicializace
	 */
	init : function() {
		AjaxContent.contentContainer = $("#Content");
		AjaxContent.Links.root = window.location.protocol + "//" + window.location.hostname;
		AjaxContent.checkCurrentUrl(true);
		if(AjaxContent.contentContainer.length == 1) {
			AjaxContent.Links.findAll();
		}
		
		$(window).hashchange( function(){
			if(AjaxContent.getContentLocation() != "" && AjaxContent.getContentLocation() != "#" && AjaxContent.getContentLocation() != null) {
				//AjaxContent.setContentLocation(window.location.hash);
				try {
					if(window.location.hash.length > 2) {
						AjaxContent.setContentLocation(window.location.hash.substr(1));
					}
					// redirect
					if(!AjaxContent.checkCurrentUrl(true)) {
						window.location.href = "/";
					}
				}
				catch(e) { alert('hashchange() '+e) }
				/*
				else {
					AjaxContent.onLinkClick();
				}
				*/
			}
		});
	},
	setContentLocation : function(link) {
		AjaxContent.contentLocation = link;
		window.location.hash = "#"+AjaxContent.contentLocation;
	},
	getContentLocation : function() {
		return AjaxContent.contentLocation;
	},
	/**
	 * Zobrazení uvítacího dialogu
	 */
	showWelcomeDialog : function() {
		var cookies = document.cookie.split('; ');
		var show = true;
		for(var i in cookies) {
			var parts = cookies[i].split('=');
			if(parts[0] == "WelcomeDialog") {
				if(parts[1] == "true") {
					show = false;
				}
			}
		}
		if(show) {
			$.post("/cz/vyskakovaci-clanek-1404041530.html", { load_only_content : true, wait : 0 }, function(data) {
				//alert(data);
				//alert(data.trim().length);
				if(data.trim().length > 0) {
					document.cookie="WelcomeDialog=true;";
					Dialog.open(data,'');
				}
			});
		}
	},
	searchBox : function(searchString) {
		AjaxContent.setContentLocation("/vyhledavani/?q="+searchString);
		window.location.hash = "#/vyhledavani/?q="+searchString;
		//AjaxContent.onLinkClick();
	},
	/**
	 * Kontrola adresy při načtení stránky
	 */
	checkCurrentUrl : function(open) {
		if(typeof open == "undefined") var open = false;
		var hash = window.location.hash;
		//alert(hash+' - '+open);

		if(hash.length > 2) {
			//if(typeof url == "undefined") url = AjaxContent.homepageUrls[0];
			var url = hash.substr(1);
			for(var i = 0; i < AjaxContent.homepageUrls.length; i++) {
				if(AjaxContent.homepageUrls[i] == url) {
					AjaxContent.showWelcomeDialog();
					return false;
				}
			}
			if(open) {
				AjaxContent.openPage(url, true);
			}
		}
		return true;
	},
	/**
	 * Zpracování odkazů
	 */
	Links : {
		root : "",
		/**
		 * Vyhledání všech odkazů na stránce
		 */
		findAll : function() {
			$("a").each(function(index,el){
				if(!$(el).hasClass("hp")) {
					AjaxContent.Links.linkToHash(el);
				}
			});
		},
		/**
		 * Vyhledání všech odkazů v objektu (jQuery selectoru)
		 * @var object|string
		 */
		findInside : function(selector) {
			$(selector).find("a").each(function(index,el){
				AjaxContent.Links.linkToHash(el);
			});
		},
		/**
		 * Upraví klasický odkaz na odkaz s kotvou
		 * @var object jQuery selector
		 */
		linkToHash : function(el) {
			try {
				var href = $(el).attr("href");
				if(typeof href == "undefined") return;
				var link = href.replace(this.root,'');
				var isInternalLinkPattern = new RegExp(this.root);
				var isInternalLink = isInternalLinkPattern.test(href);
				var isRes = /^\/res/.test(link);
				var isDownload = /download/.test(link);
				//console.log(el.href+": isInternalLink = "+isInternalLink+", isRes = "+isRes+", isDownload = "+isDownload+", link = "+link);
				if(isInternalLink && link != "/" && !isRes && !isDownload) {
					$(el).click(function(e){
						var link = href.replace(/(http:\/\/[^/]+)/i,'');
						var link2 = window.location.href.replace(AjaxContent.Links.root,"");
						var isMenulink = $(el).hasClass("menulink");
						
						e.preventDefault();
						if(link.substr(0,2) != "/#" && link2.substr(0,2) != "/#") {
							window.location.href = AjaxContent.Links.root + "/#"+ link;
						}
						else {
							//window.location.hash = "#"+link;
							AjaxContent.setContentLocation(link);
							//AjaxContent.onLinkClick();
						}
						if(isMenulink) {
							menu0.hideAll();
						}
					});
				}
			}
			catch(e) { }
		}
	},
	/**
	 * Kliknutí na odkaz
	 */
	onLinkClick : function() {
		PanesEffect.clickCount++;
		AjaxContent.contentContainer.removeClass("hp");
		if(AjaxContent.contentLoading == false) {
			AjaxContent.contentContainer.removeData("jsp");
			AjaxContent.contentContainer.fadeOut(200, function(){
				AjaxContent.contentContainer.html('<div class="loading"></div>').show();
				AjaxContent.loadingBegin();
				AjaxContent.getBackground();
			});
			//AjaxContent.getContent();
		}
	},
	/**
	 * Otevření stránky
	 * @var string
	 */
	openPage : function(url, force) {
		if(typeof force == "undefined") var force = false;
		AjaxContent.contentLocation = url;
		if(force) {
			AjaxContent.onLinkClick();
		}
	},
	/**
	 * Otevření stránky voláním
	 * @var string
	 * @var object
	 */
	openCustomLink : function(url, el) {
		//window.location.hash = "#"+url;
		AjaxContent.setContentLocation(url);
		//AjaxContent.checkCurrentUrl(true);
	},
	/**
	 * Získat typ pozadí
	 */
	getBackground : function() {
		if(!BackgroundSlide.animate) {
			AjaxContent.backgroundComplete(0);
		}
		else {
			try {
			$.post(AjaxContent.contentLocation, { load_only_background : true, wait : 0 }, function(data) {
				AjaxContent.backgroundComplete(data);
			});
			} catch(e) { }
		}
	},
	/**
	 * Pozadí bylo získáno
	 * @var integer
	 */
	backgroundComplete : function(data) {
		try {
			var lastIndex = AjaxContent.loadedIndex;
			var index = parseInt(data);
			if(!isNaN(index)) {
				AjaxContent.loadedIndex = index;
			}
		}
		catch(e) {
			
		}
		finally {
			if(!BackgroundSlide.animate) {
				BackgroundSlide.move(AjaxContent.loadedIndex);
			}
			else {
				AjaxContent.contentContainer.fadeOut(300, function(){
					BackgroundSlide.move(AjaxContent.loadedIndex);
				});
			}
		}
	},
	/**
	 * Získat obsah
	 */
	getContent : function() {
		try {
			$.post(AjaxContent.contentLocation, { load_only_content : true, wait : 0 }, function(data) {
				AjaxContent.contentComplete(data);
			});
		} catch(e) { AjaxContent.contentComplete('<h1 style="color: red">Při načítání stránky nastala chyba</h1><br /><p>'+e+'</p>'); }
	},
	/**
	 * Start získávání obsahu stránky
	 */
	loadingBegin : function() {
		AjaxContent.contentLoading = true; 
		//AjaxContent.contentContainer.html('<div class="loading"></div>');
	},
	/**
	 * Stránka načtena
	 */
	loadingFinish : function() {
		AjaxContent.contentLoading = false;
	},
	/**
	 * Obsah načten
	 * @var string
	 */
	contentComplete : function(data) {
		//alert(data);
		AjaxContent.loadingFinish();
		if(!BackgroundSlide.animate) {
			AjaxContent.contentContainer.fadeOut(300, function(){
				AjaxContent.contentContainer.css("overflow-y","hidden");
				AjaxContent.contentContainer.html(data).fadeIn(300,function(){
					AjaxContent.Links.findInside(AjaxContent.contentContainer);
					Inicialize.slimbox(AjaxContent.contentContainer);
					//Inicialize.scrollbar(AjaxContent.contentContainer);
					setTimeout("AjaxContent.contentPostRender()",500);
					//Inicialize.contentFlow(AjaxContent.contentContainer);
				});
			});
		}
		else {
			AjaxContent.contentContainer.css("overflow-y","hidden")
			AjaxContent.contentContainer.html(data).fadeIn(300,function(){
				AjaxContent.Links.findInside(AjaxContent.contentContainer);
				Inicialize.slimbox(AjaxContent.contentContainer);
				//Inicialize.scrollbar(AjaxContent.contentContainer);
				setTimeout("AjaxContent.contentPostRender()",500);
				//Inicialize.contentFlow(AjaxContent.contentContainer);
			});
		}
		//BackgroundSlide.move(this.loadedIndex);
	},
	
	contentPostRender : function() {
		if(Inicialize.contentFlow(AjaxContent.contentContainer)) {
			var detail = $("#detail", AjaxContent.contentContainer);
			if(detail.length == 1) {
				detail.height(detail.height() + 300);
			}
		}
		if(!/1404041551/.test(AjaxContent.contentLocation)) {
			Inicialize.scrollbar(AjaxContent.contentContainer);
		}
	}
}
/**
 * Posouvání článků v záložkách
 */
var PanesEffect = {
	/**
	 * Pole ID článků
	 * @var array
	 */
	artIds : [],
	/**
	 * Počáteční index
	 */
	initialIndex : 2,
	/**
	 * Počet kliknutí
	 * @var integer
	 */
	clickCount : 0,
	/**
	 * jQuery objekt záložek
	 * @var object jQuery
	 */
	tabsObject : null,
	/**
	 * Inicializace
	 */
	init : function() {
		try {
		var body = $("body");
		if(body.length == 1) {
			BackgroundSlide.bgHolder = body;
		}
		var form = $("mainForm");
		PanesEffect.tabsObject = $("#content-panes div.menu ul");
		BackgroundSlide.windowWidth = $(document).width();
		if(window.location.hash == "") {
			var li = $("#content-panes div.menu ul").find("li").get( PanesEffect.initialIndex );
			var link = $(li).find("a").get(0);
			//window.location.hash = "#"+$(link).attr("href");
			window.location.hash = AjaxContent.homepageUrls[0];
		}
		//PanesEffect.initTabs();
		// handler na změnu šířky okna
		$(window).resize(function() {
			BackgroundSlide.resizeHandler();
		});
		}
		catch(e) { alert('init() '+e); }
	},
	/**
	 * Inicializace záložek
	 */
	initTabs : function() {
		try {
		$.tools.tabs.addEffect("switchPane",function(tabIndex, callback) { PanesEffect.switchPane(this, tabIndex, callback); });
		PanesEffect.tabsObject.tabs("#content-panes div.paneList > div", {
			history : false,
			initialIndex : PanesEffect.initialIndex,
			effect : 'switchPane',
			fadeInSpeed : 1500,
			fadeOutSpeed : 0,
			onBeforeClick : function(event, tabIndex) {
				PanesEffect.click(tabIndex, event);
			}
		});
		}
		catch(e) { /*alert('initTabs() '+e);*/ }
	},
	/**
	 * Kliknutí na záložku
	 * @var integer
	 * @var object Event
	 */
	click : function(index,event) {
		try {
		this.clickCount++;
		BackgroundSlide.move(index,this.clickCount);
		}
		catch(e) { alert('click() '+e); }
		/*
		var lastIndex = BackgroundSlide.index;
		this.setIndex(index);
		BackgroundSlide.index = index;
		BackgroundSlide.move(index);
		var widthDiff = (BackgroundSlide.windowWidth - BackgroundSlide.slideWidth) / 2;
		BackgroundSlide.position = (BackgroundSlide.index * BackgroundSlide.slideWidth) - widthDiff;
		if(this.clickCount > 1) {
			BackgroundSlide.bgHolder.animate({
				'backgroundPosition' : '-'+BackgroundSlide.position+'px 0px'
			},1500);
		}
		else {
			BackgroundSlide.bgHolder.css("backgroundPosition", "-"+BackgroundSlide.position+"px 0px");
		}
		*/
		return true;
	},
	/**
	 * Externí inicializace záložky
	 * @var integer Index záložky (2 = homepage)
	 */
	clickFlash : function(index) {
		try {
		PanesEffect.tabsObject.data("tabs").click(index);
		}
		catch(e) { alert(e) }
	},
	/**
	 * Prohození panelů
	 * @var object jQuery tabs
	 * @var integer
	 * @var object Callback
	 */
	switchPane : function(tabs, tabIndex, callback) {
		try {
		//alert(tabs.getIndex()+" vs "+tabIndex);
		//alert(this.clickCount);
		if(this.clickCount > 0) {
			tabs.getPanes().hide();
			tabs.getPanes().eq(tabIndex).fadeIn(800);
			callback.call();
		}
		}
		catch(e) { alert(e); }
	}
	
}
/**
 * Posouvání pozadí
 */
var BackgroundSlide = {
	/**
	 * Index pozadí (0-4)
	 * @var integer
	 */
	index : -1,
	/**
	 * Pozice v pixelech
	 * @var integer
	 */
	position : 0,
	/**
	 * Šířka jednoho pozadí v pixelech
	 * @va integer
	 */
	slideWidth : 1754,
	/**
	 * Šířka pozadí
	 * @var integer
	 */
	windowWidth : 0,
	/**
	 * jQuery objekt s pozadím (body)
	 * @var object jQuery
	 */
	bgHolder : null,
	/**
	 * Animování pozadí
	 * @var boolean
	 */
	animate : false,
	/**
	 * Posunutí pozadí na pozici index
	 * @var integer
	 * @var integer Počet kliknutí (využito jen na HP)
	 */
	move : function(index, clickCount) {
		if(typeof clickCount == "undefined") clickCount = PanesEffect.clickCount;
		var lastIndex = BackgroundSlide.index;
		if(lastIndex == index) {
			BackgroundSlide.positionAchieved();
			return false;
		}
		BackgroundSlide.index = index;
		var widthDiff = (BackgroundSlide.windowWidth - BackgroundSlide.slideWidth) / 2;
		BackgroundSlide.position = (BackgroundSlide.index * BackgroundSlide.slideWidth) - widthDiff;
		if(clickCount > 1) {
			BackgroundSlide.bgHolder.animate({
				'backgroundPosition' : '-'+BackgroundSlide.position+'px 0px'
			},1500,function(){
				BackgroundSlide.positionAchieved();
			});
		}
		else {
			BackgroundSlide.bgHolder.css("backgroundPosition", "-"+BackgroundSlide.position+"px 0px");
			BackgroundSlide.positionAchieved();
		}
		return true;
	},
	/**
	 * Korekce změn velikosti okna
	 */
	resizeHandler : function() {
		var lastWidth = BackgroundSlide.windowWidth;
		BackgroundSlide.windowWidth = $(document).width();
		//document.title = "Window width = "+BackgroundSlide.windowWidth+"px";
		var diff = (lastWidth - BackgroundSlide.windowWidth);
		//document.title = "Window diff = "+diff+"px";
		var width = 0;
		if(diff < 0) {
			width = BackgroundSlide.position;
		}
		else {
			width = BackgroundSlide.position + (diff / 2);
		}
		//document.title = "Window width = "+BackgroundSlide.windowWidth+"px";
		//document.title = "Window diff = "+diff+"px | Window width = "+width+"px | Window old = "+BackgroundSlide.backgroundPosition+"px";
		BackgroundSlide.bgHolder.css('backgroundPosition', '-'+width+'px 0px');
	},
	/**
	 * Funkce volaná po dosažení pozice pozadí
	 */
	positionAchieved : function() {
		if(AjaxContent.contentLoading) {
			AjaxContent.getContent();
		}
	}
}
/**
 * Inicializace
 */
var Inicialize = {
	
	lightbox : function() {
		this.slimbox();
	},
	
	slimbox : function(selector) {
		if(typeof selector == "undefined") {
			var jQ = $("a[rel^='lightbox']");
		}
		else {
			var jQ = $(selector).find("a[rel^='lightbox']");
		}
		jQ.slimbox({/* Put custom options here */}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
	},
	
	scrollbar : function(selector) {
		try {
			$(selector).jScrollPane( {showArrows:true, contentWidth: 660, verticalDragMaxHeight: 32, mouseWheelSpeed : 70});
			/*
			var api = selector.data("jsp");
			if(api == null) {
				$(selector).jScrollPane( {showArrows:true, contentWidth: 660});
			}
			else {
				$(selector).removeData("jsp");
				$(selector).jScrollPane();
			}
			*/
		}
		catch(e) { alert(e) }
	},

	contentFlow : function(selector) {
		if($(selector).find("#contentFlow").length == 1) {
			try {
				var myNewFlow = new ContentFlow('contentFlow', {width: '300px', height: '600px'});
				myNewFlow.init();
				return true;
				//ContentFlowGlobal.init();
			}
			catch(e) { alert(e) }
		}
		return false;
	}
}
/**
 * Dialogové okno pro frontend.
 * Statická třída.
 * 
 * @example
 *   Dialog.open('obsah dialog','Nadpis dialogu',objekt, callback);
 */
var Dialog = {
	speed_open_bg : 0,
	speed_open_win : 0,
	speed_close_bg : 200,
	speed_close_win : 200,
	/**
	 * Otevření dialogu
	 * @param  string Obsah
	 * @param  string Nadpis
	 * @param  objekt Objekt, kde se kliklo
	 * @param  objekt Callback
	 * @return objekt this
	 */
	open : function(content, header, e, callback) {
		if(typeof header == 'undefined') var header = 'Dialog'; 
		var id = Math.ceil(Math.random()*100000);
		var html = '';
		html += '<div class="dialog_bg" style="height: '+$("body").outerHeight()+'px; width: '+$("body").outerWidth()+'px" id="dialog_bg_'+id+'"></div>';
		html += '<div class="dialog_window" style="display: none" id="dialog_window_'+id+'">';
		html += ' <div class="close" onclick="Dialog.close('+id+');"></div>';
		html += ' <div class="container">';
		html += '  <div class="header">';
		html += '  '+header;
		html += '  </div>';
		html += '  <div class="content">';
		html += '  '+content;
		html += '  </div>';
		html += ' </div>';
		html += '</div>';
		/* vložíme pozadí, ale okno zůstane zatím skryté */
		$("#dialogs").html( html );
		/*
		var window_width = $("#dialogs div.dialog_window").outerWidth();
		var body_width = $("body").outerWidth();
		var percent_body_width = parseInt($("body").outerWidth() / 100);
		var left = (50 * percent_body_width) - parseInt(window_width / 2);
		/* position absolute pouze pro IE6 a starší */
		var position = ($.browser.msie) ? ((parseFloat($.browser.version) > 7) ? "absolute" : "fixed") : "fixed";
		/*
		var top = (position == "fixed") ? "20%" : "40%";
		$("#dialogs div.dialog_window").css( { 'left' : (left / percent_body_width)+'%', 'position' : position, 'top' : top } ).show();
		*/
		$("#dialogs div.dialog_window").css( {'position' : position} ).show();
		return this;
	},
	/**
	 * Zavření dialogu
	 * @param  mixed Objekt nebo ID
	 * @param  objekt Callback
	 * @return boolean
	 */
	close : function(param,callback) {
		if(typeof callback == 'undefined') {
			var callback = null;
		}
		if(typeof param == 'undefined') { 
			this._close(null,callback);
		}
		else if(typeof param == 'object') {
			var w = $(param).parents("div[id^='dialog_window_']");
			//var w = $(param).parent();
			if(w.length == 1) {
				this._close($(w).attr("id"),callback);
			}
			else {
				this._close(null,callback);
			}
		}
		else {
			this._close(param,callback);
		}
	},
	_close : function(id,callback) {
		// pokud není předán parametr, zavřeme vše
		if(typeof id == 'undefined' || id == null) {
			$("#dialogs").html('');
			CallBack.call( callback );
			return true;
		}
		else {
			// zkusíme získat ID dialogu
			try {
				id = parseInt(id);
			}
			// pokud selže, zavřeme vše
			catch(e) {
				return this._close(null,callback);
			}
			// výsledek není platné číslo, zavřeme vše
			if(isNaN(id)) {
				return this._close(null,callback);
			}
			// zavřeme dialog s pozadím (předpokládáme, že jsou obě ID shodná....proč by nebyla?)
			try {
				$("#dialog_window_"+id).fadeOut(200,function(){
					$("#dialog_bg_"+id).fadeOut(200,function(){
						CallBack.call( callback );
					});
				});
			}
			catch(e) {
				return this._close(null,callback);
			}
			return true;
		}
	}
}
/**
 * Volání callbacku.
 * Statická třída.
 * 
 * @example
 *   var source = { callback : 'MojeFunkce', params : [1,true,'hodnotaX','hodnotaY'] }
 *   Callback.call( source );
 */
var CallBack = {
	/**
	 * Volání samotného callbacku s parametry
	 * @param  mixed
	 * @return boolean
	 */
	call : function( source ) {
		if(typeof source == "object") {
			try {
				/* Vytvoříme objekt pro volání */
				var cb = CallBack._callback;
				/* Nastavíme funkci */
				cb._setFunction( source.callback );
				/* Připravíme parametry */
				var params = [];
				try {
					for(var i = 0; i < source.params.length; i++) {
						var p = source.params[i];
						if(typeof p == "string") {
							params.push("'"+p+"'");
						}
						if(typeof p == "boolean" || typeof p == "number" || typeof p == "boolean") {
							params.push(p.toString());
						}
					}
					/* Nastavíme parametry */
					cb._setParams( params.join(",") );
				}
				catch(e) { }
				/* Zavoláme výsledek */
				cb._call();
			}
			catch(e) {
				return false;
			}
			return true;
		}
	},
	/**
	 * Privátní objekt volaná uvnitř objektu Callback.
	 */
	_callback : {
		/**
		 * Název funkce
		 * @var function
		 */
		_fnc : null,
		/**
		 * Parametry funkce
		 * @var array
		 */
		_params : new Array(),
		/**
		 * Volání objektu.
		 */
		_call : function() {
			try {
				eval(this._fnc+"("+this._params+");");
			}
			catch(e) { }
		},
		/**
		 * Nastavení funkcí
		 * @param string Funkce
		 */ 
		_setFunction : function( fnc ) {
			try {
				this._fnc = fnc.toString();
			}
			catch(e) { }
		},
		/**
		 * Nastvení parametrů funkce
		 * @param string Parametry v jednom řetězci
		 */
		_setParams : function( params ) {
			try {
				this._params = params.toString();
			}
			catch(e) { }
		}
	}
}


