/*
Version: 0.1.6
Updated: Wednesday, 16.01.2008 @ 18:15
------------------------------------------------------------*/


$(document).ready(function(){

    // arranges input text behavior
    $('.logonfield').hint();


    //navigation stability
	$("ul#h-nav").superfish({
		hoverClass	: "sfHover",
		delay		: 0,
		speed		: "fast"
	});

	$("ul#v-nav").superfish({
		hoverClass	: "sfHover",
		delay		: 0,
		speed		: "fast"
	});
    

    
    //Detect OE
    if ( jQuery.browser.msie) {
    
        if ( $("#grid_container_home") ) {
        
            $("ul#h-nav").hover(
                function () {
                    $("ul#h-nav").find("li").css('z-index',1000);
                    $("#grid_container_home").css('z-index',-2);
                    $("#grid_container_home").css('position', "relative");
                    $("#sidebar").css('z-index',-3);
                    $("#set_content").css('z-index',-3);
                    $(".bottom_home").css('z-index',-1);
                    $("li > ul > li > a").find("li").css('z-index',1000);
                }, 
                function () {
                    $("ul#h-nav").find("li").css('z-index',1000);
                    $("#grid_container_home").css('z-index',1);
                    $("#set_content").css('z-index',1);
                    $("#sidebar").css('z-index',1);
                    $(".bottom_home").css('z-index',1);
                }
            );
        
        };
        
        if ( $("#grid_container") ) {
            $("ul#h-nav").hover(
                function () {
                    $("ul#h-nav").find("li").css('z-index',1000);
                    $("#grid_container").css('z-index',-2);
                    $("#grid_container").css('position', "relative");
                    $("#sidebar").css('z-index',-3);
                    $("#set_content").css('z-index',-3);
                    $(".side_logo").css('z-index',-1);
                    $("li > ul > li > a").find("li").css('z-index',1000);
                }, 
                function () {
                    $("ul#h-nav").find("li").css('z-index',1000);
                    $("#grid_container").css('z-index',1);
                    $("#set_content").css('z-index',1);
                    $("#sidebar").css('z-index',1);
                    $(".side_logo").css('z-index',1);
                }
            );
        
        };
    };
    
    
    //Detect IE 6
    if ( jQuery.browser.msie && jQuery.browser.version == '6.0') {

 
        $("ul#h-nav").hover(
            function () {
                $("#frm_products").css('visibility','hidden');
            }, 
            function () {
                $("#frm_products").css('visibility','visible');
            }
        );
	$("ul#v-nav").hover(
            function () {
                $("#frm_products").css('visibility','hidden');
            }, 
            function () {
                $("#frm_products").css('visibility','visible');
            }
        );



        //Hover persistence
        $(".arrow_list > li").hover(
            function () {
            	$(this).addClass("hoverme");
            }, 
            function () {
            	$(this).removeClass("hoverme");
            }
        );
        
        $(".spotlight").hover(
            function () {
            	$(this).addClass("hover-spotlight");
            }, 
            function () {
            	$(this).removeClass("hover-spotlight");
            }
        );
        
        $(".option_frame > a").hover(
            function () {
            	$(this).addClass("hover-option_frame");
            }, 
            function () {
            	$(this).removeClass("hover-option_frame");
            }
        );
        
        $(".product_cat_menu").hover(
            function () {
            	$(this).addClass("hover-product-cat-menu");
            }, 
            function () {
            	$(this).removeClass("hover-product-cat-menu");
            }
        );
        
        $("#return").hover(
            function () {
            	$(this).addClass("cat-switch");
            }, 
            function () {
            	$(this).removeClass("cat-switch");
            }
        );
        $("#more").hover(
            function () {
            	$(this).addClass("cat-switch");
            }, 
            function () {
            	$(this).removeClass("cat-switch");
            }
        );
    };
    

    //Hide focus on search when navigation is hovered
    $("ul#h-nav > li").hover(
        function () {
        	$("#search").blur();
            $("body").focus();
        }, 
        function () {
        	$("#search").focus();
        }
    );

    $("ul#v-nav").hover(
        function () {
        	$("#search").blur();
            $("body").focus();
        }, 
        function () {
        	$("#search").focus();
        }
    );
    
    //Button Hover Persitence
    /*
	$(".send_button").hover(
        function () {
        	$(this).css("background","#ff5f00");
        }, 
        function () {
        	$(this).css("background","#6b5c8b");
        }
    );
	*/
	$("input[@type=submit]").hover(
        function () {
        	$(this).css("background","#ff5f00");
        }, 
        function () {
        	$(this).css("background","#6b5c8b");
        }
    );
	
    
	$("#more").hide();

	$("#more").click(function () {

		$("#return").show();
		$("#setone").animate({marginLeft: "-415px"}, 1000);
		$("#more").hide();

    });

    $("#return").click(function () {

		$("#more").show();
		$("#setone").animate({marginLeft: "0"}, 1000);
		$("#return").hide();
    });

  	/*
	$("#more").click(function () {
        $("#setwo").fadeOut("slow");
		$("#setone").fadeIn("slow");
    });

    $("#return").click(function () {
        $("#setone").fadeOut("slow");
		$("#setwo").fadeIn("slow");
    });

    //Column switch animator
    //$("#return").click(function () {
    //    $("#setone").hide("slow", function()
	//		{
	//			$("#settwo").show("slow");
	//		}
	//	);
    //});
    
    // animate columns at 05c
    
	$("#more").click(function () {
        $("#setwo").fadeOut("slow", function()
			{
				$("#setone").fadeIn("slow");
			}
		);
    });

    $("#return").click(function () {
        $("#setone").fadeOut("slow", function()
			{
				$("#setwo").fadeIn("slow");	
			}
		);
    });
    */
    
    //sitemap
    $("#sitemapping").treeview({
        persist: "cookie", //this reads out the location.href and uses it as a unique location within the sitemap
        collapsed: true,
        unique: true
    });    

    
 });


 
/* no jquery - solid focus solution */
function init() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;
    if (_timer) clearInterval(_timer);
	  document.getElementById("search").focus();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    document.write("<script id=__ie_onload defer src='/blank.js'><\/script>");
    var script = document.getElementById("__ie_onload");
    script.onreadystatechange = function() {
        if (this.readyState == "complete") {
            init();
        }
    };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init();
        }
    }, 10);
}

/* for other browsers */
window.onload = init;
 
 
 
/*
 * Superfish v1.3.4 - jQuery menu widget
 *
 * Copyright (c) 2007 Joel Birch
 */

(function($){
	$.fn.superfish = function(o){
		var $sf = this,
			defaults = {
			hoverClass	: 'sfHover',
			pathClass	: 'overideThisToUse',
			delay		: 800,
			animation	: {opacity:'show'},
			speed		: 'normal',
			onshow		: function(){} // in your function, 'this' is the revealed ul
		},
			over = function(){
				clearTimeout(this.sfTimer);
				$(this)
				.showSuperfishUl(o)
				.siblings()
				.hideSuperfishUl(o);
			},
			out = function(){
				var $$ = $(this);
				if ( !$$.is('.'+o.bcClass) ) {
					this.sfTimer=setTimeout(function(){
						$$.hideSuperfishUl(o);
						var sf = $$.parents('ul.superfish:first')[0];
						if (!$('.'+o.hoverClass,sf).length) {
							over.call(sf.o.$currents.hideSuperfishUl(o));
						}
					},o.delay);
				}		
			};
		$.fn.extend({
			hideSuperfishUl : function(o){
				$('li.'+o.hoverClass,this)
				.andSelf()
					.removeClass(o.hoverClass)
					.find('>ul')
						.hide()
						.css('visibility','hidden');
				return this;
			},
			showSuperfishUl : function(o){
				return this
					.addClass(o.hoverClass)
					.find('>ul:hidden')
						.css('visibility','visible')
						.animate(o.animation,o.speed,function(){
							o.onshow.call(this);
						})
					.end();
			},
			applySuperfishHovers : function(){
				return this[($.fn.hoverIntent) ? 'hoverIntent' : 'hover'](over,out);
			}
		});
		
		return this
		.addClass('superfish')
		.each(function(){
			o = $.extend({bcClass:'sfbreadcrumb'},defaults,o);
			o = $.extend(o,{$currents:$('li.'+o.pathClass,this)});
			this.o = o;
			
			if (o.$currents.length) {
				o.$currents.each(function(){
					$(this)
					.addClass(o.hoverClass+' '+o.bcClass)
					.filter(':has(ul)')
						.removeClass(o.pathClass);
				});
			}
			
			var $sfHovAr=$('li:has(ul)',this)
				.applySuperfishHovers(over,out)
				.not('.'+o.bcClass)
					.hideSuperfishUl(o)
				.end();
			
			$('a',this).each(function(){
				var $a = $(this), $li = $a.parents('li');
				$a.focus(function(){
					over.call($li);
					return false;
				}).blur(function(){
					$li.removeClass(o.hoverClass);
				});
			});
		});
	};
	$(window).unload(function(){
		$('ul.superfish').each(function(){
			$('li:has(ul)',this).unbind('mouseover').unbind('mouseout');
			this.o = this.o.$currents = null; // clean up
		});
	});
})(jQuery);