// JavaScript Document

// Odstranění fokusu u Firefoxu a IE
$("a").live("click",function(){
	$(this).blur();
});
$(".katalog img").live("click",function(){
	$(".katalog a").blur();
});


// u tiskovin proklik jednotlivých náhledů
$(".nahled-maly").live('click',nahraj);
function nahraj(){
	var url = $(this).parent().attr("href");
	
	$(".katalog-big").attr("src",url);

	$(".katalog-big").hide();
	$(".katalog-big").fadeIn(500);

	return false;
};


$(document).ready(function(){

	galery();  
	arrow();
//Posouvatko referencí	
	function arrow(){
		if($(".galery").is(".one-line")){
			$('#arrow-up, #arrow-down').addClass("disable");
		}
		else{ 
			var scrollheight = $(".galery-inside")[0].scrollHeight - $(".galery-inside").height();
			if((scrollheight % 88) != 0){ scrollheight = scrollheight-8;} // oprava u Firefoxu!
			
			var topheight = $(".galery-inside")[0].scrollTop;			
			if (scrollheight == topheight) { $('#arrow-up').addClass("disable"); }
			if (topheight == 0) { $('#arrow-down').addClass("disable"); }	
	  	}
	}
	
	function galery(){
		if($(".galery-inside").is("div")){
			var pohybdolu = 88;
			var pohybnahoru = 88;
			$(".galery-inside").css('overflow','hidden');
			arrow();
			$('#arrow-up').live("click", function() {
				$('#arrow-down').removeClass("disable");
				$('.galery-inside').animate({
					scrollTop: "+=" + pohybdolu
				}, 300, function() {
					arrow();  	  		  	
			  });
			  return false;
		});
		$('#arrow-down').live("click",function() {
			$('#arrow-up').removeClass("disable");
		  	$('.galery-inside').animate({
		    	scrollTop: "-=" + pohybnahoru
		  	}, 300, function() { // Animation complete.	
			  arrow(); 	  		
		  });
		  return false;
		});	
		}
	}
	
	
	/*hide-info*/
	$(".toggle-cont").hide();
	$(".toggle-manage span").live("click",function () {
    	$(".toggle-cont").slideToggle("slow");
    });
    $('.toggle-manage').live("click",function() {
		$(this).toggleClass("toggle-manage-hover");		
	});	    
	
	$(".galery-inside a").live("mouseover mouselive",function () {
		$(this).toggleClass("galery-inside-hover");
	});
	
	$(".galery-inside a").live("mouseout",function () {
		$(this).removeClass("galery-inside-hover");
	});


	var acthash;
	var gal_flag;
	function load(url,fout){
		
		if ($("#article_text").is('div') && gal_flag == 1){
			$(".realizace-pro-klienta").hide();
			$("#article_text").html("<div id='loading'><img src='/images/ajax-loader-square.gif'></div>").load(url + " #article_text", function(data){				
	 			$(this).hide();
				$(this).fadeIn(500);$(".realizace-pro-klienta").fadeIn(500);

				galery();

				Shadowbox.clearCache(); // <= clear Shadowbox's cache 
				Shadowbox.setup(); // <= set up all Shadowbox links

				acthash = window.location.hash;

				// titulka pro stránku	
				if (document.getElementById("nadpis-titulek").firstChild.nodeValue=="Úvodní stránka") {document.getElementById("titulek").firstChild.nodeValue="Grafika, DTP, Webdesign, Produkce tiskovin | SAVIO, s.r.o., grafické studio v Brně"}
				else {document.getElementById("titulek").firstChild.nodeValue = document.getElementById("nadpis-titulek").firstChild.nodeValue+" | SAVIO, s.r.o., grafické studio v Brně";}
					
			});
		}
		else
		{		
			$("#right").html("<div id='loading'><img src='/images/ajax-loader-square.gif'></div>").load(url + " #right .text", function(data){				
	 			$(this).hide();
				$(this).fadeIn(500);

				galery(); 

				Shadowbox.clearCache(); // <= clear Shadowbox's cache 
				Shadowbox.setup(); // <= set up all Shadowbox links

				acthash = window.location.hash;

				// titulka pro stránku 
				if (document.getElementById("nadpis-titulek").firstChild.nodeValue=="Úvodní stránka") {document.getElementById("titulek").firstChild.nodeValue="Grafika, DTP, Webdesign, Produkce tiskovin | SAVIO, s.r.o., grafické studio v Brně"}
				else {document.getElementById("titulek").firstChild.nodeValue = document.getElementById("nadpis-titulek").firstChild.nodeValue+" | SAVIO, s.r.o., grafické studio v Brně";}

			});
		}
	}

	
	setInterval(function(){
		if (window.location.hash != "" && window.location.hash != acthash)
			{	
				acthash = window.location.hash;				
				id_div = window.location.hash;
				id_div = id_div.split("#");
				load(id_div[1],0);				
			}
	},100);




	/*Nacitani stranek*/	

	$("#left a,.galery a,.ajax,#top a").live("click",function(){
		if ($(this).parents('.galery').is('div')){gal_flag = 1}else{gal_flag = 0}

		$("#menu-v1 a").removeClass("active");
		$(this).addClass("active");
	 	var url = $(this).attr("href");
		
	 	url = url.split("/");

		if(!url[2]){
			window.location.hash = "/" + url[1];
		}
		else	{
			window.location.hash = "/" + url[1] + "/" + url[2];}	
	 	return false;
	});
	
	

	// hover malého náhledu tiskoviny
	$(".nahled-maly").live('mouseover mouseout', function (event) {
		if (event.type == 'mouseover') {
			$(this).animate({opacity: 0.75}, 200, 'linear', function() {});
		} else {
			$(this).animate({opacity: 1}, 200, 'linear', function() {});
  		}
	});

	$(".webdesign-live").live('mouseover mouseout', function (event) {
		if (event.type == 'mouseover') {
			$(this).animate({opacity: 0.75}, 200, 'linear', function() {});
		} else {
			$(this).animate({opacity: 1}, 200, 'linear', function() {});
  		}
	});
	

});



