if (typeof(REWIND) == 'undefined') {
	REWIND	= {};
	REWIND.UI	= {};
}

REWIND.UI.Home	= function()
{
	if( jQuery.browser.msie && (jQuery.browser.version <= 7)) {
		var slideshow	= {
			totalImages: 6,
			speed: 'slow',
			path: '/assets/img/feature-thefestival-bg-1.gif',
			current: 'a'
		}
	}else{
		var slideshow	= {
			totalImages: 6,
			speed: 'slow',
			path: '/assets/img/feature-thefestival-bg-1.png',
			current: 'a'
		}
	}
	
	var init	= function() {
		
		if ($('#feature')) {
			initFeature();
		}

	}
	
	
	var initFeature	= function() {
		
		var panelWidth = 820;
		
		
		$.get('/_ajax/homefeature', function(data){
			$('#feature .feature-content:first').after(data);
			$('#feature .feature-container').wrapInner('<div id="scrollplane"></div>');
			$('#feature .feature-container, #feature .feature-content').css('height', $('#scrollplane').css('height'));
			
			$('#feature-tabs li a').click(function(e){
				e.preventDefault();
				var link = $(e.target);
				var screenNo = parseInt(link.attr('href').replace('/home/', ''));
				
				var newLeft = (panelWidth * screenNo) - panelWidth;
				
				$('#scrollplane').animate({
					left: (0 - newLeft) + 'px'
				}, {
					duration: 1000,
					easing: 'swing'
				});
				
				$('#feature-tabs li a').removeClass('cur');
				link.addClass('cur');
				
			});
			
			drawHomeHeadings();
			initFeatureSlideshow();
		});
		
		
	}
	
	var initFeatureSlideshow = function() {
		var totalImages = 6; // max 9 in current implementation
		var container = $('#feature .screen1 div.img');
		
		container.html('<img id="slideshow-a" src="'+slideshow.path+'" alt="" /><img id="slideshow-b" src="" alt="" />');
		$('#feature #slideshow-b').hide();
		
		window.setInterval('REWIND.UI.Home.nextImage()', 3000);
	}
	
	var nextImage = function() {
		if (slideshow.current == 'a') {
			var incoming = $('#slideshow-b');
			var outgoing = $('#slideshow-a');
			var nextCurrent = 'b';
		}else{
			var incoming = $('#slideshow-a');
			var outgoing = $('#slideshow-b');
			var nextCurrent = 'a';
		}
		
		var currentPath = outgoing.attr('src')
		var currentIndex = parseInt(currentPath.substring(currentPath.length-5, currentPath.length-4));
		
		if (currentIndex == slideshow.totalImages) {
			var nextIndex = 1;
		}else{
			var nextIndex = currentIndex + 1;
		}
		if( jQuery.browser.msie && (jQuery.browser.version <= 7)) {
			
			incoming.attr('src', slideshow.path.replace('1.gif', nextIndex+'.gif'));
		}else{
			incoming.attr('src', slideshow.path.replace('1.png', nextIndex+'.png'));
		}
		outgoing.fadeOut(slideshow.speed);
		incoming.fadeIn(slideshow.speed);
		slideshow.current = nextCurrent;
	}
	

	return {
		init: init,
		nextImage: nextImage
	}
	
}();

jQuery(function($) { REWIND.UI.Home.init(); });