﻿jQuery(function() {


    //sets up the Main Menu
    jQuery('ul.nav').supersubs({
        minWidth: 5,   // minimum width of sub-menus in em units 
        maxWidth: 25,   // maximum width of sub-menus in em units 
        extraWidth: 1

    }).superfish({
        animation: { height: 'show', height: 'show' },
        speed: 'fast',
        autoArrows: false

    }).find('ul').bgIframe({ opacity: false });


    //set up local navigation
    $(".columnLeft .local ul a").hover(
        function() { $(this).stop().animate({ paddingLeft: "20px" }, 200); },
        function() { $(this).stop().animate({ paddingLeft: "15px" }, 500); }
    );

    //sets up the focus events for form elements
    $("input:text, input:password, textarea, input:checkbox").focus(function() {
        $(this).addClass("activeElement");
        $(this).closest("li").css("background-color", "#fdfdfd");
    }).blur(function() {
        $(this).removeClass("activeElement");
        $(this).closest("li").css("background-color", "#f6f6f6");
    });

    $("input:submit, input:reset").focus(function() {
        $(this).addClass("activeElement");
    }).blur(function() {
        $(this).removeClass("activeElement");
    });


    //homepage content scroller
    $('#photos').galleryView({
        panel_width: 980,
        panel_height: 389,
        frame_width: 10,
        frame_height: 10,
        overlay_color: '#222',
        overlay_text_color: 'white',
        caption_text_color: '#222',
        background_color: '',
        border: 'none',
        nav_theme: 'dark',
        easing: 'easeInOutQuad',
        pause_on_hover: true,
        transition_interval: 11000,
        transition_speed: 900
      
    });


    //prepare external links
    $('.content a:not(:has(img),".button"), .sidebar_callout a:not(:has(img)), #content_bottom a:not(:has(img))').filter(function() {
        return this.hostname && this.hostname !== location.hostname;
    }).append(' <img src="/images/external.png" alt="external link">');

    $("a[href^='mailto:']:not(:has(img),'.button','.hide_graphic')").append('<img src="/images/email.png" class="email_icon" alt="email link" />');

    //prepare pdf links
    $("a[href$='.pdf']:not(:has(img),'.button')").addClass("pdf");

    //Smooth PageScroll
    function filterPath(string) { return string.replace(/^\//, '').replace(/(index|default).[a-zA-Z]{3,4}$/, '').replace(/\/$/, '') } var locationPath = filterPath(location.pathname); $('a[href*=#]').each(function() { var thisPath = filterPath(this.pathname) || locationPath; if (locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/, '')) { var $target = $(this.hash), target = this.hash; if (target) { var targetOffset = $target.offset().top; $(this).click(function(event) { event.preventDefault(); $('html, body').animate({ scrollTop: targetOffset }, 1000, function() { location.hash = target }) }) } } });



    /* --------------------------------------------
    * multitoggles
    * -------------------------------------------- */

    function showToggle(el) {
        $(el).parents('div.toggle').addClass('open').find('.slidetarget').slideDown();
        setToggleAll(el);
    }
    function hideToggle(el) {
        $(el).parents('div.toggle').removeClass('open').find('.slidetarget').slideUp();
        setToggleAll(el);
    }

    function setToggleAll(el, mtoggle) {
        var mtoggle = mtoggle || $(el).parents('div.mtoggle').get(0);
        var allOpen = $(mtoggle).find('.toggle.open').length == $(mtoggle).find('.toggle').length;
        if (allOpen) {
            $(mtoggle).find('h2 a')
				.unbind('click')
				.find('span').html('hide all').end()
				.bind('click', function(e) {
				    $(mtoggle).find('h3 a').each(function() { hideToggle(this); })
				    return false;
				});
        } else {
            $(mtoggle).find('h2 a')
				.unbind('click')
				.find('span').html('show all').end()
				.bind('click', function() {
				    $(mtoggle).find('h3 a').each(function() { showToggle(this); })
				    return false;
				});
        }

    }


    $('div.mtoggle').each(function() { setToggleAll(null, this) });


    // initialize the individual toggles
    $(".toggle").each(function() {
        $(this).find('.slidetarget').hide();

        $(this).find('h3:first')
			.click(function(e) {
			    e.preventDefault();
			    var isOpen = $(this).parents('div.toggle').hasClass('open');
			    if (isOpen) {
			        hideToggle(this);
			    } else {
			        showToggle(this);
			    }
			})
			.find('a').append('<span>Expand Details</span>');
    });


    $('div.success_story a, div.prod_serv a').bigTarget({
        clickZone: 'div:eq(0)'
    });

    //$('#content_bottom').pngFix();
    //$('#header').pngFix();
    //$('#navigation').pngFix();
});
