﻿var i;

$(window).load(function() {
    $('#slider').nivoSlider({
        effect:'sliceDown',
        slices:15,
        animSpeed:1000,
        pauseTime:12000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:true, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:false, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        captionOpacity:0.8, //Universal caption opacity
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false //Force manual transitions
    });
});
        
$(document).ready(function() {
    i = 1;
    if ($("#slidingPanelsContainer").is(":visible")) {
	    var slideShow = window.setInterval(slide, 8000);
	}
	
	//Slide the photo panels on home page depending on which button was clicked
	$(".slide1button").click(function() {
	    window.clearInterval(slideShow);
	    $(".current").removeClass("current");
	    $(this).addClass("current");
	    $("#banner").scrollTo($("#slidingPanelsContainer .slide:nth-child(1)"), 1000, {axis:'x'});
	});
	
	$(".slide2button").click(function() {
		window.clearInterval(slideShow);	
		$(".current").removeClass("current");
		$(this).addClass("current");
		$("#banner").scrollTo($("#slidingPanelsContainer .slide:nth-child(2)"), 1000, {axis:'x'});					  
	});
	
	$(".slide3button").click(function() {
		window.clearInterval(slideShow);	
		$(".current").removeClass("current");
		$(this).addClass("current");
		$("#banner").scrollTo($("#slidingPanelsContainer .slide:nth-child(3)"), 1000), {axis:'x'};					  
	});	
	
	$(".slide4button").click(function() {
		window.clearInterval(slideShow);	
		$(".current").removeClass("current");
		$(this).addClass("current");
		$("#banner").scrollTo($("#slidingPanelsContainer .slide:nth-child(4)"), 1000, {axis:'x'});					  
	});
	
	$(".slide5button").click(function() {
	    window.clearInterval(slideShow);
	    $(".current").removeClass("current");
	    $(this).addClass("current");
	    $("#banner").scrollTo($("#slidingPanelsContainer .slide:nth-child(5)"), 1000, {axis:'x'});
	});
	
	$(".slide6button").click(function() {
		window.clearInterval(slideShow);	
		$(".current").removeClass("current");
		$(this).addClass("current");
		$("#banner").scrollTo($("#slidingPanelsContainer .slide:nth-child(6)"), 1000, {axis:'x'});					  
	});
	
	$(".slide7button").click(function() {
		window.clearInterval(slideShow);	
		$(".current").removeClass("current");
		$(this).addClass("current");
		$("#banner").scrollTo($("#slidingPanelsContainer .slide:nth-child(7)"), 1000, {axis:'x'});					  
	});	
	
	$(".slide8button").click(function() {
		window.clearInterval(slideShow);	
		$(".current").removeClass("current");
		$(this).addClass("current");
		$("#banner").scrollTo($("#slidingPanelsContainer .slide:nth-child(8)"), 1000, {axis:'x'});					  
	});
	
	//Scroll the Small Biz slides
	$("#slidingPanelsContainerSmallBiz").serialScroll({
        items:'div.projectSlide',
		prev:'.prev_slide',
		next:'.next_slide',
		duration:1200,
		force:true,		
		axis:'y',
		stop:true,
		lock:false,
		cycle:true, //pull back once you reach the end
        interval:8000, // yeah! I now added auto-scrolling
        onAfter: function() {
            if (i == 2) {
                $(".projectsNav:hidden").fadeIn("slow");
            }
            i++;
        }
    }); 
    
    //Center the client logos
    $(".logo_container img").each(function() {
        var $img = $(this);
        var $height = $img.height();
        var $width = $img.width();
        var $containerHeight = $img.parent().height();
        var $containerWidth = $img.parent().width();
        
        if ($height > 150) {
            $img.css("max-width", "none");
            $img.css("max-height", "130px"); 
            $height = 150;                                       
        }
        
        var $topMargin = ($containerHeight - $height) / 2;
        var $leftMargin = ($containerWidth - $width) / 2;
        
        $img.css("margin-top", $topMargin + "px");
    });
      
    //Cycle the client logos      
    $(".client_logos").cycle({
        fx: 'fade'  
    });
	
	//scroll the featured events
	$(".featured_event_frame").serialScroll({
        items:'div.featured_event',
		duration:1200,
		force:true,		
		axis:'x',
		stop:true,
		lock:false,
		cycle:true, //pull back once you reach the end
        interval:8000 // yeah! I now added auto-scrolling
    });
});

//Auto-slide the photo panels on home page
function slide() {	
		i = i + 1;
		if (i == 9) {
			i = 1;	
		}
		$("ul#slideNav:hidden").fadeIn("slow");
		var button = (".slide" + i + "button");
		$(".current").removeClass("current");
		$(button).addClass("current");
		$("#banner").scrollTo($("#slidingPanelsContainer .slide:nth-child(" + i + ")"), 1000, {axis:'x'});	
}
