$(document).ready(function() {
    
    var rotation_time = 10; //In seconds

	//Show Banner
	//$(".main_image .desc").show(); //Show Banner
	//$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity

	//Click and Hover events for thumbnail list
	$(".image_thumb ul li:first").addClass('active'); 
        
        rotate = function(){
        
        
            //Set Variables
            var imgAlt = $active.find('img').attr("alt"); //Get Alt Tag of Image
            var imgTitle = $active.find('span').attr("title"); //Get Main Image URL
            var imgDesc = $active.find('.block').find('.content').html(); 	//Get HTML of block
            var imgLink = $active.find('.block').find('.follow_link').html(); 	//Get link from block
            var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block
            
            $(".image_thumb ul li").removeClass('active'); //Remove all active class
            $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

            //Slider Animation
            
            //Animate the Teaser				
            $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 0 , function() {
                    //$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
                    $(".main_image img").attr({ src: imgTitle , alt: imgAlt});
                    $(".main_image a").attr("href",imgLink);
            });
        }; 

        //Rotation  and Timing Event
        rotateSwitch = function(time){
            play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
                $active = $('.image_thumb ul li.active').next(); //Move to the next paging
                if ( $active.length === 0) { //If paging reaches the end...
                    $active = $('.image_thumb ul li:first'); //go back to first
                }
                rotate(); //Trigger the paging and slider function
            }, time * 1000); //Timer speed in milliseconds (7 seconds)
        };

	
        //On Hover
        $(".image_thumb ul li").hover(function() {
            $(this).addClass('hover');
            clearInterval(play); //Stop the rotation
        }, function() {
            $(this).removeClass('hover');
            rotateSwitch(rotation_time); //Resume rotation timer
        });	
        
        $(".main_image").hover(function() {
            clearInterval(play); //Stop the rotation
        }, function() {
            rotateSwitch(rotation_time); //Resume rotation timer
        });	

	
        //On Hover
        $(".image_thumb ul li a img").hover(function() {
            clearInterval(play); //Stop the rotation
            
            $active = $(this).parent().parent(); //Activate the clicked paging
            //Reset Timer
            rotate(); //Trigger rotation immediately
            
        });	
     
	 
	  //tilføjelse rotate ved hover 20111103 AKR

	  $(".image_thumb ul li").hover(function() {
         clearInterval(play); //Stop the rotation
            $active = $(this); //Activate the clicked paging
            //Reset Timer
            rotate(); //Trigger rotation immediately
            //rotateSwitch(); // Resume rotation timer
            
        });	
		//akr end

        //On Click
        $(".image_thumb ul li").click(function() {
            clearInterval(play); //Stop the rotation
            $active = $(this); //Activate the clicked paging
            //Reset Timer
            rotate(); //Trigger rotation immediately
            //rotateSwitch(); // Resume rotation timer
        });
        
        rotateSwitch(rotation_time); //Run function on launch
        
});//Close Function
