$(document).ready(function(){
    $('#nav li').hover(
        function () {
            $('.callout',this).fadeIn("fast");
            $('.tab',this).fadeIn("fast");
        },
        function () {
            $('.callout',this).fadeOut("fast");
            $('.tab',this).fadeOut("fast");
        }
    );
});

/* ------------------------------------------------------------------------*/
/* son of suckerfish http://www.htmldog.com/articles/suckerfish/dropdowns/ */
/* ------------------------------------------------------------------------*/

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


/* ------------------------------------------------------------------------*/
/* show/hide links in facets on search results                             */
/* ------------------------------------------------------------------------*/
var categoryShown = false;
function toggleCategory() {
	if (!categoryShown) {
		$('.facetcatextra').show();
		categoryShown = true;
		$('#catgoryfacetshowmore').html('<em>Show less</em>');
	} else {
		$('.facetcatextra').hide();
		categoryShown = false;
		$('#catgoryfacetshowmore').html('<em>Show more</em>');
	}
}
var typeShown = false;
function toggleType() {
	if (!typeShown) {
		$('.facettypeextra').show();
		typeShown = true;
		$('#typefacetshowmore').html('<em>Show less</em>');
	} else {
		$('.facettypeextra').hide();
		typeShown = false;
		$('#typefacetshowmore').html('<em>Show more</em>');
	}
}
var arcsizeShown = false;
function toggleArcsize() {
	if (!arcsizeShown) {
		$('.facetarcsizeextra').show();
		arcsizeShown = true;
		$('#arcsizefacetshowmore').html('<em>Show less</em>');
	} else {
		$('.facetarcsizeextra').hide();
		arcsizeShown = false;
		$('#arcsizefacetshowmore').html('<em>Show more</em>');
	}
}
var colorShown = false;
function toggleColor() {
	if (!colorShown) {
		$('.facetcolorextra').show();
		colorShown = true;
		$('#colorfacetshowmore').html('<em>Show less</em>');
	} else {
		$('.facetcolorextra').hide();
		colorShown = false;
		$('#colorfacetshowmore').html('<em>Show more</em>');
	}
}
var priceShown = false;
function togglePrice() {
	if (!priceShown) {
		$('.facetpriceextra').show();
		priceShown = true;
		$('#pricefacetshowmore').html('<em>Show less</em>');
	} else {
		$('.facetpriceextra').hide();
		priceShown = false;
		$('#pricefacetshowmore').html('<em>Show more</em>');
	}
}

/* ------------------------------------------------------------------------*/
/* alternate images                                                        */
/* ------------------------------------------------------------------------*/

function switchimage(newimage) {
	document.getElementById('mainimage').src = newimage;
}




/* ------------------------------------------------------------------------*/
/* prevent double click on OPAY screen                                     */
/* ------------------------------------------------------------------------*/

var opaySubmitted = false;
function submitOnce(theform) {
	if (opaySubmitted) {
		return false;
	}
//	document.getElementById('btnContinue').className='btnOrangeDisabled';
	document.getElementById('btnContinue').style.backgroundImage='url(/images/buttons/button_orange_disabled.gif)';
	opaySubmitted = true;
	return true;
}


/* ------------------------------------------------------------------------*/
/* large image format viewer (php script)                                  */
/* ------------------------------------------------------------------------*/

function popupimage(filename) {
	doPopUpWindow = window.open("/popup_larger.php?file="+filename,"popupImage","scrollbars=yes,resizable=yes,left=50,top=50,screenX=50,screenY=50,width=600,height=600");
}




/* ------------------------------------------------------------------------*/
/*  all other popups from http://www.alistapart.com/articles/popuplinks/   */
/* ------------------------------------------------------------------------*/

//var _POPUP_FEATURES = 'location=0, statusbar=0, menubar=0, width=400, height=300';
var _POPUP_FEATURES = '';

function raw_popup(url, target, features) {
	if (isUndefined(features)) {
		features = _POPUP_FEATURES;
	}
	if (isUndefined(target)) {
		target = '_blank';
	}
	var theWindow = window.open(url, target, features);
	theWindow.focus();
	return theWindow;
}

function link_popup(src, features) {
	return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

function isUndefined(v) {
	var undef;
	return v===undef;
}


/* ------------------------------------------------------------------------*/
/*  shows and hides the faceting divs on the search results pages          */
/* ------------------------------------------------------------------------*/

function showhide(div_name) {
	if (document.getElementById(div_name + "_link").innerHTML == "more")	{
		document.getElementById(div_name + "_div").style.display = "block";
		document.getElementById(div_name + "_link").innerHTML = "hide";
	}
	else {
		document.getElementById(div_name + "_div").style.display = "none";
		document.getElementById(div_name + "_link").innerHTML = "more";
	}
}

/* ------------------------------------------------------------------------*/
/*  apply filters from facet dropdowns on category pages                   */
/* ------------------------------------------------------------------------*/

function applyFilter(dropdown) {
	if (dropdown.value) {
		location.href=dropdown.value;
	}
}

/* ------------------------------------------------------------------------*/
/*  validate all fields are filled out on contact form                     */
/* ------------------------------------------------------------------------*/

function validateForm(theForm) {
	if (theForm.form_replyto_name.value == '') {
		alert("Please enter a value in the Name field.");
		theForm.form_replyto_name.focus();
		return false;
	}
	if (theForm.form_replyto_email.value == '') {
		alert("Please enter a value in the Email field.");
		theForm.form_replyto_email.focus();
		return false;
	}
	if (theForm.form_replyto_phone.value == '') {
		alert("Please enter a value in the Phone field.");
		theForm.form_replyto_phone.focus();
		return false;
	}
	if (theForm.form_subject.value == '') {
		alert("Please select a choice in the Subject dropdown field.");
		theForm.form_subject.focus();
		return false;
	}
	if (theForm.form_message.value == '') {
		alert("Please enter a value in the Message field.");
		theForm.form_message.focus();
		return false;
	}
	return true;
}
