	function urlencode( str ) {
	 var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
	 var ret = str.toString();
	 
	 var replacer = function(search, replace, str) {
	 var tmp_arr = [];
	 tmp_arr = str.split(search);
	 return tmp_arr.join(replace);
	 };
	 
	 // The histogram is identical to the one in urldecode.
	 histogram['!']   = '%21';
	 histogram['%20'] = '+';
	 
	 // Begin with encodeURIComponent, which most resembles PHP's encoding functions
	 ret = encodeURIComponent(ret);
	 
	 for (search in histogram) {
	 replace = histogram[search];
	 ret = replacer(search, replace, ret) // Custom replace. No regexing
	 }
 
	 // Uppercase for full PHP compatibility
	 return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
	 return "%"+m2.toUpperCase();
	 });
	 
	 return ret;
	}		
	
	function setTitulos(titulo, bajada){
		var tituloVideo = document.getElementById("tituloVideo");
		var bajadaVideo = document.getElementById("bajadaVideo");
		
		tituloVideo.innerHTML = decodeURIComponent(titulo);
		bajadaVideo.innerHTML = decodeURIComponent(bajada);
	}
	
	function setVideoHome(swf_id){
		var video_id = swf_id;
		var moogaloop = false;

		/*seteo de los botones compartir de facebook y twitter*/
		var fb_share2 = document.getElementById("fb_share2");
		var twitt_share2 = document.getElementById("twitt_share2");
		
		fb_share2.href = 'http://www.facebook.com/share.php?u='+urlencode('http://www.sergioaguero.com/videos.php?vID='+swf_id);
		twitt_share2.href = 'http://twitter.com/login?redirect_after_login=/home%3Fstatus%3D'+urlencode('http://www.sergioaguero.com/videos.php?vID='+swf_id);

		function vimeo_player_loaded(swf_id) {
			moogaloop = document.getElementById(swf_id);
			//document.getElementById('controls').style.display = '';

			moogaloop.api_addEventListener('onProgress', 'vimeo_on_progress');
			moogaloop.api_addEventListener('onLoading',  'vimeo_on_loading');
			moogaloop.api_addEventListener('onFinish',   'vimeo_on_finish');
			moogaloop.api_addEventListener('onPlay',     'vimeo_on_play');
			moogaloop.api_addEventListener('onPause',    'vimeo_on_pause');
			moogaloop.api_addEventListener('onSeek',     'vimeo_on_seek');

			document.getElementById('vimeo_duration').innerHTML = moogaloop.api_getDuration();
		}

		function vimeo_on_play(swf_id) {
			document.getElementById('state').innerHTML = 'Playing';
		}

		function vimeo_on_pause(swf_id) {
			document.getElementById('state').innerHTML = 'Paused';
		}

		function vimeo_on_seek(time, swf_id) {
			document.getElementById('state').innerHTML = 'Seeking to ' + time;
		}

		function vimeo_on_progress(time, swf_id) {
			document.getElementById('vimeo_cur_time').innerHTML = time + 's';
		}

		function vimeo_on_loading(data, swf_id) {
			document.getElementById('vimeo_bytes_loaded').innerHTML = data.bytesLoaded;
			document.getElementById('vimeo_bytes_total').innerHTML = data.bytesTotal;
			document.getElementById('vimeo_decimal_loaded').innerHTML = data.decimal;
			document.getElementById('vimeo_percent_loaded').innerHTML = data.percent + '%';
		}

		function vimeo_on_finish(swf_id) {
			document.getElementById('state').innerHTML = 'Finished';
		}

		function toggle_loop(el) {
			if (el.value == 'Loop is off') {
				el.value = 'Loop is on';
				moogaloop.api_setLoop(true);
			}
			else {
				el.value = 'Loop is off';
				moogaloop.api_setLoop(false);
			}
		}

		// Run the javascript when the page is ready
		var swf_id = 'moogaloop';

	 	var flashvars = {
	        clip_id: video_id,
	        show_portrait: 0,
	        show_byline: 0,
	        show_title: 0,
			js_api: 1, // required in order to use the Javascript API
			js_onLoad: 'vimeo_player_loaded', // moogaloop will call this JS function when it's done loading (optional)
			js_swf_id: 'moogaloop' // this will be passed into all event methods so you can keep track of multiple moogaloops (optional)
	    };
		var params = {
			allowscriptaccess: 'always',
			allowfullscreen: 'true'
		};
		var attributes = {};

		// For more SWFObject documentation visit: http://code.google.com/p/swfobject/wiki/documentation
		swfobject.embedSWF("http://vimeo.com/moogaloop.swf", swf_id, "500", "380", "9.0.0","expressInstall.swf", flashvars, params, attributes);
			/*var swfObj = new SWFObject('player.swf', 'CajaTV', 500, 380, '8');
			swfObj.addParam('flashvars','type=video&stretching=fill&menu=false&file='+my_file+'&image='+my_image+'&backcolor=333333&frontcolor=ffffff&skin=bright.swf');
			swfObj.addParam('allowfullscreen','true');
			swfObj.addParam('wmode','transparent');
			swfObj.addParam('allowscriptaccess','always');
			swfObj.write('__CajaTV');*/
	}	

	
	/*function loadNewFile(myflv, myimagen){	
		var player = window.document["__cajaTV"];
		player.sendEvent('LOAD', {file: myflv, image: myimagen});
		player.sendEvent('PLAY');
	}*/

	
	function setTele(swf_id, img, divcontent) {
		
		var video_id = swf_id;
		var moogaloop = false;

		function vimeo_player_loaded(swf_id) {
			moogaloop = document.getElementById(swf_id);
			//document.getElementById('controls').style.display = '';

			moogaloop.api_addEventListener('onProgress', 'vimeo_on_progress');
			moogaloop.api_addEventListener('onLoading',  'vimeo_on_loading');
			moogaloop.api_addEventListener('onFinish',   'vimeo_on_finish');
			moogaloop.api_addEventListener('onPlay',     'vimeo_on_play');
			moogaloop.api_addEventListener('onPause',    'vimeo_on_pause');
			moogaloop.api_addEventListener('onSeek',     'vimeo_on_seek');

			document.getElementById('vimeo_duration').innerHTML = moogaloop.api_getDuration();
		}

		function vimeo_on_play(swf_id) {
			document.getElementById('state').innerHTML = 'Playing';
		}

		function vimeo_on_pause(swf_id) {
			document.getElementById('state').innerHTML = 'Paused';
		}

		function vimeo_on_seek(time, swf_id) {
			document.getElementById('state').innerHTML = 'Seeking to ' + time;
		}

		function vimeo_on_progress(time, swf_id) {
			document.getElementById('vimeo_cur_time').innerHTML = time + 's';
		}

		function vimeo_on_loading(data, swf_id) {
			document.getElementById('vimeo_bytes_loaded').innerHTML = data.bytesLoaded;
			document.getElementById('vimeo_bytes_total').innerHTML = data.bytesTotal;
			document.getElementById('vimeo_decimal_loaded').innerHTML = data.decimal;
			document.getElementById('vimeo_percent_loaded').innerHTML = data.percent + '%';
		}

		function vimeo_on_finish(swf_id) {
			document.getElementById('state').innerHTML = 'Finished';
		}

		function toggle_loop(el) {
			if (el.value == 'Loop is off') {
				el.value = 'Loop is on';
				moogaloop.api_setLoop(true);
			}
			else {
				el.value = 'Loop is off';
				moogaloop.api_setLoop(false);
			}
		}

		// Run the javascript when the page is ready
		var swf_id = 'moogaloop';

	 	var flashvars = {
	        clip_id: video_id,
	        show_portrait: 0,
	        show_byline: 0,
	        show_title: 0,
			js_api: 1, // required in order to use the Javascript API
			js_onLoad: 'vimeo_player_loaded', // moogaloop will call this JS function when it's done loading (optional)
			js_swf_id: 'moogaloop' // this will be passed into all event methods so you can keep track of multiple moogaloops (optional)
	    };
		var params = {
			allowscriptaccess: 'always',
			allowfullscreen: 'true'
		};
		var attributes = {};

		// For more SWFObject documentation visit: http://code.google.com/p/swfobject/wiki/documentation
		swfobject.embedSWF("http://vimeo.com/moogaloop.swf", swf_id, "358", "200", "9.0.0","expressInstall.swf", flashvars, params, attributes);
		
		
		/*var swfObj = new SWFObject("player.swf", "swfcajaTV", 358, 200, "8");
		swfObj.addParam("flashvars","type=video&stretching=fill&menu=false&file="+myflv+"&image="+img+"&backcolor=333333&frontcolor=ffffff&controlbar=over&skin=bright.swf");
		swfObj.addParam("allowfullscreen","true");
		swfObj.addParam("wmode","transparent");
		swfObj.addParam("allowscriptaccess","always");
		swfObj.write(divcontent);*/	
	}

	
	function setComentario(obj){		
	
		this.onRollOver = onRollOver;
		function onRollOver(obj){
			var guia = obj.id;
			document.getElementById("titulo_tele_id").innerHTML = obj.alt;
			document.getElementById(guia).style.border = "solid 2px #CCCCCC";
		}
		
		this.onRollOut = onRollOut;
		function onRollOut(obj){
			var guia = obj.id;
			var guia_activa = document.getElementById("guia_activa").value;
			document.getElementById("titulo_tele_id").innerHTML = document.getElementById(guia_activa).alt;
			for(i=1; i<=3; i++){
				if(guia_activa!="img"+i){
					document.getElementById("img"+i).style.border = "";			
				}
			}			
		}
		
		this.setTitulo = setTitulo;
		function setTitulo(){
			var guia = obj.id;
			document.getElementById("titulo_tele_id").innerHTML = obj.alt;
			document.getElementById(guia).style.border = "solid 2px #FFFFFF";
			document.getElementById("guia_activa").value = guia;
		}
		
		this.Click = Click;
		function Click(obj){
			var guia = obj.id;
			var guia_activa = document.getElementById("guia_activa").value;
			document.getElementById(guia_activa).style.border = "";
			
			document.getElementById("titulo_tele_id").innerHTML = obj.alt;
			document.getElementById("guia_activa").value = guia;	
			document.getElementById(guia).style.border = "solid 2px #FFFFFF";
		}
		

	}
