

$eyeslide = {

    context: false,
    tabs: false,
    timeout: 6000,      // time before next slide appears (in ms)
    slideSpeed: 500,   // 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
    fx: 'fade',   		// the slide effect to use: fade,scrollUp,shuffle, zoom, turnDown, curtainX, scrollRight
		width:944,
    
    init: function() {
	
        // set the context to help speed up selectors/improve performance
        this.context = $('#eyeslide');
        
        // set tabs to current hard coded navigation items
        this.tabs = $('ul.slider-control li', this.context);
        
        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();
        
        // prepare eyeslide and jQuery cycle tabs
        this.prepareSlideshow();
		
		// $('div.slide-container').hover(
			 // function () {
				// $('div.slide-container ', $eyeslide.context).cycle('pause');
				// $('#loader').stop();
			  // }, 
			  // function () {
				// $('div.slide-container ', $eyeslide.context).cycle('resume');
				// $('#loader').animate({width:  $eyeslide.width}, $eyeslide.timeout, function() { $('#loader').css('width', 0); });
			  // }
		// );
		
		this.tabs.click(function(){
			$('#loader').stop(true, true);
			$('#loader').css('width', 0);
			$('#loader').animate({width:  $eyeslide.width}, $eyeslide.timeout, function() { $('#loader').css('width', 0); });
		});
    },
	    
    prepareSlideshow: function() {
        // initialise the jquery cycle plugin - for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        $('div.slide-container ', $eyeslide.context).cycle({
            fx: $eyeslide.fx,
            timeout: $eyeslide.timeout,
            speed: $eyeslide.slideSpeed,
            fastOnEvent: $eyeslide.tabSpeed,
            pager: $('ul.slider-control', $eyeslide.context),
            pagerAnchorBuilder: $eyeslide.prepareTabs,
            before: $eyeslide.activateTab,
            pauseOnPagerHover: false,
            pause: false,
			width: $eyeslide.width
        });            
    },
    
    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $eyeslide.tabs.eq(i);
    },

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

/*
jQuery plugin : pause resume animation
Created by Joe Weitzel
BOX Creative LLC
http://plugins.jquery.com/project/Pause-Resume-animation
*/
jQuery.fn.startAnimation = function(  params, duration, easing, callback ) {
	jQuery(this).animate( params, duration, easing, callback );
	var data = { target:this.get(0), params: params, duration: duration, easing: easing, callback: callback,
				startTime: new Date().getTime(), timePlayed: 0, timeRemaining: 0 };
	if( !jQuery.pauseableAnimations ) {
		jQuery.extend({ pauseableAnimations: new Array( data ) });
	} else {
		for( var i in jQuery.pauseableAnimations ) {
			if( jQuery.pauseableAnimations[i].target == this.get(0) ) {
				jQuery.pauseableAnimations[i] = data;
			} else {
				jQuery.pauseableAnimations.push( data );
			};
		};
	};
};
jQuery.fn.pauseAnimation = function() {
	if( jQuery.pauseableAnimations ) {
		for(var i in jQuery.pauseableAnimations ) {
			if( jQuery.pauseableAnimations[i].target == this.get(0) ) {
				jQuery(this).stop();
				var now = new Date().getTime();
				var data = jQuery.pauseableAnimations[i];
				data.timePlayed += ( now - data.startTime );
				data.timeRemaining = data.duration - data.timePlayed;
				if( data.timePlayed > data.duration ) {
					var newArray = new Array();
					for( var p in jQuery.pauseableAnimations ) {
						if( jQuery.pauseableAnimations[p] != data ) newArray.push( jQuery.pauseableAnimations[p] );
					};
					jQuery.pauseableAnimations = newArray.length > 0 ? newArray : null;
					delete newArray;
					return this;
				};
				break;
			};
		};
	};
	return this;
};
jQuery.fn.resumeAnimation = function() {
	if( jQuery.pauseableAnimations ) {
		for(var i in jQuery.pauseableAnimations ) {
			var data = jQuery.pauseableAnimations[i];
			if( data.target == this.get(0) ) {
				this.animate( data.params, data.timeRemaining, data.easing, data.callback );
				data.startTime = new Date().getTime();
				return this;
			};
		};
	};
};

