
function heroPanel(){
	var maxItems = 5;
	var rotationTime = 8; // time in seconds
	var maxChars = 100; //max number of words appear in the summary
	var currentHeroIndex = 0;
	var heroElements = $('#heroPanel .heroPanelNav .hero');
	var heroMiniElements = $('#heroPanel .heroPanelNav .heroMini');
	var heroImages = $('#heroPanel .heroPanelContent .herooptL');
	var arrow = $('.selectedArrow');
	var arrowYPos = 0;
	var heroHeight = $('.hero').height();
	var heroMiniHeight = $('.heroMini').height();
	var timer;
	var pre;
	
	heroPanelInit();
	performRotation();
	setTimer();
	
	$('.hero, .heroPanelContent').mouseover(function() {
		window.clearInterval(timer);
	});
	
	$('.hero, .heroPanelContent').mouseout(function() {
		setTimer();
	});
	
	$('.heroMini').click(function(){
		
		var clickedId = $(this);
						$.each( heroImages, function(i, l){
				$(heroImages[i]).hide();
				});
		$.each( heroMiniElements, function(i, l){
			if($(this).attr("id") == $(clickedId).attr("id")){
				currentHeroIndex = i;
				$(heroImages[i]).show();
				performRotation();		
			}
		});
		
		return false;
	});
	
	
	function heroPanelInit(){
		$(heroMiniElements[0]).css("display","block");
		$(heroMiniElements[0]).hide();
		
		//bind the links to the arrow
		$.each( arrow, function(i, l){
			$(this).click(function(){
				var link = $(heroImages[i]).attr("href");
				//window.location.replace(link);
			});
		});
		
		

	}
	
	//update the hero panel after a set interval
	function performRotation(){

		$.each( heroElements, function(i, l){
		$(".heroarrow"+(i+1)).css("display","none");
			if(currentHeroIndex == i){
				
				arrowYPos = (currentHeroIndex * heroMiniHeight) + heroHeight/2 - $(arrow).height()/2;
				$(".heroarrow"+(i+1)).css("display","block");
				$(".heroarrow"+(i+1)).animate({"left": -20}, "fast");
				$(heroElements[i]).slideDown("fast");
				$(heroMiniElements[i]).slideUp("fast");	
				
			}else{
				$(".heroarrow"+(i+1)).animate({"left": 0}, "fast");
				$(".heroarrow"+(i+1)).css("display","none");
				$(heroElements[i]).slideUp("fast");
				$(heroMiniElements[i]).slideDown("fast");
			}
			
		});
		
		if(pre == null){
			pre = heroImages[0];
			$(pre).show();
		}else{
		$(pre).hide();
		if ($.browser.msie) {
		    $(heroImages[currentHeroIndex]).show();
		}
		else {
		    $(heroImages[currentHeroIndex]).fadeIn(100);
		}
			
			pre = heroImages[currentHeroIndex];
		}
		currentHeroIndex++;
		if(currentHeroIndex == maxItems){ currentHeroIndex = 0; }
	}
	
	function setTimer(){
		timer = window.setInterval(function() {
			performRotation();
		}, rotationTime * 1000);
	}
}
