/*
	home.js	
*/

// =========================================================================================
//
// jQuery home
//
// =========================================================================================
	$(document).ready(function() {
		
		// homepage scroller
		var api = $("div.scrollable").scrollable({
			vertical: true, 
			size: 1,
			clickable: false,
			loop: true
		}).mousewheel().autoscroll({
			autoplay: true,
			autopause: true,
			steps: 1,
			interval: 5000,
			api: true
		})/*.circular({api: true})*/;	
		
		// on auto change update highlight
		api.onSeek(function() {
					  
			// remove highlight on previously selected item
			$('#promo-right .scrollable a.active').removeClass('active');
			
			// get new selected item
			var selectedItem = $('#promo-right .scrollable a').eq(this.getIndex()/* + this.getConf().size*/);
			
			// highlight new selected item
			selectedItem.addClass('active');
			
			// alert new selected item href
			
			var displayImg = '#promo-right a.display';
			var href = selectedItem.attr('href');
			var src = selectedItem.find('img').attr('src');
			src = src.replace('.small', '.large');
			var width = $(displayImg).find('img').attr('width');
			var height = $(displayImg).find('img').attr('height');
			
			var image = $(displayImg).find('img');
			image.removeClass('new').after('<img src="' + src + '" width="' + width + '" height="' + height + '" alt="" class="display new" style="display: none">');
			$(displayImg).find('img.new').fadeIn('slow', function() {
				$('#promo-right a.display').attr('href',href);
				image.remove();
			});
			
/*			$(displayImg).find('img').fadeOut('normal', function(){
				$(this).remove();
				$(this).parent('a.display').attr('href', href);
				$('#promo-right a.display').html('<img src="' + src + '" width="' + width + '" height="' + height + '" alt="" class="display" style="display: none">');
				$(displayImg).find('img').fadeIn('slow');
			});*/

		});		
		
		$('#promo-right .scrollable a').click(function(e) {
			e.preventDefault();
			
			api.seekTo($('#promo-right .scrollable a').index($(this)));
			
		});
		
	});
