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") == "option1")
                {
                    $("#brand").css("background-image", "url(/css/images/brand/home1.jpg)");
					document.all.brandText.innerHTML="<br/><h2>Productivity</h2><p>With the range of solutions from Mobile Managed Services your organisation can sweat the mobile device assets to increase productivity and reduce costs.<br /><br /></p>";
                }
                else if ($(this).attr("id") == "option2")
                {
                    $("#brand").css("background-image", "url(/css/images/brand/home3.jpg)");
					document.all.brandText.innerHTML="<br/><h2>Security</h2>With the mobile phone capable of being the single device for the task at hand, security and control of that piece of hardware is critical. Mobile Managed Services provide the capability to control and eliminate those potential security risks.</p>";
                }
				 else if ($(this).attr("id") == "option3")
                {
                    $("#brand").css("background-image", "url(/css/images/brand/home2.jpg)");
					document.all.brandText.innerHTML="<br/><h2>Management</h2><p>With two million phones lost and stolen in 2007, Mobile Managed Services have the solutions to provide the physical replacement and configuration set to minimise the loss.</p>";
                }
				 else if ($(this).attr("id") == "option4")
                {
                    $("#brand").css("background-image", "url(/css/images/brand/MMS-home-casestudy.jpg)");
					document.all.brandText.innerHTML="<br/><h2>Device Portfolio</h2><p>With the ever increasing demands to maximise efficiencies within an organisation, Mobile Managed Services (MMS) provides a device portfolio range that is geared to enabling productivity, functionality and connectivity.</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/MMS-home-casestudy.jpg)");
				document.all.brandText.innerHTML="<br/><h2>Device Portfolio</h2><p>With the ever increasing demands to maximise efficiencies within an organisation, Mobile Managed Services (MMS) provides a device portfolio range that is geared to enabling productivity, functionality and connectivity.</p>";
            }
        );
    }
);
