function set_video_fon(num)
{
	document.getElementById("video_fon_"+num).style.height=document.documentElement.scrollHeight+"px";
	document.getElementById("video_fon_"+num).style.width=document.documentElement.scrollWidth+"px";
}

function place_center(num)
{
	var width=document.getElementById("video_"+num).clientWidth;
	var height=document.getElementById("video_"+num).clientHeight;
    var left = document.documentElement.scrollLeft + (document.documentElement.clientWidth - width )/2 ;
    var top = document.documentElement.scrollTop + (document.documentElement.clientHeight - height)/2 ;
	document.getElementById("video_"+num).style.marginLeft = Math.max(0,left) + 'px';
    document.getElementById("video_"+num).style.marginTop  = Math.max(document.documentElement.scrollTop,top) + 'px';
}

function show_video(num)
{
	document.getElementById("video_fon_"+num).style.display="block";
	document.getElementById("video_"+num).style.display="block";
	set_video_fon(num);
	place_center(num);
}

function hide_video(num)
{
	document.getElementById("video_fon_"+num).style.display="none";
	document.getElementById("video_"+num).style.display="none";
}

function video_select(video_name,video_description,video_file, video_photo)
{
	try
	{
		document.getElementById("video_player_name").innerHTML=video_name;
		document.getElementById("video_description").innerHTML=video_description;
		document["video_player2"].SetVariable("/:flv_name",video_file);
		document["video_player2"].SetVariable("/:jpg_name",video_photo);
	}
	catch(e)
	{
		window.setTimeout("video_select('"+video_name+"','"+video_description+"','"+video_file+"','"+video_photo+"')",500);
	}
}

function playVideo(id, width, height, video_name, close_text){

	var div = document.createElement("DIV");
	div.id = "coverdiv";
	div.style.zIndex = 1000;
	div.style.position = "absolute";
	div.style.top = 0+"px";
	div.style.left = 0+"px";
	//div.style.width = document.body.scrollWidth+"px";
	
	if(document.documentElement.scrollWidth>=document.documentElement.clientWidth)
	{
		div.style.width = document.documentElement.scrollWidth+"px";
	}
	else
	{
		div.style.width = document.documentElement.clientWidth+"px";
	}	
	
	if(document.documentElement.scrollHeight>=document.documentElement.clientHeight)
	{
		div.style.height = document.documentElement.scrollHeight+"px";
	}
	else
	{
		div.style.height = document.documentElement.clientHeight+"px";
	}

	
	div.style.backgroundImage = "url(/images/semitransparent.png)";
	//div.style.filter ="progid:DXImageTransform.Microsoft.BasicImage(Opacity=0.75, GrayScale=1)";
	if(window.addEventListener)
		div.addEventListener("mouseup", HidePhoto, false);
	else if(window.attachEvent)
		div.attachEvent("onmouseup", HidePhoto);
	document.body.appendChild(div);
	
	div = document.createElement("DIV");
	div.id = "photodiv";
	div.style.zIndex = 1001;
	div.style.display = "block";
	div.style.position = "absolute";
	div.style.borderWidth = "5px";
	div.style.borderColor = "#fff";
	div.style.borderStyle = "solid";
	div.style.backgroundColor = "#f0f0f0";
	div.style.padding = "10px";
	//div.style.filter = "progid:DXImageTransform.Microsoft.Shadow(color='#606060', Direction=135, Strength=2)";
	
	//div.style.top =  document.body.scrollTop + (document.body.clientHeight - height)/2 - 11+"px"; 
	//div.style.left =  document.body.scrollLeft + (document.body.clientWidth - width)/2 - 14+"px";
	//div.style.width = width+"px";
	//div.style.height = height+60+"px";
	
	var width_tmp=div.clientWidth;
	var height_tmp=div.clientHeight;
	var left_tmp =  (document.documentElement.clientWidth - width )/2 ;
	var top_tmp =  (document.documentElement.clientHeight - height)/2 ;
	div.style.left = Math.max(0,left_tmp) + 'px';
	div.style.top = top_tmp + 'px';
	
	div.style.minWidth = width+"px";
	div.style.minHeight = height+60+"px";
	//div.style.top=0;
	//div.style.left=0;
	
	if(window.addEventListener)
		div.addEventListener("mouseup", HidePhoto, false);
	else if(window.attachEvent)
		div.attachEvent("onmouseup", HidePhoto);

	/*var fo = new SWFObject("/FlowPlayer.swf", "FlowPlayer", width, height, "7", "#333333", true);
	// need this next line for local testing, it's optional if your swf is on the same domain as your html page
	fo.addParam("allowScriptAccess", "always");
	fo.addVariable("config", "{ playList: [ {overlayId: 'play' }, { url: 'http://lof.dev.2sun.ru/file.asp?"+ id +"' } ], initialScale: 'scale' }");
	fo.write(div);*/

	var s1 = new SWFObject("/mediaplayer.swf","mediaplayer", width, height,"7","#333333", true);
	s1.addParam("allowscriptaccess", "always");
	s1.addParam("allowfullscreen","true");
	s1.addVariable("width", width);
	s1.addVariable("height", height);
	s1.addVariable("file",id);
	//s1.addVariable("file","/file.asp?"+id);
	//s1.addVariable("image","video.jpg");
	s1.write(div);
	
	var span= document.createElement("span");
	span.innerHTML = video_name;
	span.style.display="block";
	span.style.color= "rgb(153, 153, 153)";
	span.style.fontFamily= "Tahoma";
	span.style.fontSize= "14px";
	span.style.fontWeight= "bold";
	span.style.margin= "0";	
	span.style.padding= "0";
	span.style.paddingTop= "8px";
	span.style.width= width - 100 + "px";
	
	var href = document.createElement("A");
	href.href="";
	href.style.position = "absolute";
	href.style.top = height+20+"px";
	href.style.left = width - 36+"px";
	href.style.float = "right";
	href.style.clear = "left";
	
	var img = document.createElement("IMG");
	img.src = "/images/i_close.gif";
	img.style.border = 0+"px";
	img.title= close_text;
	
	href.appendChild(img);
	div.appendChild(span);
	div.appendChild(href);
	document.body.appendChild(div);
	
	/*if(window.addEventListener){
		window.addEventListener("scroll", PositionPhoto, false);
		window.addEventListener("resize", PositionPhoto, false);
	}
	else if(window.attachEvent){
		window.attachEvent("onscroll", PositionPhoto);
		//window.attachEvent("onresize", PositionPhoto);
		document.body.onresize = PositionPhoto;
	}*/
}

function HidePhoto(){
	var div = document.getElementById("coverdiv");
	document.body.removeChild(div);
	var div = document.getElementById("photodiv");
	document.body.removeChild(div);
	/*if(window.addEventListener){
		window.removeEventListener("scroll", PositionPhoto, false);
		window.removeEventListener("resize", PositionPhoto, false);
	}
	else if(window.attachEvent){
		window.detachEvent("onscroll", PositionPhoto);
		window.detachEvent("onresize", PositionPhoto);
	}*/
}



function PositionPhoto(){
	var div = document.getElementById("coverdiv");
	div.style.width = document.body.scrollWidth+"px";
	div.style.height = document.body.scrollHeight+"px";
	//div.style.width = document.body.scrollLeft + document.body.clientWidth;
	//div.style.height = document.body.scrollTop + document.body.clientHeight;
	var div = document.getElementById("photodiv");
	//div.style.top =  document.body.scrollTop + (document.body.clientHeight - parseInt(div.style.height))/2 - 11+"px"; 
	//div.style.left =  document.body.scrollLeft + (document.body.clientWidth - parseInt(div.style.width))/2 - 14+"px";
	//	var width=div.clientWidth;
	//var height=div.clientHeight;
	//var left = document.documentElement.scrollLeft + (document.documentElement.clientWidth - width )/2 ;
	//var top = document.documentElement.scrollTop + (document.documentElement.clientHeight - height)/2 ;
	//div.style.marginLeft = Math.max(0,left) + 'px';
	//div.style.marginTop = Math.max(document.documentElement.scrollTop,top) + 'px';
}
