var heroStartHeight=0;
var heroInfoTimer=350;

$(document).ready(function(){
	
	heroStartHeight = $('#home-page .lhs #hero-item div').css('height');
	
	$('#home-carousel #productCarousel').jcarousel({'scroll' : 3});

	var thisItem;
	var startHeight;
	$('#home-carousel .item').hover(function(){		
		startHeight = $(this).find('span').css('height'); 		
		$(this).find('span').animate({'height' : '110px'}, 250);
		$(this).find('div').animate({'height' : '110px'}, 250);
	}, function(){
		
		$(this).find('span').animate({			
			'height' : '30px'
		});
		$(this).find('div').animate({			
			'height' : '30px'
		});
	});
	
	var startOpacity;
	var thisSpan;
	var startZIndex;
	var startPos;
	$('#news-items ul li').hover(function(){		
		thisSpan = $(this).find('span.overlay');		
		
		//Get starting vars
		startOpacity = $(thisSpan).css('opacity');	
		startZIndex = $(thisSpan).css('z-index');
		startPos = $(thisSpan).css('left');		
		startFilter = startOpacity*100;
		
		//Animate and move the overlay
		$(thisSpan).animate({
			'opacity' : 0.0
			,filter: 'alpha(opacity = 0)'
		}, 250);
		$(thisSpan).css({
			'z-index' : 5
			,'left' : '-10000px'
		});
	}, function(){
		
		//Move the overlay back into place
		$(thisSpan).animate({
			'opacity' : startOpacity
			,filter: 'alpha(opacity = '+startFilter+')'
		}, 250);
		$(thisSpan).css({'z-index' : startZIndex});
		$(thisSpan).css({'left' : startPos});
	});
		
	 Local = 
	  {
	    config: 
	    {
	    	clip:
	    	{		    		
	    		bitrates: [
							{ url: "mp4:" + $("#hid_stream_file").val(), bitrate: 1500 }
			         ]
	 			,onFinish : function(){
	 				$f(0).unload();
	 				$('#home-page .lhs #hero-item div').css('display', 'block');	
	 				$('#home-page .lhs #hero-item div').animate({
	 					'height' : heroStartHeight
	 				}, heroInfoTimer);
	 			} 
	    	},
	    	plugins :
	    	{
	    		rtmp: { netConnectionUrl: $("#hid_stream_base").val() },
	    		bwcheck: { netConnectionUrl: $("#hid_stream_base").val() },
	 			controls:
		        {
		  			'play' : false
		    		,"scrubber" : true //Show the timeline bar
		        }
	    	}	    	
	    }
	  };
			  
	//Activate the player and remove all decoration
	$('a#media-player').click(function(e)
	{
		e.preventDefault();
		if(!$f(0)){
			$('#home-page .lhs #hero-item div').animate({
				'height' : '0px'
			}, heroInfoTimer, function(){
				$.extend(true, Global.config, Local.config);
				$('#home-page .lhs #hero-item div').css('display', 'none');			
				$f("media-player", "/_assets/flowplayer/flowplayer.commercial-3.2.5.swf", Global.config);
				$f(0).play();			
			});
		}		
	});	 
			
});	


