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--=-=-=-==-*/
	
	
	/* --- 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){

	var mydata = {
		slides : [

			{
				typeId : "1786",
				imageUrl : "victory_greenbike.jpg",
				url: "showcaseproductslist.htm?Brand=37&Type=1786"
			},					{
				typeId : "1786",
				imageUrl : "victory_mountain.jpg",
				url: "showcaseproductslist.htm?Brand=37&Type=1786"
			},		
			{
				typeId : "1786",
				imageUrl : "victory_threebikes.jpg",
				url: "showcaseproductslist.htm?Brand=37&Type=1786"
			},				
			{
				typeId : "1786",
				imageUrl : "victory_twobikes.jpg",
				url: "showcaseproductslist.htm?Brand=37&Type=1786"
			},			
			{
				typeId : "1786",
				imageUrl : "victory_twobikesalley.jpg",
				url: "showcaseproductslist.htm?Brand=37&Type=1786"
			}				
		]
	};

	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); }
