var cGUI = function() {

	this.init = function(result) {
		if (!result) result = 'yes';
		this.container = '';
		this.loaded = '';
		this.queueing = false;
		this.autocomplete();
		this.locatorInit();
		$.historyInit(pageload);
		if (result == 'no') {
			this.locatorForm('no');
		} else if (typeof GUI.loaded == 'undefined' || result != 'no') {
			this.locatorForm();
		} else {
			this.locatorForm('no');
		}
		this.searchForm();
		this.processHeader();
		this.postLoad();
//		alert(typeof GUI.loaded);
		this.resultPager();
		this.version = getInternetExplorerVersion();
		this.clicked_on="";

	};

	this.resultPager = function(){
		$('.result_pager a').unbind('click');
		$('.result_pager a').bind('click', function(){
			$('#numResults .loading').show();
			url = $(this).attr('href');
			GUI.load(url, null, null, 'GUI.resultPager();GUI.parseResults();GUI.resultInit();$("#numResults .loading").hide();');
			return false;
		});
	};

	this.sortSubmit = function(){
		target = 'content_box';
		$('#' + target).css({position: 'relative'});
		$('#' + target).append('<div class="loadingContent" style="position: absolute; top: 0px; left: 0px; background: #fff; width: ' + $('#' + target).width() + 'px; height: ' + $('#' + target).height() + 'px;"></div>');
		$('.loadingContent').css({opacity: 0.1, cursor: 'wait', zIndex: 1000});
		$('#numResults .loading').show();
		$('.result_sort form').ajaxSubmit({
			success:       GUI.sortResponse
		});
	};

	this.sortResponse = function(data){
		$('#content_box').html($(data).find('#content_box').html());
		$('#numResults .loading').hide();
		GUI.postLoad();
		GUI.resultPager();
		GUI.parseResults();
		GUI.resultInit();
	};

	this.autocomplete = function() {
		$('#search_input').autocomplete({
			url: $('#search_input').parent().attr('action') + '?cloud',
			minChars: 3,
			max: 10,
			autoFill: false,
			selectFirst: false,
			matchContains: true,
			scrollHeight: 330,
			scroll: false,
			width: 160
		});
	};

	this.processHeader = function() {
		$('#header a').each(function(){
			if (typeof $(this).attr('href') != 'undefined' && $(this).attr('id') != 'logo_home') {
				$(this).unbind('click');
				$(this).bind('click', function(){
					_href = $(this).attr('href');
					closeFlash();
					//GUI.load(_href, null, null, "GUI.searchboxMin('yes');closeFlash();", 'no');
					GUI.load(_href, null, null, "GUI.searchboxMin('yes');", 'no');
					return false;
				});
			};
		});
	};
	this.openFlash = function() {
		GUI.resize("950","360","video_box");
	};
	this.closeFlash = function() {
		GUI.resize("950","210","video_box");
	};

	this.locatorForm = function(submit) {
		if (!submit) submit = 'yes';
		if (typeof $.fn.ajaxSubmit == 'undefined') {
			setTimeout(function(){
				GUI.locatorForm(submit);
			}, 250);
			return false;
		}
		$('#numResults .reset').fadeIn('slow').bind('click', function(){
			GUI.load(WWW_ROOT + LANG_SHORTCUT + '/locator.html?locatorReset=1', 'locator', 'locator', 'GUI.init("no");', 'no', 'no');//$.getScript("' + JS_LIBS_URL + 'libs/sifr-config.js");
			GUI.load(WWW_ROOT + LANG_SHORTCUT, null, null, null, 'no', 'no');
//			alert(GUI.loaded.indexOf('results'));
			if (GUI.loaded.indexOf('results') != -1) GUI.load(WWW_ROOT + LANG_SHORTCUT, null, null, null, 'no', 'no');
			return false;
		});

		GUI.locatorSubmit(submit);
/*
		$('#locatorForm').bind('mouseover', function(){
			$('#numResults').show();
		});
		*/
		$('#locatorForm label:not(.expand)').bind('click', function(){
			GUI.clicked_on=this;
			GUI.hash_test = '';
			GUI.locatorSubmit();
			closeFlash();
		});
		return;
	};

	this.locatorRequest = function(formData, jqForm, options) {
		var queryString = $.param(formData);
// 		console.log(queryString);
		if (GUI.container != queryString && GUI.queueing == false) {
			GUI.container = queryString;
			GUI.queueing = true;
//			$('#locator .blocked').show();
			$('#locator #numResults .count').html('.....');
			return true;
		}
		setTimeout(function(){
			GUI.locatorSubmit();
		}, 100);

		return false;
	};

	this.locatorSubmit = function(results) {
		if (!results) results = 'yes';
		$('#locator_results_temp').remove();
		$('#locatorForm').append('<input id="locator_results_temp" type="hidden" name="form[results]" value="' + results + '"/>');
		if(GUI.clicked_on!="")
			{
			$('#clicked_on').remove();
			var attr_name=$(GUI.clicked_on).find("input").attr('name');
			if(attr_name!==undefined)
				{
				var first_o_br=attr_name.indexOf("[")+1;
				var first_c_br=attr_name.indexOf("]");
				var list_name=attr_name.substr(first_o_br,first_c_br-first_o_br);
				$('#locatorForm').append('<input id="clicked_on" type="hidden" name="form[clicked_on]" value="' + list_name + '"/>');
				}
			}
		$('#locatorForm').ajaxSubmit({
/*			target:        '#locator #numResults .count', */
			dataType:  'json',
			beforeSubmit:  GUI.locatorRequest,
			success:   GUI.locatorProcess
		});
/*		if (results == 'yes') {
			setTimeout(function(){
				if ($('#locator #numResults .count').text() > 0) GUI.showResults();
					else GUI.load(WWW_ROOT + LANG_SHORTCUT);
			}, 1000);
		}*/
	};

	this.showResults = function() {
		$('#numResults .loading').show();
		//GUI.load(WWW_ROOT + LANG_SHORTCUT + '/results.html', null, null, 'GUI.parseResults();GUI.resultPager();GUI.resultInit();closeFlash();');
		GUI.load(WWW_ROOT + LANG_SHORTCUT + '/results.html', null, null, 'GUI.parseResults();GUI.resultPager();GUI.resultInit();');
	};

	this.parseResults = function(){
		$('#result_box a.left_box,#result_box a.right_box').unbind('click');
		$('#result_box a.left_box,#result_box a.right_box').bind('click', function(){
			url = $(this).attr('href');
			GUI.load(url, null, null, 'GUI.availspaceInit();GUI.searchboxMin();');
			return false;
		});
		$('#numResults .loading').hide();
	};

	this.locatorProcess = function(data) {
//		$('#locator .blocked').hide();
		GUI.queueing = false;
		if (!data) {} else {
			$('#locator #numResults .count').html(data.count || '0');
			eval(data.eval);
			//kdyz je seznam prvne inicializovan vymazou se regiony, kde nic neni
			var is_ses=false;
			if(data.SES!==undefined)
				{
				is_ses=data.SES;
				}
			GUI.updateLocator(data.boxes,is_ses);
		}
	};
	this.updateLocator=function(boxes,remove_empty_regions)
		{
//  		console.log(boxes);
		/*
		$("ul.search_list li label input").each(function(){
			console.log($(this).attr('name'));
		});
		*/
		var lis=new Array;
		lis[0]=$("#step1 ul.search_list li");
 		lis[1]=$("#step2 ul.search_list li");
 		lis[2]=$("#step3 ul.search_list li ul li");
 		/*
		console.log("step3 "+lis[2].length);
		lis[2].each(function()
			{
			console.log($(this).html());
			});
		*/
		for(var i=0;i<lis.length;i++)
			{
			lis[i].each(function()
				{
	// 			console.log($(this).find("label input").attr('name'));
				var attr_name=$(this).find("label input").attr('name');
				var first_o_br=attr_name.indexOf("[")+1;
				var first_c_br=attr_name.indexOf("]");
	// 			console.log(first_o_br+" "+first_c_br);
				var list_name=attr_name.substr(first_o_br,first_c_br-first_o_br);
				var attr_value=attr_name.substr(first_c_br+2);
				attr_value=attr_value.substr(0,attr_value.indexOf("]"));
				var box_array;
				switch(list_name)
					{
					case "type":
						box_array=boxes.devel_types;
					break;
					case "area":
						box_array=boxes.areas;
					break;
					case "country":
						box_array=boxes.countries;
					break;
					case "region":
						box_array=boxes.regions;
					break;
					}
// 				console.log(list_name+" "+attr_value+" "+jQuery.inArray(attr_value,box_array));
				//zobrazit vsechno pred zrusenim prazdnych moznosti
				if(list_name=="country")
					{
					var parent_ul=$(this).parent();
					var parent_li=parent_ul.parent();
					parent_li.css("display","block");
					}
				$(this).css("display","block");
				//regiony maji value="id_regionu-id_country", protoze musi byt znam v post pozadavku
				//na locator.php z jake zeme je region, aby kdyz je zaskrtnute all se odstranily regiony
				//dane zeme a nevkladaly se do sql dotazu
				if(list_name=="region")
					{
					var temp_array=attr_value.split("-");
					attr_value=temp_array[0];
					}
				if(box_array!="clicked"&&jQuery.inArray(attr_value,box_array)===-1)
					{
					if(list_name=="country")
						{
						var parent_ul=$(this).parent();
						var parent_li=parent_ul.parent();
						parent_li.css("display","none");
						}
					$(this).css("display","none");
					if(remove_empty_regions===true)//vsechno ne jen regiony&&list_name=="region")
						{
						$(this).remove();
						}
					}
	// 			console.log(boxes.devel_types[0]);
				});
			}
		$('ul.search_list').jScrollPane();
		};

	this.searchForm = function() {
		if (!document.getElementById('searchForm')) return;

		$('#searchForm').unbind('submit');
		$('#searchForm').bind('submit', function(){
			url = $(this).attr('action');
//			alert(url);
			target = 'content_box';
			$('#' + target).css({position: 'relative'});
			$('#' + target).append('<div class="loadingContent" style="position: absolute; top: 0px; left: 0px; background: #fff; width: ' + $('#' + target).width() + 'px; height: ' + $('#' + target).height() + 'px;"></div>');
			$('.loadingContent').css({opacity: 0.1, cursor: 'wait', zIndex: 1000});
			//closeFlash();
			GUI.searchboxMin('yes');
			$(window).scrollTo( $("#content_box"), 1500 );


			url = url.replace(/^.*#/, '');
			GUI.hash_test = url;
			$.historyLoad(url);

			url = '/ajax' + url + '/content_box';

			$(this).ajaxSubmit({
				url: url,
				target: '#content_box',
				success:       function(data){
					GUI.availspaceInit();
					GUI.highlight = $('#search_input').val();
					if (typeof GUI.searchHighlight != 'undefined') GUI.searchHighlight();
				}
			});
			return false;
		});

/*
		$('#searchForm').prepend('<div id="searchFormHelper">&nbsp;</div>');
		url = $('#searchForm').attr('action');
		url = url.substr(0, url.lastIndexOf('.')) + '-help.html';

		$('#searchForm').bind('submit', function(){
			return false;
		});
		$('#search_input').focus(function(){
			$('#searchFormHelper').slideDown("normal");
		});
		$('#search_input').blur(function(){
			$('#searchFormHelper').fadeOut("normal");
		});

		$.post(url, function(data){
				$('#searchFormHelper').html($(data).find('#content_box').html());
		});
*/
	};
	this.loadFlash= function(){
		var so = new SWFObject('/swf/header_loader.swf', 'flash', '950', '360', '10', '#FFF');
			so.useExpressInstall(JS_LIBS_URL + 'libs/swfobject1_5/expressinstall.swf');
			so.addParam('allowScriptAccess', 'always');
			so.addParam('allowFullScreen', 'true');
			so.addParam('menu', 'false');
			//so.addParam('wmode', 'window');
			so.addParam('wmode', 'opaque');
//		so.addParam('wmode', 'transparent');
			so.setAttribute('xiRedirectUrl', 'http://www.ctpark.eu/');
		//so.addVariable("lang", 'cs');
			so.write('video_box');
	};
	this.load = function(url, target, source, callback, reurl, history) {
		/*
		if (GUI.version >= 8.0) {
			closeFlash();
		}
		*/
		//closeFlash(); ie8 fix
		if (!target) target = 'content_box';
		if (!source) source = 'content_box';
		if (!callback) callback = 'void(0);';
		if (!reurl) reurl = 'yes';
		if (!history) history = 'yes';
//		reurl = 'no';
/*		if (GUI.loading == true) {
			setTimeout(function(){
				GUI.load(url, target, source, callback, reurl);
			}, 250);
			return;
		}*/
		GUI.loading = true;

		$('#throbber').show();

		if (url.indexOf(window.location.hostname) != -1) {
			url = (url.substr(url.indexOf(window.location.hostname) + window.location.hostname.length));
		}

		if (history != 'no') {
			url = url.replace(/^.*#/, '');
			$.historyLoad(url, target, source, callback, reurl, history);
			return;
		}

		if (typeof pageTracker != 'undefined') {pageTracker._trackPageview(url);}
		if (reurl == 'yes') url = '/ajax' + url + '/' + source;
		if (target == 'content_box') {
			$('#' + target).css({position: 'relative'});
			$('#' + target).append('<div class="loadingContent" style="position: absolute; top: 0px; left: 0px; background: #FFF; width: ' + $('#' + target).width() + 'px; height: ' + $('#' + target).height() + 'px;"></div>');
			$('.loadingContent').css({opacity: 0.1, cursor: 'wait', zIndex: 1000});
			$('body').css({opacity: 0.4, cursor: 'wait'});
		};
		$.post(url, function(data){
				GUI.loading = false;
				if (reurl == 'yes') {
					$('#' + target).html(data);
				} else {
					$('#' + target).html($(data).find('#' + source).html());
				}
				if (typeof GUI.searchHighlight != 'undefined') GUI.searchHighlight();
				GUI.postLoad();
				eval(callback);
				GUI.loaded = url;
				setTimeout(function(){
					$('#throbber').hide();
				}, 100);
//				alert(GUI.loaded);
		});
	};

	this.open = function(url) {
		window.location.replace(url);
	};

	this.postLoad = function(){
		$('body').css({opacity:1, cursor: 'default'});
		if (TINY_MCE == 1) tinyMCEsetupLayout();
		GUI.processHeader();
		$('#news_list').accordion({header: "a.head"});
		$('#buildings_list').accordion({header: "a.head"});
		$('.ui-accordion a.head').mouseover(
			function(){
				GUI.curElem = $(this);
				checkAccTime = setTimeout('$(".ui-accordion").accordion("activate", GUI.curElem);',1000);
			}
		);
		$('.ui-accordion a.head').mouseout(
			function(){
				if (checkAccTime) {
					clearTimeout(checkAccTime);
				};
			}
		);
		if (typeof GUI.searchHighlight != 'undefined') GUI.searchHighlight();

		$('#result_box a.detail').each(function(){
			$(this).parent().css({'cursor': 'pointer'});
//			console.log($(this).parent().attr('class'));
			$(this).parent().bind('click', function(){
				$(this).find('a.detail').trigger('click');
			});
		});
		$("#result_box div.left_box, #result_box div.right_box").unbind("hover");
		$("#result_box div.left_box, #result_box div.right_box").hover(
			function(){
// 				$(this).css({"border":"1px solid #acacac"});
				$(this).css({"border":"none"});
			},
			function(){
// 				$(this).css({"border":"1px solid #FFFFFF"});
				$(this).css({"border":"none"});
			}
		);

		$('a.search_back, #result_box a.detail, .news_archive, .news_page .left_box a, .news_page .right_box a, #news_list a.more, #buildings_list a.more, .contacts a.more, .contacts a.more_link, #park_box #park_menu a').unbind('click');
		$('a.search_back, #result_box a.detail, .news_archive, .news_page .left_box a, .news_page .right_box a, #news_list a.more, #buildings_list a.more, .contacts a.more, .contacts a.more_link, #park_box #park_menu a, .back_home').bind('click', function(){
			url = $(this).attr('href');
					//GUI.load(url, 'result_box', 'result_box');
						GUI.load(url, null, null, null, 'no', 'yes');
			return false;
		});
		$('.immediately_left a, .immediately_right a').unbind('click');
		$('.immediately_left a, .immediately_right a').bind('click', function(){
			url = $(this).attr('href');
			if (url.substr(0, 7) == 'http://') return true;
					closeFlash();
					GUI.load(url, null, null, null, 'no', 'yes');
			return false;
		});
		$(".more, .news_archive").click(
		function() {
			GUI.searchboxMin("yes");
			//closeFlash();
			}
		);

		$(".play_video").click(
			function(){
				jumpToFlash($(this).attr("rel"));
				$(window).scrollTo( $("#container"), 1500 );
				GUI.searchboxMin("yes");
				return false;
			}
		);
		$(".view_360").click(
			function(){
				jumpToFlash($(this).attr("rel"));
				$(window).scrollTo( $("#container"), 1500 );
				GUI.searchboxMin("yes");
				return false;
			}
		);

		$('#throbber').hide();
//		$('.lists_add').show();
//		$('#numResults').show();

	};

	this.locatorInit = function()
		{
        $("#locatorForm").attr("action", $("#locatorForm").attr("rel"));
        $("#locatorForm #no_javascript").attr("value", 0);

        $('#locator #frm_submit').hide(0);

		$('#locator .blocked').remove();
		$('#locator').append('<div class="blocked">&nbsp;</div>');
		$('#locator .blocked').css({
			width: $('#locator').width() + 'px',
			height: $('#locator').height() + 'px'
			});
		$('#locator ul li ul').css({"display":"none"});
		$('ul.search_list').jScrollPane();
		$('#locator ul li input').css({"display":"none"});

        // rozbaleni zeme + sipecka
        $("ul.search_list li label.expand").css({"background":"url(/themes/images/arrow_gray_right.gif) no-repeat 0px 0px", "padding-left":"14px"});
        $("ul.search_list li span, ul.search_list li label.expand").click(function()
        	{
			if (this.parentNode.nodeName.toLowerCase() == "li")
				{
				if ( $(this).parent().children("ul").css("display") == "none" )
					{
					//rozbaleni
					$(this).parent().children("ul").css({"display":"block"});
					$($(this).parents("ul").get(0)).jScrollPane({maintainPosition:true});

					//sipecka
					if ($("ul li input:checked", $(this).parents('li').get(0) ).length > 0 )
						{
						// cervena sipka, neco je vybrano
						$(">label.expand", $(this).parents('li').get(0) ).css({"background":"url(/themes/images/arrow_red_down.gif) no-repeat 0px 0px"});
						}
					else
						{
						// seda sipka, nic neni vybrano
						$(">label.expand", $(this).parents('li').get(0) ).css({"background":"url(/themes/images/arrow_gray_down.gif) no-repeat 0px 0px"});
						}
					}
				else
					{
					// zabaleni
					$(this).parent().children("ul").css({"display":"none"});
					$($(this).parents("ul").get(0)).jScrollPane({maintainPosition:true});

					//sipecka
					if ($("ul li input:checked", $(this).parents('li').get(0) ).length > 0 )
						{
						// cervena sipka, neco je vybrano
						$(">label.expand", $(this).parents('li').get(0) ).css({"background":"url(/themes/images/arrow_red_right.gif) no-repeat 0px 0px"});
						}
					else
						{
						// seda sipka, nic neni vybrano
						$(">label.expand", $(this).parents('li').get(0) ).css({"background":"url(/themes/images/arrow_gray_right.gif) no-repeat 0px 0px"});
  						}
					}
				}
			});	//end click(function()
		$("ul.search_list li label:not(.expand)").click(function()
			{
			if ($("input", this).attr("checked") == true)
				{
				// policko je zaskrtnute
				//$("input", this).removeAttr("checked", "checked");
				$("input", this).removeAttr("checked");
				$(this).find('span').css({"color":"#888888"});
				$($(this).parents("li").get(0)).css({"background":"none"});
				$('> ul li', $(this).parents("li").get(0)).css({"background":"none"});
				//$("ul", $(this).parents("li").get(0)).css({"display":"none"});
				$(this).css({"color":"#888888"}).css({"background":"url(/themes/images/check_box_0.gif) no-repeat 0px 0px"});
				// pokud jsou podurovne, zrusi se zaskrtnuti
				$("ul li input", $(this).parents("li").get(0) ).removeAttr("checked");
				$("ul li label", $(this).parents("li").get(0)).css({"background":"url(/themes/images/check_box_0.gif) no-repeat 0px 0px"}).css({"color":"#888888"});
				//$(this).find('sup').css({"color":"#888888"});
				//pokud je to checkbox "select all"
// 				console.log( $(this).parents("li").hasClass("country_all")  );
// 				if ( $(this).parents("li").hasClass("country_all") )
				if($(this).parent().hasClass("country_all"))
					{
					//var ul_all = $(this).parents("ul").get(0);
					//$('li input', ul_all).removeAttr("checked");
// 					$(">li.country_all~li", $(this).parents("ul").get(0) ).each(function()
					$(this).parent().siblings().each(function()
						{
						$("input:checkbox", $(this)).removeAttr("checked");
						$("label", $(this)).css({"color":"#888888"});
						$(this).css({"background":"none"});
						$("label", $(this)).css({"background":"url(/themes/images/check_box_0.gif) no-repeat 0px 0px"});
						});
					}
				}
			else
				{
				// policko neni zaskrtnute
				$("input", this).attr("checked","checked");
				// $(this).find('sup').css({"color":"#FF0000"});
				$(this).find('span').css({"color":"#FF0000"});
				$("ul", $(this).parents("li").get(0)).css({"display":"block"});
				$($(this).parents("li").get(0)).css({"background":"url(/themes/images/bg_highlight.gif) repeat 0px 0px"});
				$(this).css({"color":"#FF0000"}).css({"background":"url(/themes/images/check_box_1.gif) no-repeat 0px 0px"});
				// pokud jsou podurovne, nastavi se zaskrtnuti
				$("ul li input", $(this).parents("li").get(0) ).attr("checked", "checked");
				$("ul li label", $(this).parents("li").get(0)).css({"background":"url(/themes/images/check_box_1.gif) no-repeat 0px 0px"}).css({"color":"#FF0000"});
					//pokud je to checkbox "select all"
//                         console.log(this);
//                          console.log( $( $(this).parent() + " ~ li"));
//                         console.log( $(">li.country_all~li", $(this).parents("ul").get(0) ).length );
//                         console.log( $(">li.country_all~li input", $(this).parents("ul").get(0) ).length );
//                         console.log( $(this).parents("li").hasClass("country_all")  );

//                         if ( $(this).parents("li").hasClass("country_all") ) {
//                             $(">li.country_all~li", $(this).parents("ul").get(0) ).each(function(){



// 				var ul_parent=$(this).parent();
// 				console.log(ul_parent.siblings());
				if($(this).parent().hasClass("country_all"))
					{
					$(this).parent().siblings().each(function()
						{
						$("input:checkbox", $(this)).attr("checked", "checked");
						$("label", $(this)).css({"color":"#FF0000"});
						$(this).css({"background":"url(/themes/images/bg_highlight.gif) repeat 0px 0px"});
						$("label", $(this)).css({"background":"url(/themes/images/check_box_1.gif) no-repeat 0px 0px"});
						});
					}
				}
			if ($(this).hasClass('expand'))
				{
				$($(this).parents("ul").get(0)).jScrollPane({maintainPosition:true});
				}
//			$($(this).parents("ul").get(0)).jScrollPane({maintainPosition:true});
			// zaskrtavani podurovni a vliv na nadrazeny prvek
			if (typeof( $(this).parents("li").get(1) ) != 'undefined')
				{
				var parent_label = $('> label' , $(this).parents("li").get(1));
				//console.log($("ul li input:checked" , $(this).parents("li").get(1)).length, $("ul li.country_all input:checked" , $(this).parents("li").get(1)).length);
				if ( $("ul li input:checked" , $(this).parents("li").get(1)).length == 0 )
					{
					// v podurovni neni nic zaskrtnute
					/*$(parent_label).css({"color":"#888888"}).css({"background":"url(/themes/images/check_box_0.gif) no-repeat 0px 0px"});*/
					// checkbox na vyber vsech regionu
					$('li.country_all > label', $(this).parents('ul').get(0)).css({"color":"#888888"}).css({"background":"url(/themes/images/check_box_0.gif) no-repeat 0px 0px"});
					// nadrazeny checkbox - sipecka u statu
					$(parent_label).css({"color":"#888888"}).css({"background":"url(/themes/images/arrow_gray_down.gif) no-repeat 0px 0px"});
					$($(this).parents("li").get(1)).css({"background":"none"});
					//$(' > input', parent_label).removeAttr("checked");
					//$('li.country_all  input', $(this).parents('ul').get(0)).removeAttr("checked");
					}
				else if ( ($("ul li input:checked" , $(this).parents("li").get(1)).length < ($("ul li input" , $(this).parents("li").get(1)).length-1)
					&& ($("ul li.country_all input:checked" , $(this).parents("li").get(1)).length == 0))
					|| ( $("ul li input:checked" , $(this).parents("li").get(1)).length < ($("ul li input" , $(this).parents("li").get(1)).length)
					&& $("ul li.country_all input:checked" , $(this).parents("li").get(1)).length == 1)  )
					{
					// v podurovni je zaskrtnuty aspon jeden prvek, ne vsak vsechny (pocet vsech inputu - 1 ..prvni je pro "select all")
					/*$(parent_label).css({"color":"#333333"}).css({"background":"url(/themes/images/check_box_2.gif) no-repeat 0px 0px"});*/
					// nadrazeny checkbox - sipecka u statu
					$(parent_label).css({"color":"#333333"}).css({"background":"url(/themes/images/arrow_red_down.gif) no-repeat 0px 0px"});
					// checkbox na vyber vsech regionu
					//console.log($('li.country_all > label', $(this).parents('ul').get(0)).attr('checked') );
					//console.log($('li.country_all', $(this).parents('ul').get(0)).nodeName );
					/*xx = $(this).parents('ul').get(0);
					console.log($(this).parents('ul').get(0).nodeName);
					console.log($('input', xx).nodeName);*/
					// checkbox na vyber vsech regionu
					$('li.country_all > label', $(this).parents('ul').get(0)).css({"color":"#333333"}).css({"background":"url(/themes/images/check_box_2.gif) no-repeat 0px 0px"});
					//$('> input', parent_label).removeAttr("checked");
					//$('li.country_all > input', $(this).parents('ul').get(0)).removeAttr("checked");
					$('li.country_all  input', $(this).parents('ul').get(0)).removeAttr("checked");
					}
				else
					{
					// vsechny prvky jsou zaskrtnute
					/*$(parent_label).css({"color":"#FF0000"}).css({"background":"url(/themes/images/check_box_1.gif) no-repeat 0px 0px"});*/
					// checkbox na vyber vsech regionu
					$('li.country_all > label', $(this).parents('ul').get(0)).css({"color":"#FF0000"}).css({"background":"url(/themes/images/check_box_1.gif) no-repeat 0px 0px"});
					// nadrazeny checkbox - sipecka u statu
					$(parent_label).css({"color":"#FF0000"}).css({"background":"url(/themes/images/arrow_red_down.gif) no-repeat 0px 0px"});
					$($(this).parents("li").get(1)).css({"background":"url(/themes/images/bg_highlight.gif) repeat 0px 0px"});
					$('li.country_all  input', $(this).parents('ul').get(0)).attr("checked", "checked");
					}
				}
			//if ((this.nodeName).toLowerCase() == 'label') return false;
			return false;
			});
         $('ul.search_list li label input:checked').parent().trigger('click').trigger('click');
		$('#numResults .results').bind('click', function()
			{
			$('#locatorForm').append('<input type="hidden" name="form[results' + Math.round(1000*Math.random()) + ']" value="1"/>');
			GUI.locatorSubmit();
			return false;
			});
		$('#locator h2, #finder h2').unbind('click');
		$('#locator h2, #finder h2').css({cursor: 'pointer'});
		$('#locator h2, #finder h2').bind('click', function()
			{
			GUI.searchboxMin("no",$(this));
			});
		$('#locator h2, #finder h2').unbind('mouseover');
		$('#locator h2, #finder h2').bind('mouseover', function()
			{
			if (GUI.finderState == 'min')
				{
				checkTime = setTimeout('GUI.searchboxMin();', 2500);
				};
			});
		$('#locator h2, #finder h2').unbind('mouseout');
		$('#locator h2, #finder h2').bind('mouseout', function()
			{
			if (typeof checkTime == "undefined") return;
			if (checkTime)
				{
				clearTimeout(checkTime);
				};
			});
		$('#locator h2, #finder h2, #map_container a, #step1 label').tooltip({
			track: true,
			showURL: false,
			top: 20,
    		left: -5
			});
		};
this.searchboxMin = function(force, source) {
		if (!force) force = 'no';
		if (!GUI.finderState) GUI.finderState = 'max';
			if (GUI.finderState == 'max' || force == 'yes') {
				GUI.finderHeight = $('#search_box').height();
				$('#search_box').animate({
					"height": "30px"
				}, 1000);
				//$('#step1, #step2, #step3, .reset').hide();
				//$('#locator').css({height: '30px'});
				//$('#finder').css({backgroundColor:'#FFFFFF'});
				if ($(source).parent().is('#locatorForm')) {
					GUI.finderHeight = 237;
				};
				GUI.finderState = 'min';
			} else {
				if (typeof(checktime) != "undefined") clearTimeout(checkTime);
				if ($(source).parent().is('#locatorForm')) {
					GUI.finderHeight = 237;
				};
					$('#search_box').animate({
						"height": GUI.finderHeight + "px"
					}, 1000, function(){
						$('#search_box').css({
							height: 'auto'
						});
					});
					GUI.finderState = 'max';



			};
		var locator_color={"min":"transparent","max":"#ebebeb"};
		var bg_color=locator_color[GUI.finderState];
		$("#locator").css({"background-color":bg_color});
		$("#finder").css({"background-color":bg_color});
// 		alert(bg_color);
	};
this.resultInit = function() {
		$(".result_images img, .gallery_images img").unbind("mouseover")
		$(".result_images img, .gallery_images img").bind("mouseover",
			function(){
				if ($(this).parents("div").hasClass("gallery_images")) {
					image = $(this).attr("name") + '/framecrop/382/290';
					$("img",$(this).parents("div")).removeClass("active_image");
					$(this).addClass("active_image");
									$("a.result_big_image",$(this).parents("div").get(1)).attr("href", ($(this).attr("name")+'/resize/1000/1000') );
					$("a.result_big_image img",$(this).parents("div").get(1)).attr("src",image);
									$("img.result_big_image",$(this).parents("div").get(1)).attr("src",image);
				} else {
					image = $(this).attr("name") + '/framecrop/150/150';
					$("img",$(this).parent()).removeClass("active_image");
					$(this).addClass("active_image");
					$("img.result_big_image",$(this).parents("div").get(1)).attr("src",image);
				}

			}
		);
	};
};

cGUI.prototype.resize = function(height, width, target) {
// console.log($(target+" #flash").attr("height"));
	if (!width) width = $(target).width();
	if (!height) height = $(target).height();
//  	$(target+" #flash").attr("height",height);
	$(target).animate(
		{
			"height": height + "px",
			"width": width + 'px'
		}
	);
};

cGUI.prototype.searchReset = function(){
	$('#search_input').val($('#search_input').attr('alt'));
	void(0);
}

function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

var GUI = new cGUI();

$(function(){
	GUI.init('no');
	GUI.hash_test = '';
	GUI.loading = false;
	GUI.flashVideoLoaded = 'no';
});