function better_mouseout(e, el, func) {
// This function will test if the mouse has truly left the enclosing div.
// e - event, el - passing div, func - thing to act on.
  if (!e) e = window.event;  
  if (!e) return;  
  if (el.nodeName != 'DIV') return;  
  var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;  
  while (reltg && reltg != el && reltg.nodeName != 'BODY')  
    reltg = reltg.parentNode  
  if (reltg == el) return;  

  // mouse has left the premises  
  $('.pop').removeClass("popshow");
  $('#explore').removeClass("explorefix");
}
function goToPage(value) {
	if(value != '') {
		 window.location = value;
	}
}
//image rotation logic
var pic1="#gcimg1";
function setfade1(){
	$(pic1).fadeOut('slow')
	if (pic1=="#gcimg1") {pic1="#gcimg2"}
	else if (pic1=="#gcimg2") {pic1="#gcimg3"}
	else if (pic1=="#gcimg3") {pic1="#gcimg1"}
	$(pic1).fadeIn('slow')
}
var pic2="#cimage1";
function setfade2(){
	$(pic2).fadeOut('slow')
	if (pic2=="#cimage1") {pic2="#cimage2"}
	else if (pic2=="#cimage2") {pic2="#cimage3"}
	else if (pic2=="#cimage3") {pic2="#cimage4"}
	else if (pic2=="#cimage4") {pic2="#cimage5"}
	else if (pic2=="#cimage5") {pic2="#cimage6"}
	else if (pic2=="#cimage6") {pic2="#cimage7"}
	else if (pic2=="#cimage7") {pic2="#cimage8"}
	else if (pic2=="#cimage8") {pic2="#cimage9"}
	else if (pic2=="#cimage9") {pic2="#cimage1"}
	$(pic2).fadeIn('slow')
}

var heading = "";
// start of ready functions
jQuery().ready(function(){
	function format_item(theItem) {
		if (theItem[2] == ''){
			return "<img src='/images/dot.gif' width='48px' height='16px'>" + theItem[0];
		} else {
			return "<img src=" + theItem[2]+" width='48px' height='48px'> " + theItem[0];
		}
	}

	function format_result(theItem) {
		return;
	}

	$("#suggest").autocomplete("/pages/search/querymult.php", {
		selectFirst:false,
		formatItem: format_item,
		formatResult: format_result,
		width: 300,
		scroll:false
	}).result(function(event, data, formatted) {
		window.location=data[1];
	});


	$("#suggest").val("  SEARCH");
	$("#email").val("ENTER YOUR E-MAIL ADDRESS");
	$("#contain1").hover(function(){$('#rollover1').fadeIn('fast')},function(){$('#rollover1').slideUp('fast')});
	$("#contain2").hover(function(){$('#rollover2').fadeIn('fast')},function(){$('#rollover2').slideUp('fast')});
	$("#contain3").hover(function(){$('#rollover3').fadeIn('fast')},function(){$('#rollover3').slideUp('fast')});
	$(".rechover").hover(function(){$(this).addClass("rechovering");},function(){$(this).removeClass("rechovering");});

//catering order page
	$(".menugroup").hide();
	$("#menupage .or24px").hide();
	window.setTimeout(function(){$(".selector").show();},10);
	$("#theselect").change(function(){
		$("#theselect option:selected").each(function(){
			var selector = "#"+$(this).attr("value");
			$(".menugroup").hide();
			$(selector).show();
		});
	}).trigger('change');

	$(".or24px").click(function(){$(".menugroup").hide();$(this).next().show();});
	$("#contactprompt").text("Continue").addClass("contactpromptjs");
	$("#contactprompt").hover(
		function(){
			$("#contactprompt").addClass("contactinvert");
		},
		function(){
			$("#contactprompt").removeClass("contactinvert");
		});
	$("#contactinfo").hide();
	$("#contactprompt").click(
		function(){
			$("#contactinfo").toggle();
			$(".menugroup").hide();
		});

	//gift card page
	$('#gcrc1').each(function(){window.setInterval("setfade1()",5000);});
	//cake page
	$('#cakerotate1').each(function(){window.setInterval("setfade2()",5000);});
	//baskets page
	$('.basketorder').click(function(event){
		event.stopPropagation();
		addToCart($(this).attr('itemid'));
	});
	$('.basketrow').hover(
		function(){
			$(this).addClass('basketrowiehover')
		},
		function(){
			$(this).removeClass('basketrowiehover')
		}
	);

	//rewards login page
	$('.rewardssigninbox a').click(
		function(){
			$('.rewardssigninbox').toggle();
			return false;
		}
	);
});
//end of ready functions

function clearEmailText(textArea) {
	if(textArea.value == 'Enter your email address') {
		textArea.value = '';
		textArea.style.color = '#000';
	}
}

function validateContact(form){
    var returnValue = true;
    var errorMessage = 'The following field(s) are required:\n\n';
    var focusField = null;
    
    if(!form.firstname.value) {
      errorMessage += ' - First Name\n';
      	if(!focusField){
        	focusField = form.firstname;
      	returnValue = false;
 		}
    }
    if(!form.lastname.value) {
      errorMessage += ' - Last Name\n';
      	if(!focusField){
        	focusField = form.lastname;
      	returnValue = false;
 		}
    }
    if(!form.city.value) {
      errorMessage += ' - City\n';
      	if(!focusField){
        	focusField = form.city;
      	returnValue = false;
 		}
    }
    if(!form.state.value) {
      errorMessage += ' - State\n';
      	if(!focusField){
        	focusField = form.state;
      	returnValue = false;
 		}
    }
    if(!form.zip.value) {
      errorMessage += ' - Zip Code\n';
      	if(!focusField){
        	focusField = form.state;
      	returnValue = false;
 		}
    }
    if(!form.email.value) {
      errorMessage += ' - Email Address\n';
      	if(!focusField){
        	focusField = form.email;
      	returnValue = false;
 		}
    }
    
    if(!returnValue){
      alert(errorMessage);
      	if(focusField){
      	focusField.focus();
		}
	}
	return returnValue;
}
function validateTop100(form){
    var returnValue = true;
    var errorMessage = 'The following field(s) are required:\n\n';
    var focusField = null;
    
    if(!form.item.value) {
      errorMessage += ' - Item Name\n';
      	if(!focusField){
        	focusField = form.firstname;
      	returnValue = false;
 		}
    }
    if(!form.storelocation.value) {
      errorMessage += ' - Store Location\n';
      	if(!focusField){
        	focusField = form.lastname;
      	returnValue = false;
 		}
    }
    if(!form.why.value) {
      errorMessage += ' - Why you love it\n';
      	if(!focusField){
        	focusField = form.city;
      	returnValue = false;
 		}
    }
    if(!returnValue){
      alert(errorMessage);
      	if(focusField){
      	focusField.focus();
		}
	}
	return returnValue;
	
}

	sfHover = function() {
		var sfEls = document.getElementById("footer").getElementsByTagName("li");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" hover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" hover\\b"), "");
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);