video_player_generator = function( p_video_tip, p_video_code, p_youtube_code, p_width, p_height, p_div_container )
{
	this.video_tip = p_video_tip;
	this.video_code = p_video_code;
	this.youtube_code = p_youtube_code;
	this.width = p_width;
	this.height = p_height;
	this.div_container = p_div_container;
}

video_player_generator.prototype.get_player = function ()
{
	if( this.video_tip > 0 ){
		// youtube
		if( this.video_tip == 1 )	{
			this.get_html_youtube();
		}
		// DailyMotion
		if( this.video_tip == 2 )	{
			this.get_html_dailymotion();
		}
		// 24satatv
		if( this.video_tip == 3 )	{
			this.get_html_24satatv();
		}
	}
	if( this.youtube_code != '' ){
		this.video_code = this.youtube_code;
		this.get_html_youtube();
	}
}

video_player_generator.prototype.get_html_youtube = function()
{
	if (_ip_range)
	{
		document.getElementById(this.div_container).innerHTML = '<br /><br /><br /><br /><br /><br /><br /><br /><br /><div style="width: 460px; text-align: center; "><a href="javascript: make_ajax_request(\'' + this.video_code + '\');">Ovaj se video naplaćuje. Ukoliko ga želite vidjeti, kliknite za nastavak.</a></div>';
	}
	else this.get_html_youtube_real();
}

video_player_generator.prototype.get_html_youtube_real = function()
{
	obj_swf =   new SWFObject("http://www.youtube.com/v/" + this.video_code, "mymovie", this.width, this.height, "7", "#000000");
	obj_swf.addParam("menu","false");
	obj_swf.addParam("wmode","transparent");
	obj_swf.addVariable("width", this.width );
	obj_swf.addVariable("height", this.height );
	obj_swf.write( this.div_container );
}

video_player_generator.prototype.get_html_dailymotion = function()
{
	var _arr_code = this.video_code.split("_");
	var _code = _arr_code[0];
	
	obj_swf =   new SWFObject("http://www.dailymotion.com/swf/" + _code, "mymovie", this.width, this.height, "7", "#000000");
	obj_swf.addParam("menu","false");
	obj_swf.addParam("allowFullScreen","true");
	obj_swf.addParam("allowScriptAccess","always");
	obj_swf.addVariable("width", this.width);
	obj_swf.addVariable("height", this.height);
	obj_swf.write( this.div_container );
}

video_player_generator.prototype.get_html_24satatv = function()
{	
	var obj_swf = new SWFObject( "http://www.24sata.tv/templates/assets/flash/fw3k_player/fw3k_player.swf","mediaplayer", this.width, this.height, "9","#000000");
	obj_swf.addParam("allowfullscreen","true");
	obj_swf.addParam("allowScriptAccess","always");
	obj_swf.addParam("menu","false");
	obj_swf.addVariable("preview", 0);
	obj_swf.addVariable("forbid_details", 1);
	
	obj_swf.addVariable("stat_key", stat_key); // session id
	obj_swf.addVariable("stat_source", stat_source); // server name
	obj_swf.addVariable("stats_server_url", stats_server_url); // 
	
	obj_swf.addVariable("playlist_path", playlist_path_template + this.video_code);
	
	obj_swf.write( this.div_container );
}

function make_ajax_request(video_id)
{
	$.ajax({
		type: "POST",
		url: _rewrite_base + "util_scripts/insert_watched_video.php",
		data: "video_id=" + video_id,
		success: function (){ obj_video_player_generator.get_html_youtube_real(); }
	});
}
