﻿
if ($.browser.name == "safari") {
    document.write('<link rel="stylesheet" type="text/css" href="/CustomCMSTemplates/DoorDeals/Includes/CSS/Safari.css" media="screen" />');
}
if ($.browser.name == "chrome") {
    document.write('<link rel="stylesheet" type="text/css" href="/CustomCMSTemplates/DoorDeals/Includes/CSS/Chrome.css" media="screen" />');
}
if ($.browser.name == "firefox" && $.browser.version == "3.0") {
    document.write('<link rel="stylesheet" type="text/css" href="/CustomCMSTemplates/DoorDeals/Includes/CSS/Firefox30.css" media="screen" />');
}
if ($.os.name == "mac") {
    document.write('<link rel="stylesheet" type="text/css" href="/CustomCMSTemplates/DoorDeals/Includes/CSS/Mac.css" media="screen" />');
}

/*
 * Site.js
 * Global script file.
 */

/* Initialise all common javascript functionality. */
$(document).ready(function() {

    externalLinks();
    zIndexWorkaround();

    //initialiseSearch();
});


/*
 * Handle the blur of the search box text.
 */
function initialiseSearch() {

    $('.search-input').val('Search');
    
    $('.search-input').focus(function() {
        if ($('.search-input').val() == 'Search')
            $('.search-input').val('');
    });
}

function externalLinks() {
    $("a[rel]").each(function() {
        if (this.getAttribute("rel").indexOf("external") > -1) {
            this.target = "_blank";
        }
    });
};

function isIE() {
    if (navigator.userAgent.match(/MSIE \d\.\d+/))
        return true;
    return false;
}

// IE z-index bug fix
function zIndexWorkaround() {
    // If the browser is IE,
    if (isIE()) {
        /*
        ** For each div with class menu (i.e.,
        ** the thing we want to be on top),
        */
        $(".megamenuwrapper").parents().each(function() {
            var p = $(this);
            var pos = p.css("position");

            // If it's positioned,
            if (pos == "relative" ||
               pos == "absolute" ||
               pos == "fixed") {
                /*
                ** Add the "on-top" class name when the
                ** mouse is hovering over it, and remove
                ** it when the mouse leaves.
                */
                p.hover(function() {
                    $(this).addClass("on-top");
                },
                    function() {
                        $(this).removeClass("on-top");
                    });
            }
        });
    }
}
