//Init superfish plugin (1.2.6 jQuery)
jQuery_1_2_6(document).ready(function($) {
    jQuery_1_2_6('ul.sf-menu').superfish();
});
    function querySt(ji) {
        hu = window.location.search.substring(1);
        gy = hu.split("&");
        for (i=0;i<gy.length;i++) {
            ft = gy[i].split("=");
            if (ft[0] == ji) {
                return ft[1];
            }
        }
    }

jQuery_1_3_2(function() {
    //Unhide the anythingSlider divs.
    jQuery_1_3_2(".anythingSlider").css("position", "relative").css("visibility", "visible");
    
    //Handles the level 2 menu item background glow animation fading in and out.
    jQuery_1_3_2(".menuItem").hover(function() {
        jQuery_1_3_2(this).find("span").stop().animate({ opacity: 1.0 }, 300);
    },
    function() {
        jQuery_1_3_2(this).find("span").stop().animate({ opacity: 0.0 }, 300);
    });

    //Handles the level 1 menu item background glow animation sliding up.
    jQuery_1_3_2(".tlMenuItem").hover(function() {
        jQuery_1_3_2(this).stop().animate({ backgroundPosition: "0 15px" }, { duration: 300 });
    },
    function() {
        jQuery_1_3_2(this).stop().animate({ backgroundPosition: "0 30px" }, { duration: 600 });
    });

    //Commented out to see if necessary on 1/5/10.
    //jQuery_1_3_2(".tlMenuItem ul li").hover(function() {
    //    jQuery_1_3_2(this).stop();
    //},
    //function() {
    //    jQuery_1_3_2(this).stop();
    //});
});
  
    //function required by Superfish.
    function formatText(index, panel) {
        return index + "";
    }


//Init 1.3.2 jQuery scripts
    jQuery_1_3_2(document).ready(function() {
    

        //Remove the degraded background image set by the css on menu items, since jQuery will be handling the animation.
        jQuery_1_3_2(".topMenu .tlMenuItem").css("background-image", "url('/images/menuGlowLight.png')");
        jQuery_1_3_2(".bottomMenu .tlMenuItem").css("background-image", "url('/images/menuGlowDark.png')");
        jQuery_1_3_2(".noBg").css("background-image", "none");

        //Unhide the span within menu items and set their opacity to 0 so we can hover it later.
        jQuery_1_3_2(".menuItem").each(function(i) {
            jQuery_1_3_2(this).children("span").css("visibility", "visible");
            jQuery_1_3_2(this).children("span").animate({ opacity: 0.0 }, 10);
        });


        //change the HREF of the links on the portfolio category bar so they don't have a querystring variable (rely on jQuery instead of a redirect).
        jQuery_1_3_2("#portfolio-filter li a").each(function(i) {
            var href = jQuery_1_3_2(this).attr("href").toString();
            var startIndex = href.indexOf("?");
            var endIndex = href.indexOf("#");
            var length = startIndex - endIndex;
            var string = href.substring(startIndex, endIndex);
            var newHref = href.replace(string, "");
            jQuery_1_3_2(this).attr("href", newHref);
        });
        
        //prevent click on all testimonial links to portfolio
        jQuery_1_3_2('.testimonial_link').each(function(i) {
            var href = jQuery_1_3_2(this).attr("href", "#");
        });
        jQuery_1_3_2('#testimonial_gausebuiltboats').colorbox({href:"/portfolio_files/client_html/inline_gausebuiltboats_online.htm"});
        jQuery_1_3_2('#testimonial_customqualitymanufacturing').colorbox({href:"/portfolio_files/client_html/inline_customqualitymanufacturing_online.htm"});
        jQuery_1_3_2('#testimonial_globalsyntheticice').colorbox({href:"/portfolio_files/client_html/inline_globalsyntheticice_online.htm"});
        jQuery_1_3_2('#testimonial_pammills').colorbox({href:"/portfolio_files/client_html/inline_pammills_online.htm"});
        
        
        
        
        
        //change the HREF of all the client-level portfolio items so they don't have a querystring variable (rely on jQuery instead of a redirect).
        jQuery_1_3_2("#portfolio-list li").each(function(i) {
            var href = jQuery_1_3_2(this).children("a").attr("href", "#");
        });
        
        //Bind mouseover events to the portfolio items for showing client names.
        jQuery_1_3_2('#portfolio-list li').bind('mouseover', function(e) {
            jQuery_1_3_2(this).children("a").children("p").hoverFlow(e.type, { left: 3 }, 400, 'easeOutQuart');
        }).bind('mouseout', function(e) {
            jQuery_1_3_2(this).children("a").children("p").hoverFlow(e.type, { height: 'hide' }, 100).hoverFlow(e.type, { left: 166, height: 'show' }, 2);
        });
        
        var currentPortfolioCategory = getPortfolioCategoryFromQueryString();
        
        jQuery_1_3_2('#portfolio-list .' + currentPortfolioCategory).each(function(i) {
            var divclass = jQuery_1_3_2(this).attr("class");
            var clientName = divclass.substring(0, divclass.indexOf(" "));
            var wat = "/portfolio_files/client_html/" + clientName + "_" + currentPortfolioCategory + ".htm";
            jQuery_1_3_2(this).colorbox({href:"/portfolio_files/client_html/" + clientName + "_" + currentPortfolioCategory + ".htm"});
        });
        
        jQuery_1_3_2("#portfolio-filter li a").click(function(e){
            var rel = jQuery_1_3_2(this).attr("rel").toString();
            currentPortfolioCategory = rel;
            
            jQuery_1_3_2('#portfolio-list .' + currentPortfolioCategory).each(function(i) {
                var divclass = jQuery_1_3_2(this).attr("class");
                var clientName = divclass.substring(0, divclass.indexOf(" "));
                var wat = "/portfolio_files/client_html/" + clientName + "_" + currentPortfolioCategory + ".htm";
                jQuery_1_3_2(this).colorbox({href:"/portfolio_files/client_html/" + clientName + "_" + currentPortfolioCategory + ".htm"});
            });
        });
        
        //Demo link for Loren's use on independent pages.
        //jQuery_1_3_2("#portfolioLinkGause").colorbox({href:"/portfolio_files/client_html/inline_gausebuiltboats_online.htm"});
        
        //Make portfolio filterable.
        jQuery_1_3_2('#portfolio-list').filterable();


        //Enable smooth scroll javascript for scrolling to in-page anchors.
        enable_smooth_scroll();

        //Enable various colorboxes.
        jQuery_1_3_2(".colorbox").colorbox();
        jQuery_1_3_2("a[rel='group1']").colorbox();
        jQuery_1_3_2("a[rel='group2']").colorbox();
        jQuery_1_3_2("a[rel='group3']").colorbox();
        jQuery_1_3_2("a[rel='group4']").colorbox();
        jQuery_1_3_2("a[rel='group5']").colorbox();
        jQuery_1_3_2("a[rel='group6']").colorbox();
        jQuery_1_3_2("a[rel='group7']").colorbox();
        jQuery_1_3_2("a[rel='group8']").colorbox();
        jQuery_1_3_2("a[rel='group9']").colorbox();
        jQuery_1_3_2("a[rel='group10']").colorbox();
        
        var popClient = querySt("popclient");
        if (popClient != null) {
            var clientDiv = "#inline_" + popClient;
            jQuery_1_3_2.fn.colorbox({ inline: true, href: clientDiv, open:true});
        }

        jQuery_1_3_2(".youtube").colorbox({ iframe: true, width: 650, height: 550 });
        jQuery_1_3_2(".iframe").colorbox({ width: 950, height: "80%", iframe: true });

        //Enable anythingSlider script on divs with anythingSlider class.
        jQuery_1_3_2('.anythingSlider').anythingSlider({
            easing: "easeInOutQuart",        // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
            delay: 4500,                    // How long between slide transitions in AutoPlay mode
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            animationTime: 2000,             // How long the slide transition takes
            hashTags: true,                 // Should links change the hashtag in the URL?
            buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
            pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
            startText: "Go",             // Start text
            stopText: "Stop"               // Stop text
        });

        
        jQuery_1_3_2("#accordion").accordion({ autoHeight: false });
        
        
	jQuery_1_3_2('.testimonialLink').click(function(e){
		e.preventDefault();
	});
	
    var count = 1;
	var totalItems = 4;
	
	var jQuery_1_3_2paneOptions = jQuery_1_3_2('#pane-options');
	
	var myArray = [];
	
	jQuery_1_3_2('#elements').children("div").each(function(i) {
	    myArray[i] = jQuery_1_3_2(this).height();
	});
	var AnimationStatus = 1;
	function gotoAndScroll() {
	    AnimationStatus = 1;
	    jQuery_1_3_2('#elements').children("div").css("height", myArray[count - 1]);
	    
	    var currentObj = "#" + count.toString();
	    
	    var prevObj = "#" + (count - 1).toString();
	    
	    var paneHeight = jQuery_1_3_2('#pane-options').height();
	    
	    var targetHeight = jQuery_1_3_2(currentObj).height();
	    
	    if (targetHeight > paneHeight) {
	        var targetBottom = jQuery_1_3_2(currentObj).height() - jQuery_1_3_2('#pane-options').height();
	    } else {
	        var targetBottom = jQuery_1_3_2('#pane-options').height() - jQuery_1_3_2(currentObj).height();
	    }
	    
	    var scrollSpeed = 4000;
	    
	    if ((targetHeight >= 301) && (targetHeight <= 400)) {
	        scrollSpeed = targetHeight * 18;
	    };
	    
	    if ((targetHeight >= 401) && (targetHeight <= 500)) {
	        scrollSpeed = targetHeight * 20;
	    };
	    
	    if ((targetHeight >= 501) && (targetHeight <= 600)) {
	        scrollSpeed = targetHeight * 22;
	    };
	    
	    if ((targetHeight >= 601) && (targetHeight <= 700)) {
	        scrollSpeed = targetHeight * 24;
	    };
	    
	    if ((targetHeight >= 701) && (targetHeight <= 800)) {
	        scrollSpeed = targetHeight * 26;
	    };
	    
	    if ((targetHeight >= 801) && (targetHeight <= 900)) {
	        scrollSpeed = targetHeight * 28;
	    };
	    
	    if ((targetHeight >= 901) && (targetHeight <= 1000)) {
	        scrollSpeed = targetHeight * 30;
	    };
	    
	    if (targetHeight >= 1001) {
	        scrollSpeed = targetHeight * 28;
	    };
	    
	    
	    jQuery_1_3_2paneOptions.scrollTo(prevObj, 500, {offset: {top:0},
	        onAfter:function() { 
	            jQuery_1_3_2paneOptions.scrollTo(currentObj, 2000, { 
			        onAfter:function(){
				        AnimationStatus = 0;
				        jQuery_1_3_2paneOptions.scrollTo(currentObj, scrollSpeed, {offset: {top: targetBottom}, easing: 'linear',
				            onAfter:function() {
				                jQuery_1_3_2('#pane-options').animate({ opacity: 1.0 }, 6000, function() { advanceTestimonials("next"); }); 
				            }
				        });
			        }
		        });
		    } 
		});
	};
	
	
	var timer;
	jQuery_1_3_2(document).mousemove(function(){
		clearTimeout(timer);
		timer=setTimeout(function(){
			if(jQuery_1_3_2.isHovered('#pane-options'))
	        if (AnimationStatus == 0){
	            jQuery_1_3_2('#pane-options').stop();
	        }
		},10);
	});
	
	jQuery_1_3_2('#pane-options').hover(function() {
    },
    function() {
        jQuery_1_3_2('#pane-options').animate({ opacity: 1.0 }, 6000, function() { advanceTestimonials("next"); });
    });

	jQuery_1_3_2('#next').click(function(){
	    jQuery_1_3_2('#pane-options').stop();
        advanceTestimonials("next");
	});
	
	jQuery_1_3_2('#prev').click(function(){
	    jQuery_1_3_2('#pane-options').stop();
        advanceTestimonials("prev");
	});
	
	jQuery_1_3_2('#A1').click(function(){
	    jQuery_1_3_2('#pane-options').stop();
        advanceTestimonials("1");
	});
	
	jQuery_1_3_2('#A2').click(function(){
	    jQuery_1_3_2('#pane-options').stop();
        advanceTestimonials("2");
	});
	
	jQuery_1_3_2('#A3').click(function(){
	    jQuery_1_3_2('#pane-options').stop();
        advanceTestimonials("3");
	});
	
	jQuery_1_3_2('#A4').click(function(){
	    jQuery_1_3_2('#pane-options').stop();
        advanceTestimonials("4");
	});
	
	function advanceTestimonials(target) {
	    if (target == "next"){
        count++;
        }
	    if (target == "prev"){
        count--;
        }
        if(is_int(target)) {
            count = target;
        }
        if (count > totalItems) {
            count = 1;
        } else if ((count == 0) || (count == -1)) {
            count = totalItems;
        }
        gotoAndScroll();
	}
	
	function getPortfolioCategoryFromQueryString()
    {
        var regex = new RegExp("[\\#&]([^&#]*)");
        var qs = regex.exec(window.location.href);
        if(qs == null)
        return "1";
        else
        return qs[1];
    }

    function is_int(value){
        if((parseFloat(value) == parseInt(value)) && !isNaN(parseInt(value))){
            return true;
        } else {
            return false;
        }
    }
    
    jQuery_1_3_2('#elements').children("div").css("height", myArray[count - 1]);
    
	advanceTestimonials("1");
	

    });