//3dCart specific additions and client settings

//Namespace for all 4-Tell code
(function( _4TellBoost, $, undefined ) {

	//Client settings
	_4TellBoost.SiteInfo = new _4TellBoost.Site({
		baseURL:'www.thewatchprince.com',
		alias: 'WatchPri',
		GA_UA: '', //supplying UA number here will override the tracking type
		GATrackingType: '_gaq', //valid types are 'none', 'pageTracker', '_gaq'
		GATrackID: '4TellRecs',
		rotateTopSellers: true,
		showLogo: true,
		addCartMethod: '3dCartQuickCart', //valid methods: '3dCartQuickCart', '3dCartMoreDetails'
		addCartBtnAtts: "input type='button' value='Add to Cart' class='btn' onmouseout=this.className='btn' onmouseover=this.className='btn_over'", 
		//addCartBtnAtts: "img alt='Add to Cart'",
		addCartImage: '', //'assets/images/add-cart.png', //'assets/images/buy.gif', //use '' if type=button
		salePricePre: "<span class='price-info'>On Sale: </span><span class='price'>",
		salePricePost: '</span>',
		showRatings: true,
		includeBase: false
	});


	// Page Settings
	// Defaults	
	var tout1 = {
		orientation: 'vertical',
 		newDivID: 'main4TellContainer',
 		divSelect: '#main4TellContainer', // if class use '.' -- if id use '#'
 		divPosition: 'append', //valid settings are 'append', 'replace', 'above', or 'below'
 		showCaption: true,
		captionStyle: 'menu-headers product4TCaption',
		productStyle: 'product4T',
		imageSize: "&maxx=100&maxy=100",
		showBuyButton: true,
 		wrapper: ''
	}; 
	var tout2 = {
		orientation: 'horizontal',
 		newDivID: 'second4TellContainer',
 		divSelect: '#second4TellContainer', // if class use '.' -- if id use '#'
 		divPosition: 'append', //valid settings are 'append', 'replace', 'above', or 'below'
 		showCaption: true,
		captionStyle: 'titles product4TCaption2',
		productStyle: 'product4T product4T2',
		imageSize: "&maxx=100&maxy=100",
		showBuyButton: true,		
 		wrapper: ''
	}; 
	

	_4TellBoost.getPageSettings = function(pageType) {
		var inCart = false;
		
		// These are the tout settings for different pages of the site. 
		// You may add or remove page types here to match your site architecture.
		// Any settings not specified here will use the default values listed above
		switch (pageType) {
			case 'Home': //home page
				tout1.enable = false;
				tout1.resultType = 4; //Top-sellers
				tout1.numItems = 2;
				if (_4TellBoost.SiteInfo.rotateTopSellers) {
					var d = new Date();	
					tout1.startPos = d.getDay() + 1; //roatate start position by day of week
				}
				tout1.caption = 'Top Sellers';
				tout1.captionStyle = 'menu-headers product4TCaption';
				tout2.enable = false;
				break;		
			case 'ProductDetail': //product detail page (PDP)
				tout1.enable = true;
				tout1.resultType = 0; //Cross-sell
				tout1.numItems = 3;
				tout1.caption = 'Our customers also bought...';
				tout1.divSelect = '#Table8' ;
				tout1.divPosition = "replace";
				tout2.enable = true;
				tout2.resultType = 3; //Similar
				tout2.numItems = 4;
				tout2.caption = 'Similar items...';
				break;		
			case 'Category': //category landing page 
				tout1.enable = true;
				tout1.divSelect = '#Table8' ;
				tout1.divPosition = "replace";				
				tout1.resultType = 3; //Similar
				tout1.numItems = 3;
				tout1.caption = 'Related top sellers...';
				tout2.enable = false;
				break;
			case 'Search': //search results page 
				tout1.enable = false;
				tout1.resultType = 0; //Cross-sell
				tout1.numItems = 3;
				tout1.caption = 'You may also like...';
				tout2.enable = false;
				break;		
			case 'ViewCart': //intermediate add to cart page
				tout1.enable = false;
				tout2.enable = true;
				tout2.resultType = 0; //Cross-sell
				tout2.numItems = 4;
				tout2.caption = 'You may also like...';
				tout2.captionStyle = 'checkout-headers product4TCaption';
				tout2.productStyle = 'product4T product4TSmall';
				inCart = true;
				break;
			case 'ViewCartQuick': //intermediate add to cart page
				tout1.enable = false;
				tout2.enable = false;
				tout2.resultType = 0; //Cross-sell
				tout2.numItems = 4;
				tout2.caption = 'You may also like...';
				tout2.captionStyle = 'checkout-headers product4TCaption';
				tout2.productStyle = 'product4T product4T2';
				inCart = true;
				break;
			case 'QuickView': //product view pop-up
				tout1.enable = false;
				tout2.enable = false;
				tout2.resultType = 0; //Cross-sell
				tout2.numItems = 4;
				tout2.showCaption = false;
				tout2.productStyle = 'product4T product4TSmall';
				tout2.imageSize = "&maxx=100&maxy=80";
				tout2.showBuyButton = false;
				_4TellBoost.DelayHandler.toutDiv = '#second4TellContainer';
				delayToGetItems();
				inCart = false;
				break;
			case 'OrderShipping': //intermediate add to cart page
				tout1.enable = false;
				tout2.enable = false;
				tout2.resultType = 0; //Cross-sell
				tout2.numItems = 5;
				tout2.startPos = 1 + tout2.numItems; //second block
				tout2.caption = 'You may also like...';
				tout2.captionStyle = 'checkout-headers product4TCaption';
				inCart = true;
				break;
			case 'OrderPayment': //payment options page
				tout1.enable = false;
				tout2.enable = false;
				tout2.resultType = 2; //Blended
				tout2.numItems = 5;
				tout2.caption = 'You may also like...';
				tout2.captionStyle = 'checkout-headers product4TCaption';
				inCart = true;
				break;
			case 'OrderConfirm': //order confirmation page
				tout1.enable = false;
				tout2.enable = false;
				tout2.resultType = 2; //Blended
				tout2.numItems = 5;
				tout2.startPos = 1 + tout2.numItems; //second block
				tout2.caption = 'You may also like...';
				tout2.captionStyle = 'checkout-headers product4TCaption';
				inCart = true;
				break;
			case 'OrderComplete': //checkout complete page
				tout1.enable = false;
				tout2.enable = false;
				tout2.resultType = 2; //Blended
				tout2.numItems = 5;
				tout2.startPos = 1 + (2 * tout2.numItems); //second block
				tout2.caption = 'You may also like...';
				tout2.captionStyle = 'checkout-headers product4TCaption';
				break;
			default: //any page not listed
				tout1.enable = false;
				tout1.resultType = 2; //Blended
				tout1.numItems = 3;
				tout1.caption = 'You may also like...';
				tout2.enable = false;
				break;
		}
		//update public variables with the new settings
		$.extend(_4TellBoost.FirstTout, tout1);
		$.extend(_4TellBoost.SecondTout, tout2);
		
		//setup toutType for GA tracking
		_4TellBoost.FirstTout.setToutType(pageType);
		_4TellBoost.SecondTout.setToutType(pageType);		
		
		return inCart;
	};

	_4TellBoost.getRatingImage = function(rating) {
		var rateVal = parseFloat(rating);
		if (isNaN(rateVal)) return ''; //not a number
		
		var imagePath = '';
		if (rateVal < 1) 
			imagePath = 'assets/templates/common/images/star0.png';
		else if (rateVal < 2) 
			imagePath = 'assets/templates/common/images/star1.png';
		else if (rateVal < 3) 
			imagePath = 'assets/templates/common/images/star2.png';
		else if (rateVal < 4) 
			imagePath = 'assets/templates/common/images/star3.png';
		else if (rateVal < 5) 
			imagePath = 'assets/templates/common/images/star4.png';
		else //max 5 stars
			imagePath = 'assets/templates/common/images/star5.png';

		return imagePath;
	}; 
	
	function delayToGetItems() { //use in page settings above to delay for third-party results to load
		var delayContainer = $('#tablist');
		if (!delayContainer) return;
		
		//ananomous call-back funtion is called after delayed container changes
		_4TellBoost.DelayHandler.callback = function() {
			var toutDiv = $(_4TellBoost.DelayHandler.toutDiv);
			if (!toutDiv || !(toutDiv.length)) //see if the toutDiv is visible
				_4TellBoost.DelayHandler.ended = false;			
		};
		_4TellBoost.SiteInfo.delay = true;
		_4TellBoost.delayUntilLoaded(delayContainer);
	};


}( window._4TellBoost = window._4TellBoost || {}, jQuery )); 
//self-invoked namespace that protects $ and undefined internally


