$(document).ready(function() {
	//Code goes here
	//Show the paging and activate its first link
	$(".paging").show();
	$(".paging a:first").addClass("active");
	
	//Get size of the image, how many images there are, then determin the size of the image reel.
	/*var imageWidth = $(".window").width();*/
	var imageWidth = $(".window").height();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	//$(".image_reel").css({'height' : imageReelWidth});
	
	//Paging  and Slider Function
	rotate = function(){
	    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
	    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

	    $(".paging a").removeClass('active'); //Remove all active class
	    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
	
	    //Slider Animation
	    $(".image_reel").animate({
	        top: -image_reelPosition
	    }, 200 );
	
	}; 
	
	//Rotation  and Timing Event
	rotateSwitch = function(){
	    play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
	        $active = $('.paging a.active').next(); //Move to the next paging
	        if ( $active.length === 0) { //If paging reaches the end...
	            $active = $('.paging a:first'); //go back to first
	        }
	        rotate(); //Trigger the paging and slider function
	    }, 1000); //Timer speed in milliseconds (7 seconds)
	};
	
	//rotateSwitch(); //Run function on launch    
	
	//On Hover
	$(".image_reel a").hover(function() {
	    //clearInterval(play); //Stop the rotation
	}, function() {
	    //rotateSwitch(); //Resume rotation timer
	});	
	
	//On Click - puvodne click
	$(".paging a").hover(function() {
			
			//po kliknuti docist zbytek banneru
			loadBanners();
			
	    $active = $(this); //Activate the clicked paging
	    //Reset Timer
	    //clearInterval(play); //Stop the rotation
	    rotate(); //Trigger rotation immediately
	    
	    //_BAN_ ulozit zobrazeni baneru
	    SaveShowedRotBanners($(this).attr('id'));
	    
	    //rotateSwitch(); // Resume rotation timer
	    return false; //Prevent browser jump to link anchor
	});
	
	/*$(".paging a").click(function() {
	
		alert($(this).attr('class'));	
	
	});*/
	
	var isInited = 0;
	function loadBanners(){
		
     if(isInited == 0){		
			
			//document.getElementByIdbanner_2_hidden
			$("#banner_2").html('<img src="'+$("#banner_2_name").text()+'" alt="" />');
			$("#banner_3").html('<img src="'+$("#banner_3_name").text()+'" alt="" />');
			$("#banner_4").html('<img src="'+$("#banner_4_name").text()+'" alt="" />');
		
			isInited = 1;
			
		}
		
			
		/*if(isInited == 0){
			var banner_place = document.getElementById('banner-place');
			if(banner_place){
				content = banner_place.innerHTML;
				content = content.replace(/<span>/g, "<");
				content = content.replace(/<\/span>/g, " />");
				banner_place.innerHTML = content;
			}
			
			//aktualizace obsahu
			for(i=1;i<10;i++){
			 	obrazek = document.getElementById('banner_'+i);
			 	if(obrazek){
			 		obrazek.src = obrazek.src;
			 	}
			}
			
			isInited = 1;
		} 	*/
	} 
	
	//_BAN_
	var isShowSaved = Array();
	function SaveShowedRotBanners(bannerTextID){
		if(isShowSaved[bannerTextID] != 1){
			isShowSaved[bannerTextID] = 1;
			//ulozit nacteni
			ShowedBanners(bannerTextID,bannerTextID+bannerTextID)
		}	
	}
	
	/* ************************************* FEATURED *************************************** */
	/* ************************************* FEATURED *************************************** */
	/* ************************************* FEATURED *************************************** */
	
	//Code goes here
	//Show the paging and activate its first link
	$(".paging_featured").show();
	$(".paging_featured a:first").addClass("active_featured");
	
	//Get size of the image, how many images there are, then determin the size of the image reel.
	/*var imageWidth = $(".window").width();*/
	var boxWidth = 256;//$(".window_featured").height();
	var boxSum = 1;//$(".image_reel_featured img").size();
	var boxReelWidth = boxWidth * boxSum;
	
	//Adjust the image reel to its new size
	//$(".image_reel_featured").css({'width' : boxReelWidth});
	
	//Paging  and Slider Function
	rotate_featured = function(){
	    var triggerID = $active_featured.attr("rel") - 1; //Get number of times to slide
	    var box_reelPosition = triggerID * boxWidth; //Determines the distance the image reel needs to slide
	
	    $(".paging_featured a").removeClass('active_featured'); //Remove all active class
	    $active_featured.addClass('active_featured'); //Add active class (the $active is declared in the rotateSwitch function)
	
	    //Slider Animation
	    $(".image_reel_featured").animate({
	        top: -box_reelPosition
	    }, 200 );
	
	}; 
	
	//Rotation  and Timing Event
	rotateSwitch_featured = function(){
	    play_featured = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
	        $active_featured = $('.paging_featured a.active_featured').next(); //Move to the next paging
	        if ( $active_featured.length === 0) { //If paging reaches the end...
	            $active_featured = $('.paging_featured a:first'); //go back to first
	        }
	        rotate_featured(); //Trigger the paging and slider function
	    }, 70000); //Timer speed in milliseconds (7 seconds)
	};
	
	rotateSwitch_featured(); //Run function on launch    
	
	//On Hover
	$(".image_reel_featured").hover(function() {
	    clearInterval(play_featured); //Stop the rotation
	}, function() {
	    rotateSwitch_featured(); //Resume rotation timer
	});	
	
	//On Click
	$(".paging_featured a").click(function() {
	    $active_featured = $(this); //Activate the clicked paging
	    //Reset Timer
	    clearInterval(play_featured); //Stop the rotation
	    rotate_featured(); //Trigger rotation immediately
	    rotateSwitch_featured(); // Resume rotation timer
	    return false; //Prevent browser jump to link anchor
	});
	
});
