;(function($){

$slideshow = {
    context:    false,
    tabs:       false,
    timeout:    5000,  // time before next slide appears (in ms)
    slideSpeed: 100000,   // time it takes to slide in each slide (in ms)
    tabSpeed:   500,   // time it takes to slide in each slide (in ms) when clicking through tabs
    
    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#slides_cell');
        
        // set tabs to current hard coded navigation items
        this.tabs = $('#slides_nav li', this.context);
        
        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();
        
        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },
    
    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        $('#slides', $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $('#slides_nav', $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true,
			height: '120px'
        });            
    },
    
    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);
        
        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideshow.tabs.removeClass('active');
            
            // add active styling to active button
            activeTab.parent().addClass('active');
        }            
    }            
};

$slideshowQuote = {
	init : function() {

		// Infinite scroller
		$('#right_scroll a').click(function() {
			$('#carousel_ul li:first').before($('#carousel_ul li:last'));        // Reverse the li's so that sliding left works
			$('#carousel_ul').css('left', -($('#carousel_inner').width() + 30)); // 30 = 10 pixel gutter between four icons
			$('#carousel_ul:not(:animated)').animate({'left': 0}, 500);			 
		});

		// Quotes section
		$('#carousel_ul li:first a:last').addClass('active');
		$("#quotes blockquote:last").show();
		
		$("#carousel_ul a").click(function() {
		
			$("#carousel_ul a").removeClass("active");
			$(this).addClass("active");
		
			$("#quotes blockquote").hide();
		
			var activeQuote = $(this).attr("href");
			$(activeQuote).fadeIn(250);
		
			return false;
		});
		
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
		
		//On Click Event
		$("ul.tabs li").click(function() {
		
			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content
		
			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});
	}
}

$(document).ready(function() {
	
   

	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
				//Vertical Sliding
				$('.boxgrid.slidedown').hover(function(){
					$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
				}, function() {
					$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
				});
				//Horizontal Sliding
				$('.boxgrid.slideright').hover(function(){
					$(".cover", this).stop().animate({left:'325px'},{queue:false,duration:300});
				}, function() {
					$(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300});
				});
				//Diagnal Sliding
				$('.boxgrid.thecombo').hover(function(){
					$(".cover", this).stop().animate({top:'260px', left:'325px'},{queue:false,duration:300});
				}, function() {
					$(".cover", this).stop().animate({top:'0px', left:'0px'},{queue:false,duration:300});
				});
				//Partial Sliding (Only show some of background)
				$('.boxgrid.peek').hover(function(){
					$(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
				}, function() {
					$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
				});
				//Full Caption Sliding (Hidden to Visible)
				$('.boxgrid.captionfull').hover(function(){
					$(".cover", this).stop().animate({top:'120px'},{queue:false,duration:160});
				}, function() {
					$(".cover", this).stop().animate({top:'260px'},{queue:false,duration:160});
				});
				//Caption Sliding (Partially Hidden to Visible)
				$('.boxgrid.caption').hover(function(){
					$(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160});
				}, function() {
					$(".cover", this).stop().animate({top:'220px'},{queue:false,duration:160});
				});
				
				 // Initialise slideshow
    $slideshow.init();

	// Initialise slide gallery + click to show quote
    $slideshowQuote.init();

	// Initialise show large image on click
	//$(".screenshot").fancybox({
	//	'transitionIn'			: 'elastic',
	//	'transitionOut'			: 'elastic',
	//	'hideOnContentClick'	: true,
	//	'centerOnScroll'          : true
	//});
	
});
})(jQuery);
