var estadoVideo;
var currentVideo;
var titulo_url;
var votorealizado = false;

function getUpdate(typ,pr1,pr2,swf) {
	if (typ=="item"){
		getVideo(swf,pr1);
	}else if (typ=='state'){
		estadoVideo = pr1;
		switch (pr1){
			case 0:
				var state='Parado.';
			break;
			case 1:
				var state='Buffering...';
			break;
			case 2:
				var state='Reproduciendo.';
			break;
		}
	}
}
function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
function itemData(swf,idx) {
	var obj = thisMovie(swf).itemData(idx);
	return obj;
}
function sendEvent(swf,typ,prm) {
  thisMovie(swf).sendEvent(typ,prm);
}
function pausarVideo(){
	if(estadoVideo){
		sendEvent('mediaplayer','playpause');
	}
}
function str_replace(cambia_esto, por_esto,cadena) {
	return cadena.split(cambia_esto).join(por_esto);
}
function mostrarAviso(){
	$("#aviso_voto").fadeIn("slow");
}

function quitarAviso(){
	$("#aviso_voto").fadeOut("slow");
  	votorealizado = false;
}

function votar(nvoto){
	$.ajax({
		  type: "POST",
		  url: "/votar",
		  dataType: "json",
		  data: { idcontenido: id_video, nvoto: nvoto },
		  success: function(json){
			  $("ul.stars li.cont-star ul").fadeOut("slow" , function() {
				  $(this).attr("class", "rating star"+json.rating);
				});
			  $("ul.stars li.cont-star ul").fadeIn("slow");
			  $("span.current_rating span.votos").html(json.numeroVotos);
		  }
		});
}

function getPath(){
	return window.location.href.substring(window.location.href.indexOf("/",7)+1);
}

function cerrar_enlace_video(){
   $('#zlayer').fadeOut();
}

function mostrarBanner(idioma){

    var cookie=readCookie("bannerportada");
    if(cookie==null || cookie!="activo"){
		    createCookie("bannerportada","activo",1);
		    var flashvars = {wmode:"transparent"};
			var params = {wmode:"transparent"};
		  	var attributes = {};
		  	swfobject.embedSWF("/swf/banner_movil_"+idioma+".swf", "banner_iphone", "761", "493", "9.0.0","", flashvars, params, attributes);
			//setTimeout("cerrarBanner()",milisegundos);
		   $('#banner_portada').center();
		   $('#banner_portada').attr( "className","");
		   $('#banner_portada').show('slow');

    }

}

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", "200px");
    this.css("left", ( $(window).width() - $('#banner_portada').width() ) / 2 + "px");
    return this;
}

function cerrarBanner(){
	$('#banner_portada').html("");
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
