$(document).ready(function(){
	
	var agent=navigator.userAgent.toLowerCase();
	var useHTML5 = (agent.indexOf('iphone')!=-1 || agent.indexOf('ipad')!=-1);

	//if (useHTML5){
	//	$('#video_player').append("<video height='300' width='480' id='myytplayer' class='projekktor' controls autobuffer><source src='http://www.youtube.com/demo/google_main.mp4' type='video/mp4' /></video>");
//	} else {w
		var params = { allowScriptAccess: 'always', allowFullScreen: 'true' };
		var atts = { id: "myytplayer" };
		swfobject.embedSWF("http://www.youtube.com/v/G1B3oUOjHJo?enablejsapi=1&fs=1&hd=1", 
		                       "video_player", "480", "300", "8", null, null, params, atts);
	//}

	$('.scroll').jScrollPane();
	
	products();
	
	$('.ticker').type3_ticker({
		speed:10000
	});
	
	$('#video_slider').jCarouselLite({
		btnNext:".right_arrow",
		btnPrev:".left_arrow",
		easing:"easeOutSine",
		speed:600
	});
	
	$('#video_thumbs li a').click(function(){
		
		$('#video_thumbs li.on').removeClass('on');
		$(this).parent().addClass('on');
		
		var id = $(this).attr('name');

		ytplayer.loadVideoById(id);

		return false;
	});
});


function products(){
	$('.product_thumbs li').click(function(){
		
		if ($(':animated').length) {
			return false;
		}
		
		var product = $(this).attr('id');
		
		$('.product_thumbs li').removeClass('on');
		$(this).addClass('on');
		
		$('.product.on').fadeOut('fast',function(){
			$(this).removeClass('on').addClass('off');
			$('.'+product).fadeIn('fast').addClass('on').removeClass('off');
		});	
		
	});
}

function onYouTubePlayerReady(playerId) {
    ytplayer = document.getElementById("myytplayer");
	ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}

function onytplayerStateChange(newState) {
	setytplayerState(newState);

}

function getPlayerState() {
  if (ytplayer) {
	return ytplayer.getPlayerState();
  }
}

function updateHTML(elmId, value) {
  document.getElementById(elmId).innerHTML = value;
}

function setytplayerState(newState) {
  updateHTML("playerstate", newState);
}
