/**
 * @author neil.lunn
 *
 * Now a general handler as this is the standard Javascript include
 */


$(document).ready(function(){


    // Top Menu Functions
    // Handle IE6 resize
    if ($.browser.msie && $.browser.version <= 6.0) {
        $(window).bind("resize", resizeWindow);
        function resizeWindow(e){
            var newWinWidth = $(window).width();
            if (newWinWidth > 968) {
                newWinWidth = 968
            }
            if (newWinWidth < 810) {
                newWinWidth = 810
            }
            $('#header').css("width", newWinWidth);
            $('#navbar').css("width", newWinWidth);
        }
    }
    
    // Define Structure for images
    
    var sets = {
        sites: {
            '127.0.0.1': 'set2', // Default for Development
            'trixanbody.com': 'set1',
            'trixanbody.co.uk': 'set1',
            'trixanbody.com.au': 'set1',
            'kakadupet.com': 'set3',
            'homemedwholesale.com': 'set4',
            '88fulfilment.com': 'set5'
        },
        set1: {
            // Normal Trixan Body Menu layout
            images: ["womens_bg-on.gif", "menu_bg-on.jpg", "mens_bg-on.gif", "childrens_bg-on.gif", "babies_bg-on.gif", "bath_bg-on.gif", "clearance_bg-on.gif", "menu_end-on.gif"]
        },
        set2: {
            // Pink Trixan Body Layout
            images: ["pk_womens_bg-on.gif", "pk_menu_bg-on.jpg", "pk_mens_bg-on.gif", "pk_childrens_bg-on.gif", "pk_babies_bg-on.gif", "pk_bath_bg-on.gif", "pk_clearance_bg-on.gif", "pk_menu_end-on.gif", ]
        },
        set3: {
            // Kakadu Pet Layout
            images: ["leftend_bg-on.gif", "menu_bg-on-kakadu.jpg", "middle_bg-on.gif", "menu_bg-on-kakadu.jpg", "menu_end-on-kakadu.gif"]
        },
        set4: {
            // Homemed wholesale layout
            images: ["hm-leftend_bg-on.gif", "hm-middle_bg-on.gif", "menu_bg-on-homemed.jpg", "menu_end-on-homemed.gif"]
        }
    };
    
    var csLinks = {
        '127.0.0.1': 'http://trixan.helpserve.com/?group=trixanbodyau&amp;departmentid=3&amp;_m=tickets&amp;_a=submit&amp;step=1',
        'trixanbody.com.au': 'http://trixan.helpserve.com/?group=trixanbodyau&amp;departmentid=3&amp;_m=tickets&amp;_a=submit&amp;step=1',
        'trixanbody.com': 'http://trixan.helpserve.com/?group=trixanbodyus&amp;departmentid=3&amp;_m=tickets&amp;_a=submit&amp;step=1',
        'trixanbody.co.uk': 'http://trixan.helpserve.com/?group=trixanbodyuk&amp;departmentid=3&amp;_m=tickets&amp;_a=submit&amp;step=1'
        // Add links for sites that require them
    };
    
    // Preload Required Rollover Images
    var loc = document.domain.toString().replace(/^(www|stage|dev)\./, "");
    if (typeof(sets.sites[loc]) != 'undefined') {
        var _images = sets[sets.sites[loc]].images;
        if (typeof(_images) != 'undefined') {
            var gotime = _images.length;
            var imagePath = '/static/images/';
            $.each(_images, function(e){
                $(new Image()).load(function(){
                    // Callback here
                }).attr('src', imagePath + this)
            });
        }
    }
    
    // Add customer service link to top menu - before Home
    
    var lnk = csLinks[loc];
    if (typeof(lnk) != 'undefined') {
        $('#quick-links a:last').before('<a href="' + lnk + '">Customer Service</a>');
    }
    
    
    // Install the mouseover handlers	
    $('#navbar li').each(function(){
        $(this).hover(function(){ // Mouse Over
            $(this).addClass('sfHover');
            $(this).children('ul').show();
        }, function(){ // Mouse Out
            $(this).removeClass('sfHover');
            $(this).children('ul').hide();
        });
        
    });
    
    
});
