function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function float() {
	el = skyFloat;
	$(el).stop().animate({top:-$("div#page").position().top+40},"normal");	
}

var skyFloat = "div#skyBanner";

function initMenuT() {

	$("#tmenu").find("li").hover(
		function() { $(this).addClass("over"); },
		function() { $(this).removeClass("over"); }
	);

	$("ul.level1>li").click(function() {
		window.location.href = $(this).children("a").attr("href")
	});

	$("ul.level2>li").click(function() {
		window.location.href = $(this).children("a").attr("href")
	});

	$("ul.level1>li").hover(function() { 
		$(this).addClass("over2"); },function() { $(this).removeClass("over2"); 
	});

	$("ul.level2>li").hover(function() { 
		$(this).addClass("over3"); },function() { $(this).removeClass("over3"); 
	});

	$("ul.level0>li").hover(function() { 
		$(this).addClass("over"); },function() { $(this).removeClass("over"); 
	});
}

function fancyBoxInit() {

	$("a.thickbox").fancybox({   
    	'titlePosition' : 'inside',     
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	

	$("a.thickbox[rel=gallery]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'inside',		
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-inside">Obrázek ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}

	});
}

function loadP() {
    externalLinks();

	fancyBoxInit();

	$("ul#zalozky.v2010").find("a").attr("href","javascript:void(0);");
	$("ul#zalozky.v2010").find("a").click(
		function() {
			var rel = $(this).attr("rel");
			rel = rel.split("&");
			$("#pData").load("/ajax/zalozky/?"+rel[0]+"&page="+rel[1],{},function() { 
				fancyBoxInit(); 
			});
			$("ul#zalozky.v2010>li").removeClass("active");
			$(this).parent().addClass("active");
		}
	);

	//$('span>.tool').tooltip({showURL: false}); 
	$('.tool>span').tooltip({showURL: false}); 
	$('.tool>strong').tooltip({showURL: false}); 
	$('.tool').tooltip({showURL: false}); 

	$(window).scroll(function () { 
      float();
    });
	$(window).resize(function () { 
      float();
    });

	float(); 


	$(".irobotBubble img:first").hover(function() {
		$(this).parent().find("img.bub").removeClass("hidden");
	},function() {
		$(this).parent().find("img.bub").addClass("hidden");
	});

}

window.onload = function() {
	loadP();	
}
 

function fullScreen(theURL) {
	window.open(theURL, '', 'fullscreen=yes, resizable=yes, scrollbars=yes');
}

function openWindow(path, name, width, height) {

   var winl = (screen.width - width) / 2;
   var wint = (screen.height - height) / 2;

   style = eval("'status=no,width="+width+",height="+height+",left="+winl+",top="+wint+",resizable=no,menubar=no,scrollbars=yes,toolbar=no'");
   window.open(path, name, style) ;
}

function loadInfo() {

      $("#barinfo").html("<span class=\"loading\">Nahrávám data</span>");

      $("#barinfo").load("/cetelem/info.php?barem="+$("#barem").attr("value"));
      var param = "pojisteni="+$("#pojisteni").attr("value")+"&splatek="+$("#cetCnt").attr("value")+"&barem="+$("#barem").attr("value")+"&cena="+$("#cetVal").attr("value")+"&platba="+$("#cetCash").attr("value");
//+"&splatek="+$("#cetCnt").attr("value")
      $("#cetRes").load("/cetelem/calc.php?"+param+"&wres=1", {limit: 0}, function(res) { 
              txt = res.split("#");
              $("#cetAdd").html(txt[1]);
              $("#cetPayT").text(txt[0]);

              $("#cetRPSN").val(txt[3]);
              $("#cetAdd2").val(txt[4]); // cena uveru
              $("#cetUrSaz").val(txt[5]);
              $("#cetPayT2").val(txt[6]); // vyse splatky

              $("#cetCash").val(txt[7]); // prima platba
              $("#primaPlatba").val(txt[8]); // prima platba

              if (txt[2]!="") { $("#cetError").html("<p class=\"error\">"+txt[2]+"</p>"); } else { $("#cetError").text(""); }
      } );


}

/* --- photo slider --- */
function photoSlider() {

	var slideGalleryY = 0;
	var slideGallerySteps = 0;
	var slideGalleryHeight = $("#slideGalleryContainter").css("height");
	var slideGalleryHeightC = parseInt($("#slideGalleryFoto").height());
	var slideGalleryPhoto = parseInt(slideGalleryHeight)/3;
	var slideGalleryHeightValue = parseInt(slideGalleryHeight);
	var maxSteps = Math.ceil(slideGalleryHeightC/slideGalleryHeightValue*3)-1;
	var maxStepsT = Math.ceil(slideGalleryHeightC/slideGalleryHeightValue)-1;
	var maxTop = parseInt(slideGalleryHeightValue*maxStepsT);


	$("#slideGalleryFake a").hide();
	$("#slideGalleryFake a#slGalM").show();

	$("#slideGalleryFoto a").attr("href","javascript:void(0);"); 
	$("#slideGalleryFoto a").click(function() {
		var rel = $(this).attr("rel").split("|");

		$("#slideGalleryFake a").hide();
		$("#slideGalleryFake a#slGal"+rel[2]).show();

		if (rel[2]!="M") {
			var detailFoto = rel[0]+"-os-detail/"+rel[1];
			var stepX = parseInt(rel[2])+1;
		} else {
			var detailFoto = rel[0]+"-detail/"+rel[1];
			var stepX = 0;
		}
		$("#mainFoto img").attr("src",detailFoto);
		var mainFoto = rel[0]+"/"+rel[1];
		$("#mainFoto").attr("href",mainFoto);

		var pos = stepX-slideGallerySteps;

		if (pos==2) {
			// fotka je dole...	
			slideGallerySteps++;
			$("#slideGalleryFoto").animate(
				{ top: "-="+slideGalleryPhoto }
			);
		}

		if (pos==0) {
			// fotka je dole...	
			if (slideGallerySteps>0) {
				slideGallerySteps--;
				$("#slideGalleryFoto").animate(
					{ top: "+="+slideGalleryPhoto }
				);
			}
		}

	});

	$("#slideGallery #slideUp").click(
		function() { 			
			slideGallerySteps-=3;
			if (slideGallerySteps<0) { 
				slideGallerySteps = 0; 
				$("#slideGalleryFoto").animate(
					{ top: "+20px" }
				, "fast", function() { 
					$(this).animate({ top: "0px" });
				});
				
			} else {
				$("#slideGalleryFoto").animate(
					{ top: "+="+slideGalleryHeight }
				);
			}
		}
	);

	$("#slideGallery #slideDown").click(
		function() { 			
			if (maxSteps>slideGallerySteps) {
				$("#slideGalleryFoto").animate(
					{ top: "-="+slideGalleryHeight }
				);
				slideGallerySteps+=3;
			} else {
				$("#slideGalleryFoto").animate(
					{ top: "-"+(maxTop+20)+"px" }
				, "fast", function() { 
					$(this).animate({ top: "-"+maxTop+"px" });
				});

			}
		}
	);
}


