$(document).ready(function()
{	setInterval("slideSwitch()", 7500 );
	$menuNorm = 0.4;
	$(".pageone, .portfolio, .resume, .vitals, .contact").css({opacity: $menuNorm});
	$(".pageone, .portfolio, .resume, .vitals, .contact").hover(function(){$(this).stop().fadeTo("slow",1);},function(){$(this).stop().fadeTo("slow",$menuNorm);});
	
	$(".sectionMenu ul li").css({opacity:.7});
	$(".sectionMenu ul li").hover(function(){$(this).stop().fadeTo("slow",1);},function(){$(this).stop().fadeTo("slow",.7);});
	
	$(".stat .statText").css({opacity:0});
	$(".stat img").css({opacity:.4});
	$(".stat").hoverIntent(function(){$(this).find("div.statText").stop().fadeTo("fast",1);},function(){$(this).find("div.statText").stop().fadeTo("slow",0);});
	
	$(".endorsements a").css({opacity:.5});
	$(".endorsements a").hover(function(){$(this).stop().fadeTo("fast",.9);},function(){$(this).stop().fadeTo("slow",.5);});
	
	$.localScroll.defaults.axis='x';
	$.localScroll.hash({target: '#content', queue:true, duration:1500});
	
	$('#header, .title, #pageone, .quickClick').localScroll({target:'#content',queue:true,duration:2000,hash:true,onBefore:function(e,anchor,$target){},onAfter:function(anchor,settings){}});
	$('#resume .sectionMenu').localScroll({target:'#resumeContent',queue:true,duration:1500,onBefore:function(e,anchor,$target){},onAfter:function(anchor,settings){}});
	$('#vitals .sectionMenu').localScroll({target:'#vitalsContent',queue:true,duration:1500,onBefore:function(e,anchor,$target){},onAfter:function(anchor,setting ){}});

	$('.infiniteCarousel').infiniteCarousel();
	$(".infiniteCarousel a img").hoverIntent(
		function(){$(this).stop().fadeTo("slow",.6);$(this).parent().parent().find("div.hoverPad:hidden").fadeIn(200);},
		function(){$(this).stop().fadeTo("slow",1);$(this).parent().parent().find("div.hoverPad:visible").fadeOut(500);}
	);
		
	$("div[id*='slot']").css('visibility','hidden');
	$("div[id*='slot']").css('opacity','0');
	$("img[id*='slot']").mouseover( function(e){ $("#" + this.id + "Hover").css('visibility','visible'); $("#" + this.id + "Hover").stop().fadeTo("slow",1); });
	$("img[id*='slot']").mouseout(function(e){ $("#" + this.id + "Hover").css('visibility','hidden').css('opacity','0');});
	$("img[id*='slot']").mousemove(function(e){
		var hoverDiv = "#" + this.id + "Hover";
		$(hoverDiv).css('position','absolute');
		$(hoverDiv).css('top',e.pageY-400);
		$(hoverDiv).css('left',e.pageX-480);
		$(hoverDiv).css('z-index','999');
	});
	
	$("a[target*='_blank']").click(function(){	pageTracker._trackPageview('/outbound/'+ $(this).attr('href'));});
	$(".pageone, .portfolio, .resume, .vitals, .contact, .title, #nav").click(function(){	pageTracker._trackPageview('/in/'+ $(this).attr('href'));});

});

function slideSwitch()
{	var $active=$('#slideshow DIV.active');
	if ($active.length==0) $active=$('#slideshow DIV:last');
	var $next=$active.next().length ? $active.next():$('#slideshow DIV:first');
	$active.addClass('last-active');
	$next.css({opacity:0.0}).addClass('active').fadeTo(3000,1,function(){$active.removeClass('active last-active');});
	
	var $activePortfolio=$('#portfolioSlideshow DIV.active');
	if ($activePortfolio.length==0) $activePortfolio=$('#portfolioSlideshowDIV:last');
	var $nextPortfolio=$activePortfolio.next().length ? $activePortfolio.next():$('#portfolioSlideshow DIV:first');
	$activePortfolio.addClass('last-active');
	$nextPortfolio.css({opacity:0.0}).addClass('active').fadeTo(3000,1,function(){$activePortfolio.removeClass('active last-active');});
}

$.fn.infiniteCarousel = function () 
{	function repeat(str, num) { return new Array( num + 1 ).join( str ); }
  
    return this.each(function () 
    {	var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),
            
            singleWidth = $single.outerWidth(), 
            visible = Math.ceil($wrapper.innerWidth() / singleWidth),
            currentPage = 1,
            pages = Math.ceil($items.length / visible);            

			if (($items.length % visible) != 0) 
			{	$slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
           		$items = $slider.find('> li');
			}

        	$items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        	$items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        	$items = $slider.find('> li');
       		$wrapper.scrollLeft(singleWidth * visible);
        
        	function gotoPage(page) 
        	{	var dir = page < currentPage ? -1 : 1,
               		n = Math.abs(currentPage - page),
                	left = singleWidth * dir * visible * n;
            
           		$wrapper.filter(':not(:animated)').animate({
	            scrollLeft : '+=' + left
	            }, 500, function () {
	                if (page == 0) {
	                    $wrapper.scrollLeft(singleWidth * visible * pages);
	                    page = pages;
	                } else if (page > pages) {
	                    $wrapper.scrollLeft(singleWidth * visible);
	                    // reset back to start position
	                    page = 1;
	                } 
	                currentPage = page;
			});
            return false;
        }
        
        $wrapper.after('<a class="arrow back"> </a><a class="arrow forward"> </a>');
        $('a.back', this).click(function () { return gotoPage(currentPage - 1); });
        $('a.forward', this).click(function () { return gotoPage(currentPage + 1); });
        $(this).bind('goto', function (event, page) { gotoPage(page); });
    });  
};