/******************************
*
* Javascript for www.scootersfriends.com
*
* @date: 2007-0606
*
* some code may be borrowed or heavily inspired by Jeremy Keith's DOM Scripting (2005) from Friends of Ed.
*
*********************************/


/* custom stuff */



/* function to handle thumbnails replacing main image in portfolio/project.php */
function prep_thumbLinks(){
	if(!document.getElementsByTagName || !document.getElementById){
		return false;
	}
	if(document.getElementById("pdBigImage")){
		var bullseye = document.getElementById("pdBigImage");
		if(document.getElementById("productViews")){
			var box = document.getElementById("productViews");
			var links = box.getElementsByTagName("a");
			for (var i=0; i<links.length; i++){
				links[i].onclick = function(){
					//alert("click");
					
					bullseye.src = "../i/products/full/" + this.firstChild.src.substring(this.firstChild.src.lastIndexOf("/"));
					
				}
			}
		}
	}
}
addLoadEvent(prep_thumbLinks);


//function to resize container on the /portfolio/index.php page 
function resizeContainer(){
	if(document.getElementById("productNav")){
		var frame = document.getElementById("productNav");
		var maxHeight = frame.height;
		maxHeight = maxHeight + 20; // extra height to make all browsers happy
		//var maxHeight = document.body.parentNode.scrollHeight;
		//var frame2 = document.getElementById("container");
		//frame2.style.height = maxHeight + "px";
		frame.style.height = maxHeight + 20 + "px";
	}
}
addLoadEvent(resizeContainer);



/* global resources */

/* function to simply multiple functions in window.onload
* DOM Scripting (103) :: Simon Willison (http://simon.incution.com) */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}
	else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}


/* generic popup window function to act as an interface to window.open() 
* DOM Scripting (88) */
function popUp(winURL, title, w, h){
	d = "width=" + w + ",height=" + h;
	window.open(winURL, title, d);
}


/* javascript to preload the full-size images on the portfolio/project.php pages * takes 4 image arguments to correspond to the 4 possible images in the portfolio */
function portfolioPreloader(img1, img2, img3, img4) {
	var i = 0;
	
	imageObj = new Image();
	
	//set image list
	images = new Array();
	images[0] = img1;
	images[1] = img2;
	images[2] = img3;
	images[3] = img4;
	
	// start preloading
	for(i = 0; i<=3; i++) {
		imageObj.src=images[i];
	}
}




function bbopenpopup(popurl){
var winpops=window.open(popurl,"","width=566,height=370")
}

function bbCatCheck(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable && pair[1] == 4) {
	  var title_div = document.getElementById('ctl00_ContentPlaceHolder1_antProductTitle');
	  var link_div = document.getElementById('bblink');
	  if (title_div.innerHTML == "\"Binth Baby Book\"") {
		  link_div.innerHTML = " &nbsp; <a style=\"color:#C2CD23;font-size:11px;font-family:Arial, Helvetica, sans-serif;\" href=\"javascript:bbopenpopup('babybook1.html')\"><div onMouseDown=\"bbopenpopup('babybook1.html')\">view inside pages</div></a>"
	  }else {
		  link_div.innerHTML = "";
	  }
	}
  } 
}





function openCloseSection(which){
	var selectedDiv = document.getElementById(which);
	
	if(selectedDiv.style.display != 'block'){
		selectedDiv.style.display = 'block';
	} else {
		selectedDiv.style.display = 'none';
	}
}



function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable && pair[1] == 'true') {
      //return pair[1];
    	
	}
  } 
}


function maintainRetailer(which,theXMLPath,theName){
	
	var theDivToChange = document.getElementById(which);

	//this only happens the first time a button is clicked----->
	try{eval(thePrevDivThatChanged);}
	catch(e) {
		thePrevDivThatChanged = document.getElementById(which);
		thePrevToWhat = which;
		thePrevThePath = theXMLPath;
		thePrevTheName = theName;
	}
	//------------------------>
	
	theDivToChange.innerHTML = "<div class=\"tertiaryLink_selected\"><a href=\"javascript:;\" onclick=\"chooseRetailer('"+theXMLPath+"');maintainRetailer('"+which+"','"+theXMLPath+"','"+theName+"');\">"+theName+"</a></div>";
	if (theDivToChange != thePrevDivThatChanged) {
		thePrevDivThatChanged.innerHTML = "<div class=\"tertiaryLink\"><a href=\"javascript:;\" onclick=\"chooseRetailer('"+thePrevThePath+"');maintainRetailer('"+thePrevToWhat+"','"+thePrevThePath+"','"+thePrevTheName+"');\">"+thePrevTheName+"</a></div>";
		thePrevDivThatChanged = document.getElementById(which);
		thePrevToWhat = which;
		thePrevThePath = theXMLPath;
		thePrevTheName = theName;
	}else {
	}
	
	
}





function switchPress(which){
	
	
	var theDivToChange = document.getElementById(which);

	//this only happens the first time a button is clicked----->
	try{eval(thePrevDivThatChanged);}
	catch(e) {
		thePrevDivThatChanged = document.getElementById(which);
	}
	//------------------------>
	
	theDivToChange.style.display = 'block';
	if (theDivToChange != thePrevDivThatChanged) {
		thePrevDivThatChanged.style.display = 'none'; 
		thePrevDivThatChanged = document.getElementById(which);
	}else {
	}
	
	
}
