/**
 * Functions for displaying video and audio players
 *
 * (c) PRO PLUS, 2008
 */

/**
 * This variable will be set TRUE if page has video player
 */
var video_player_on_page = false;

/**
 * By default video player does not need to set access token
 */
 var video_needs_access_token = false;

/**
 * If video needs registration and if user is not logged in
 *	show "video_needs_login" div, not actual video
 */
var video_needs_registration = false;

/**
 * Function displays flash audio player
 */
function flash_audio_show(m_id, m_dir, container)
{
	flvplayer_div = 'flvvideo';
	if('undefined' !== typeof container)
	{
		audio_media_id = m_id;
		audio_media_dir = m_dir;
		flvplayer_div = container + '_' + audio_media_id;
	}

	file_no_server = '/'+section_video+'/'+audio_media_dir+'/'+audio_media_id+'.mp3';
	file = stream_server+file_no_server;

	flv_params = "/static/shared/app/mp3player.swf?showdigits=true&autostart="+autostart_audio[m_id]+"&showfsbutton=false&file="+file;

	so = new SWFObject(flv_params, flvplayer_div, 385, 20, "7", "#FFFFFF");
	so.write(flvplayer_div);
}

/**
 * Function sets all parameters for pop player
 */
var _text_flash_no = ""; 
function pplayer_audio_show(audio_seqno)
{
	if (typeof(audio_seqno) == "undefined")
		audio_seqno = 0;

	if (typeof(autostart_audio[amedia_id[audio_seqno]]) === 'undefined')
		autostart_audio[amedia_id[audio_seqno]] = true;
	
	// we check if we'll not use default player dimensions
	if (typeof(aplayer_width) == "undefined" && typeof(aplayer_height) == "undefined")
	{
		width = 416;
		height = 312;
		//height = parseInt(height) + 40;
	}
	else
	{
		width = aplayer_width;
		height = aplayer_height;
		//height = parseInt(height) + 40;
		
		if (width == 'full' || height == 'full')
		{
			width = '100%';
			height = '99%';
		}
	}
	// we set path to player swf file
	if (typeof(media_center_swf) == "undefined")
		media_center_swf = '/static/'+app_lang+'/shared/app/'+((window.location.hostname.indexOf("24ur.com")==0||window.location.hostname.indexOf("fe.slo.")!=-1)?'Video':'Media')+'Center.swf';

	so = new SWFObject(media_center_swf, 'mediacenter2', width, height, '9');
	so.addParam('allowfullscreen', 'true');
	so.addParam('allowscriptaccess', 'always');
	so.addParam('wmode', 'transparent');
	
	so.addVariable('autostart', autostart_audio[amedia_id[audio_seqno]]);

	if (amedia_id[audio_seqno] == '')
		so.addVariable('type', 'browse');
	else
		so.addVariable('media_id', amedia_id[audio_seqno]);
	
	so.addVariable('section_id', 'audio');
	
	
	// we can set new config file or append parameters to current one
	if (typeof(config_file) !== 'undefined')
		so.addVariable('config_file', config_file);
	
	config_file_append = '';
	if (typeof(site_id) !== 'undefined')
		config_file_append += 'site_id=' + site_id + '%26';
	
	if (config_file_append != '');
		so.addVariable('config_file_append', config_file_append);

	so.write('flvaudio_'+amedia_id[audio_seqno]);
}



/**
 * Function sets all parameters for pop player
 */
function pplayer_video_show()
{
	if (typeof(autostart) === 'undefined')
		autostart = true;
	
	// we check if we'll not use default player dimensions
	if (typeof(player_width) == "undefined" && typeof(player_height) == "undefined")
	{
		width = 416;
		height = 312;
		height = parseInt(height) + 40;
	}
	else
	{
		width = player_width;
		height = player_height;
		height = parseInt(height) + 40;
		
		if (width == 'full' || height == 'full')
		{
			width = '100%';
			height = '99%';
		}
	}
	
	// we set path to player swf file
	if (typeof(media_center_swf) == "undefined")
		media_center_swf = '/static/'+app_lang+'/shared/app/'+((window.location.hostname.indexOf("24ur.com")==0||window.location.hostname.indexOf("fe.slo.")!=-1)?'Video':'Media')+'Center.swf';

	if(app_lang == 'slo')
	{
		if(typeof(refresh_version) !== 'undefined'){
			if(media_center_swf.indexOf("?v=") == -1)
				media_center_swf = media_center_swf + '?v=' + refresh_version;
		}
	}
	
	so = new SWFObject(media_center_swf, 'mediacenter2', width, height, '9');
	so.addParam('allowfullscreen', 'true');
	so.addParam('allowscriptaccess', 'always');
	so.addParam('wmode', 'transparent');
	
	// if media_id is empty, we show main playlist as default in menu
	if (media_id == '')
		so.addVariable('type', 'browse');
	else
		so.addVariable('media_id', media_id);

	if (typeof(player_openplaylist) !== 'undefined' && player_openplaylist != '')
		so.addVariable('openplaylist', player_openplaylist);

	so.addVariable('ad_file', 'noad'); // hack..

	// if video ad
	if ( (typeof(phpadsbanner_flash) !== "undefined") && (phpadsbanner_flash != '') )
	{
		so.addVariable('ad_file', phpadsbanner_flash);
		if (phpadsbanner_flash_url)
			so.addVariable('ad_url', phpadsbanner_flash_url);
		so.addVariable('ad_type', 'preroll');
	}

	
	// user identifiers (session id - used for payable content; bit - used for usertrack; userad_id - used for adserver)
	so.addVariable('session_id', Cookie.get('c4d'));
	so.addVariable('bit', Cookie.get('bit'));
	userad_id = Cookie.get('phpAds_id');
	if (!userad_id)
		userad_id = Cookie.get('bit');
	so.addVariable('userad_id', userad_id);
	
	
	if ((typeof(player_mute) !== 'undefined') && (player_mute != '')){
	     so.addVariable('mute', player_mute);
     }
	
	if ((typeof(player_soundOnMove) !== 'undefined') && (player_soundOnMove != '')){
          so.addVariable('soundOnMove', player_soundOnMove);
     }
	
	
	// section is used for ads and usertrack
	so.addVariable('section_id', section_id);
	
	// we need referer (site name) for usertrack
	preferer = '';
	if (typeof(player_referer) !== 'undefined')
		preferer = player_referer;
	so.addVariable('referer', preferer);

	// color template of the player
	if (typeof(player_color) === 'undefined')
		player_color = '#000000';
	if (player_color != 'none')
		so.addVariable('color', player_color);
	
	so.addVariable('autostart', autostart);

	// we can set new config file or append parameters to current one
	if (typeof(config_file) !== 'undefined')
		so.addVariable('config_file', config_file);
	
	so.addVariable('banner', escape(banner_flashvar));
	
	config_file_append = '';
// Need to specify why is next lines commented	- comments removed
	if (typeof(site_id) !== 'undefined')
		config_file_append += 'site_id=' + site_id + '%26';
	
	// set for other player interface type ('mini')
	if (typeof(player_interface_type) !== 'undefined')
		config_file_append += 'interface_type=' + player_interface_type[media_id] + '%26';
	
	if (typeof(player_big_playlist) !== 'undefined')
		config_file_append += 'big_playlist=' + player_big_playlist + '%26';
	
	if (config_file_append != '');
		so.addVariable('config_file_append', config_file_append);

	// if content is payable
	if (typeof(player_access_key) !== 'undefined')
		so.addVariable('access_key', player_access_key);
}

/**
 * Functions displays warning instead of player if user does not have flash or has flash version below 9
 */
function video_no_flash()
{
	var flv_element = $('flvvideo');
	if(flv_element)
		flv_element.innerHTML = _text_flash_no;
}

/**
 * Function decides if flash version on client side is fresh enough to display video player
 */
function video_show_player()
{
	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	var isiPhone = navigator.userAgent.match(/iPhone/i) != null;

	if ( ( $defined(window.player_html5_allow) && player_html5_allow ) && 	( isiPad || isiPhone ) 	)
	{
		video_setup_render_html5_player();
	}
	else if ((flash_version == 9 && flash_ver['rev'] != 16) || flash_version >= 10)
	{
		if(app_lang == 'slo' && flash_version <= 10 &&  flash_ver['rev'] < 3 ) { 
			video_no_flash();
			return;
		}
		video_setup_render_player();
	}
	else
		video_no_flash();
		
	//this fixes the title after loading the video
	if(typeof titlefix == 'function') titlefix();
}

/**
 * Returns access type for payable content
 */
function user_payable_access()
{
	if ( typeof check_user_product != "function" )
		return "active";

	return check_user_product('popplus');
}

/**
 * We set video ad, call player setup and render player
 */
function video_setup_render_player(response)
{
	eval(response);

	/**
	 * On SLO site, we're checking if user has enough permissions to watch
	 *	a video. global_video_check_access variable enables this check.
	 */
	if ( (typeof global_video_check_access == "boolean") && (global_video_check_access) ) {
		video_check_access();
		return;
	}

	// not checking access permissions,
	// just show video
        pplayer_video_show();

        if ( (typeof(video_div) === 'undefined') || (video_div == '') )
                video_div = 'flvvideo';

        if ($(video_div))
                so.write( video_div );
}


/**
 * Check if user has enough access to see video.
 * If it has not enough access, show div that says he needs to log in or 
 *	buy access. 
 */
function video_check_access() 
{
	var access = user_payable_access();

	if ( !video_needs_registration || (video_needs_registration == "0") 
	  || (access == "active") ) {
		$j(".video_needs_login").hide(0);
		$j(".video_needs_access").hide(0);
		$j(".player").fadeIn(100);

		// video is accessible to all	
		pplayer_video_show();

		if ( (typeof(video_div) === 'undefined') || (video_div == '') )
			video_div = 'flvvideo';

		if ($(video_div))
			so.write( video_div );
	} else if (access == "login") {
		// user needs to login first
		$j(".video_needs_access").hide(0);
		$j(".player").hide(0);
		$j(".video_needs_login").fadeIn(100);

		if ( (typeof run_after_login == "undefined") )
			window.run_after_login = false;

		if ( !window.run_after_login )
			window.run_after_login = "video_setup_render_player()";
	} else {
		// user has no payable content access, but is logged in
		$j(".video_needs_login").hide(0);
		$j(".player").hide(0);
		$j(".video_needs_access").fadeIn(100);
	}
}


/**
 * Render the HTML5 video tag
 */
function video_setup_render_html5_player()
{
  	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	var isiPhone = navigator.userAgent.match(/iPhone/i) != null;

	// low quality for iPhone, otherwise high
	if (isiPhone) {
		item_quality=1;
	}
	else{
		item_quality=2;
	}
	item_poster_dimension = '615x320';

	if ( (typeof(video_div) === 'undefined') || (video_div == '') )
		video_div = 'flvvideo';

	// we check if we'll not use default player dimensions
	if (typeof(player_width) == "undefined" && typeof(player_height) == "undefined")
	{
		width = 416;
		height = 312;
		height = parseInt(height) + 40;
	}
	else
	{
		width = player_width;
		height = player_height;
		height = parseInt(height) + 40;
		
		if (width == 'full' || height == 'full')
		{
			width = '100%';
			height = '99%';
		}
	}


  	// get the info about video
	new Ajax("/bin/player/?mod=serve&site_id=1&media_id="+media_id+"&section_id="+section_id, {
		onComplete: function(res)
		{
			item_src = res.match(/<item(.*?)src=\"(.*?)\"/i);
			if (!item_src)
				return false;

			item_src = item_src[2];

			item_server = res.match(/<item(.*?)server=\"(.*?)\"/i);
			item_server = item_server[2];

			item_thumb = res.match(/<item(.*?)thumb=\"(.*?)\"/i);
			item_thumb = item_thumb[2];

			item_mime = res.match(/<item(.*?)mimetype=\"(.*?)\"/i);
			if (item_mime)
				item_mime = item_mime[2];

			// this video does not support H264
			if (item_mime != "mp4")
			{
				$(video_div).innerHTML='';
				return false;
			}

			// get info about video's server
			new Ajax("/bin/player/?mod=config", {
				onComplete: function(res)
				{
					r = new RegExp('<flvserver(.*?)id="'+item_server+'"(.*?)url="(.*?)"', "i");
					video_server_url = res.match(r);
					video_server_url = video_server_url[3];

					item_url = video_server_url+'/'+item_src+'-'+item_quality+'.mp4';

					r = new RegExp('<imageserver(.*?)url="(.*?)"', "i");
					image_server_url = res.match(r);
					image_server_url = image_server_url[2];
					
					item_poster_url = image_server_url+'/'+item_thumb;
					item_poster_url = item_poster_url.replace(/\*SIZE\*/, item_poster_dimension);
					
					$(video_div).innerHTML = "";
					
					player_html = '<video width="'+width+'" height="'+height+'" controls="true" autobuffer="true" preload="true" poster="'+item_poster_url+'" tabindex="0"><source src="'+item_url+'" type="video/mp4"></source></video>';
					
					$(video_div).innerHTML = player_html;

				}
			}).request();
			
		}
	}).request();

}

function video_logAndPLay(media_id, section_id, href, article_id) 
{
	$j("#video_logger").css("display", "none");

	var url = "/bin/player/?mod=iapps_log" +
		"&site_id=1" +
		"&media_id=" + media_id +
		"&article_id=" + article_id +
		"&section_id=" + section_id + 
		"&click_nb=" + video_play_click_nb;

	$j("#video_logger").append("<img src='" + url + "' border='0' width='1' height='1'>");
	top.location.href = href;
//	setTimeout("top.location.href = '" + href + "';", 200);
	video_play_click_nb++;
}

function video_log(media_id, section_id, $article_id) 
{
	$j("#video_logger").css("display", "none");

	var url = "/bin/player/?mod=iapps_log" +
		"&site_id=1" +
		"&media_id=" + media_id +
		"&article_id=" + article_id +
		"&section_id=" + section_id + 
		"&click_nb=" + video_play_click_nb;

	$j("#video_logger").html("<img src='" + url + "' border='0' width='1' height='1'>");
	video_play_click_nb++;
}

var video_play_click_nb = 0;

/**
 * Render the HTML5 video tag (for iDevices)
 * 
 * @return void
 * @param int prefix media id
 * @param string prefix to be used in html object's id
 * @param bool anchor if render link to video or video
 * @author matej.balantic@pop-tv.si
 * @author benjamin.povirk@pop-tv.si
 */
function video_setup_render_iphone_player(media, prefix, anchor)
{
  	var isiPad = navigator.userAgent.match(/iPad/i) != null;
    	var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
	var isAndroid = navigator.userAgent.match(/Android/i) != null;
	var isWP7 = (navigator.userAgent.match(/Windows Phone OS/i) != null)
			|| (navigator.userAgent.match(/ZuneWP7/i) != null);

	// low quality for iPhone, otherwise high
	if (isiPhone || isAndroid || isWP7)
		var item_quality=1;
	else
		var item_quality=2;

	var item_poster_dimension = '615x320';

	// we check if we'll not use default player dimensions
	if (typeof(player_width) == "undefined" && typeof(player_height) == "undefined")
	{
		var width = 416;
		var height = 312;
		var height = parseInt(height) + 40;
	}
	else
	{
		var width = player_width;
		var height = player_height;
		var height = parseInt(height) + 40;
		
		if (width == 'full' || height == 'full')
		{
			width = '100%';
			height = '99%';
		}
	}

  	// get the info about video
	new Ajax("/bin/player/?mod=serve&site_id=1&media_id="+media+"&section_id="+section_id, {
		onComplete: function(res)
		{
			var item_src = res.match(/<item(.*?)src=\"(.*?)\"/i);
			if (!item_src)
				return false;

			item_src = item_src[2];

			var item_server = res.match(/<item(.*?)server=\"(.*?)\"/i);
			item_server = item_server[2];

			var item_thumb = res.match(/<item(.*?)thumb=\"(.*?)\"/i);
			item_thumb = item_thumb[2];

			var item_mime = res.match(/<item(.*?)mimetype=\"(.*?)\"/i);
			if (item_mime)
				item_mime = item_mime[2];

			// this video does not support H264
			if (item_mime != "mp4")
			{
				$(prefix+media).innerHTML='';
				return false;
			}

			// get info about video's server
			new Ajax("/bin/player/?mod=config", {
				onComplete: function(res)
				{
					var r = new RegExp('<flvserver(.*?)id="'+item_server+'"(.*?)url="(.*?)"', "i");
					var video_server_url = res.match(r);
					video_server_url = video_server_url[3];

					var item_url = video_server_url+'/'+item_src+'-'+item_quality+'.mp4';

					var r = new RegExp('<imageserver(.*?)url="(.*?)"', "i");
					var image_server_url = res.match(r);
					image_server_url = image_server_url[2];
					
					var item_poster_url = image_server_url+'/'+item_thumb;
					item_poster_url = item_poster_url.replace(/\*SIZE\*/, item_poster_dimension);
					
					$(prefix+media).innerHTML = "";

					if (typeof(anchor)!='undefined') {
						var player_html = '<a onclick="video_logAndPLay('+media+','+section_id+', \''+item_url+'\','+article_id+')"><img src="'+item_poster_url+'" width="'+width+'" height="'+height+'" style="border:none" alt="'+item_poster_url+'" /></a>';
					} else {
						var player_html = '<video onplay="video_log('+media+','+section_id+','+article_id+')" width="'+width+'" height="'+height+'" controls="true" autobuffer="true" preload="true" poster="'+item_poster_url+'" tabindex="0"><source src="'+item_url+'" type="video/mp4"></source></video>';
					}


					$("video-thumb-"+media).addEvent('click', function() {
						video_logAndPLay(media,section_id,item_url,article_id);
					});
					
					$(prefix+media).innerHTML = player_html;
				}
			}).request();
			
		}
	}).request();

}

/**
 * Main function called for showing video player
 */
function video_player_setup()
{
	if ( video_needs_access_token ) {
		// get info about video's server
		new Ajax("/lbin/ajax_generate_token.php?media_id="+media_id, {
			onComplete: function(res)
			{
				player_access_key = res;
				video_show_player();
			}
		}).request();
	} else
		video_show_player();	
}
video_loading = Array();
/**
 * Function for displaying video player when clicking on thumbnail on a website
 */
function video_at_thumb( video_id, div_id, width, height, _90secplayer, diff, bgcolor )
{
	if ( typeof(width) != 'undefined' )
		player_width = width;

	if ( typeof(height) != 'undefined' )
		player_height = height;

	if ( thumb_div_id != '' )
		video_at_thumb_previous();

	var div = $(div_id);

	if ( typeof(div) == 'undefined' )
		return;

	if ( typeof(diff) == 'undefined' )
		diff = 0;

	if ( typeof(show_banners) == 'undefined' )
		show_banners = 0;

	if ( typeof(bgcolor) == 'undefined' )
		bgcolor = "#FFFFFF";

	thumb_div_html = div.innerHTML;
	thumb_div_id = div_id;

	video_div = div_id;
	media_id = video_id;

	 //check for RO site
	if (app_lang == 'ro')
	{
		if (flash_version >= 9 && flash_ver['rev'] != 16 && !video_loading[video_id])
		{
			//video_loading[video_id] = 1;
			if (!dom_ready)	
			{
				window.addEvent('domready', function() {
       					video_setup_render_player(); 
        			});
			}
			else
				 video_setup_render_player();

			return true;
		}
		else
		{
		 	$(div_id).setStyle('width', '400px');
		 	$(div_id).setStyle('height', '300px');
			$(div_id).innerHTML = _text_flash_no;
			return;
		}
	}

	if ( flash_version < 9) {
		$(video_div).onclick = function () { document.location.href = 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;promoid=BIOW' };
		if ( $('image_pool') )
			$('image_pool').href = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;promoid=BIOW";
		$(div_id).innerHTML = _text_flash_no;
		thumb_div_html = _text_flash_no;
		return;
	}

	if ( video_id != 'undefined' && parseInt(video_id) ) {
		if ( diff != 0) {
			$(video_div).setStyle('height', $(video_div).getStyle('height').toInt() + diff.toInt());
			thumb_div_diff = diff;
		} else
			thumb_div_diff = 0; //reset height change

		if ( typeof(_90secplayer) === 'undefined' || _90secplayer === false ) {
			player_hide_ads = true;
			video_player_setup();
		} else { //if we have _90secplayer passed in as argument, we show small player ( like on 90sec box on frontpage )
			var player_url = "/static/cz/main/swf/90sec.swf?flv="+video_id
		        var so = new SWFObject(player_url, "90secplayer", player_width, player_height+diff, "9", bgcolor);
	        	so.write(video_div);
		}
	}
}

function video_at_thumb_previous()
{
	var div = $(thumb_div_id);

	if ( typeof(div) != 'undefined' ) 
		div.innerHTML = thumb_div_html;

	if (thumb_div_diff != 0)
		$(thumb_div_id).setStyle('height', div.getStyle('height').toInt() - thumb_div_diff.toInt());	

}

/**
 * Function for displaying promo player
 * Promo player in player which plays video only in fullscreen, in normal state it only display thumbnail given through flashvar
 */
function video_show_promo_player(promo_image)
{
	window.addEvent('domready', function()
	{
		if ( flash_version < 9) {
			$("promo_player").innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;promoid=BIOW">' + _text_flash_no + '</a>';
			return;
		}

		var pbanner = new SWFObject("/static/"+app_lang+"/shared/app/"+((window.location.hostname.indexOf("24ur.com")==0||window.location.hostname.indexOf("fe.slo.")!=-1)?'Video':'Media')+"Center.swf", "MediaCenter_banner", "250", "205", "9");
		pbanner.addVariable('type', 'promo');
		pbanner.addVariable('promo_image', promo_image);
		pbanner.addVariable('bit', Cookie.get('bit'));
		pbanner.addVariable('color', '000000');
		pbanner.addVariable('userad_id', Cookie.get('bit'));
		pbanner.addParam('allowfullscreen', 'true');
		pbanner.write("promo_player");
	});
}
/*
 * Function which send request to  media send script
 * @param div_name Name of the div to write in
 * @param script_name name of the script to execute
 * @param text_ok text if media was sent
 * @param text_error text if there goes something wrong
 *
*/
function mediaSend(div_name,script_name,text_ok, text_error) {

	new Ajax(script_name, {
		method: 'post',
		encoding: 'utf-8',
		postBody: document.media_send,
		onComplete: function(response) {
			
			switch(response)
			{
				case 'OK':
					$(div_name).innerHTML = text_ok;
					try	{
						$("email_to").value = "";
					} catch (r) {null;}
				break;
				case 'INCOMPLETE_INFO':
					$(div_name).innerHTML = incomplete_info;
				break;
				case 'INVALID_FROM_EMAIL':
					$(div_name).innerHTML = invalid_from_email;
				break;
				case 'INVALID_TO_EMAIL':
					$(div_name).innerHTML = invalid_to_email;
				break;
				case 'INVALID_CAPTCHA':
					$(div_name).innerHTML = invalid_captcha;
				break;
				case 'MEDIA_ALREADY_SENT':
					$(div_name).innerHTML = media_already_sent;
				break;
				case 'INVALID_REQUEST':
					$(div_name).innerHTML = invalid_request;
				break;
				default:
					$(div_name).innerHTML = text_error;
			}
		}
	}).request();
}

/**
 * Function display banner ad inside of video banner ad holder
 * Function is callend when banner is attched to the video ad inside of the video player
 */
function player_append(content)
{
	html_content = '<iframe src="/adserver/adjs_i.php?bannerid=' + content + '" widht="300" height="250" frameborder="0" scrolling="no" margingwidth="0" marginheight="0" name="i_banner_VIDEO_IMG_'+content+'" id="i_banner_VIDEO_IMG_'+content+'"></iframe>';
	if (content == '')
		html_content = '';

	$('div_banner_VIDEO_IMG').setHTML(html_content);
}

/**
 * Function logs view of an ad with external monitoring script
 */
function ad_log_view(id)
{
	var logFrame = new Element('iframe', {
		width: '0',
		height: '0',
		src: '/adserver/adjs_external.php?id='+id,
		border: '0'
	});
	logFrame.injectInside(document.body);
}

/**
 * functions called from player to load related|preferred|... videos
 */
var videojs_player_coordinates = undefined;
function videojs_last_published_render(item_image,item_title) {
	if (!$("videojs_container")) return;
	
	try {
		videojs_player_coordinates = $("mediacenter2").getCoordinates();
	} catch (e) {
		videojs_player_coordinates = {
			width:	$("mediacenter2").width
			,height:$("mediacenter2").height
		}
	}
	if ($("videojs_current_title")) $("videojs_current_title").innerHTML = item_title; 
	if (typeof(site_id)=='undefined') site_id = 1;
	if (typeof(section_id)=='undefined') section_id = 0;
	if (typeof(article_id)=='undefined') article_id = 0;
	if (typeof(media_id)=='undefined') media_id = 0;
	new Ajax("/lbin/videojs_last_published.php?site_id="+site_id+"&section_id="+section_id+"&article_id="+article_id+"&media_id="+media_id, {
		onComplete: function(res) {
			$("videojs_container").innerHTML = res;
			if (videojs_player_coordinates.width<=580 || videojs_player_coordinates.height<=340) $("videojs_wrapper").addClass("small"); 
			$("videojs_current_image").innerHTML = "<img src='http://imgres.24ur.com/"+item_image.replace("*SIZE*","640x338")+"' width='"+videojs_player_coordinates.width+"' height='"+videojs_player_coordinates.height+"' />";
		}
	}).request();
}	

function videojs_last_published_show() {
	if (!$("videojs_container")) return;
	
	$("flvvideo").setStyle("height","0");
	$("flvvideo").setStyle("z-index","-10");
	
	$("videojs_container").setStyle("display","block");
	$("videojs_container").setStyle("z-index","10");
}

function videojs_video_show() {
	if (!$("videojs_container") || typeof(videojs_player_coordinates)=='undefined') return;
	
	$("videojs_container").setStyle("display","none");
	$("videojs_container").setStyle("z-index","-10");
	$("flvvideo").setStyle("height",videojs_player_coordinates.height+"px");
	$("flvvideo").setStyle("z-index","10");
}

function videojs_replay() {
	if (!$("videojs_container")) return;
	
	$("videojs_container").setStyle("display","none");
	$("videojs_container").setStyle("z-index","-10");
	$("flvvideo").setStyle("height",videojs_player_coordinates.height+"px");
	$("flvvideo").setStyle("z-index","10");
	try {
		$("mediacenter2").replay();
	} catch (e) {
		null;
		//alert(e);
	}
}
