// function for the landing slider
var position = 0;
var sliding = true;
var max_length = 1;
var captions = new Array('Digital-Sets','Ford F250 Super Duty','Nissan','Photorealism','Auto Trader','Prestone','Automotive','Aviation','Digital-Sets','Visual Effects');
	
function slide() {
	if (sliding) {
		position++;
		if (position==$("#landing_canvas a").length) {
			$("#landing_canvas a").hide();
			$("#image1").fadeIn();
			position = 0;
		} else {
			$("#image" + position).fadeOut();
			$("#image" + parseInt(position + 1)).fadeIn();
		}
		$(".caption").text(captions[position]);
		if ($(".active_dot").next().length) {
			temp = $(".active_dot").next();
			$(".active_dot").removeClass("active_dot");
			temp.addClass("active_dot");
		} else {
			$(".slider_dot:first").addClass("active_dot");
			$(".slider_dot:last").removeClass("active_dot");
		}
		setTimeout("slide()",4000);
	}
}
// youtube init
var ytplayer = null;
function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("YOUTUBE");
}
var vmplayer = null;
function onVimeoPlayerReady(playerId) {
	vmplayer = document.getElementById("VIMEO");
}
$(document).ready(function() {
	if ($('.novid').length) $(".novid img:first").fadeIn();
	if ($("#content").height()-215-$("#page").height() < $(window).height()) $("#footer").height($(document).height()-215-$("#page").height());
	$("#landing_slider a").click(function() {
		position = $(this).index();
		$("#landing_canvas a").hide();
		//if ($("#landing_canvas").children(":eq(" + position + ")").is('img'))
		$("#landing_canvas").children(":eq(" + position + ")").fadeIn("fast");
		$(".active_dot").removeClass("active_dot");
		$(this).addClass("active_dot");
		$(".caption").text(captions[position]);
		// turn off sliding
		sliding = false;
		return false;
	});
	max_length = $("#detail_nav a").children().length;
	$("#detail_slider").text('1/' + max_length);
	
	// detail navigation click
	$("#detail_nav a").click(function() {
		// to handle youtube, quicktime, and images, we need custom loading sequences handled in javascript:
		// the href will contain the type and then the filepath or youtube id
		exploded = $(this).attr("href").split(':');
		type = exploded[0]; // youtube, image, quicktime
		source = exploded[1]; // source of file or the youtube id
		
		$("#detail_canvas").html('');
		if (type == 'image') {
			image = $('<img src="/img/' + source + '" />');
			$("#detail_canvas").append(image);
			image.fadeIn();
		} else if (type == 'youtube') {
			params = { allowScriptAccess: "always", wmode: "transparent"};
			atts = { id: "ytPlayer" };
			youtube = $('<div id="youtube_detail"></div>');
			$("#detail_canvas").append(youtube);
			swfobject.embedSWF("http://www.youtube.com/v/" + source + "&enablejsapi=1&playerapiid=player1",'youtube_detail', "880", "520", "8", null, null, params, atts);
		}
		else if (type == 'vimeo') {
			vimeo = $('<div id="vimeocanvas"><iframe src="http://player.vimeo.com/video/' + source + '?title=0&amp;byline=0&amp;portrait=0" width="880" height="500" frameborder="0"></iframe></div>');	
			$("#detail_canvas").append(vimeo);
		
		} else if (type == 'quicktime') {
			quicktime = $('<embed type="video/quicktime" src="/img/' + source + '" style="margin-left:40px;" width="880" height="512" scale="ASPECT" AUTOPLAY="true" pluginspage="http://www.apple.com/quicktime/download/"></embed>');	
			$("#detail_canvas").append(quicktime);
		}
		$('.active').removeClass("active");
		$(this).addClass("active");
		$("#detail_slider").text($('.active').index() + 1 + "/" + $("#detail_nav a").length);
		return false;
	});
	
	// detail slider on bottom left on feature content
	$("#detail_slider").click(function() {
		if ($("#detail_nav a.active").next().is('a')) quickLink = $("#detail_nav a.active").next();
		else quickLink = $("#detail_nav a:first");
		$('.active').removeClass("active");
		quickLink.addClass("active");
		exploded = quickLink.attr("href").split(':');
		$("#detail_slider").text($('.active').index() + 1 + "/" + $("#detail_nav a").length);
		type = exploded[0]; // youtube, image, quicktime
		source = exploded[1]; // source of file or the youtube id
		$("#detail_canvas").html('');
		if (type == 'image') {
			image = $('<img src="/img/' + source + '" />');
			$("#detail_canvas").append(image);
			image.fadeIn();
		} else if (type == 'youtube') {
			params = { allowScriptAccess: "always", wmode: "transparent"};
			atts = { id: "ytPlayer" };
			youtube = $('<div id="youtube_detail"></div>');
			$("#detail_canvas").append(youtube);
			swfobject.embedSWF("http://www.youtube.com/v/" + source + "&enablejsapi=1&playerapiid=player1",'youtube_detail', "880", "520", "8", null, null, params, atts);
		} else if (type == 'vimeo') {
			vimeo = $('<div id="vimeocanvas"><iframe src="http://player.vimeo.com/video/' + source + '?title=0&amp;byline=0&amp;portrait=0" width="880" height="500" frameborder="0"></iframe></div>');	
			$("#detail_canvas").append(vimeo);

		} else if (type == 'quicktime') {
			quicktime = $('<embed type="video/quicktime" src="/img/' + source + '" style="margin-left:40px;" width="880" height="512" scale="ASPECT" AUTOPLAY="true" pluginspage="http://www.apple.com/quicktime/download/"></embed>');	
			$("#detail_canvas").append(quicktime);
		}
		return false;
	});
});


			//vimeo thumb
			if (type == 'vimeo') {

			source = exploded[1];
			$.getJSON('http://www.vimeo.com/api/v2/video/' + source + '.json?callback=?', {format: "json"}, function(data) {
				
				$(".thumbs").attr('src', data[0].thumbnail_small);
			});
			}
