var STD_PLATFORM_PRODUCT_WIDTH = 221; //image is 220 + 1 for margin
var featuredPlatformProductsURL = '/webapp/wcs/stores/servlet/FSAJAXService?service=getProductsByCategoryIdentifier&URL=HomepageFeaturedPlatformProductsView&langId=' + getLangId() + '&storeId=' + getStoreId() + '&catalogId=' + getCatalogId();
var featuredPlatformProducts_localURL = '/AssetStore/WatchStation/_common/request/featuredPlatformProductsContent.php?store_name=WatchStation&store_directory=WatchStation&local_lang=en_US';
if(isDevelopment){ featuredPlatformProductsURL = featuredPlatformProducts_localURL; }

var boutique_JSON = {
	"boutique":[
		{
			"className" : "featureFirst",
			"linkWatch" : "/product/ZO8535P?departmentCategoryId=288189",
			"imagePath" : "/wcsstore/WatchStation/images/en_US/boutique/boutique_homepage.jpg",
			"header" : {
				"linkCollectionMens" : "/webapp/wcs/stores/servlet/CategoryView?NRec=&Nso=&departmentCategoryId=287583&catalogId=23503&categoryId=288130&N=0&langId=-1&parent_category_rn=288121&Ns=&storeId=34054",
				"linkCollectionWomens" : "/webapp/wcs/stores/servlet/CategoryView?NRec=&Nso=&departmentCategoryId=287584&catalogId=23503&categoryId=323592&N=0&langId=-1&parent_category_rn=288098&Ns=&storeId=34054",
				"linkStory":"http://journal.watchstation.com/iterations-of-color/",
				"featureTitle" : "Iterations of color",
				"featureIntro" : "Serious spring style starts with a shot of color"
			}
		},
		{
			"className" : "featureSecond",
			"linkWatch" : "/product/MK8233P?departmentCategoryId=288186",
			"imagePath" : "/wcsstore/WatchStation/images/en_US/boutique/boutique_homepage2.jpg",
			"header" : {
				"linkCollectionMens" : "",
				"linkCollectionWomens" : "",
				"linkStory":"http://journal.watchstation.com/iterations-of-color/",
				"featureTitle" : "Iterations of color",
				"featureIntro" : "Serious spring style starts with a shot of color"
			}
		},
		{
			"className" : "featureThird",
			"linkWatch" : "/product/DZ7234P?departmentCategoryId=288182",
			"imagePath" : "/wcsstore/WatchStation/images/en_US/boutique/boutique_homepage3.jpg",
			"header" : {
				"linkCollectionMens" : "",
				"linkCollectionWomens" : "",
				"linkStory" : "http://journal.watchstation.com/iterations-of-color/",
				"featureTitle" : "Iterations of color",
				"featureIntro" : "Serious spring style starts with a shot of color"
			}
		}/*,
		{
			"linkurl":"LINK NEEDED HERE",
			"imagepath":"/wcsstore/WatchStation/images/en_US/home/rotator/home_image3.jpg",
			"thumbpath":"/wcsstore/WatchStation/images/en_US/home/rotator/home_image3_t.jpg",
			"platformId":"FSSCMensHandbags",
			"heading":{
				"customClass":"secondRotator",
				"text":"Fossil-ize",
				"offsetLeft":"450px",         	
				"offsetTop":"220px",
				"subheadingText":"Shop and be timeless"
			}
		}*/
	]
}

$(document).ready( function() {
	//IE6 hack because it does not calculate width correctly
	//IE6 is less than 1% - michael d
	/*if ( $.browser.msie && $.browser.version == '6.0' ) {
		STD_PLATFORM_PRODUCT_WIDTH = 222;
	}*/
	
	//remove two parent divs that are unnecessary to get markup the way WSI needs it to be
	$('#homeRotatorControls').unwrap().unwrap();
	
	setupRotator();
	loadFeaturedWatches();
});

function setupRotator(){
	var boutique_html = "";
	var boutique_desc = "";
	
	for(var i = 0; i < boutique_JSON.boutique.length; i++){
		boutique_desc = "<div class='featureDesc'><h1 class='ir'>" + boutique_JSON.boutique[i].header.featureTitle + "</h1>"
				  + "<p class='intro ir'>" + boutique_JSON.boutique[i].header.featureIntro + "</p>"
				  + "<a class='ir shop' title='Shop Men&lsquo;s Collection' href='" + boutique_JSON.boutique[i].header.linkCollectionMens + "'>Shop Men's Collection</a>"
				  //+ "<a class='ir womens' title='Shop Women&lsquo;s Collection' href='" + boutique_JSON.boutique[i].header.linkCollectionWomens + "'>Shop Women's Collection</a><hr />"
				  + "<a class='ir read' title='Read the Story' href='" + boutique_JSON.boutique[i].header.linkStory + "'>Read the Story</a></div>";
		
		boutique_html += "<div class='fadeTabs'>" + boutique_desc + "<a class='watchImg' href='" + boutique_JSON.boutique[i].linkWatch + "'><img src='" + boutique_JSON.boutique[i].imagePath + "'/></a></div>";
	}
	
	$("body").prepend("<div id='homeRotator'><div class='imageWrapper'><div class='imageSlide' id='rotator'><div class='items'>" + boutique_html +"</div></div></div></div>");
	//$("#homeRotatorControls").html(boutique_desc);
	$("#contentBg").css("margin-top","0px");
	
	initRotator();
}

function initRotator(){
	/*$("#rotator").scrollable({
		vertical: false,
		circular: true,
		speed: 500,
		onBeforeSeek: function() { $("#rotator .items").fadeOut(300); },
		onSeek: function() { $("#rotator .items").fadeIn(250); }
	}).autoscroll({
		autoplay: true,
		interval: 4000
	});*/
	
	$("#fakeTabs").tabs(".fadeTabs", {
		effect: "fade",
		fadeOutSpeed: 500,
		fadeInSpeed: 500,
		rotate: true
	}).slideshow({
		autoplay: "true",
		interval: 4500
	});
	
}

function loadFeaturedWatches(){
	
	$('#featPlatformPrimaryHome .featPlatformViewPort').animate( {'opacity': 0}, 500, function() {
		$(this).parent().empty();
		
		$('#featPlatformPrimaryHome').load( featuredPlatformProductsURL + '&identifier=FSSCMensPlatformsColor', function() {
			//set the widths of the platform row divs
			var numOfMaxPlatformProducts = $(this).find('.scrollSectionRowOne>div').length;
			var maxPlatformRowWidth = numOfMaxPlatformProducts * STD_PLATFORM_PRODUCT_WIDTH;
			$(this).find('.scrollSectionRowOne, .scrollSectionRowTwo').css('width', maxPlatformRowWidth + 'px');
			
			$(this).find('.featPlatformViewPort')
				.jScrollPane( { horizontalDragMinWidth: 208, horizontalDragMaxWidth: 208 } )
				.css('opacity', 0).animate( {'opacity': 1}, 500, function() {
				
				$(this).find('.product').each( function() {
					//Get the product's unique id
					var itemId = $(this).find('.prodCompare').attr('id').substringAfterLast('_');
					var productSku = $(this).attr('id').substringAfterLast('_');
					
					//Add to Comparison
					$(this).find('.prodCompare a').click( function() {
						addToComparison( itemId );
						return false;
					});
					
					//product specific quicklook
					$(this).find('.prodQuicklook a').click( function() {
						openQuickLook( productSku );
						return false;
					});
				});
				
				// highlight compare icons
				highlightCompareIcon();
				
				isPlatformProductsDone = true;
			});
			
			if( numOfMaxPlatformProducts < 5 ) {
				$(this).find('.featScrollBar1').hide();
				$(this).find('.featPlatformViewPort').css('background', 'none');
			}
			else {
				$(this).find('.featScrollBar1').show();
			}
		});
	});
}
