(function($) {

    $.globalNav = function(options) {
        return $.globalNav.impl.init(options);
    };

    $.fn.globalNav = function(options) {
        return $.globalNav.impl.init(this, options);
    };

    /*
    * default options
    */
    $.globalNav.defaults = {

};

$.globalNav.impl = {

    /*
    * options
    */
    opts: null,

    /*
    * helper
    */
    helper: {},

    /*
    * Initialize the nav
    */
    init: function(nav, options) {

        var self = this;

        this.opts = $.extend({}, $.globalNav.defaults, options);

        // helper objects
        self.helper.list = $(nav);

        // append container
        self.helper.list.find('ul.ul-2')
            .each(function(i, item){
                
                $(item)
                    .prepend($('<div class="bg-2"></div>'))
                    ;
                
                // fix ie6
                if ($.browser.msie && ($.browser.version < 7))
                {
                    $(item).find('.bg-2')
                        .css({
                            width: $(item).outerWidth() + 'px',
                            height: $(item).outerHeight() + 'px'
                        })
                        ;
                }
            })
            ;
        
//        self.helper.list.find('.a-1:contains("Sales"), .a-1:contains("Sale"), .a-1:contains("Soldes"), .a-1:contains("Rebajas"), .a-1:contains("Saldi")').parent()
//            .addClass('li-1-sale')
//            ;

            
        
        self.bindEvents();

        return self;
    },

    /*
    * Binds the events
    */
    bindEvents: function() {

        var self = this;

        // hover
        self.helper.list.children('li.li-1')
		        .hover(
		            function() {
		                $(this)
		                    .addClass('li-1-hover')
		                    ;
		            },
		            function() {
		                $(this)
		                    .removeClass('li-1-hover')
		                    ;
		            }
		        )
		        ;

        return;
    },

    /*
    * Fixes IE 6--prevent select boxes from showing through dropdown
    */
    fixIE: function() {

        var self = this;
        var $iframe = $('<iframe src="javascript:false;">')
				.css($.extend(this.opts.iframeCss, {
				    opacity: 0,
				    position: 'absolute',
				    height: wHeight,
				    width: wWidth,
				    zIndex: 1000,
				    width: '100%',
				    top: 0,
				    left: 0
				}))
				.hide()
				.prependTo(self.helper.list.find('ul.ul-2'));

        return;
    }

};
})(jQuery);
