   // Controls .js effects for right-hand nav and homepage multi-banners
   // Also handles powerreviews paging via AJAX


	// Sets speed of open/close in (25millisecond) steps.  Higher is slower.
	var speed = 10;
	var cnh = 0;
	var coh = 0;

	// Currently open Nav Box
	var opennav = "optinNav";
	var NavHeights = new Array();
		  NavHeights["optinNav"] = 80;
		  NavHeights["storeNav"] = 50;
		  NavHeights["helpNav"] = 50;

	// Sets open heights for proper calculation

	function openthis(selectednav){
		if(selectednav==opennav){
			return;
			}
		else{
			cnh = 0;
			nd = document.getElementById(selectednav);
			nh = NavHeights[selectednav];
			sd = document.getElementById(opennav);
			coh = sf = NavHeights[opennav];
			goswap(nd, nh, sd, sf);
			}
		};
	
	function goswap(nd, nh, sd, sf){
	if(cnh >= nh){
		nd.style.height = nh + 'px';
		sd.style.height = '0px';
		opennav = nd.id;
		return;
		}

	else{
		cnh = cnh + nh/speed;
		coh = coh - sf/speed;
		nd.style.height = cnh + 'px';
		sd.style.height = coh + 'px';
		t=setTimeout("goswap(nd, nh, sd, sf);",25);
		}
	};

	function createPrivacyWindow(){
			var xWin = window.open('/privacy/index.cfm','window2','height=450,width=700,scrollbars,resizable');
		};

	function createFlashCatalogWindow(){
		window.name = "catalogparent";
		var xWin = window.open("/flashcatalog/index.cfm","FlashCatalog","height=610,width=1050,scrollbars,resizable");
		};
	
	function createWhySignupWindow(){
		var xWin = window.open('/whysignup.cfm','window2','height=450,width=700,scrollbars,resizable');
		};

var chgspeed=10;
var currentopacity=100;
var swapdirection=1;
var defaultrotationspot = 1;
var protectauto = 0;
	function intRot()
		{
		olddiv = 'product'+defaultrotationspot;
		newrotspot = defaultrotationspot+1;
		newdiv = 'product'+newrotspot;
		protectauto = 1;
		defaultrotationspot=newrotspot;
		if(defaultrotationspot==5){
			defaultrotationspot=1;
			}
		swapmulti(olddiv,newdiv);
		};


	function startRotation(){autobot = setInterval("intRot()",4000);};
	

	function swapmulti(originaldiv, newdiv)
			{	
				if(newdiv=="product0"){newdiv="product4";}
				else if(newdiv=="product5"){newdiv="product1";}
				//top div is the old div, which will fade out
				//bottom div is the new div, which is merely covered up

				if(protectauto!=1){
				clearInterval(autobot);
				}
				protectauto=0;

				oldpos=originaldiv.charAt(7)*1;
				newpos=newdiv.charAt(7)*1;
				
				//if old one is behind, we'll fade the new one IN
				if(oldpos<newpos){
				staticdiv=document.getElementById(originaldiv);
				changingdiv=document.getElementById(newdiv);
				changingdiv.style.opacity = 0;
				changingdiv.style.filter = 'alpha(opacity='+(0)+')';
				changingdiv.style.visibility = "visible";
				currentopacity=0;
				swapdirection = 1;
				}
				
				//if new one is behind, we'll fade the old one OUT
				else{
				changingdiv=document.getElementById(originaldiv);
				staticdiv=document.getElementById(newdiv);
				staticdiv.style.opacity = 1;
				staticdiv.style.filter = 'alpha(opacity='+(100)+')';
				staticdiv.style.visibility = "visible";
				currentopacity=100;
				swapdirection = -1;
				}
				
				//now, start the fade
					fademulti(staticdiv,changingdiv,currentopacity,swapdirection);
			};


	function fademulti(stat,faded,opset,fadedir)
			{
				currentopacity = opset+(chgspeed*fadedir);
					faded.style.opacity = currentopacity/100;
					faded.style.filter = 'alpha(opacity='+currentopacity+')';
				a=stat;
				b=faded;
				c=fadedir;
				if (currentopacity<=0){
					faded.style.visibility="hidden";
					return;
					}
				else if(currentopacity>=100){
					stat.style.visibility="hidden";
					return;
					}
				t=setTimeout("fademulti(a, b, currentopacity, c);",20);
			};

//Determines the proper ajax method			
var request = false;
   try {
     request = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }  
     }
   }

   if (!request)
     alert("Error initializing XMLHttpRequest!");

//Why not just request2 = request?  because safari sucks.
var request2 = false;
   try {
     request2 = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       request2 = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request2 = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request2 = false;
       }  
     }
   }

   if (!request)
     alert("Error initializing XMLHttpRequest!");
	 
var getmainURL = "";
var thrutop = 0;

//Scrolls through reviews.  Updates reviews via Ajax and instantly updates x-x of x header/footer
function ajaxNextPage(prodID,sortBy,sortOrder,startNum,maxRev){
	// paste in animated throbber
	document.getElementById('ajaxReviewSpace').innerHTML = "<div style=\"text-align:center;border-bottom:1px solid #cccccc;\"><img src=\"/images/graphics/rotatingthingyOriginal.gif\" alt=\"Reviews are loading\" border=0 width=300 height=70 align=\"center\" style=\"padding:15px;\" /></div>";

	// set up ajax request
	getmainURL = 'http://www.step2.com/ajaxGrabReviews.cfm?id=' + prodID + '&sortby=' + sortBy + '&direction=' + sortOrder + '&startpoint=' + startNum + '&totalreviewsnum=' + maxRev;
	request.open("GET", getmainURL, true);
	request.onreadystatechange = updateRevs;
	request.send(null);

	if((startNum + 9) > maxRev){thrutop = maxRev;}
	else {thrutop = startNum + 9;}
	replaceTopNav = "<span class=\"prPageCount\">Displaying Reviews <strong>" + startNum + "-" + thrutop + "</strong> of " + maxRev + "</span><span class=\"prPageNav\">";
		 if(startNum > 10){
		 	replaceTopNav = replaceTopNav + "<a href=\"#ReviewHeader\" onclick=\"ajaxNextPage(" + prodID + ",'" + sortBy + "','" + sortOrder + "'," + (startNum - 10) + "," + maxRev + "); return false;\">&laquo; Previous</a>&nbsp;|&nbsp;";
			}
 		else {
			replaceTopNav = replaceTopNav + "Previous&nbsp;|&nbsp;";
			} 
		if((startNum + 10) < maxRev){
			replaceTopNav = replaceTopNav + "<a href=\"#ReviewHeader\" onclick=\"ajaxNextPage(" + prodID + ",'" + sortBy + "','" + sortOrder + "'," + (startNum + 10) + "," + maxRev + "); return false;\">Next &raquo;</a></span>";
			} 
		else {
			replaceTopNav = replaceTopNav + "Next</span>";
			}
	document.getElementById('ajaxTopNav').innerHTML = replaceTopNav;
	document.getElementById('ajaxBottomNav').innerHTML = replaceTopNav;	
	};

// When ajax data comes back, paste it into the website.
function updateRevs(){
		if (request.readyState == 4){
       if (request.status == 200){
			var response = request.responseText;
			document.getElementById('ajaxReviewSpace').innerHTML = response;
			}
		}

	};
	
// Handles the select box to sort reviews
function ajaxReviewSort(sortKey,prodID,maxRev){
	var midKey = "";
	if(sortKey=="date_new"){
		sB = "createddate";
		sO = "DESC";
		}
	else if (sortKey=="date_old"){
		sB = "createddate";
		sO = "ASC";
		}
	else if (sortKey=="rating_high"){
		sB = "rating";
		sO = "DESC";
		}
	else if (sortKey=="rating_low"){
		sB = "rating";
		sO = "ASC";
		}
	else if (sortKey=="helpful_high"){
		sB = "helpful_votes";
		sO = "DESC";
		}
	else if (sortKey=="helpful_low"){
		sB = "not_helpful_votes";
		sO = "DESC";
		}
	a=ajaxNextPage(prodID,sB,sO,1,maxRev);
	};

// Simultaneously occurs with PowerReviews.com vote to update our Database with a new Helpful/Not Helpful vote -- not anymore, since PR changes their .js and it's not worth trying to keep up.
// Also blurs our rating options.

function dbUpdate (reviewId,vote){
	voteURL = "http://www.step2.com/ajaxVote.cfm?globalID=" + reviewId + "&vote=" + vote;
		request2.open("GET", voteURL, true);
		request2.send(null);
	divtoClear = 'picRate' + reviewId;
	divtoClear2 = 'textRate' + reviewId;
	document.getElementById(divtoClear).innerHTML = "<span style='color:#cccccc;'>Thanks!</span>";
	document.getElementById(divtoClear2).style.display = "none";

	};