$(document).ready(function(){

    // main navigation: active tab
    var loc = window.location;

    if (loc.href.indexOf('product') != -1) {
        $('#n1 a').addClass('active');
    } else if (loc.href.indexOf('systems') != -1) {
        $('#n2 a').addClass('active');
    } else if (loc.href.indexOf('sealing-technologies') != -1) {
        $('#n3 a').addClass('active');
    } else if (loc.href.indexOf('resource') != -1) {
        $('#n4 a').addClass('active');
    } else if (loc.href.indexOf('industry') != -1) {
        $('#n5 a').addClass('active');
    } else if (loc.href.indexOf('about') != -1) {
        $('#n6 a').addClass('active');
    }

    // side navigation: active link
    var i = 2;
    var position = null;
    while (position == null && i > 0) {
        position = $.url.segment(i);
        i--;
    }
    //console.log(position);
    if (position != null) {
        $('#local a.' + position.toLowerCase()).addClass('current');
    } else {
        $('#local a.landing').addClass('current');
    }

    // focus/blur search form field
	$("#search input").focus(
		function() {
			if(this.value == this.defaultValue) {
			this.value = "";
			}
		}
	).blur(
		function() {
			if(!this.value.length) {
			this.value = this.defaultValue;
			}
		}
	);

	// image button hover
	$('input.bttn').hover(function() {
		    $(this).css('background-position', '0 -23px');
		},
		function() {
		    $(this).css('background-position', '0 0');
		}
	);

	if ($('#thumbs').length) { // init gallerific plugin only on pages with thumbs
	    $('#thumbs').galleriffic({
	        delay: 2500,
	        numThumbs: 15,
	        preloadAhead: 10,
	        enableTopPager: false,
	        enableBottomPager: false,
	        imageContainerSel: '#slideshow',
	        controlsContainerSel: '#controls',
	        captionContainerSel: '#caption',
	        loadingContainerSel: '#loading',
	        renderSSControls: false,
	        renderNavControls: true,
	        playLinkText: 'Play Slideshow',
	        pauseLinkText: 'Pause Slideshow',
	        prevLinkText: '&lsaquo; Previous Photo',
	        nextLinkText: 'Next Photo &rsaquo;',
	        nextPageLinkText: 'Next &rsaquo;',
	        prevPageLinkText: '&lsaquo; Prev',
	        enableHistory: false,
	        enableKeyboardNavigation: true,
	        autoStart: false,
	        syncTransitions: true,
	        defaultTransitionDuration: 900
	    });
	}

	if ($('#tabs').length) {
	    $("#tabs").tabs({
	        cookie: { expires: 1} // store the tab state for a day
	    });
	}

    // zebra-stripe resource tables
	$("#resources tr:nth-child(even)").addClass("alt");

});
