$(document).ready(function() {
	

	$(".work-category").hover(function() {
		$(this).find("h2").stop(true, true).slideDown(150); 
		return false;			
	}, function () {		
		$(this).find("h2").stop(true, true).slideUp(350); 
		return false;	
	});
	
	
	$("#next-image a, #prev-image a").hover(function() {
			if ($(this).hasClass("active")) 
			{
				$(this).stop(true, true).animate({"opacity": 1}, 150);
			}				
	}, function() {
			$(this).stop(true, true).animate({"opacity": 0}, 150);
	});


	$("#work-thumbs a").click(function() {
		
		$("#main-image").attr("src", $(this).attr("href"));
		$("p.description").text($(this).attr("data-descr"));
		$("#video").remove();	
				
		$("#main-image").show();
		$("#video-holder").html("<div id='vertical-holder'><div id='video'></div></div>");	
		$("#video-holder").hide();
				 
		$("#work-thumbs a.active").removeClass("active");
		$(this).addClass("active");
			
		if ($(this).attr("data-video") != undefined) {
			$("#vertical-holder").css("marginTop", -($(this).attr("data-height") / 2));
			//$("#prev-image a, #next-image a").stop(true, true).css({"height": "90px"});
			$("#main-image, #prev-image a, #next-image a").addClass("video");
					
			showVideo($(this).attr("data-video"), $(this).attr("data-width"), $(this).attr("data-height"));
			
			if ($(this).attr("href") == "/") 
			{
				$("#main-image.video").trigger("click"); 
			}
			else
			{
				$("h2.clicktoplay").slideDown(150);
			}	
						
			
		} else {
			
			$("h2.clicktoplay").slideUp(150);
			$("#main-image, #prev-image a, #next-image a").removeClass("video");
			
			//if ($("#prev-image a").height() != 374)
			//	$("#prev-image a, #next-image a").stop(true, true).css({"height": "374px"});
		}

		var id = $(this).attr("data-id");
	
		if (id == 0) $("#prev-image a").removeClass("active").animate({"opacity": 0}, 250);
		if (id == $("#work-thumbs li").length-1) $("#next-image a").removeClass("active").animate({"opacity": 0}, 250);
		
		if (id > 0) $("#prev-image a").addClass("active");
		if (id < $("#work-thumbs li").length-1) $("#next-image a").addClass("active");	
	
		return false;
	
	});
	
	
	$("#next-image a").click(function() {
		$("#work-thumbs a.active").parent().next().find("a").trigger("click");
		
		return false;
	});

	$("#prev-image a").click(function() {
		$("#work-thumbs a.active").parent().prev().find("a").trigger("click");
		
		return false;
	});
	
	
	$("#work-thumbs a.active").trigger("click");

	
});


function showVideo(url, width, height) {
	
			
	$("#main-image").click(function() {
		
		if ($(this).hasClass("video"))
		{
			$("#main-image").hide();
			$("h2.clicktoplay").slideUp(150);
			$("#video-holder").show();
			var flashvars = { sourceurl: url, autoplay: 1, width: width, height: height };
			swfobject.embedSWF('/includes/flash/videoplayer.swf', 'video', width, height, '9.0.0', '', flashvars);
		}
	
		return false;
	});

	


}


