/*  ------------------------------------------------------------------
    Background Image Fix --------------------------------------------- */
    try { document.execCommand("BackgroundImageCache", false, true)} catch(e) {};


/*  ------------------------------------------------------------------
    Functions -------------------------------------------------------- */


/*  ------------------------------------------------------------------
    Extend jQuery Functions ------------------------------------------ */
    (function ($) {


    /*  ------------------------------------------------------------------
        Vertical Align --------------------------------------------------- */
        $.fn.verticalAlign = function() {
            return this.each(function(i){
                var ah = $(this).height();
                var ph = $(this).parent().height();
                var mh = (ph - ah) / 2;
                $(this).css('margin-top', mh);
            });
        };


    })(jQuery);


/*  ------------------------------------------------------------------
    On Load ---------------------------------------------------------- */
    $(function(){
		
		/*  ------------------------------------------------------------------
        Accordian ------------------------------------------------------------- */
		$(".toggle_container").hide(); 
		$("h4.trigger").click(function(){
			$(this).toggleClass("active").next().slideToggle("slow");
			return false;
		});


    /*  ------------------------------------------------------------------
        DFC Widget ------------------------------------------------------- 
        var DFCcookie = $.DFCCookie('DFCWidget') ? false : true;
        $("#dfc_data").DFCWidget({
            minWidth: 968,
            onLoad: {show:DFCcookie, delay:2500},
            onShow:function (widget) { 
                if (DFCcookie) {
                    $.DFCCookie('DFCWidget', true, { expires: 1, path: '/'  });
                } else { $('#dfc_widget').width(305); }
            }
        });


      ------------------------------------------------------------------
        Navigation ------------------------------------------------------- */
        $('ul#nav li').hover(function() {
            $(this).addClass('hover');
            $('.nav_sub', this).show();
        }, function() {
            $(this).removeClass('hover');
            $('.nav_sub', this).hide();

        });

        
    /*  ------------------------------------------------------------------
        Misc ------------------------------------------------------------- */
        $('.valign').verticalAlign();
        $(".js_show").removeClass("js_show");


    /*  ------------------------------------------------------------------
        External Link ---------------------------------------------------- */
        var allowedDomains = [location.hostname];
        $("a[href^=http]:not(.internal):not([rel^='popup'])")
        .filter(function(el){
            for ( var i=0; i < allowedDomains.length; i++ ) {
                if ( this.href.indexOf(allowedDomains[i])>-1 ) return false;
            }
            return true;
        }).bind("click", function(){ return !window.open(this.href); });


    /*  ------------------------------------------------------------------
        Popup ------------------------------------------------------------ */
        $("a[rel^='popup']").bind("click", function(){
            rel = $(this).attr("rel");
            rel = rel.replace("popup", "").split("x");
            w = rel[0];
            h = rel[1];
            var my_popup = window.open($(this).attr("href"), $(this).attr("id"), "location=0, status=0, scrollbars=1, menubar=0, toolbar=0, width="+w+", height="+h);
            if (my_popup) {my_popup.focus();}
            return !my_popup;
        });


    /*  ------------------------------------------------------------------
        Remove default value on Focus ------------------------------------ */
        $("input[type='text'][@title]")
        .bind("focus",function(){ if(this.value==this.title){ this.value=""; } })
        .bind("blur",function(){ if(this.value==""){ this.value=this.title; } });


    /*  ------------------------------------------------------------------
        Postal Code Search Form ------------------------------------------ */
        var $frm_find = $("#frm_find");
        var $frm_find_text = $(":text", $frm_find);

        // no submit if no value
        $frm_find.submit(function(){ return !($frm_find_text.val() == "" || $frm_find_text.val() == $frm_find_text.attr('title')); });

        // radio
        var $frm_filter = $('#frm_filter');
        $(':radio', $frm_filter).click(function(){ $frm_filter.submit(); });
    });

