var SUBMENU_MILLISECONDS_DELAY = 1500;
var timeout = null;

jQuery.preloadImages = function()
{
    for(var i = 0; i < arguments.length; i++)
    {
        jQuery("<img>").attr("src", arguments[i]);
    }
}

$.preloadImages("/css/images/brand/home2.jpg", "/css/images/brand/home3.jpg", "/css/images/structure/menu_button_active.png");

$(document).ready(

    function ()
    {
        var ltie7 = true;

        $("li.main div.subNav").hide();
        $("ul.subNav li:first-child a").addClass("first");

        $("ul.subNav").each(
            function()
            {
                $(this).css("margin-left", $(this).parent("div.subNav").parent("li.main").children("a.main")[0].offsetLeft - 1);
            }
        );
        
        $("li.main").mouseover(
            function ()
            {
                $("div.subNav").hide();
                $("li.main").removeClass("mainHover");
                $(this).addClass("mainHover");

                if ($(this).children("div.subNav").is(":hidden"))
                {
                    $(this).children("div.subNav").show();
                }
            }
        );

        $("div.subNav").mouseover(
            function ()
            {
                clearTimeout(timeout);
            }
        );
        
        $("div.subNav").mouseout(
            function ()
            {
                var sub = this;
                
                timeout = setTimeout(
                    function ()
                    {
                        $(sub).hide();
                        $(sub).parent("li.main").removeClass("mainHover");
                    },SUBMENU_MILLISECONDS_DELAY);
            }
        );

        if (ltie7)
        {
            $("#brandMenu a").ifixpng();
        }
        
        $("#brandMenu a").hover(
            function ()
            {
                if (ltie7)
                {
                    //$(this).css("background-image", "url(/css/images/structure/menu_button_active.png)");
                    $(this).ifixpng();
                }
                
                if ($(this).attr("id") == "option2")
                {
                    $("#brand").css("background-image", "url(/css/images/brand/home2.jpg)");
					document.all.brandText.innerHTML="<h2>Value. Added.</h2><p>Distribution isn&rsquo;t just about moving boxes from A to B, it&rsquo;s about adding value along the way. Over 80% of the products that move through the Data Select Distribution Centre are enhanced in one way or another.<br /><br /></p>";
                }
                else if ($(this).attr("id") == "option3")
                {
                    $("#brand").css("background-image", "url(/css/images/brand/home3.jpg)");
					document.all.brandText.innerHTML="<h2>Putting it all together.</h2><p>Every second of every day, mobile companies and beyond are using IT & Online solutions developed, maintained and powered by Data Select.<br /> <br />Our innovative approach to the challenges facing our customers have resulted in making Data Select an important and integral part of some of Europes largest companies.</p>";
                }
            },

            function ()
            {
                if (ltie7)
                {
                    //$(this).css("background-image", "url(/css/images/structure/menu_button.png)");
                    $(this).ifixpng();
                }
                
                $("#brand").css("background-image", "url(/css/images/brand/home1.jpg)");
				document.all.brandText.innerHTML="<h2>The UK&rsquo;s leading distributor of mobile phones, accessories &amp; airtime.</h2><p>Providing customers with a one-stop shop for all mobile products.<br /><br />Through our direct supply relationships, and our innovative approach to new products, we leave no corner of your market uncovered.</p>";
            }
        );
    }
);