var Name;
var Text;
var Zajem;
var Rozpocet;
var ID = 0;
var slideshow_interval;
$(document).ready(function(){

	function resolution(){
		Window = $(window).height();
		Header = $("div#header").height()
		Box = $("div#box").height()
		Content = $("div#content").height()
		Detail = $("div#detail").height()
		Footer = $("div#footer").height()
		Web = Header + Content + Footer + Box + Detail;
		if(Window > Web){
			$("div#footer").animate({"margin-top": (Window-Web-Footer-30)+"px"}, 0);
		}
	}
	resolution();
	$(window).resize(function(){
		resolution();
	});
	// slideshow
	slideshow_interval = setInterval("nextslide()", 8000);
	$("div.href").click(function(){
		$("div.slide div.href").removeClass('selected');
		clearInterval(slideshow_interval);
		slideshow_interval = setInterval("nextslide()", 8000);
	});
	$("div.slide div.href").click(function(){
		ID = $(this).attr('id').substr(-1);
		$("div.slider").animate({"margin-left": ID*(-1050)+"px"}, "slow");
		$("div#slide_"+ID).addClass('selected');
	});
	$("a.close").click(function(){
		$("span.notification").fadeOut("slow");
	});
	$("span.select").click(function(){
		Name = $(this).attr("name");
		if($("ul#"+Name).hasClass("visible")){
			$("ul#"+Name).animate({"height": "1px"}, 300);
			$("ul#"+Name).removeClass("visible")
		}else{
			$("ul#"+Name).animate({"height": "154px"}, 300);
			$("ul#"+Name).addClass("visible")
		}
	});
	$("img.select").click(function(){
		Name = $(this).attr("alt");
		if($("ul#"+Name).is(':hidden')){
			$("ul#"+Name).slideDown("medium");
		}else{
			$("ul#"+Name).slideUp("fast");
		}
	});
	// kod pro spojeni selectu a hidden pole
	$("ul.select li").click(function(){
		Text = $(this).text();
		var fieldName = $(this).parent().attr("id");
		$('input[name$='+fieldName+']').val($(this).children('a').attr("name"));
		$("span."+Name).text(Text);
		$("ul#"+Name).animate({"height": "1px"}, 0);
		$("ul#"+Name).removeClass("visible")
	});
	/******Menu*****/
	$("ul#menu li a").live('mouseover mouseout', function(event){
		if($(this).attr('class')=='uvod' || $(this).attr('class')=='sluzby' || $(this).attr('class')=='reference' || $(this).attr('class')=='cena' || $(this).attr('class')=='kontakt'){
			if(event.type == 'mouseover'){
				$(this).animate({"margin-top": "-4px"}, 150);
			}else{
				$(this).animate({"margin-top": "0"}, 150);
			}
		}
	});
	/******Reference*****/
	$('div#reference div a').hover(function() {
		$(this).animate({"margin-top": "-10px"}, 150);
		$(this).children("span").delay(100).stop(true, true).fadeIn(200);
	}, function() {
		$(this).stop();
		$(this).children("span").stop(true, true).fadeOut(5);
		$(this).animate({"margin-top": "0"}, 150);
	});
	/******Detail reference*****/
	 $("div#detail div.previews img").live('click', function(event){
		var Name = $(this).attr("alt");
		$("div#detail div.images img").hide();
		$("div#detail div.images img[alt$="+Name+"]").show();
	});
});
function nextslide() {
	ID++;
	if(ID==4){ID=0;}
	$("div.slide div.href").removeClass('selected');
	$("div#slide_"+ID).addClass('selected');
	$("div.slider").animate({"margin-left": ID*(-1050)+"px"}, "slow");
}
