/*
	Scripts for Adaptive Mall
	Copyright 2010 Fastpivot.com
*/

// Rotates the image for Kiddie Pool	
function swapPool() {
	
	jQuery("#rotatingImage").toggleClass("kpool");
	
	if (jQuery("#rotatingImage").hasClass("kpool")) {
		jQuery("#rotatingImage").attr("src", "http://lib.store.yahoo.net/lib/am/kiddiepool-left2.gif");
	} else {
		jQuery("#rotatingImage").attr("src", "http://lib.store.yahoo.net/lib/am/kiddiepool-left.gif");
	}
	
}

// Fixes Select Boxes
(function($){$.fn.fixSelect=function(minWidth){return(!($.browser.msie&&$.browser.version<9))?this:this.each(function(){if(this.tagName.toLowerCase()=='select'){var el=this,$this=$(this),minWidth=minWidth?minWidth:el.offsetWidth,elementWidth=$this.outerWidth(),$wrapper=$('<span class="selectFix"></span>').css({display:($this.css('display')=='block')?'block':'inline-block',cssFloat:$this.css('float'),overflowX:'hidden',overflowY:'visible',width:minWidth}),naturalWidth;$.each('marginTop marginRight marginBottom marginLeft'.split(' '),function(i,prop){$wrapper.css(prop,$this.css(prop));$this.css(prop,0);});if($this.is(':visible')){$this.width('auto');naturalWidth=$this.outerWidth();$this.width(minWidth);$this.wrap($wrapper).bind('mousedown keyup applyfix',function(){$this.width((naturalWidth<elementWidth)?minWidth:'auto');if($.browser.version==6)$this.css('marginLeft',1);}).blur(function(){$this.width(minWidth);if($.browser.version==6)$this.css('marginLeft',0);}).bind('initfix',function(){$this.width('auto');naturalWidth=$this.outerWidth();$this.width(minWidth);});}}});}})(jQuery);

// Ready Aim Fire
jQuery(document).ready(function(){

	// Quick Look on Section Pages
	jQuery("td.item").hover(  
		function () {
    		jQuery(this).addClass("hover");
  		},
  		function () {
    		jQuery(this).removeClass("hover");
  		}
	);
	
	// Jumps the page down and opens the Accessories Tab on Item Page
	jQuery('a#jumpAcc').click(function() {
		jQuery('ul.tabs li:last a').trigger('click');
		jQuery('html, body').animate({scrollTop: '515px'}, 300);
		return false;
	});
	
	// On the BRANDS section pages, it will show/hide the sub-categories
	jQuery(".showSub").click(function() {
		jQuery(this).parent().parent().parent().find(".subHolder").toggleClass("showme");
		jQuery(this).toggleClass("greenicon");
		return false;
	});
	
	// Adds border to the last footer table cell to remove the border
	jQuery(".footerInner table td:last").addClass("noborder");
	
	// Creates the top nav flyout
	jQuery(".mainNav li").hover(
	    function() {
	        jQuery(this).find("ul.sub").addClass("showme");
	        jQuery(this).addClass("hover");
	    }, function() {
	        jQuery(this).find("ul.sub").removeClass("showme");
	        jQuery(this).removeClass("hover");
	});	
	
	// Rotates the image for Kiddie Pool
	window.setInterval("swapPool()", 2000);  
		
	// Fixes Select Boxes	
	jQuery(".piOptions select").fixSelect([145]);

	// For Item Page Price Change 
	// Get and Manipulate Original Price
	var orig = jQuery('#fcPrice').text(); // store original
	var oprice = orig.replace(/\$/, ""); // removeing the dollar sign
	var mprice = oprice.replace(",", ""); // remove comma if larger than 999
	var price = parseFloat(mprice); // converting this to a number
	
	function addCommas(nStr) {
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
	
	
	jQuery('.piOptions select').change(function(){
	
		// Reset Price In Case none Selected
		jQuery('#fcPrice').empty();
		jQuery('#fcPrice').text(orig);	
		
		var temp = null;
		var finalPrice = null;
		
		
		$('.piOptions select').each(function(){			
			var thisVal = $(this).val();
			var patt = /\+/;
			var hasPlus = patt.test(thisVal);
			
			
			if(hasPlus) {
	
				// Gather Addition
				var uVal = thisVal.replace(/.*\(\+/, "").replace(/\)/, ""); // Regex to remove the paren and plus
				var addi = parseFloat(uVal); // Making our value a number
				
				// Createing and Adding New Price
				if(temp){
					fprice = temp + addi; // addition of two numbers		
				} else {
					fprice = price + addi; // addition of two numbers			
				}
						
				temp = fprice;		
						
				finalPrice = fprice;		
				
					
			}			
		});
	
		if(finalPrice != null){
			finalPrice = "$" + finalPrice.toFixed(2); // replacing the dollar sign and fixing the decimil place
			finalPrice = addCommas(finalPrice);
			
			jQuery('#fcPrice').hide();
			jQuery('#fcPrice').text(finalPrice); // show the price again.	
			jQuery('#fcPrice').fadeIn();
		}
	
	});






});


function toggleRowColor(obj, x) {
	var rowID = "multiadd_row" + x;
	if(obj.checked) { 
		document.getElementById(rowID).className="purplebg"; }
	else { 
		document.getElementById(rowID).className = "";  
	}
}

function moreInfo(divID) {
	document.getElementById(divID).className = "multiaddInfoFront";
}
function hideMoreInfo(divID) {
	document.getElementById(divID).className = "multiaddInfoBack";
}



