/**
 * Funkcije in ostalo za delo z videi.
 *
 * 'detect.js' mora biti tudi includana na pagu.
 *
 * Na strani morata biti definriani spremenljivki:
 *      - url_wmv
 *
 * (c) PRO PLUS, 2005
 */


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Procesiranje in izbira videa
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/**
 * Glavna funkcija za VIDEO. V HTML-ju klices to.
 */
function video_show( video_size, zoneid ) {
        document.write( video_get_html( video_size, zoneid ) );
}

/**
 * Funkcija vrne HTML za prikaz videa
 */
function video_get_html( video_size, zoneid ) {
        // kaksen size se mora prikazat?
        if ( !video_size )
                video_size = get_cookie('video_size');

        // kaksen tip?
        video_type = get_cookie('video_type');

        // is this zone connected?
        if ( !zoneid )
                zoneid = "" + section_id + "41";

        connected_banner = banner_zone_is_connected( zoneid );

        if ( connected_banner ) {
                url_wmv += "&bannerid=" + connected_banner;
        }

        // dobim html
        switch ( video_size ) {
                 case 'small':
                        html = video_wmv_small(url_wmv); break;
                 case 'extra':
                 default:
                        html = video_wmv_normal(url_wmv);
       }

	return html;
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Procesiranje in izbira videa
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/**
 * Glavna funkcija za BAR VIDEO. V HTML-ju klices to.
 */
function video_bar_show_2( video_size, zoneid ) {

        // kaksen size se mora prikazat?
        if ( !video_size )
                video_size = get_cookie('video_size');

        // kaksen tip?
        video_type = get_cookie('video_type');

        // is this zone connected?
        if ( !zoneid )
                zoneid = "" + section_id + "41";


        // dobim html
        switch ( video_size ) {
            case 'small':
                video_bar_2('1', '176', '144'); break;
            case 'extra':
                video_bar_2('3', '600', '480'); break;
            default:
                video_bar_2('2', '320', '256'); break;
        }
}

/**
 * Spremeni velikost video okna
 */
function video_change_size( change_to ) {

        if ( typeof(change_to) == "undefined" ) {
                video_size = get_cookie('video_size');

                if (video_size == 'small')
                        set_cookie('video_size', 'normal');
                else
                        set_cookie('video_size', 'small');
        } else {
                set_cookie('video_size', change_to);
        }

        window.location.reload();
}

/**
 * Spremeni velikost video okna v BAR2
 */
function bar2_video_change_size( change_to, media_id, subtype ) {

        if ( typeof(change_to) == "undefined" ) {
                video_size = get_cookie('video_size');

                if (video_size == 'small')
                        set_cookie('video_size', 'normal');
                else
                        set_cookie('video_size', 'small');
        } else {
                set_cookie('video_size', change_to);
        }

        window.location.href = 'bar_video_show.php?media_id=' + media_id + '&subtype=' + subtype;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Funkcije za prikaz HTML-jev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/**
 * Prikaz WINDOWSMEDIA - SMALL videa
 *
 * @param string url URL, ki se klice, da se prikaze video
 */
function video_wmv_small(url) {

        if (url == '')
                return '';

        html  = '<OBJECT id="mp_object" name="mp_object" width="176" height="214" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">';
        html += '\n<param NAME="filename" value="' + url + '&size=-2">';
        html += '\n<param NAME="autoStart" value="true">';
        html += '\n<param NAME="showControls" value="true">';
        html += '\n<param name="ShowStatusBar" value="true">';
        html += '\n<param NAME="Autorewind" value="true">';
        html += '\n<param NAME="ShowDisplay" value="false">';
        html += '\n<param NAME="uiMode" value="mini">';
        html += '\n<EMBED id="mp_embed" name="mp_embed" type="application/x-mplayer2" ';
        html += '\npluginspage="http://www.microsoft.com/Windows/MediaPlayer/" ';
        html += '\nsrc="' + url + '&size=-2" ';
        html += '\nname="MediaPlayer1" ';
        html += '\nautostart=1 showcontrols=1 showstatusbar=1 autorewind=1 showdisplay=0 uiMode="mini" ';
        html += '\nwidth=176 ';
        html += '\nheight=214 ';
        html += '\nautostart=1 ';
        html += '\nshowcontrols=1> ';
        html += '\n</OBJECT>';

        return html;
}


/**
 * Prikaz WINDOWSMEDIA - NORMAL videa
 *
 * @param string url URL, ki se klice, da se prikaze video
 */
function video_wmv_normal(url) {

        if (url == '')
                return '';

        html  = '<object id="mp_object" name="mp_object" width="320" height="326" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">';
        html += '\n<param NAME="filename" value="' + url + '&size=-1">';
        html += '\n<param NAME="autoStart" value="true">';
        html += '\n<param NAME="showControls" value="true">';
        html += '\n<param name="ShowStatusBar" value="true">';
        html += '\n<param NAME="Autorewind" value="true">';
        //html += '\n<param NAME="FullScreen" value="true">';
        html += '\n<param NAME="ShowDisplay" value="false"> ';
        html += '\n<param NAME="uiMode" value="mini">';
        html += '\n<embed id="mp_embed" name="mp_embed" type="application/x-mplayer2"';
        html += '\nsrc="' + url + '&size=-1" ';
        html += '\nautostart=1 showcontrols=1 showstatusbar=1 autorewind=1 showdisplay=0 uiMode="mini" ';
        html += '\nname="MediaPlayer" fullscreen=1 ';
        html += '\nwidth="320" ';
        html += '\nheight="326"> ';
        html += '\n</embed>';
        html += '\n</object>';

        return html;
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("&") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("&")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}

/**
 * Prikaz FLASHa za BAR2
 *
 * @param string url URL, ki se klice, da se prikaze video
 * phpadsbanner_flash is set by max in adjs_flash.php (on max server)
 */
function video_bar_2(f_size, f_width, f_height) {

	player = "bar2player.swf";

	if (getURLParam('dontplay'))
		autostart = 'false';
	else
		autostart = 'true';

        var flash_banner = "";

        if ( (typeof(url_max) == "undefined") || (url_max=='') )
                url_max = "http://213.250.2.176/";
        if ( (typeof(phpadsbanner_flash) !== "undefined") && (phpadsbanner_flash != '') )
                flash_banner = 'oglas=' + url_max + phpadsbanner_flash + '-' + f_size;

	if ( (typeof(fullscreen) == "undefined") || (fullscreen=='') )
	{
		fullscreen = false;
		fullscreen_url = "/bar2/fullscreen.html?video=" + url_fl.replace('*SIZE*', 3) +"&backurl="+escape(document.URL);
		url_fl = url_fl.replace('*SIZE*', f_size);
	}
	else
	{
		document_url = document.URL;
		document_url_split = document_url.split("video=");
		document_url = document_url_split[1];
		
		document_url_split = document_url.split("&backurl=");
	
		url_fl = document_url_split[0];
		backlink = escape(document_url_split[1] + "&dontplay=1");
	}


	var host = "http://" + document.domain;
	var urlplaylist = host + "/bar2/playlist.php?" + flash_banner + "%26video=" + url_fl + "-" + f_size;

	if (fullscreen)
	{
		flv_params = "/furniture/system/"+player+"?showdigits=true&shuffle=false&repeat=true&autostart=true&callback=statistics.php&showfsbutton=true&fullscreenmode=true&fsreturnpage="+backlink+"&file="+urlplaylist;
		so = new SWFObject(flv_params, "sotester", "100%", "100%", "7", "#FFFFFF");
	}
	else
	{
		flv_params = "/furniture/system/"+player+"?width="+f_width+"&height="+f_height+"&showdigits=true&shuffle=false&repeat=true&autostart="+autostart+"&callback=statistics.php&showfsbutton=true&fullscreenpage="+escape(fullscreen_url)+"&file="+urlplaylist;
		so = new SWFObject(flv_params, "sotester", f_width, f_height, "7", "#FFFFFF");
	}
}

function swf_object_write() {
	if (typeof(so) == "object")
		so.write("flvvideo");
}

function flash_video_change_size_link(change_to) {
	for (i = 1; i <= 2; i++)
	{
		if (i == change_to)
			document.getElementById('vq'+i).className = 'artvb_exe_selected';//className = 'artvb_exe_selected';
		else
			document.getElementById('vq'+i).className = 'artvb_exe';
	}
}
function flash_send_playpause()
{
	setTimeout("sendEvent('playpause')", 1000);
}
function flash_video_change_size_playlist(change_to)
{
	if (ad_played != 1)
	{
		set_cookie('flash_video_size', change_to);
		flash_video_change_size_link(change_to);
		loadfile = file.replace("*SIZE*", change_to);
		obj = {file: loadfile, id: '123', autostart: 'true'};
		loadFile(obj);
	}
}

function flash_video_change_size(change_to)
{
	set_cookie('flash_video_size', change_to);
	flash_video_change_size_link(change_to);
	flash_video_show(change_to);
	swf_object_write();
}

function flash_video_show(size)
{
	if (typeof(media_filename) == 'undefined')
		media_filename = media_id;
	video_size = size;
	if (video_size != '1' || video_size != '2' || video_size != '3')
		video_size = get_cookie('flash_video_size');

	if (video_size != '1' && video_size != '3')
		video_size = '2';
	if (typeof(stream) == "undefined")
		stream = 0;

	if (fullscreen)
	{
		fsmode = 'true';
		file = '';
		width = '100%';
		height = '100%';
	}
	else
	{
		if (typeof(player_width) == "undefined" && typeof(player_height) == "undefined")
		{
			width = '416';
			height = '332';
		}
		else
		{
			width = player_width;
			height = player_height;
		}
		fsmode = 'false';
		file_no_server = '/'+section_video+'/'+media_dir+'/'+media_filename+'-'+video_size+'.flv';
		if (stream == 1)
		{
			file_id = section_video+'/'+media_dir+'/'+media_filename+'-'+video_size;
			file = stream_server+'_____id-----'+file_id;
			file_no_server = file_id;
		}
		else
			file = stream_server+file_no_server;
	}

	flv_ad = '';
	flv_ad_url = '';
	if ( (typeof(phpadsbanner_flash) !== "undefined") && (phpadsbanner_flash != '') )
	{
		if (stream == 1)
			flv_ad = url_max + '_____ad_id-----' + phpadsbanner_flash + "-" + video_size;
		else
			flv_ad = url_max + phpadsbanner_flash + "-" + video_size+".flv";
		flv_ad_url = '';
		if (phpadsbanner_flash_url)
			flv_ad_url = escape(phpadsbanner_flash_url);
	}
	
	section_video_stripped = section_video;
	if (section_video.indexOf('/') > 0)
		section_video_stripped = section_video.substring(0, section_video.indexOf('/'));
	
	file_title = file_no_server+'||'+media_filename+'||'+section_video_stripped;
	host = "http://" + document.domain;
	urlplaylist = host+'/bin/playlist.php?g=section_id-----'+section_id+'_____file-----'+file+'_____ad_file-----'+flv_ad+'_____ad_url-----'+flv_ad_url+'_____file_title-----'+file_title;

	so = new SWFObject('/furniture/system/24ur.swf', 'flvplayer', width, height, '8', '#FFFFFF');
	so.addParam('allowfullscreen', 'true');
	
	if (flv_ad != '')
	{
		so.addVariable('linkfromdisplay', 'true');
		so.addVariable('linktarget', '_blank');
	}

	so.addVariable('overstretch', 'false');
	if (!fullscreen)
		so.addVariable('callback', '/bin/statistics_'+played_site+'.php');
	so.addVariable('showdigits', 'true');
	so.addVariable('autostart', 'true');
	so.addVariable('repeat', 'false');
	so.addVariable('enablejs', 'true');
	so.addVariable('repeat', 'false');
	so.addVariable('showfsbutton', 'true');
	so.addVariable('fullscreenpage', '/bin/fullscreen_'+played_site+'.html');
	so.addVariable('fullscreenmode', fsmode);
	so.addVariable('fsreturnpage', document.URL);
	so.addVariable('logo', '/bin/logo_'+played_site+'.png');
	so.addVariable('file', urlplaylist);
}

function thisMovie(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};
function loadFile(obj) { thisMovie("flvplayer").loadFile(obj); flash_send_playpause();};
function sendEvent(typ,prm) { thisMovie("flvplayer").sendEvent(typ,prm); };
function getUpdate(typ,pr1,pr2,pid) {
	if (typ == "state" && pr1 == 3 && is_ad)
	{
		id = 123;
		if (stream == 1)
		{
			id = file_id;
			file = stream_server;
		}
		obj = {file: file, id: id, category: 'none', autostart: 'true'};
		loadFile(obj);
		is_ad = 0;
	}
};


function flash_video_load(loadfile, video_ad, ad_load)
{
	category = "none";
	if (video_ad && ad_played == 0)
	{
		ad_played = 1;
		tmp_load = loadfile;
		loadfile = url_max+'/'+video_ad+'-'+video_size+'.flv';
	}
	else
		ad_played = 0;
	
	if (typeof(so) == "object")
	{
		obj = {file: loadfile, id: '123', autostart: 'true'};
		loadFile(obj);
	}
	else
	{
		flv_params = "/furniture/system/24ur.swf?overstretch=false&showdigits=true&autostart=true&enablejs=true&file="+loadfile;
		so = new SWFObject(flv_params, "flvplayer", 416, 332, "8", "#FFFFFF"); // we create new swf object
		so.addParam("allowfullscreen", "true");
		so.write("flvvideo"); // we show player into div with id "player"
	}
	if (video_ad && ad_played == 0)
		loadfile = tmp_load;
}

function flash_audio_show()
{
	file_no_server = '/'+section_video+'/'+media_dir+'/'+media_id+'-1.flv';
	file = stream_server+file_no_server;
	flv_params = "/furniture/system/mp3player.swf?showdigits=true&autostart=true&showfsbutton=false&file="+file;
	so = new SWFObject(flv_params, "flvplayer", 385, 20, "7", "#FFFFFF");
}

function pplayer_video_show() {
/*	flash_video_show();
	return '';*/
	
	// we check if we'll not use default player dimensions
	if (typeof(player_width) == "undefined" && typeof(player_height) == "undefined")
	{
		width = 416;
		height = 312;
	}
	else
	{
		width = player_width;
		height = player_height;
	}

	height = height + 40;

	so = new SWFObject('/furniture/system/MediaCenter.swf', 'mediacenter', width, height, '9');
	so.addParam('allowfullscreen', 'true');
	so.addVariable('media_id', media_id);

	so.addVariable('ad_file', 'noad');
	// 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');
	}

	so.addVariable('section_id', section_id);
	so.addVariable('bit', get_cookie('bit'));
	so.addVariable('referer', 'FLASH_PLAYER');
	so.addVariable('color', '#000000');
	so.addVariable('userad_id', get_cookie('phpAds_id'));
	if (typeof(playlist_file) !== 'undefined')
		so.addVariable('playlist_file', playlist_file);
}

function video_no_flash()
{
	phpadsbanner_flash_beacon = '';
	phpadsbanner_flash = '';
	video_flash_banner_id = '';
	window.addEvent('domready', function()	{
		$('flvvideo').innerHTML = _text_flash_no;
	});
}

function video_show_player()
{
	if (typeof(show_ads) !== 'undefined' && !show_ads)
		remove_video_ads();
	
	if (flash_version >= 9)
	{
		pplayer_video_show();
	}
	else if (flash_version == 8)
	{
		window.addEvent('domready', function()	{
			$('video_notice').style.display = 'block';
			try { $('video_quality_change').style.display = 'block'; } catch(error) {};
			flash_video_change_size_link(video_size);
		});
		flash_video_show();
	}
	else
	{
		video_no_flash();
	}
}