$(document).ready(function(){ 	
	
	//start the placeholder div at 0, 0
	$("#placeholder").css("width","0px");
	$("#placeholder").css("height","0px");
	
	//get the center position for movie
	var w = (window.innerWidth)/2 - 240;
	
	//set the center position of movie
	$("#placeholder_wrap").css("left", w);
	
	//load the movie into the #placeholder div
	function loadMovie(url){
		return (function(){
			$('#placeholder').removeClass('loading');
			$('#placeholder').load(url);
	    });
	}
	
	//main function
	$("a.motion").click(function(event) {
		event.preventDefault();
		var getUrl =  $(this).attr("href");
		var funcRef = loadMovie(getUrl);
				
		if($("#placeholder").is(":not(animated)")){
			$("#placeholder_wrap").fadeIn("5000", function(){
				var t = setTimeout(funcRef, 1000);
			})
			$("#transparent_bg").fadeIn("1000");

			$("#placeholder").animate({
				height:"360px",
				 width:"480px"
			},300);

		}
		//var description = $(this).attr("title");
			//$("#desc").empty();
			//$("#desc").append(description);
		});
	
	//close button and set everything to default
	$("#close a").click(function(event){
		event.preventDefault();	
			
		if($("#placeholder").is(":not(animated)")){
			$("#transparent_bg").fadeOut("1000");
			
			$("#placeholder_wrap").fadeOut("1000", function(){
				$("#placeholder").addClass("loading");
			})
			$("#placeholder").empty();			
			$("#placeholder").animate({
				height: "0px",
				width: "0px"
			},500);
		}
	});
});
