// JavaScript Document
$(document).ready(function() {

/* Search form Action */
$("#search").submit(function(){
	var action = $('#search').attr('action') + $(".searchBox").val();
	$('#search').attr('action', action)
});
 
 $("a.grouped_elements, a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
	// Carousel with pagination
	$(".carousel").carousel({
		 pagination: true,
		 autoSlide: true,
		 dispItems: 4,
         autoSlideInterval: 5000
	});
	$(".carousel .carousel-pagination p a").text('');
	$("input.carousel-control").attr("value","");
  
 /**
   *    NASTAVENI ODSAZENI OBRAZKU V OBSAHU PODLE TOHO NA KTEROU STRANU JE ZAROVNANY  
   */     

	var images = $('#content img');
	
	$.each(images, function(i, img){                                                                                                                                                                              
		var value = null;
		switch ( $(img).css( 'float' ) ){
		case 'right':
			value = "0px 0px 5px 10px";
			break;
		case 'left':
			value = "0px 10px 5px 0px";
			break;
		default:
			value = "0px auto";
			break;
		}
		$(img).css( 'margin', value );
	});
 /**
   *    
   */ 
   
   	$(".slider-controll a").click(function(){ 
		$("#slider img.slider").fadeOut();
		$(".slider-controll a").removeClass("active"); 
		$("#slider ."+$(this).attr('class')).fadeIn();
		$(this).attr("class", $(this).attr("class") + " active");
		return false;   
	});
    /* PAGINATOR */
    photoCount = $("#content .gallery-info .allphotos").text();
    $("#gallery-paginator").pagination(photoCount, {
        items_per_page:9,
        next_text: "Další stránka",
        prev_text: "Předchozí stránka",
        next_show_always: true,
        prev_show_always: true,
        num_display_entries: 0,
        callback:handlePaginationClick
	});
	
	pagesCount = 0;
	
	$("#Searchresult .photoContainer").each(function(i, l){
	    	if(i>8) {
				$(this).css("display","none");
			}
			pagesCount++;
	});
	if(pagesCount) {
		$("#content .gallery-info .all").text(Math.ceil(pagesCount/9));
	}

    /* NOVINKY CONTROLL */   
	$("#content .news .new h3 a").click(function(){
		$(this).parent().find("span.date").animate({height: "toggle"}, 1);

		$(this).parent().parent().find(".closer").slideToggle('slow', function() {
		  // Animation complete.
		});
		return false;
	});	
	
	/* search box */
	$(".searchBox").click(function(){
		text = $(".searchBox").val();
		if(text == "Hledaný text") {
			$(".searchBox").val("");	
		}		
	});
	
	$(".searchBox").focusout(function(){
		text = $(".searchBox").val();
		if(text == "") {
			$(".searchBox").val("Hledaný text");	
		}	
	});		
//END	
});

function handlePaginationClick(new_page_index, pagination_container) {
    array = [];

    counter=0;
	$("#Searchresult .photoContainer").css("display","none");
	$("#Searchresult .photoContainer").each(function(i, l){
    	counter++;
		if((i >= (new_page_index*9)) && (i <= photoCount) ) {
    		    if(counter < (((new_page_index+1)*9)+1))
				$(this).css("display","block");
				$("#content .gallery-info .actual").text(new_page_index+1);
		}
	});
	              
    return false;   
}



