$(document).ready(function() {

    //active tab
    var loc = window.location;

    if (loc.href.indexOf('/product/') != -1) {
        $('#n1 a').addClass('active');
    } else if (loc.href.indexOf('/solution/') != -1) {
        $('#n2 a').addClass('active');
    } else if (loc.href.indexOf('/wheretobuy/') != -1) {
        $('#n3 a').addClass('active');
    } else if (loc.href.indexOf('/news/') != -1) {
        $('#n4 a').addClass('active');
    } else if (loc.href.indexOf('/partnercenter/') != -1) {
        $('#n5 a').addClass('active');
    } else if (loc.href.indexOf('/resource/') != -1) {
        $('#n6 a').addClass('active');
    } else if (loc.href.indexOf('/aboutpentair/') != -1) {
        $('#n7 a').addClass('active');
    }

    var i = 5;
    var position = null;
    while (position == null && i > 0) {
        position = $.url.segment(i);
        i--;
    }
    $('#local a.' + position).addClass('current');

    // focus/blur search form field
    $("#search input, #resource-search input").focus(
		function() {
		    if (this.value == this.defaultValue) {
		        this.value = "";
		    }
		}
	).blur(
		function() {
		    if (!this.value.length) {
		        this.value = this.defaultValue;
		    }
		}
	);

    // go buttons hover
    $('#go, #resource-search-go').hover(
		function() { // Change the input image's source when we "roll on"
		    $(this).attr({ src: '/pro/images/bttn_go-over.gif' });
		},
		function() { // Change the input image's source back to the default on "roll off"
		    $(this).attr({ src: '/pro/images/bttn_go.gif' });
		}
	);

	// submit button hover
	$('#submit').hover(
		function() { // Change the input image's source when we "roll on"
		    $(this).attr({ src: '/pro/images/bttn_submit-over.gif' });
		},
		function() { // Change the input image's source back to the default on "roll off"
		    $(this).attr({ src: '/pro/images/bttn_submit.gif' });
		}
	);

    // tabs (product detail page)
    $('#tabcontainer > ul').tabs({ fx: { opacity: 'toggle'} });

    // main navigation/dropdowns
    $('#nav').superfish({
        hoverClass: 'sfHover',          				// the class applied to hovered list items 
        //pathClass:     'overideThisToUse', 			// the class you have applied to list items that lead to the current page 
        //pathLevels:    1,                  			// the number of levels of submenus that remain open or are restored using pathClass 
        delay: 250,                				// the delay in milliseconds that the mouse can remain outside a submenu without it closing 
        animation: { opacity: 'show', height: 'show' },  	// fade-in and slide-down animation 
        speed: 1,           					// speed of the animation. Equivalent to second parameter of jQuery’s .animate() method 
        autoArrows: true               				// if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance 
    }).find('ul').bgIframe({ opacity: false }); 		// bgIframe plugin to fix IE6 bug overlapping <select> elements

});
