$(document).ready(function(){	
	bind_hover ();
	bind_menu ();
	bind_slider ();
	bind_form ();
	bind_presets ();
	bind_checkbox ();
});

/**
 * hover efekt na menu
 **/
function bind_hover ()
{
	$(".menu li, .path li").hover(
		function() {
			$(this).addClass("sfhover");
		},
		function() {
			$(this).removeClass("sfhover");
		}
	);
}

/**
 * vyjizdejici menu http://www.noupe.com/tutorial/drop-down-menu-jquery-css.html
 **/
function bind_menu ()
{
	$(".menu>ul").addClass("topnav");
	$(".menu ul ul").addClass("subnav");
	
	//$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$(".menu ul li.nase-sluzby a").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown(200).show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp(300); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
}

/**
 * slider
 **/
function bind_slider ()
{
	$(window).load(function() {
		$('#slider').nivoSlider({
			effect:'random', //Specify sets like: 'fold,fade,sliceDown'
			//slices:15,
			animSpeed:500,
			pauseTime:7000,
			//startSlide:0, //Set starting Slide (0 index)
			//directionNav:false, //Next & Prev
			//directionNavHide:true, //Only show on hover
			controlNav:false //1,2,3...
			//controlNavThumbs:true, //Use thumbnails for Control Nav
	      	//controlNavThumbsFromRel:false, //Use image rel for thumbs
			//controlNavThumbsSearch: '.jpg', //Replace this with...
			//controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			//keyboardNav:true, //Use left & right arrows
			//pauseOnHover:true, //Stop animation while hovering
			//manualAdvance:false, //Force manual transitions
			//captionOpacity:0.8, //Universal caption opacity
			//beforeChange: function(){},
			//afterChange: function(){},
			//slideshowEnd: function(){} //Triggers after all slides have been shown
		});
	});
}

/**
 * pridani tridy prvku
 **/
function bind_form ()
{
	var i=0;
	$(".formcontent div").each(function(){
		$(this).addClass("form-type"+i);
		i++;
	});
}

/**
 * presety inputu
 **/
function bind_presets ()
{
	$(".form-type1 input").val('+420');
	$(".form-type2 input").val('@');
	$(".form-type3 input").val('typ, tloušťka, barva');
	$(".form-type5 input").val('mm');
	$(".form-type8 input").val('dd/mm/rrrr');
	$(".form-type9 input").val('dd/mm/rrrr');
	$(".form-type6 input").attr('checked', true);
	$(".form-type6 input").addClass("item6");
	$(".form-type7 input").addClass("item7");
	
	// preusporadani checkboxu
	$('.form-type7').each(function(){
			$(this).after('<div class="line checkbox type-bool form-type-fakebox"><a href="#item6" class="fakecheck" id="fakeitem6">Balení</a><a href="#item7" class="fakecheck" id="fakeitem7">Doprava</a></div>');
	});	
}

/**
 * obrazkovy checkbox http://john.mcclumpha.org/javascript/Creating_custom_styled_checkboxes_with_jQuery/
 **/
function bind_checkbox ()
{
	// check for what is/isn't already checked and match it on the fake ones
	$("input").each( function() {
		(this.checked) ? $("#fake"+this.name).addClass('fakechecked') : $("#fake"+this.name).removeClass('fakechecked');
	});
	
	// function to 'check' the fake ones and their matching checkboxes
	$(".fakecheck").click(function(){
		($(this).hasClass('fakechecked')) ? $(this).removeClass('fakechecked') : $(this).addClass('fakechecked');
		if(this.id=="fakeitem6") $("input.item6").trigger("click");
		else $("input.item7").trigger("click");
		return false;
	});

}

