function menuHover() { // keeps active item when submenu is visible
	$("#menu li").hover(function(){
   		$(this).addClass("hover");
 	},function(){
		$(this).removeClass("hover");
	});
}



function inputFocus() { // keeps default text in inputs
	$('#search-inp').focus(function() { if (this.value==this.defaultValue) this.value=""; });
	$('#search-inp').blur(function() { if (this.value=="") this.value=this.defaultValue; });
}



function jSliders() { // 3 sliders on hp
	$("#slider-main").jshowoff({
		speed: 5000,
		changeSpeed: 500,
		effect: 'fade',
		controls: false,
		hoverPause: false,
	});
	$("#hp .item-1").jshowoff({
		speed: 5000,
		changeSpeed: 500,
		effect: 'fade',
		controls: false,
		hoverPause: false,
		cssClass: 'slider-box-1'
	});
	$("#hp .item-2").jshowoff({
		speed: 5000,
		changeSpeed: 500,
		effect: 'fade',
		controls: false,
		hoverPause: false,
		cssClass: 'slider-box-2'
	});
	$("#hp .item-3").jshowoff({
		speed: 5000,
		changeSpeed: 500,
		effect: 'fade',
		controls: false,
		hoverPause: false,
		cssClass: 'slider-box-3'
	});
}



function faqToggle() { // toggle faq answers
	$(".faq h3").click(function () {
		$(this).next().slideToggle('fast');
		$(this).toggleClass('act');
	});
}



function mapHover() { // hover on map
	$("#map area").hover(function(){
		$("#map-div").append("<div></div>");
		var id = $(this).attr('id').split('-')[1];
		var top = $(this).attr('class').split(' ')[0];
		var left = $(this).attr('class').split(' ')[1];
		var ycord = id * 154;
		$("#map-div").css({backgroundPosition: '0 -'+ycord+'px'});
		$('#map-div div').css('top', top+'px');
		$('#map-div div').css('left', left+'px');
		$("#map-div div").html($(this).attr('title')).show();
	},function(){
		$('#map-div div').remove();
		$("#map-div").css({backgroundPosition: '0 0'});
	});
}



function filterClose() { // close filter
	$("#filter").removeClass("act");
	$("#f").hide();
	$("#overlay").remove();
}



function filterOpen() { // open filter
	$("#filter h2").click(function () {
		if ($('#f').is(':visible')) {
			filterClose();
		} else {
			$("body").append("<div id=\"overlay\" onclick=\"filterClose();\"></div>");
			$("#filter").addClass("act");
			$("#overlay").css('opacity', 0).animate({ opacity: 0.60 }, 100, function() {
				$("#f").show();
			});
		}
	}); 
  $(".changeFilterParams").click(function () {
		if ($('#f').is(':visible')) {
			filterClose();
		} else {
			$("body").append("<div id=\"overlay\" onclick=\"filterClose();\"></div>");
			$("#filter").addClass("act");
			$("#overlay").css('opacity', 0).animate({ opacity: 0.60 }, 100, function() {
				$("#f").show();
			});
			$("#f-main").animate({
    			scrollBott: '#filter-big-zone'
		  }, 500 );
		}
	});   
}



$(document).keyup(function(e) { // close filter on ESC key
	if (e.keyCode == 27) { filterClose(); }  
}); 



function filterItemToggle() { // toggle filter items
	$("#f h5").click(function () {
		if ($(this).next().is(':visible')) {
			$(this).removeClass("act");
			$(this).next().slideUp();
		} else {
			$(this).addClass("act");
			$(this).next().slideDown();
		}
	});
}



function filterToggle() { // lets have filter higher
	$("#filter-big").toggle(function () {
		//$("#f-main").animate({
    //			height: "580px"
		//}, 500 );
		$("#filter-big-zone").show(); 
    $("#f-main").animate({
    			scrollBott: '#filter-big-zone'
		}, 500 );
		$(this).text("Zúžit výběr");
		$(this).addClass("act");
	}, function() {
		//$("#f-main").animate({
    //			height: "334px"
		//}, 500 );
		$("#filter-big-zone").hide(); 
		
    $(this).text("Rozšířit výběr");
		$(this).removeClass("act");
	});
}



function filterCheckAll() { // all checkboxes checked
	$(".item .all").click(function () {
		$(this).parent().nextAll('ul').find('input').attr('checked','checked');
	});
}



function filterUncheckAll() { // all checkboxes unchecked
	$(".item .none").click(function () {
		$(this).parent().nextAll('ul').find('input').removeAttr('checked');
	});
}

function filterUncheckAllAll()
{
	$("#filter-big-clear").click(function () {
		$('#f-main').find('input').removeAttr('checked');
		$('#filter').find('input').removeAttr('checked');
		$('#filter_cats_zone').find('input').removeAttr('checked');
	});
}


function tooltipHint() { // tooltip
	$('.hint').bt({ centerPointX: 0.4, padding: 8, width: 155, spikeLength: 15, spikeGirth: 15, fill: '#FFF', cornerRadius: 0, strokeWidth: 1,  strokeStyle: '#769196',  shadow: true, shadowOffsetX: 4, shadowOffsetY: 6, shadowBlur: 4, shadowColor: 'rgba(0,0,0,.3)', shadowOverlap: false, noShadowOpts: {strokeStyle: '#769196', strokeWidth: 1}, positions: ['top', 'left', 'right'], cssStyles: { marginLeft: '40px' } });
}



function lightBox() { // lightbox
	$("a.zoom").fancybox({ 'overlayOpacity': 0.6, 'overlayColor': '#000', 'imageScale': false, 'hideOnContentClick': true });
}

function filterCats()
{
	$("#MAIN_FILTER_CATS_1").click(function () {
		if($(this).is(':checked'))
    {
      document.getElementById('FILTER_CATS_1').checked=true;  
    }
    else
    {
      document.getElementById('FILTER_CATS_1').checked=false;
    }
	});

	$("#MAIN_FILTER_CATS_2").click(function () {
		if($(this).is(':checked'))
    {
      document.getElementById('FILTER_CATS_2').checked=true;  
    }
    else
    {
      document.getElementById('FILTER_CATS_2').checked=false;
    }
	});
  
	$("#MAIN_FILTER_CATS_3").click(function () {
		if($(this).is(':checked'))
    {
      document.getElementById('FILTER_CATS_3').checked=true;  
    }
    else
    {
      document.getElementById('FILTER_CATS_3').checked=false;
    }
	});  	
}

$(document).ready(function() {
	menuHover();
	inputFocus();
	jSliders();
 	faqToggle();
 	mapHover();
 	filterOpen();
 	filterItemToggle();
 	filterToggle();
 	filterCheckAll();
 	filterUncheckAll();
 	filterUncheckAllAll();
 	filterCats();
	tooltipHint();
	//lightBox();
});
