
// TODO:  global side effects
var hitButton;
var xPosOfCarWidget;
var yPosOfCartWidget;

function dimmerOn(color) {
	var dimmer = document.getElementById("dimmer");
	// Adjust the size of the dimmer to the height of the page
	dimmer.style.height = getDocHeight();
	
	// Add the class to color the dimmer
	dimmer.className = color;
	
	// Turn on the dimmer
	dimmer.style.display = "block";
}

function dimmerOff(color) {
	// Kill the dimmer
	document.getElementById("dimmer").style.display = "none";
}

// Get the document height, for the dimmer
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function getWindowDimensions() {
  var myWidth = 0, myHeight = 0;
  var dims = new Array();
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  dims['x'] = myWidth;
  dims['y'] = myHeight;
  return dims;
}

/*-------------------------------------------------------------------------------------------------
loadChooser
-------------------------------------------------------------------------------------------------*/
function loadChooser(whichChooser, action, data, dropdownId, groupId, productName) {
	var doAjax = true;
	var triggerId = dropdownId + "_chooser";
	var currentDropdown = document.getElementById(dropdownId);
	
	// Make clicking the dimmer exit
	document.getElementById("dimmer-white").setAttribute("onclick", "closeChooser('" + dropdownId + "','" + action + "','" + productName + "')");
	
	if (action == 'launch') {
		if (currentDropdown.options[currentDropdown.selectedIndex].id === triggerId) {
	
			// We're going to need jQuery, so if it's not here, load it.
			if (typeof jQuery == 'undefined') {  
				var head = document.getElementsByTagName('head')[0];
				var script = document.createElement('script');
				script.type = 'text/javascript';
				script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js';
				head.appendChild(script);  
			}
			
	 		// Where is the dropdown located?
	 		var posX = findPosX(document.getElementById(dropdownId)) - 720;
	 		var posY = findPosY(document.getElementById(dropdownId)) - 77;
		
			// Move popup relative to dropdown
	 		document.getElementById("chooser").style.top  = posY + "px";
	 		document.getElementById("chooser").style.left = posX + "px";
			
			// Adjust the size of the dimmer to the height of the page
			document.getElementById("dimmer-white").style.height = getDocHeight();
			
			// Turn on the dimmer
			document.getElementById("dimmer-white").style.display = "block";
			
	 		// Turn on the popup
	 		document.getElementById("chooser").style.display = "block";
			
			window.scrollTo(0,posY-70);
			
			// Log chooser launch
			pageTracker._trackEvent('Product Chooser', 'Chooser Launched', productName);
			
		} else {
			doAjax = false;
		}
 	}

	if (doAjax) {
		// Do Ajax call
		params = new Array();
		params.push("action=" + action);
		params.push("smarts=" + data);
		params.push("dropdown=" + dropdownId);
		params.push("group=" + groupId);
		params.push("product_name=" + productName);
		ajaxMagic('/store/chooser/chooser_' + whichChooser + '.php',params,'loadChooser_results','','doNotFade','doNotLoad', delayDisableLinks());
	}
	
	
}

function closeChooser(dropdownId, action, productName) {
	if (action != "finish") {
		// Set the select back to the default
		$('#' + dropdownId + '  option:first').attr('selected', 'selected');
		
		// Log chooser close
		pageTracker._trackEvent('Product Chooser', 'Chooser Closed', productName + ' | After action : ' + action);
	}
	
	// Close the popup
	document.getElementById("chooser").style.display = "none";

	// Kill the dimmer
	document.getElementById("dimmer-white").style.display = "none";
	
	// Wipe the chooser content
	document.getElementById("loadChooser_results").innerHTML = '';
}

function pressChooserSkipButton(whichOne, state) {
	//console.log("Skip button pressed!");
	if(state == 0) {
		//console.log("Setting pressed bgimage");
		whichOne.style.backgroundImage = "url(/store/chooser/images/assets/chooser_skip_down.png)";
	} else {
		whichOne.style.backgroundImage = "url(/store/chooser/images/assets/chooser_skip_up.png)";
	}
}

function delayDisableLinks() {
	// This is rediculous, I know. :)
	// For potentially slow loading ajax responses, run a few times.
	disableLinks();
	setTimeout('disableLinks()', 500);
	setTimeout('disableLinks()', 1000);
	setTimeout('disableLinks()', 1500);
	setTimeout('disableLinks()', 2000);
	setTimeout('disableLinks()', 3000);
	setTimeout('disableLinks()', 4000);
	setTimeout('disableLinks()', 5000);
	
	// And one for good measure
	setTimeout('disableLinks()', 10000);
}

// This requires jquery, only call it if jquery has been loaded.
function disableLinks() {
	if (typeof jQuery != 'undefined') {
		$(".disable-href").click(function(e) {
			e.preventDefault();
		});
	}
}

/*-------------------------------------------------------------------------------------------------
armAnimation(productName)
Broken down to a series of steps that are called with setTimeouts / onCompletes
The setTimeouts are staggered to do the timing.. ex, three might get called in a 
row but one is after 50 ms, the next at 100 ms, the next at 150 ms, etc
Whenever there's actual movement we don't need the setTimeout frame delay, because
the movement itself does the timing. Movement is triggered in a step which has an onComplete calling the next step.
-------------------------------------------------------------------------------------------------*/
function armAnimation(productName) {

	// Tracks arm pull in Google Analytics event tracking
	pageTracker._trackEvent('Product Page', 'Clicked lever', productName);
	
	//	This is asynchronous version we should be using for events tracking, but our ga.js include isn't updated for it
	//	_gaq.push(['_trackEvent', 'Product Page', 'Clicked lever', productName]);
	
	var imgPath = "/store/awesomeness/images/armAnimation/";
	
	document.getElementById("lever").style.display    = "none";
	document.getElementById("leverHit").style.display = "block";
	
	// Where is the cart widget? We want arm to start just left of that
	xPosOfCartWidget = findPosX(document.getElementById("results_refreshCartWidget"));
	yPosOfCartWidget = findPosY(document.getElementById("results_refreshCartWidget"));
	document.getElementById("arm").style.top  = -280; // Reposition at top for when dev testing and replaying
	document.getElementById("arm").style.left = xPosOfCartWidget - 225;
	
	// Slide first arm down from out of page, onComplete go to step 2
	var attributes = {
        top: { to: -25 } // where
    };
    var anim = new YAHOO.util.Anim('arm', attributes);

  	anim.duration = .15; // speed
  	anim.onComplete.subscribe(function () {step1() });
	anim.animate();

}

function step1() {
	togglePngs("arm","001","002"); // Swap image immediately (blob)
	setTimeout('togglePngs("arm","002","003")',25); // Swap image 
	setTimeout('togglePngs("arm","003","004")',50); // Swap image again
	setTimeout('shift(-750); togglePngs("arm","004","005")',75); // Shift arm up because 005.png is the really long one
	setTimeout('step2()',100); // Go to the next step
}

function step2() {

	// Long arm moves up a little...
	var attributes = {
        top: { to: -775 }
    };
    var anim = new YAHOO.util.Anim('arm', attributes);
    
    anim.method = YAHOO.util.Easing.easeOut;
  	anim.duration = .15; 
  	anim.onComplete.subscribe(function () {step3() });
	anim.animate();
}

function step3() {

	// Long arm moves back down...
	var attributes = {
        top: { to: -600 }
    };
    var anim = new YAHOO.util.Anim('arm', attributes);
    
    anim.method = YAHOO.util.Easing.easeOut;
  	anim.duration = .15; 
  	anim.onComplete.subscribe(function () {step4() });
	anim.animate();
	
}

function step4() {

	// Switch to grab
	togglePngs("arm","005","006"); 
	
	// Slide page up
	setTimeout('scrollWindow(700)',300);
	
}


function step5() {
	
	// WRAP UP
	
	// Toggle the switch back
	document.getElementById("lever").style.display    = "block";
	document.getElementById("leverHit").style.display = "none";
	
	// Reset arm
	togglePngs("arm","006","001");
	
}


/* Helper functions for armAnimation(). Called from setTimeouts */
function slide(newTop,duration) {
	var slideMe = new Fx.Style("arm", 'top', {duration:duration});
	slideMe.start(newTop);
}

function shift(newTop) {
	document.getElementById("arm").style.top = newTop;
}




/*-------------------------------------------------------------------------------------------------
scrollWindow
-------------------------------------------------------------------------------------------------*/
function scrollWindow(yPosition) {
	var scrollWindowAnimation = new YAHOO.util.Scroll(document.body, { scroll: { to: [0, yPosition] } }, .5, YAHOO.util.Easing.easeNone);
	
	// Temp hack to make this do something specific when called from arm animation - fix
	if(yPosition == 700) scrollWindowAnimation.onComplete.subscribe(function () { step5() });
		
	scrollWindowAnimation.animate();
	
	
}




/*-------------------------------------------------------------------------------------------------
toggleFacebookPopup()
-------------------------------------------------------------------------------------------------*/
function toggleFacebookPopup(onOrOff) {

	// Only show it if they're not logged in
	if(document.getElementById("fbCookie") == "") {
		setTimeout("toggleDisplay(\"facebookConnect_popup\",1)", 500)
	}


}




/*-------------------------------------------------------------------------------------------------
yahoo curve animation
-------------------------------------------------------------------------------------------------*/
function curve(whichButton,qty) {

	// Only do this if the demo div isn't in the document...ie if another animation isn't running
	if(!document.getElementById("demo")) {

		// Set this global variable so we can reference it later in the replace1up function
		hitButton = whichButton;
		
		// Where exactly is our cart widget? This is where we throw the bubble
		xPosOfCarWidget = findPosX(document.getElementById("results_refreshCartWidget"));
		yPosOfCarWidget = findPosY(document.getElementById("results_refreshCartWidget"));
	
		// Is the x position of this add to cart button greater than the button thats before it? and on the same Y level
		thisButtonX 	= findPosX(document.getElementById("addToCart_" + whichButton));
		thisButtonY     = findPosY(document.getElementById("addToCart_" + whichButton));
		
		// LEFT OR RIGHT?
			// Where is the button positioned in relation to the cart widget? To the left or the right?
			controlX = thisButtonX - xPosOfCarWidget;
			
			// If buttons are stacked (ex. premium mailers) we want the top one to go left and the bottom one to go right
			// Get previous button x pos.
			previousButton = whichButton - 1;
			if(document.getElementById("addToCart_" + previousButton)) { // Only attempt to do this if there actually is a previous button
				previousButtonX = findPosX(document.getElementById("addToCart_" + previousButton));
			}
			else { // If there isn't just set it to 0
				previousButtonX = 0;
			}
			
			// Go Left - if buttonx is less than widget x and this button isn't lined up with the button above
		    //if(whichButton % 2 != 0) { 
			if(controlX < 0 && previousButtonX != thisButtonX) { 
				shakeDirection = 5;
				controlX = xPosOfCarWidget - 120; // Go left 120px from left side of cart
			}
			// Go Right
			else {
				shakeDirection = -5;
				controlX = xPosOfCarWidget + 120 + 120; // Go right 120px from right side of cart. Extra 120 is added because thats the width of the widget. so x + width = y
			}
	
		// The html we'll put in the new bubble
		var bubble = "<div style='position:absolute; z-index:0; left:35px; color:white; background-image:url(http://cdn.photojojo.net/store/awesomeness/images/oneUp.gif); width:30px; height:30px; margin-bottom:1em;'>";
		bubble 	  += "<div style='padding:2px; padding-top:4px; font-family:lucida grande; font-weight:800;'>+"+qty+"<\/div>";
		bubble    += "<\/div>";
		
		// Create our new bubble div
		var newBubble 		     = document.createElement("div");
		newBubble.id 		     = "demo";
		newBubble.style.zIndex   = 60;
		newBubble.style.position = "absolute";
		newBubble.style.width    = 99;
		newBubble.style.height   = 37;
		newBubble.style.top      = -37;
		newBubble.style.left     = 0;
		
		// Append new bubble div to the document / add to cart button
		whichAddToCart = document.getElementById("addToCart_" + whichButton);
		whichAddToCart.appendChild(newBubble);
		
		// Insert our html into this div we just created
		newBubble.innerHTML = bubble;
	
		var attributes = {
			points: { to: [xPosOfCarWidget, 40], control: [ [controlX, -120] ] }
		};
		
		// Setup animation object
		var anim = new YAHOO.util.Motion('demo', attributes);
		
		// Set duration
		anim.duration = .75; 
		
		// Set ease
		anim.method = YAHOO.util.Easing.easeOut;
		
		// Set onComplete function
		anim.onComplete.subscribe(function () {postCurveAction(qty)});
		
		// For every frame, see how close we are to the end so we know when to fire the shake
		anim.onTween.subscribe(function() { 
			
			// Shake between the windows of 175-150 frames before completion
			if(anim.currentFrame > anim.totalFrames - 175 && anim.currentFrame < anim.totalFrames - 150) {
				shake(shakeDirection);
			}
			 
		});
		
		// Move it!
		anim.animate();
		
	} // end demo div not existing

}




// ^^
/*-------------------------------------------------------------------------------------------------
postCurveAction()
after curve is done, fade out the 1up and refreshCartWidget()
-------------------------------------------------------------------------------------------------*/
function postCurveAction(qty) {

	// Fade out 1up
	var attributes = {  opacity: {from: 1, to: 0 }  }	
	var ani = new YAHOO.util.Anim('demo' , attributes, 0, YAHOO.util.Easing.easeNone);
	ani.onComplete.subscribe(replace1up);
	ani.animate(); 
	
	refreshCartWidget(qty);
	
}


// ^^
/*-------------------------------------------------------------------------------------------------
shake() shake the cart widget
-------------------------------------------------------------------------------------------------*/
function shake(shakeDirection) {

	// Where's the cart at this moment? 
	cartNowY = findPosY(document.getElementById("results_refreshCartWidget"));
	
	/// Only if the cart now is where it should be do we shake it
	if(cartNowY == yPosOfCarWidget) {
		var attributes = {
			points: { to: [xPosOfCarWidget, yPosOfCarWidget], control: [ [xPosOfCarWidget + shakeDirection ,yPosOfCarWidget + 5] ] }
		};
		var shake = new YAHOO.util.Motion('results_refreshCartWidget', attributes);
		shake.duration = .1; 
		shake.method = YAHOO.util.Easing.easeOut;
		shake.method = YAHOO.util.Easing.easeOut;				 
		shake.animate();
		
	}
	
	
}

// ^^
/*-------------------------------------------------------------------------------------------------
replace 1up
-------------------------------------------------------------------------------------------------*/
function replace1up() {
	whichAddToCart = document.getElementById("addToCart_" + hitButton);
	whichAddToCart.removeChild(document.getElementById('demo'));	
}




/*-------------------------------------------------
clearAllErrors
--------------------------------------------------*/
function clearAllErrors() {

	var arrayOfDivs = document.getElementsByTagName('div');
	
	for (var i = 0; i < arrayOfDivs.length; i++){
		if (arrayOfDivs[i].className == "errorTab"){
			arrayOfDivs[i].style.display = "none";
		}
	}

}




/*-------------------------------------------------
toggleStockMessage
--------------------------------------------------*/
function toggleStockMessage(buttonCounter) {
	
	var theDropdown = document.getElementById("selectOption_" + buttonCounter + "_input");
	var n           = theDropdown.selectedIndex;     		
	var optionId    = theDropdown[n].value;  

	// Grab the stock message from the hidden field which holds it
	stockMessage    = document.getElementById("stockMessageHolder_" + optionId).innerHTML;
	
	// Now put it in the div for line 0 (may be blank)
	document.getElementById("buttonStockMessageLine0_" + buttonCounter).innerHTML = stockMessage;
	
	// Turn off the "We'll letcha know" line in case it was on
	document.getElementById("buttonStockMessageLine2_" + buttonCounter).style.display = "none";
	
	// Determine whether to turn on line 1 (notify me link)
	blockOrNone = (stockMessage != "") ? "block" : "none";
	
	document.getElementById("buttonStockMessageLine1_" + buttonCounter).style.display = blockOrNone; 
	document.getElementById("buttonStockMessage_" + buttonCounter).style.display      = blockOrNone;

}




/*-------------------------------------------------
notifyMePopup
--------------------------------------------------*/
function notifyMePopup(optionIdOrDropdown,linkObj,buttonCounter) {
	
	// optionIdOrDropdown will be either the optionId number or something like "select_3" where three is the drop down id count
	
	// If it's just a number, then it's the optionId
	if(optionIdOrDropdown == parseInt(optionIdOrDropdown)) {
		var optionId = optionIdOrDropdown;
	}
	// Otherwise 
	else {		
		optionIdOrDropdown = optionIdOrDropdown.replace("select_", "");
		var theDropdown        = document.getElementById("selectOption_" + optionIdOrDropdown + "_input");
		var n                  = theDropdown.selectedIndex;     		
		var optionId           = theDropdown[n].value;  
	} 
	
	var popup = document.getElementById('notifyMePopup');
	
	// Find out where the notify link is 
	xPosLink = findPosX(linkObj);
	yPosLink = findPosY(linkObj);
	
	// Position and turn on the popup
	popup.style.display = "block";
	popup.style.left     = xPosLink - 281;
	popup.style.top      = yPosLink - 80;
	
	// Insert the sku in the hidden field
	document.getElementById("notifyOptionId_hidden").value = optionId;
	document.getElementById("buttonCounter_hidden").value  = buttonCounter;
		
}




/*-------------------------------------------------
submitNotifyMe
--------------------------------------------------*/
function submitNotifyMe() {

	// Variables
	var email         = document.getElementById("notifyEmail").value;
	var optionId      = document.getElementById("notifyOptionId_hidden").value;
	var buttonCounter = document.getElementById("buttonCounter_hidden").value;

	// Email test
	var filter=/^.+@.+\..{2,4}$/
	
	// Fail
	if (!filter.test(email) || email == "you@email.com") {
		document.getElementById("notifyEmail").style.backgroundImage = "url(/store/checkout/images/field-status-pink.jpg)";
	}
	// Pass
	else {
		// Clear the error background
		document.getElementById("notifyEmail").style.backgroundImage = "";
		
		// Close the popup
		document.getElementById('notifyMePopup').style.display = "none";
		
		// Turn on the "We'll letcha know" confirmation
		document.getElementById("buttonStockMessageLine2_" + buttonCounter).style.display = "block";
		
		// Turn off the nofity link
		document.getElementById("buttonStockMessageLine1_" + buttonCounter).style.display = "none";
		
		params     = new Array();i = 0;
		params[i]  = "action=submitNotifyMe"; i++;	
		params[i]  = "email=" + email; i++;
		params[i]  = "optionId=" + optionId; i++;
		putResults = "submitNotifyMe_results";	
		ajaxMagic('/store/awesomeness/product_ajax.php',params,putResults,'','doNotFade');
	}

}




/*-------------------------------------------------
pressAddToCart
Used on the onmousedown and onmouseup event attached
to the add to cart button. 1=up 0=down
--------------------------------------------------*/
function pressAddToCart(whichOne,state) {

	if(state == 0) {
		whichOne.src = '/store/awesomeness/images/addToCart_down.gif';
	}
	else {
		whichOne.src = '/store/awesomeness/images/addToCart.gif';
	}

}




/*-------------------------------------------------
addToCart
--------------------------------------------------*/
function addToCart(buttonCounter,optionId,qty,giftCert) {
	
	clearAllErrors();
	
	// If no optionId is passed we have to grab it from the select
	if(optionId == 0) {
		selectObj    = document.getElementById("selectOption_" + buttonCounter + "_input");
		var n        = selectObj.selectedIndex;     // Which menu item is selected
		var optionId = selectObj[n].value;          // Return string value of menu item
		
		// They haven't chosen an option
		if(n == 0 || optionId == "notAnOption") {
			// Throw error
			errorField("selectOption_" + buttonCounter,false,"You need to choose which one you'd like.",1,true);	
			return 0;
		}
	}
	
	
	// Add to cart or move on to check gift certificate function
	if(giftCert) {
		checkGiftCertificate(optionId,qty,buttonCounter);
	} 
	else {
		changeQuantity(optionId,"",qty,"product",buttonCounter); 
		window.scroll(0,0);
		curve(buttonCounter,qty);
	}
	
	// ensures the optimizely object is defined.
	window.optimizely = window.optimizely || [];
	// sends a tracking call to Optimizely for the given event name.
	// event name does not need to be 'pre-registered'
	window.optimizely.push(['trackEvent', 'Added to cart']);

}




/*-------------------------------------------------------------------------------------------------
checkGiftCertificate() 
-------------------------------------------------------------------------------------------------*/
function checkGiftCertificate(optionId,theqty,resultPosition) {
	
	// Innocent until proven guilty
	var pass = true;
	
	var toField   = document.getElementById("giftCertTo_input").value;
	var fromField = document.getElementById("giftCertFrom_input").value;
 
	// Make sure To: is filled out
	if(toField == "") {
	
		// Throw error
		errorField("giftCertTo",false,"Don't forget the lucky recipient's name!",1,false);
		
		// Guilty
		pass = false;
		 
	}
	// Make sure To: has only usable characters
	else if(englishOnlyChars(toField) != true) {
		// Throw error
		errorField("giftCertTo",false,"Only letters A-Z and numbers 1-9 please!",1,false);
		
		// Guilty
		pass = false;
	}
	else {
		errorField("giftCertTo",true);
	}
	
	// Make sure From: is filled out
	if(fromField == "") {
		
		// Throw error
		errorField("giftCertFrom",false,"Don't forget to take <br>credit for your gift!",1,false);
		
		// Guilty
		pass = false;
	}
	
	// Make sure From: has only usable characters
	else if(englishOnlyChars(fromField) != true) {
		// Throw error
		errorField("giftCertFrom",false,"Only letters A-Z and numbers 1-9 please!",1,false);
		
		// Guilty
		pass = false;
	}
	else {
		errorField("giftCertFrom",true);
	}
	
	
	// Did it pass all tests?
	if(pass == true) {
	
		// Throw a 1up
		curve(resultPosition,1);
		
		// Connect To and From as custom variable
		custom = document.getElementById("giftCertTo_input").value + "_" + document.getElementById("giftCertFrom_input").value;
		
		// Add to cart
		changeQuantity(optionId,custom,theqty,"product",resultPosition);
	
	}
	
}




/*-------------------------------------------------------------------------------------------------
englishOnlyChars(theValue)
THIS SAME FUNCTION IS IN checkout_functions.php
pass it a value and it'll return true if its english only, false if its not
-------------------------------------------------------------------------------------------------*/
function englishOnlyChars(stringToTest) {

	var matchString = new RegExp("[a-zA-Z0-9]");

	// Loop through each character in this string
	for(i=0; i < stringToTest.length; i++ ) {
	
		charToTest = stringToTest.charAt(i);
				
	     // If this char does not match our ascii chars, return false
		 if(!charToTest.match(matchString) && charToTest != " ") {
		 	//console.log("non ascii!:" + charToTest);
		 	return false;
		 }
	}
	
	// If we made it this far and didn't get any non-asciis, return true
	return true;

}




/*-------------------------------------------------------------------------------------------------
slideDiv()
Generic slid-o-div function
-------------------------------------------------------------------------------------------------*/
function slideDiv(whichDiv,direction,location) {
	var moveDiv = new Fx.Style($(whichDiv),
	direction, {duration: 300}).addEvent('onComplete', function() {
		//console.log("slide is complete");
	});
	moveDiv.start(location);
}

 

/*-------------------------------------------------------------------------------------------------
toggleTabs()
-------------------------------------------------------------------------------------------------*/
function toggleTabs(whichOne,howManyTabs) {

	// Turn this one's content on
	document.getElementById("tabContent_" + whichOne).style.display = "block";
	
	// Make sure its small tab version is off
	document.getElementById("smallTab_" + whichOne).style.display          = "none";
	
	// And its big tab version is on
	document.getElementById("bigTab_" + whichOne).style.display            = "block";
	
	// Turn the rest off
	for(var i = 0; i < howManyTabs; i++) {
		if(i != whichOne) {
			document.getElementById("tabContent_" + i).style.display = "none";
			document.getElementById("bigTab_" + i).style.display     = "none";
			document.getElementById("smallTab_" + i).style.display   = "block";
		}
	}

}






/*-------------------------------------------------------------------------------------------------
googleplus_promo_enter()
-------------------------------------------------------------------------------------------------*/
function googleplus_promo_enter() {
		
	// Position the errors
	var posX = findPosX(document.getElementById("googleplus_promo_email_input")); 
	var posY = findPosY(document.getElementById("googleplus_promo_email_input")); 
		
	posX = posX - 255;
	posY = posY - 3;

	// Grab the values
	var googleplus_promo_email = document.getElementById('googleplus_promo_email_input').value;

	params     = new Array();i = 0;
	params[i]  = "action=googleplus_promo_enter"; i++;		
	params[i]  = "googleplus_promo_email=" + googleplus_promo_email; i++;		
	putResults = "googleplus_promo_enter_results";	
	ajaxMagic('/store/awesomeness/product_ajax.php',params,putResults,'','doNotFade','doNotLoad', googleplus_close_slowly);

}



