/*
	Motoring Common Javascript
*/

// ie6 background cache fix.
if ($.browser.msie && $.browser.version == "6.0")
    document.execCommand("BackgroundImageCache", false, true);

scriptroot = "/carcontent/motoring/scripts/";
include(scriptroot + "pagination.js");
include(scriptroot + "jquery.watermark.js");

// Global on page ready function
$(document).ready(function () {

    // Correct the 'active' style for the search control.
    container = $(".csn-editorial-search");

    function hideSlider() {
        container.find('.browse-refinements li.current').removeClass("current");
        $('#search-content-wrapper').removeClass("current");
        container.find('.search-result-slider').removeClass("show-slider");
    }

    $('.search-content').wrap("<div id=\"search-content-wrapper\"></div>");
    container.find('.browse-refinements li').click(function () {
        test = container.find('.search-result-slider').hasClass("show-slider");

        if (test) {
            $('#search-content-wrapper').addClass("current");
        }
        else {
            $('#search-content-wrapper').removeClass("current");
        }
    });
    container.find('.close-action').click(function () {
        $('#search-content-wrapper').toggleClass("current");
    });

    container.find('.multilist-panel').click(function () {
        hideSlider();
    });

    $("body").click(function (ev) {
        var target = $(ev.target);
        if (target.parents(".csn-editorial-search").length === 0) {
            hideSlider();
        }
    });

    // Put the missing expander graphic against the lifestyle menu.
    if (!($.browser.msie && $.browser.version == "6.0"))
        $('#menu2807555 a b:first').append("<img class=\"lifestyle_expander\" src=\"/carcontent/motoring/dropdown_expand.png\"></img>");



    // Add a watermark to new car showroom modules.
    showroomTargets = $(".csn-showroom-module .search-body .keyword input");
    if(showroomTargets != undefined && showroomTargets.length > 0)
        $(".csn-showroom-module .search-body .keyword input").watermark("Enter Keyword Search...");
});


function include(file)
{
	var script  = document.createElement('script');
	script.src  = file;
	script.type = 'text/javascript';
	document.getElementsByTagName('head').item(0).appendChild(script);
}

