function chrs_string(chrs){
	arr=chrs.split(',');
	text='';
	for (var i=0; i<arr.length; i++)
	 text=text+String.fromCharCode(arr[i]);
	return text;
}
function swf(filename,thumbnail,caption,type,link,hq,hqwidth) {
	if (type==undefined) var type = 'videos';
	if (type=='videos') var untype = 'tv';
	 else if (type=='tv') var untype = 'videos';
	var playerID = 'swfobject'+type;
	document.getElementById('video_cancel_'+type).style.display = '';
	document.getElementById('video_right_cancel_'+type).style.display = '';
	if (type!='ad') swf_cancel(untype);
	if (type=='tv') document.getElementById('image_tv').style.display = 'none';
	if (hq!=undefined&&hq!='undefined'&&hq!='null'&&hq!='') {
		var hqthumb = hq.substr(0,hq.length-3);
		document.getElementById('video_right_cancel_'+type).innerHTML='<a href="javascript:void(0);" onclick="swfhq(\''+playerID+'\',\''+hq+'\',\''+hqthumb+'\',\''+caption+'\',\''+link+'\',\''+hqwidth+'\');return false;" title="В высоком качестве"><img src="http://baltavia.ru/apps/videoblock/images/hq.gif" width="30" height="30" border="0" /></a>';
	} else document.getElementById('video_right_cancel_'+type).innerHTML='<img src="http://baltavia.ru/objects/2/images/blank.gif" width="30" height="1" border="0" />';
	if (document.getElementById(playerID).style.display!='none') {
		document.getElementById(playerID).sendToUppod('comment:'+caption);
		document.getElementById(playerID).sendToUppod('poster:'+thumbnail);
		document.getElementById(playerID).sendToUppod('link:'+link);
		document.getElementById(playerID).sendToUppod('file:'+filename);
		document.getElementById(playerID).sendToUppod('text:'+caption);
		//setTimeout("document.getElementById('"+playerID+"').sendToUppod('xtext')",3000);
		setTimeout("var xtext=document.getElementById('"+playerID+"'); if (xtext.style.display!='none') xtext.sendToUppod('xtext')",3000);
	} else {
		var flashvars = {"uid":playerID,"st":"2iob3gRLva9h0iohG54hvI9zvak8UfyRvcyb6xW43NJa2xo401nMt1tavIolGArr","file":filename,"poster":thumbnail,"comment":caption,"link":link};
		var params = {wmode:"transparent", allowFullScreen:"true", allowScriptAccess:"always"};
		new swfobject.embedSWF("http://baltavia.ru/flash/uppod.swf", playerID, "320", "240", "9.0.0", "http://baltavia.ru/flash/expressInstall.swf", flashvars, params);
		captiontext = caption;
	}
	pageTracker._trackEvent('VideosJS',type+' - Play',filename);
}
function swffl(filename,thumbnail,caption,type,link,hq,hqwidth) {
	swf(filename,thumbnail,chrs_string(caption),type,link,hq,hqwidth);
	ndimg();
}
function swf_cancel(type) {
	if (type==undefined) var type = 'videos';
	if (document.getElementById('swfobject'+type).style.display!='none') {
		document.getElementById('swfobject'+type).sendToUppod('stop');
		document.getElementById('swfobject'+type).style.display = 'none';
	}
	document.getElementById('video_cancel_'+type).style.display = 'none';
	document.getElementById('video_right_cancel_'+type).style.display = 'none';
	if (type!='ad') document.getElementById('image_tv').style.display = '';
}
function swf_start(n) {
	document.getElementById('videoplayer').sendToUppod('start'+n);
	uppodGetNpl(n,'videoplayer')
	//pageTracker._trackEvent('VideosJS','all_video - StartN','videoplayer_start'+n);
}
function overlibimg(imgsrc,caption,width,height,align,imgsize,param1,param2,param3) {
	if (imgsize!==undefined) if (imgsize==1) imgsize = 'width="'+width+'" height="'+height+'"';
	 else imgsize = '';
	overlib("<img src='"+imgsrc+"' alt='"+caption+"' "+imgsize+" />",BGCOLOR, '#4584d0', FGCOLOR, '#4584d0', CAPTION, caption, WIDTH, width, HEIGHT, height, HAUTO, VAUTO, align, param1, param2, param3);
}
function overlibimgfl(imgsrc,caption,width,height,align,imgsize) {
	overlibimg(imgsrc,chrs_string(caption),width,height,align,imgsize);
}
function ndimg() {
	nd();
}
function overlibcenter(imgsrc,caption,width,height,e) {
	if ((windowWidth()-120)<width) {
		height = height*(windowWidth()-120)/width;
		width = windowWidth()-120;
	}
	overlib("<a href='javascript:return cClick();' title='Закрыть' onclick='return cClick();'><img src='"+imgsrc+"' alt='"+caption+"' title='Закрыть' width='"+width+"' height='"+height+"' border='0' /></a>",BGCOLOR, '#4584d0', FGCOLOR, '#4584d0', CAPTION, caption, WIDTH, width, HEIGHT, height, CENTERPOPUP, EXCLUSIVE, EXCLUSIVEOVERRIDE, EXCLUSIVESTATUS, 'Закройте просматриваемый слой', STICKY, CLOSECLICK, CLOSETEXT, 'Закрыть');
	e = e || window.event;
	e.preventDefault ? e.preventDefault() : (e.returnValue=false);
}
function getElementPosition(elemId) {
	var elem = document.getElementById(elemId);
	var w = elem.offsetWidth;
	var h = elem.offsetHeight;
	var l = 0;
	var t = 0;
	while (elem)
	{
		l += elem.offsetLeft;
		t += elem.offsetTop;
		elem = elem.offsetParent;
	}
	return {"left":l, "top":t, "width": w, "height":h};
}
function showbigimg(imgsrc,imgh) {
	if (imgh===undefined) var imgh = 0;
	var img = document.getElementById('bigimg');
	img.src = imgsrc;
	img.style.display = 'block';
	var pos = getElementPosition('imagesblock');
	var d = document.getElementById('imagesblock');
	img.style.left = (pos.left+21)+'px';
	if (imgh>0) img.style.top  = (pos.top-imgh-2)+'px';
	 else img.style.top  = (pos.top-114)+'px';
}
function hidebigimg() {
	var img = document.getElementById('bigimg');
	img.style.display = 'none';
}
function swfhq(playerID,filename,thumbnail,caption,link,width) {
	document.getElementById(playerID).sendToUppod('pause');
	if (width!=undefined&&width>0) {
		if (width>=640) var width = 640; //480
		else if (width>=560) var width = 560; //420
		else if (width>=512) var width = 512; //384
		else if (width>=480) var width = 480; //360
		else var width = 480;
	} else var width = 640;
	var height = width*3/4;
	overlib("<div id='swfobjecthq'>&nbsp;</div>",BGCOLOR, '#4584d0', FGCOLOR, '#4584d0', CAPTION, caption, WIDTH, width, HEIGHT, height, CENTERPOPUP, EXCLUSIVE, EXCLUSIVEOVERRIDE, EXCLUSIVESTATUS, 'Закройте просматриваемый слой', STICKY, CLOSECLICK, CLOSETEXT, '<a href="javascript:void(0);" onclick="swfhqend();return false;">Закрыть</a>');
	var flashvars = {"uid":"swfobjecthq","st":"http://baltavia.ru/flash/styles/video2-hq"+width+".txt","file":filename,"poster":thumbnail,"comment":caption,"link":link};
	var params = {wmode:"transparent", allowFullScreen:"true", allowScriptAccess:"always"};
	new swfobject.embedSWF("http://baltavia.ru/flash/uppod.swf", "swfobjecthq", width, height, "9.0.0", "http://baltavia.ru/flash/expressInstall.swf", flashvars, params);
	captiontext = caption;
	pageTracker._trackEvent('VideosJS','HQ - Play',filename);
}
function swfhqend() {
	document.getElementById('swfobjecthq').sendToUppod('stop');
	overlibcenter('http://baltavia.ru/objects/2/images/blank.gif','',0,0)
	cClick();
}
function uppodInit(playerID) {
	if (playerID!='videoplayer') {
		document.getElementById(playerID).sendToUppod('play');
		document.getElementById(playerID).sendToUppod('text:'+captiontext);
		setTimeout("var xtext=document.getElementById('"+playerID+"'); if (xtext.style.display!='none') xtext.sendToUppod('xtext')",3000);
	}
}
