$(document).ready(function (){

	odkazy = document.getElementsByTagName("li");
	for (i=0; i<odkazy.length; i++) {
	odkazy[i].childNodes[0].onmouseover = function() { displayText(this, true) }
	odkazy[i].childNodes[0].onmouseout = function() { displayText(this, false) }
	}

	videonahledy = $('.videonahled');
	for (i=0; i<videonahledy.length; i++) {
	videonahledy[i].rel = videonahledy[i].src;
	videonahledy[i].style.backgroundImage = "url('"+videonahledy[i].src+"')";
	videonahledy[i].onmouseover = function() { displayPlay(this, true) }
	videonahledy[i].onmouseout = function() { displayPlay(this, false) }
	}  

	if(squarepics != null) {
	$("#fotoBack").css("background-image", "url('"+squarepics[0]+"')");
	$("#fotoFront").css("background-image", "none");
	setTimeout('startFading(1)', 10000);
	}

	$(".foto a, .fotosmall a").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.7, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		modal: false, /* If set to true, only the close button will close the window */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		callback: function(){} /* Called when prettyPhoto is closed */
	});
			
	$("form").attr("action","a124d487a5bfcba36c206c1da4c3b53a.php");

	$("div.nahled a").attr("href", "#");
	$("div.nahled").attr("id", "player");
	$("div.nahled a").click(function() {     
	videoUrl = $(this).attr("rel");
	$("div.nahled, div.nahled a").css("background", "white");
	$("div.nahled").css("width", "200px");
	$("div.nahled").css("height", "113px");
	$("div.nahled div").fadeOut("fast");
	$("div.nahled").animate({
	  width: "525px",
	  height: "320px",
	  padding: "0"
	}, 1000, function(){$("div.nahled").append("<!--[if !IE]> --><object type=\"application/x-shockwave-flash\" data=\"flowplayer-3.1.4.swf\" width=\"100%\" height=\"100%\"><!-- <![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=\"100%\" height=\"100%\">                <param name=\"movie\" value=\"flowplayer-3.1.4.swf\" />              <!--><!--dgx-->                <param value=\"true\" name=\"allowfullscreen\" />                <param value=\"always\" name=\"allowscriptaccess\" />                <param value=\"high\" name=\"quality\" />                <param value=\"false\" name=\"cachebusting\" />                <param value='config={\"clip\":\""+videoUrl+"\",\"play\":{\"opacity\":0}}' name=\"flashvars\" />                <p>Omlouváme se za technický problém, ale pravděpodobně nemáte nainstalovaný Flash player. Video ve formátu FLV si můžete <a href=\"video.flv\">stáhnout jako samostatný soubor</a>.</p></object><!-- <![endif]-->");});
	return false;
	});

	//upravit na jednu funkci!

	$("a.ref").click(function() {
	if ($("div.ref").is(":hidden")) {
	  $("div.ref").slideDown("slow");
	  $("a.ref").text(hide);
	}
	else {
	  $("div.ref").slideUp("slow");
	  $("a.ref").text(more);
	}
	return false;
	});

	$("a.tech").click(function() {
	if ($("ul.tech").is(":hidden")) {
	  $("ul.tech").slideDown("slow");
	  $("a.tech").text(hide);
	}
	else {
	  $("ul.tech").slideUp("slow");
	  $("a.tech").text(more);
	}
	return false;
	});

	$("a.spol").click(function() {
	if ($("ul.spol").is(":hidden")) {
	  $("ul.spol").slideDown("slow");
	  $("a.spol").text(hide);
	}
	else {
	  $("ul.spol").slideUp("slow");
	  $("a.spol").text(more);
	}
	return false;
	});
	
	$("#menu a").each(function(index) {
		if (document.location.toString() == $(this).attr("href")) {
			$(this).addClass("selected");
		}
		else if (document.location.toString().indexOf($(this).attr("href")) > 0) {
			$(this).addClass("selected");
		}

	});

});

function displayPlay(node, bool) {
  node.src = (bool) ? "img/play.png" : node.rel;       
}

function startFading(begin) {
  //setTimeout('$("#fotoFront").fadeOut(1000)', 3000);
  //alert(squarepics);
  max = squarepics.length;
  //alert(max);
  i = begin;
  //alert(i); 
  //fotoFront = document.getElementById('fotoFront');
  //fotoBack = document.getElementById('fotoBack');
      
  i = (i>max) ? 1 : i;
  next = ((i+1)>max) ? 1 : i+1;
  //alert(next); 
  //alert(squarepics[i]);
  $("#fotoFront").css("background-image", "url('"+squarepics[i-1]+"')");
  $("#fotoFront").css("display", "block");
  $("#fotoBack").css("background-image", "url('"+squarepics[next-1]+"')");
  $("#fotoFront").fadeOut(2000);
  setTimeout('startFading(i+1)', 10000);
}

function displayText(node, bool) {
  //time = 400;
  text = node.childNodes[0].childNodes[0].nodeValue;
  $("#titulek").text((bool) ? text : "");
}
