var show = new Array();
show['strollers']=0;
show['accessories']=0;
show['why']=0;
show['buy']=0;
show['community']=0;

function showMenu(object) {
 hideAll();
 show[object]=1;
 document.getElementById('dd_'+object).style.visibility='visible';
}

function hideMenu(object) {
 if (show[object]==0) {
  document.getElementById('dd_'+object).style.visibility='hidden';
 }
}

function preHide(object) {
 show[object]=0;
 setTimeout("hideMenu('"+object+"')",1000);
}

function hideAll() {
 show['strollers']=0;
 show['accessories']=0;
 show['why']=0;
 show['buy']=0;
 show['community']=0;
 hideMenu('strollers');
 hideMenu('accessories');
 hideMenu('why');
 hideMenu('buy');
 hideMenu('community');
}

var timer = null;
function sSize(pic) {
 clearTimeout(timer);
 properSize=0;
 for (i=0;i<pics.length;i++) {
  if (pic==i) {
   var targetHeight=120;
  } else if (i-1==pic || i+1==pic) {
   var targetHeight=105;
  } else {
   var targetHeight=90;
  }
  if (targetHeight+2>document.getElementById('p'+i).offsetHeight && targetHeight-2<document.getElementById('p'+i).offsetHeight) {
   document.getElementById('p'+i).style.height=targetHeight+"px";
   document.getElementById('p'+i).style.width=Math.round(pics[i]*targetHeight/120)+"px";
   properSize++;
  } else {
   document.getElementById('p'+i).style.height=(document.getElementById('p'+i).offsetHeight+(targetHeight-document.getElementById('p'+i).offsetHeight)/4)+"px";
   document.getElementById('p'+i).style.width=Math.round(pics[i]*document.getElementById('p'+i).offsetHeight/120)+"px";
  }
 }
 if (properSize<pics.length) {
  timer=setTimeout("sSize("+pic+")",100);
 }
}

function scalePics(e) {
 //get X position
 var mouseX = 0;
 if (!e) var e = window.event;
 if (e.pageX) {
  mouseX = e.pageX;
 } else if (e.clientX) {
  mouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
 }
 //figure out what it lines up with
 var tableLeft=findLeft(document.getElementById('table'));
 var acc_width=0;
 for (i=0;i<pics.length;i++) {
  acc_width+=pics[i];
  if (i>0)
   acc_width+=spacing;
  else
   acc_width+=Math.round(spacing/2);
  if (mouseX < tableLeft + acc_width) {
   sSize(i);
   break;
  }
 }
 if (mouseX > tableLeft + acc_width) {
  sSize(pics.length-1);
 }
}

function findLeft(obj) {
 var curleft = 0;
 if (obj.offsetParent) {
  do {
   curleft += obj.offsetLeft;
  } while (obj = obj.offsetParent);
 }
 return curleft;
}

function showLabel(pic,caption) {
 var p = document.getElementById('p'+pic);
 document.getElementById('label_txt').innerHTML=caption;
 label.style.top=(document.getElementById('table').offsetTop-20)+"px";
 label.style.left=Math.round(findLeft(p)+(p.offsetWidth/2)-label.offsetWidth/2)+"px";
 label.style.visibility="visible";
}

function hideLabel() {
 label.style.visibility="hidden";
}

function swapContent(current) {
 for (i=0;i<content.length;i++) {
  if (current==content[i]) {
   document.getElementById("div_"+content[i]).style.display='block';
   document.getElementById("arrow_"+content[i]).style.color='#000000';
  } else {
   document.getElementById("div_"+content[i]).style.display='none';
   document.getElementById("arrow_"+content[i]).style.color='#FFFFFF';
  }
 }
}

function swapColor(current) {
 document.getElementById('mainpic').style.backgroundImage='url(img/stroller-'+model+'-'+current+'.jpg)';
 return false;
}

function checkEmail(email) {
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.toLowerCase())) {
  return true;
 } else {
  return false;
 }
}
