$(document).ready(function() {
    $("#ban").cycle();
});

$(document).ready(function() {
    $("a[rel=publications]").fancybox({
        'type' : 'image'
    });
    $("a[rel=products]").fancybox({
        'type' : 'image'
    });
    $("a[rel=gallery]").fancybox({
        'type' : 'image'
    });
});

$(document).ready(function() {
    $("div#newproducts a").each(function() {
        $(this).css("display","block");
        var product = $(this).find("img").attr("alt").toString();
        var image = $(this).find("img").attr("src").toString();
        $(this).prepend('<img src="' + image.replace(".png", "_off.png") + '" alt="' + product + '" class="productHover" />');
        $(this).find("img.productHover").css("display","block");
        $(this).find("img.productHover").css("position","absolute");
        $(this).hover(
            function() {
                $(this).find("img.productHover").fadeOut(100);
            },
            function() {
                $(this).find("img.productHover").fadeIn(200);
            }
        );
    });
});

$(document).ready(function() {
    Cufon.replace("ul#menu",{textShadow: '2px 2px rgba(0, 0, 0, 0.8)'});
    $("input#search").focus(function(){
        if ($(this).val() == "search") {
            $(this).val("");
            $(this).css("color","#333");
        }
    });
    $("input#search").blur(function(){
        if ($(this).val() == "") {
            $(this).val("search");
            $(this).css("color","#aaa");
        }
    });
});

function SubmitSmallSearch() {
	var url = "/product/";
	var form = document.getElementById("smallsearchform");
	url += form["words"].value;

	location.href=url;
	return false;
}

function SubmitFullSearch() {
	var url = "/product/";
	var form = document.getElementById("fullsearchform");
        
        if(form["words"].value != "") {
            url += form["words"].value;
        } else {
            url += "all";
        }
	url += "/";
	url += form["productType"].value;
	url += "/";
	url += form["ProdCategory"].value;
	url += "/";
	if (form["ProdDiscontinued"].checked == true) {
		url += "1";
	} else {
		url += "0";
	}

	location.href=url;
	return false;
}

function CheckContactForm() {

	var form = document.getElementById("contactform");
	var isValid = true;

	for (var i=0; i < form.elements.length; i++) {
		elem = form.elements[i];
		if (elem.value == "") {
			elem.style.borderColor="#FF0000";
			isValid = false;
		}
	}
	if ( ! isValid) {
		var validationDiv = document.getElementById("validationmsg");
		validationDiv.style.visibility='visible';
	}
	return isValid;
}
