// © David Adalberth Andersen
// Created by Adalberth.dk
var videoHeightHalf = videoHeight/2;
var videoWidthHalf = videoWidth/2;

$(document).ready(function(){
	
	$("body").prepend('<div id="box_" style="position:fixed;display:none;width:100%; height:100%;background-image:url(js/bg.png);background-repeat:repeat;z-index:1;"></div><div id="video_" style="position:fixed; display:none;width:'+ videoWidth+'px; height:'+ videoHeight+'px; margin:auto;top:50%;left:50%;margin-top: -'+ videoHeightHalf +'px;margin-left: -'+ videoWidthHalf+'px;z-index:1;"></div>');
	
	$(".youtube").click(function(event){
		event.preventDefault();
		$("#box_").fadeIn("slow");
		$("#video_").fadeIn("slow");
		var url = $(this).attr("href");
		openVideo(url);	
	});
	
	$(".swf").click(function(event){
		event.preventDefault();
		$("#box_").fadeIn("slow");
		$("#video_").fadeIn("slow");
		var url = $(this).attr("href");
		openSwf(url);		
	});
	
	$("#box_").click(function(event){
		$("#box_").fadeOut("slow");
		$("#video_").fadeOut("slow");	
		$("#video_").html('');
	});
	
	/* For blog comments */
	$(".comment:even").addClass('oddeven');
	
});

function openVideo(e){
	var a_split = e.split("/");	
	var b_split = a_split[3].slice(8,a_split[3].length);
	if(b_split.search("&") != -1){
		var c_split = b_split.indexOf("&");
		var d_split = b_split.slice(0,c_split);
	}else{
		d_split = b_split;
	}
	
	var url = "http://www.youtube.com/v/" + d_split;
	$("#video_").html('<object width="'+ videoWidth+'" height="'+ videoHeight+'"><param name="movie" value="' + url +  '&amp;hl=da_DK&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + url +  '&amp;hl=da_DK&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+ videoWidth+'" height="'+ videoHeight+'"></embed></object>');
};

function openSwf(e){
	$("#video_").html('<div id="swf"></div>');
	var flashvars = {
	};
	var params = {
	  wmode: "transparent"
	};
	var attributes = {
	};
	swfobject.embedSWF(e, "swf",videoWidth,videoHeight, "9.0.0", "", flashvars, params, attributes);
};
