var slides = getSlides(typeListArray);
jQuery(document).ready(function(){
	jQuery('#ecms_primeNav .navItem').hover(function() {
		jQuery(this).attr('id', 'hoverTab');
	},function(){
		jQuery('#hoverTab').attr('id', '');
	});
	
	/*=-=-=--==---Polaris Scripts--=-=-=-==-*/
	
	/* --- Show Active Units in header --- */
	for(var i = 0; i < typeListArray.length; i++){
		if($('.headerUnit'+typeListArray[i]).is('*')){
			$('.headerUnit'+typeListArray[i]).css('display', 'block');
		}
	}
	
	/* --- Index Slideshow --- */

	if($('#showcaseSlideShow').is('*')){
		$('#showcaseSlideShow').append('<div id="slideShowContainer"></div>');
		$('#slideShowContainer').hide();
		loadAnImage(slides);
	}	
	

});

function loadAnImage(){

		slides.slides.push(slides.slides[0]);
		slides.slides.shift();
					
		//Load next Promo image and wait until it loads to animate.
		var img = new Image();
      $(img).load(function () {

			if($('#slideShowContainer img').is('*')){
				$('#slideShowContainer img').fadeOut(500, function(){
					$('#slideShowContainer').empty();
					$('#slideShowContainer').hide();					
					$('#slideShowContainer').append('<a href="'+slides.slides[0].url+'"></a>');
					$('#slideShowContainer a').html(img);					
					$('#slideShowContainer').fadeIn(500);
				});				
				

			}
			else{
				$('#slideShowContainer').append('<a href="'+slides.slides[0].url+'"></a>');
				$('#slideShowContainer a').html(this);
				$('#slideShowContainer').fadeIn(600);
			}

			
			var timeout = window.setTimeout("loadAnImage()",8000);
		
       }).error(function () {
	       // notify the user that the image could not be loaded
       }).attr('src', skinPath+'images/slides/'+slides.slides[0].imageUrl);

}

	function getSlides(types){

	/*	
		1507 <!-- Snowmobile-->
		1787 <!-- Spyder-->
		1508 <!-- ATVs-->
		1510 <!-- PWC-->
		2717 <!-- SportBoat-->
	*/
	
	
	var mydata = {
		slides : [
		
			{
				typeId : "1508",
				imageUrl : "atv_1.jpg",
				url: "showcaseproductslist.htm?Brand=98&Type=1508"
			},
			{
				typeId : "1508",
				imageUrl : "atv_2.jpg",
				url: "showcaseproductslist.htm?Brand=98&Type=1508"
			},
			{						
				typeId : "1508",
				imageUrl : "atv_3.jpg",
				url: "showcaseproductslist.htm?Brand=98&Type=1508"
			},		
			{
				typeId : "1507",
				imageUrl : "snow_1.jpg",
				url: "showcaseproductslist.htm?Brand=178&Type=1507"
			},
			{
				typeId : "1507",
				imageUrl : "snow_2.jpg",
				url: "showcaseproductslist.htm?Brand=178&Type=1507"
			},
			{
				typeId : "1507",
				imageUrl : "snow_3.jpg",
				url: "showcaseproductslist.htm?Brand=178&Type=1507"
			},
			{
				typeId : "1507",
				imageUrl : "snow_4.jpg",
				url: "showcaseproductslist.htm?Brand=178&Type=1507"
			},			
			{
				typeId : "1510",
				imageUrl : "pwc_1.jpg",
				url: "showcaseproductslist.htm?Brand=176&Type=1510"
			},								
			{
				typeId : "1510",
				imageUrl : "pwc_2.jpg",
				url: "showcaseproductslist.htm?Brand=176&Type=1510"
			},								
			{
				typeId : "1787",
				imageUrl : "spyder_1.jpg",
				url: "showcaseproductslist.htm?Brand=98&Type=1787"
			},
			{
				typeId : "1787",
				imageUrl : "spyder_2.jpg",
				url: "showcaseproductslist.htm?Brand=98&Type=1787"
			},					
			{
				typeId : "2717",
				imageUrl : "sportboat_1.jpg",
				url: "showcaseproductslist.htm?Brand=173&Type=2717"
			},			
			{
				typeId : "2717",
				imageUrl : "sportboat_2.jpg",
				url: "showcaseproductslist.htm?Brand=173&Type=2717"
			}
		]
	};

	var filtered = {
		slides : []
	};
	
	for(var j = 0; j < types.length; j++){
		for(var i=0; i < mydata.slides.length; i++){ 
			if(mydata.slides[i].typeId == types[j]){
				filtered.slides.push(mydata.slides[i]);
			}
		}
	}
	
	filtered.slides.sort( randOrd );
		
	return filtered;
	
};
function randOrd(){
return (Math.round(Math.random())-0.5); }
