// jQuery onReady
$(document).ready(function() {

		
	/*
	 *	Home Feature
	 */
	 	$("#home_feature").find('.fallback').hide();
	 	$("#home_feature").find('.features, .nav_features, .nav, .arrow_left, .arrow_right').show();
		
		$("#home_feature").scrollable({
			items: '.features',
			next: '.arrow_right a',
			prev: '.arrow_left a',
			speed: 800,
			easing: 'easeInOutSine',
			circular: true,
			
			onBeforeSeek: function() {
				// animate out image
				var feature = this.getItems().eq(this.getIndex()).find('img:not(:animated)').animate({
					top: ['250', 'swing']
				}, 250);
			},
			
			onSeek: function() {
				var $index = this.getIndex();
				
				// update secondary nav
				$("#home_feature").find('.nav_items a').eq($index).addClass('active').siblings().removeClass('active');
				
				// animate in image
				this.getItems().eq($index).find('img').animate({
					top: ['-100', 'swing']
				}, 750);
			}
		}).navigator({
			navi: '.nav_features'
		}).autoscroll({
			interval: 7500,
			autoplay: false //Autoplay needs to be started with api (below) or it can't be stopped
		});
		
		//When user clicks on a nav item we will stop autoscroll
		$('.nav_features>a, .nav_items a, .arrow_left, .arrow_right').bind('click', function() {
			  scrollableApi.stop();
		});
		
		
		// animate in feature image on load
		$("#home_feature").find('.feature:first img').animate({
			top: ['-100', 'easeOutBack']
		}, 750);
		
		
		$("#home_feature").find('.nav_items a').click(function() {
			var $index = $("#home_feature").find('.nav_items a').index(this);
			$("#home_feature").data('scrollable').seekTo($index);
		});
		
		// get handle to scrollable API 
		scrollableApi = $("#home_feature").data("scrollable"); 
	 		
	 		
	

	 	
	/*
	 *	Process feature
	 */
	 	$("#home_feature").find(".XXXcontent").fadeOut().delay(1000).fadeIn('slow');
	 	
	 	
	 	
	/*
	 *	Start homepage scrollable autoplay after 5.5 seconds
	 */	
		if (scrollableApi) {
			setTimeout ( "startAutoScroll()", 5500 );
		}
	
	
	
	/*
	 *	PNG fix for ie6
	 */	
		var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
		if (badBrowser) {
			// png fix
			$('img[src$=.png]').each(function() {
				if (!this.complete) {
					this.onload = function() { fixPng(this) };
				} else {
					fixPng(this);
				}
			});
			// cache bg images
			try {
				document.execCommand("BackgroundImageCache", false, true);
			  } catch(err) {}
		}

	
});



	
	
	// Jquery Scrollable start auto scroll
	function startAutoScroll()
	{
		scrollableApi.play();
	}


	// PNG fix for ie6	
	function fixPng(png)
	{
		var src = png.src;
		if ( ! png.style.width)
		{
			png.style.width = $(png).width();
		}
		if ( ! png.style.height)
		{
			png.style.height = $(png).height();
		}
		png.onload = function() { };
		png.src = blank.src;
		png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	}

