var sortmode = false;
			
$(document).ready(function(){
	function slide(direction) {
		var itemWidth = 104;
		var numItems = $("#mask ul li").length;
		var currentOffset = $("#mask ul").position().left;
		
		if (!direction) {
			$("#mask ul").animate({left:"0px"});
		}
		if (numItems > 6) {
			if (direction == 1 && currentOffset < 104) {
				$("#mask ul").animate({left:(currentOffset+(itemWidth*direction))+"px"});
			} else if (direction == -1 && currentOffset > ((numItems - 6)*itemWidth*-1)) {
				$("#mask ul").animate({left:(currentOffset+(itemWidth*direction))+"px"});
			}
		}
	}
	
	function sort(typ) {
		sortmode = true;
		slide(0);
		$('#mask ul').append($('#mask ul li[movietype='+typ+']'));
		$('#mask ul li').attr('faded','false');
		$('#mask ul li[movietype='+typ+']').attr('faded','true');
		$('#mask ul li').css({opacity:1});
		$('#mask ul li[movietype='+typ+']').fadeTo('slow',0.1);
		return false;
	};
	
	$("#homepage, #aboutpage").css({opacity:0,visibility:'visible'}).fadeTo(231,.3).fadeTo(66,0).fadeTo(66,1).fadeTo(66,.2).fadeTo(66,0).fadeTo(330,1,function(){
		$('.scrollLeft, .scrollRight, #mask').fadeIn();
	});
	$("#NowPlaying").click(function() { return sort('ComingSoon'); });
	$("#ComingSoon").click(function() { return sort('NowPlaying'); });
	$(".scrollLeft").click(function() { slide(1); });
	$(".scrollRight").click(function() { slide(-1); });
	$("#mask ul li").click(function() {
		// este is spanish for this...
		var este = this;
		if ($("#aboutpage").size()) {
			window.location.href = '/projects.php?pid='+$(este).attr('movieid');
		}
		$("#player").fadeIn('fast',function(){
			$("#info").html('');
			$("#info").append('<h2>'+$(este).attr('movie')+($(este).attr('chasQT')=='true'||$(este).attr('chasFlash')=='true'? ' - Clip':'')+'</h2>');
			$("#info").append('<h3>&nbsp;'+$(este).attr('subtext')+'</h3>');
			$("#info").append('<a href="/projects.php?pid='+$(este).attr('movieid')+'">Click for synopsis</a><br />');
			if ($(este).attr('site'))
				$("#info").append('<a href="'+$(este).attr('site')+'" target="_blank">Visit the Official Site</a>');
			$("#info").append('<br><a class="tweetThis" target="tweet" href="http://twitter.com/share?via=ambushent&url=http%3A%2F%2Fwww.ambushentertainment.com%2Fprojects.php%3Fpid%3D'+$(este).attr('movieid')+'">Tweet</a><br />');
			
			if ($(este).attr('thasFlash') == 'true' && swfobject.hasFlashPlayerVersion("9.0.0")) {
				var flashvars = {
					flv:"/movies/"+$(este).attr('moviepath')+"/trailer.flv",
					autoplay:1,
					loop:0,
					margin:0,
					bgcolor:'#000000',
					buffermessage:''
				};
				swfobject.embedSWF("/flash/player_flv_maxi.swf", "playerdiv", "320", "170", "9.0.0","",flashvars);
				return;
			}
			if ($(este).attr('thasQT') == 'true' && haveqt) {
				$('#playerdiv').replaceWith(QT_GenerateOBJECTText('/movies/'+$(este).attr('moviepath')+'/trailer.mov','320','170','','playerdiv','obj#ID','playerdiv','autostart','true','bgcolor','#1C150C','scale','tofit','showlogo','false'));
				return;
			}
			if ($(este).attr('chasFlash') == 'true' && swfobject.hasFlashPlayerVersion("9.0.0")) {
				var flashvars = {
					flv:"/movies/"+$(este).attr('moviepath')+"/clip.flv",
					autoplay:1,
					loop:0,
					margin:0,
					bgcolor:'#000000',
					buffermessage:''
				};
				swfobject.embedSWF("/flash/player_flv_maxi.swf", "playerdiv", "320", "170", "9.0.0","",flashvars);
				return;
			}
			if ($(este).attr('chasQT') == 'true' && haveqt) {
				$('#playerdiv').replaceWith(QT_GenerateOBJECTText('/movies/'+$(este).attr('moviepath')+'/clip.mov','320','170','','playerdiv','obj#ID','playerdiv','autostart','true','bgcolor','#1C150C','scale','tofit','showlogo','false'));
				return;
			}
			$('#player').html('<div id="playerdiv">Trailer Coming Soon!</div>');
			
		});
	});
	$("#mask ul li").mouseover(function() {
		$("#yellowbar").stop(true);
		if ($(this).attr('faded')=='true') {
			$(this).css({opacity:1});
		}
		$("#yellowbar").html($(this).attr('movie')+'<span style="text-transform:none;"> - Click to View</span>');
		$("#yellowbar").fadeIn("fast").css({opacity:1});
	});
	$("#mask ul li").mouseout(function() { 
		if ($(this).attr('faded')=='true') {
			$(this).css({opacity:.1});
		}
		$("#yellowbar").fadeOut('slow');
	});
	$("#mask").mousemove(function(e) {
		var _xmouse = e.pageX - ($(window).width() - 672)/2;
		var stripewidth = $("#yellowbar").text().length * 8
		$("#yellowbar").css({'text-indent':Math.floor(_xmouse - (stripewidth*(_xmouse/672)))+'px'});
	});
});
