$(document).ready( function() {
	
    $(".baseform").validate();
    $("input.safemail").each(function(){
        $(this).val($(this).val().replace(/ at /,"@").replace(/ dot /g,"."));
    });
	
    //CLICKABLE LI
    //if you have a list item and you need the each of the whole li's to link to a url, use this.
    //This will grab the first <a> tag (inside the selected li) and use it as the location to open (on li click).
    $("ul.clickable_li li").each(function() {
        var link = $(this).find("a").attr("href")

        if ( link ) {
            $(this).addClass("pointer")
            $(this).bind('click', function(){
                window.location = link
            });
        }
    });
  
    //sidebar nav
    //    $("ul.sf-menu").superfish({
    //        animation: {
    //            height:'show'
    //        },   // slide-down effect without fade-in
    //        delay:     1200               // 1.2 second delay on mouseout
    //    });
   
    // open external link in new tab/window
    // use rel="external" instead of target="_blank"
    $('a[rel="external"]').click( function() {
        this.target = "_blank";
    });
    
    //email replacement
    $("span.mailto").each(function(){
        exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
        match = exp.exec($(this).text());
        addr = match[1] ? match[1].replace(/ at /,"@").replace(/ dot /g,".") : match[0].replace(/ at /,"@").replace(/ dot /g,".");
        emaillink = match[2] ? match[2] : addr;
        subject = $(this).attr('title') ? "?subject="+$(this).attr('title').replace(/ /g,"%20") : "";
        $(this).after('<a href="mailto:'+addr+subject+'">'+ emaillink + '</a>');
        $(this).remove();
    });
    //    $("ul.sf-menu").superfish();
   	
    $("#banner ul").cycle();
    
    // sign up default value
    $("#search_form input, #newsletter_form input").focus(function() {
        if( this.value == this.defaultValue ) {
            this.value = "";
        }
    }).blur(function() {
        if( !this.value.length ) {
            this.value = this.defaultValue;
        }
    });
    //validate no-default
    jQuery.validator.addMethod("defaultInvalid", function(value, element) {
        return value != element.defaultValue;
    }, "This can't be left blank");

    $('#payment_type').change(function(){
        if($(this).val() == "credit card"){
            $('#cc_details').show();
        }
        else{
            $('#cc_details').hide();
        }
    });
   
});

var agt=navigator.userAgent.toLowerCase();
if(agt.indexOf('mozilla')!=-1 && agt.indexOf("gecko")!=-1 && agt.indexOf("safari") && agt.indexOf("mac") != -1){ 
    document.write('<style type="text/css">ul#shopping_cart {background-position:170px 0}</style>');
}
 
