var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

$(document).ready(function() {
  $('#menu-tabs > li').bind('mouseover', menu_open);
    $('#menu-tabs > li').bind('mouseout',  menu_timer);
	$(document).click(menu_close);
	
	$(document).find('#slideshow').cycle({ 
    fx:    'fade', 
    speed:  2500 
  });
	
	$(document).find('#bannerRotate').cycle({ 
    fx:    'cover',
		direction: 'down',
    speed:  500 ,
		timeout: 7000
  });
 
  $(document).find('.whats-new-slot:odd').css("background","#485340");
	
	$("#twitter_div a").attr("target","_blank");
});

function menu_open() {
  menu_canceltimer();
     menu_close();
     ddmenuitem = $(this).find('ul').width($(this).width()).show();
}
  
function menu_close() {
  if(ddmenuitem) {
	  ddmenuitem.hide();
	}
}
  
function menu_timer() {
  closetimer = setTimeout(menu_close, timeout);
}
  
function menu_canceltimer(){
  if(closetimer) {
    clearTimeout(closetimer);
      closetimer = null;
  }
}

function showLightbox() {
  $("body").append('<div id="lightbox"></div>');
	$("#lightbox").css({"width":$(document).width(),"height":$(document).height()}).show();
}

function closeLightbox() {
  $("#lightbox").remove();
}

function popImg(make,model) {

	var imgUrl = "images/" + make + "/" + make + "_" + model + "_z.jpg";
  	var x = screen.width/2 - 285;
  	var y = screen.height/2 - 175;

	imgWin = window.open("","imgWindow","width=570,height=350,resizable=no,srollbars=no,status=no,left="+x+",screenX="+x+",top="+y+",screenY="+y);
	imgWin.focus();
	imgWin.document.write("<html><head><title>Topanga Creek Bicycles</title></head><body bgcolor=#A7A7A7 topmargin=10 leftmargin=10 marginwidth=10 marginheight=10>");
	imgWin.document.write("<table border=0 cellpadding=0 cellspacing=0>");
	imgWin.document.write("<tr><td align=center>");
	imgWin.document.write("<img src=" + imgUrl + " border=0 width=550 height=330><br>");
	imgWin.document.write("<a href=javascript:window.close()><img src=images/main/close_window.gif border=0 width=70 height=10></a>");
	imgWin.document.write("</td></tr>");
	imgWin.document.write("</table>");
	imgWin.document.write("</body></html>");
	imgWin.document.close();
	
}

function enlgImg(path,model) {

	var imgUrl = "images/" + path + "/" + model + "-z.jpg";
  	var x = screen.width/2 - 285;
  	var y = screen.height/2 - 175;

	imgWin = window.open("","imgWindow","width=570,height=350,resizable=no,srollbars=no,status=no,left="+x+",screenX="+x+",top="+y+",screenY="+y);
	imgWin.focus();
	imgWin.document.write("<html><head><title>Topanga Creek Bicycles</title></head><body bgcolor=#A7A7A7 topmargin=10 leftmargin=10 marginwidth=10 marginheight=10>");
	imgWin.document.write("<table border=0 cellpadding=0 cellspacing=0>");
	imgWin.document.write("<tr><td align=center>");
	imgWin.document.write("<img src=" + imgUrl + " border=0 width=550 height=330><br>");
	imgWin.document.write("<a href=javascript:window.close()><img src=images/main/close_window.gif border=0 width=70 height=10></a>");
	imgWin.document.write("</td></tr>");
	imgWin.document.write("</table>");
	imgWin.document.write("</body></html>");
	imgWin.document.close();
	
}

function imgZoom(model) {
	  var imgUrl = "images/" + model;
  	var x = screen.width/2 - 285;
  	var y = screen.height/2 - 175;

	imgWin = window.open("","imgWindow","width=550,height=350,resizable=no,srollbars=no,left="+x+",screenX="+x+",top="+y+",screenY="+y);
	imgWin.focus();
	imgWin.document.write("<html><head><title>Topanga Creek Bicycles</title></head><body bgcolor=#A7A7A7 topmargin=10 leftmargin=10 marginwidth=10 marginheight=10>");
	imgWin.document.write("<table border=0 cellpadding=0 cellspacing=0>");
	imgWin.document.write("<tr><td align=center>");
	imgWin.document.write("<img src=" + imgUrl + " border=0 width=550 height=330><br>");
	imgWin.document.write("<a href=javascript:window.close()><img src=images/main/close_window.gif border=0 width=70 height=10></a>");
	imgWin.document.write("</td></tr>");
	imgWin.document.write("</table>");
	imgWin.document.write("</body></html>");
	imgWin.document.close();
	
}

function enlargeImg(pic) {

	  var imgUrl = "img_popup.php?images/shop/" + pic + "_z.jpg";
  	var x = screen.width/2 - 285;
  	var y = screen.height/2 - 200;

	imgWin = window.open(imgUrl,"imgWindow","width=550,height=350,resizable=yes,scrollbars=yes,left="+x+",screenX="+x+",top="+y+",screenY="+y);
	imgWin.focus();
	
}

function enlargeCustomImg(pic) {

	  var imgUrl = "img_popup.php?images/custom/" + pic + "_z.jpg";
  	var x = screen.width/2 - 285;
  	var y = screen.height/2 - 200;

	imgWin = window.open(imgUrl,"imgWindow","width=550,height=350,resizable=yes,scrollbars=yes,left="+x+",screenX="+x+",top="+y+",screenY="+y);
	imgWin.focus();
	
}
	
function resizeWindow() {

	var NS = (navigator.appName=="Netscape") ? true : false;
	
	iWidth = (NS) ? imgWin.window.innerWidth : imgWin.document.body.clientWidth; 
  iHeight = (NS) ? imgWin.window.innerHeight : imgWin.document.body.clientHeight; 
  iWidth = imgWin.document.images[0].width - iWidth; 
  iHeight = imgWin.document.images[0].height - iHeight; 
  imgWin.resizeBy(iWidth, iHeight); 
	
}

function checkData(form) {
	if (form.realname.value == "") {
		alert ("Please enter your name.");
		return false;
		}
	else if (form.email.value == "") {
		alert ("Please enter your e-mail address.");
		return false;
		}
	else if (form.comments.value == "") {
		alert ("Please fill out your comments.");
		return false;
		}
	else { return true; }
}
