
$(document).ready(function() {	

	//Show Banner
	$("#banner #headline").show(); //Show Banner
	$("#banner #headline").animate({opacity: 1.0}, 1 , function(){
        $(this).css('filter','');
   }); //Set Opacity
	$("#banner #thumbnails ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)

	//Click and Hover events for thumbnail list
 	// commented this line out so it doesnt highlight the first tab when the page loads $("#banner #thumbnails ul li:first").addClass('active');


rotater = setInterval( 'auto_rotate()', 6000 );


// this is for ie's benefit
$('#banner').delegate('#banner-image, .block' , 'click' , fix_ie_click );
$('#banner').delegate('.block' , 'hover' , fix_ie_hover );
//runs function on click

	$("#banner #thumbnails ul li").click(rotateSlider).hover(
      function(){
            stop_auto_rotate();
            $(this).addClass('hover');
      },
      function() {
                  restart_auto_rotate();
                  $(this).removeClass('hover');
      }
   );
	
	function rotateSlider(){

      
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL

		var imgDesc = $(this).find('.title').html(); 	//Get HTML of block
		var imgDescHeight = $("#banner").find('.block').height();	//Calculate height of block	

      var link = $(this).find('a').attr("rel");

		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			//Animate the Teaser		
			$("#banner #banner-image img").animate({opacity: 0}, 250 );
			$("#banner .block").animate({opacity: 0, marginBottom: -imgDescHeight}, 250 , function() {
				$("#banner .block").html(imgDesc).animate({opacity: 1.0, marginBottom: "0"}, 250 , function(){
                  $(this).css('filter','');
            });

            $('#banner-image a').attr('href', link);

				$("#banner #banner-image img").attr({src: imgTitle , alt: imgAlt}).animate({opacity: 1}, 250, function(){
                  $(this).css('filter','');
            });
			});
		}
		
		$("#banner #thumbnails ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;	
	}
	
	
	//Toggle Teaser
	$("a.collapse").click(function(){
		$("#banner .block").slideToggle();
		$("a.collapse").toggleClass("show");
	});
	
});

//Close Function

/**
 * auto_rotate
 */
function auto_rotate() {
    
    var number_of_slides = $('#thumbnails li').size();

    $current_thumbnail = $('#thumbnails .active');

    var current_pos = $current_thumbnail.index() + 1;

    // where are at the end so click the first one
    if( current_pos == number_of_slides )
         $('#thumbnails li:first').click();
    else
         $current_thumbnail.next().click();
}

/**
 * stop_auto_rotate
 */
function stop_auto_rotate() {
   clearInterval( rotater );
}

function restart_auto_rotate() {
   rotater = setInterval( 'auto_rotate()', 6000 );
}

/**
 * fix_ie_click
 */
function fix_ie_click() {

    $this = $('#thumbnails .active a');
    window.location = ( $this.attr('rel') );
}

/**
 * fix_ie_hover
 */
function fix_ie_hover( e ) {
   if (e.type == 'mouseover'){
      $(this).css('cursor','pointer');
   } else {
      $(this).css('cursor','auto');
   }

}
