
$(document).ready(function(){
	var api = $("div.scrollable").scrollable({api: true});
	
	var player = document.getElementById("player");
	var img = document.getElementById("img");
	var info = document.getElementById("info");
	var movieSrc = 'images/thumbs/announcers.mov'; 
	var deviceCheck = new Array("android","blackberry","iphone","ipad","ipod","series60","symbian","windows ce","palm")
	var uagent = navigator.userAgent.toLowerCase();
	var targetVidIndex;
	var mobile;
	
	for(var i; i < deviceCheck.lenth; i++){
		if(uagent.search(deviceCheck[i])!= -1){
			mobile = true;
		}
	}

	
	var loc = window.location.href;
	var targetVid = new Array;
	targetVid = loc.split('#');
	
	if(targetVid[1] == -1 || targetVid[1] == undefined){
		var targetVidIndex = 0;
	}	
	else{
		var targetVidIndex = parseFloat(targetVid[1]);
	}


	function loadGallery(){
		//clear everything out
			img.src = 'images/clear.gif';
			info.innerHTML = '';
			player.innerHTML = '';
			$('#player').css('display','none');

		//load back in
			$('#img').fadeIn("fast");
			movieSrc = $('#'+targetVidIndex).attr("rel");
			img.src = $('#'+targetVidIndex).attr("href");
			info.innerHTML = $('#'+targetVidIndex).attr("vtitle");
			$('#gallery').fadeIn("slow");
			api.click(targetVidIndex);
	}

	$("a.gallery").each(function (i){
		$(this).click(function(){
			$('#gallery').fadeOut("slow", function() {
				targetVidIndex = i;
				loadGallery();
      });
			return false;
		});
	});
	
	$("#img").click(function(){
		$('#player').css('display','block');
			$('#img').fadeOut("slow", function() {
				img.src = 'images/clear.gif';
      });
		
		if (mobile == true){
			movieSrc = movieSrc.replace(".mov", ".m4v");
			player.innerHTML = '<script language="javascript">QT_WriteOBJECT("'+movieSrc+'", "720","421", "", "autoplay", "true");</script>';
			//document.location("http://www.revelatorproductions.com/justaheart.mov");
			//document.location.replace(movieSrc);
		}
		else{
			//alert(movieSrc);
			player.innerHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="405" width="720"><param name="src" value="'+movieSrc+'"><param name="autoplay" value="true"><param name="type" value="video/quicktime" height="405" width="720"><param name="wmode" value="opaque" /><embed src="'+movieSrc+'" height="405" width="720" wmode="opaque" autoplay="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" /></object>';
		}
	});

	$("a.gallery").each(function (i){
		$(this).attr('id',i);
	});
	loadGallery();
	$('.scrollable').scrollLeft(0);
	
});
