var lg = "ES";

function getdataBlob(action,target,blob,lasttit) {
	$("#"+blob).html(lang["cargando"]);
	$("#"+target).load(action, null, function () {
		$("#"+blob).html(lasttit);
	});
}
function getdata(action, target) {
	$("#"+target).html(lang["cargando"]);
	$("#"+target).load(action);
}
function tab(pos,cant) {
	for (n=1;n<=cant;n++) {
		if (document.getElementById("tab_"+n)) {
			if (n == pos) {
				document.getElementById("tab_"+n).className = "sel";
				document.getElementById("block_"+n).className = "";
			} else {
				document.getElementById("tab_"+n).className = "";
				document.getElementById("block_"+n).className = "hide";
			}
		}
	}
}
function submenu(pos) {
	var el = document.getElementById("submenu2").getElementsByTagName("ul")[0].getElementsByTagName("li");
	var el2 = $("#tabblock .block");
	var cant = el.length;
	for (n=0;n<cant;n++) {
		if (n == pos) {
			el[n].getElementsByTagName("a")[0].className = "sel";
			$(el2[n]).show();
		} else {
			el[n].getElementsByTagName("a")[0].className = "";
			$(el2[n]).hide();
		}
	}
}
function ltab(pos,cant) {
	for (n=1;n<=cant;n++) {
		if (document.getElementById("ltab_"+n)) {
			if (n == pos) {
				document.getElementById("ltab_"+n).className = "selected";
			} else {
				document.getElementById("ltab_"+n).className = "";
			}
		}
	}
}
function dropDown(name,arrow) {
	var el = document.getElementById(name);
	arrow = document.getElementById(arrow);
	if (el.className == "hide") {
		el.className = "";
		arrow.className = "ar_drop2";
	} else {
		el.className = "hide";
		arrow.className = "ar_drop";
	}
}
function setTitle(name) {
	document.title = "Cuevana | "+name;
}
function showRate(rate) {
	for (n=1;n<=5;n++) {
		if (n <= rate) {
			document.getElementById("star"+n).className = "on";
		} else {
			document.getElementById("star"+n).className = "";
		}
	}
	var tx = document.getElementById("rating_label");
	if (rate == 1) {
		tx.innerHTML = lang["malo"];
	} else if (rate == 2) {
		tx.innerHTML = lang["regular"];
	} else if (rate == 3) {
		tx.innerHTML = lang["bueno"];
	} else if (rate == 4) {
		tx.innerHTML = lang["muybueno"];
	} else if (rate == 5) {
		tx.innerHTML = lang["excelente"];
	}
}
function hideRate() {
	var rate = document.getElementById("puntaje").value;
	for (n=1;n<=5;n++) {
		if (n <= rate) {
			document.getElementById("star"+n).className = "sel";
		} else {
			document.getElementById("star"+n).className = "";
		}
	}
	document.getElementById("rating_label").innerHTML = "";
}
function doRate(rate) {
	document.getElementById("puntaje").value = rate;
	for (n=1;n<=5;n++) {
		if (n <= rate) {
			document.getElementById("star"+n).className = "sel";
		} else {
			document.getElementById("star"+n).className = "";
		}
	}
}
function ajaxError(act, status) {
	if (document.getElementById("error")) {
		if (act == "off") {
			document.getElementById("error").style.display = "none";
		} else {
			document.getElementById("error").style.display = "block";
			$("#errortit").html(lang["error"]+": "+status);
			if (status == "error") {
				$("#errortxt").html(lang["ajax_error1"]);
			} else {
				$("#errortxt").html(lang["ajax_error2"]);
			}
		}
	}
}
function showLogin() {
	if (document.getElementById("loginblock").className == "hide") {
		if (document.getElementById("login_but").className == "") {
			$("#loginblock").slideDown("fast");
			document.getElementById("login_but").className = "sel";
			$("#loginblock").html("<center>"+lang["cargando"]+"</center>");
			$("#loginblock").load("/login_get.php");
		} else {
			document.getElementById("login_but").className = "";
			$("#loginblock").slideUp("fast");
		}
		if (document.getElementById("reg_but")) {
			document.getElementById("reg_but").className = "";
		}
	}
}
function showReg() {
	if (document.getElementById("loginblock").className == "hide") {
		if (document.getElementById("reg_but").className == "") {
			$("#loginblock").slideDown("fast");
			document.getElementById("reg_but").className = "sel";
			$("#loginblock").html("<center>"+lang["cargando"]+"</center>");
			$("#loginblock").load("/registro_get.php");
		} else {
			document.getElementById("reg_but").className = "";
			$("#loginblock").slideUp("fast");
		}
		document.getElementById("login_but").className = "";
	}
}
function getHash() {
	if (location.hash != null) {
		if (location.host.match('peliculas/')) {
			if (location.hash == "#info") {
				tab(1,2);
			} else if (location.hash == "#criticas") {
				tab(2,2);
			}
		} else {
			if (location.hash == "#info") {
				tab(1,3);
			} else if (location.hash == "#criticas") {
				tab(2,3);
			} else if (location.hash == "#episodios") {
				tab(3,3);
			}
		}
	}
}
function showList(num) {
	if (document.getElementById("list_icon")) {
		document.getElementById("list_icon").src = "/img/list_icon"+num+".gif";
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1);
		var goto = "peliculas";
		if (window.location.href.match('series')) {
			goto = "series";
		}
		$("#list").html("<center>"+lang["cargando"]+"</center>");
		$("#list").load("/list_"+goto+".php?list="+num+"&"+hashes);
	}
}
function listSeries(num, valor) {
	if (valor != "") {
		if (num == 1) {
			$("#temporada").html("<li>"+lang["cargando"]+"</li>");
			$("#temporada").load("/list_search_id.php?serie="+valor);
			$("#boxtop").load("/list_search_info.php?serie="+valor);
		} else if (num == 2) {
			$("#episodio").html("<li>"+lang["cargando"]+"</li>");
			$("#episodio").load("/list_search_id.php?temporada="+valor);
			$("#boxtop").load("/list_search_info.php?temporada="+valor);
		} else if (num == 3) {
			$("#boxtop").html(lang["cargando"]);
			$("#boxtop").load("/list_search_info.php?episodio="+valor);
		} else if (num == 4) {
			$("#episodio_list").html("<li>"+lang["cargando"]+"</li>");
			$("#episodio_list").load("/list_search_serie.php?temporada="+valor);
		}
	}
}
function showError(el) {
	$("#"+el).addClass("formerror");
}
function hideError(el) {
	$(el).removeClass("formerror");
}
function changeType(id, valor) {
	if (valor == true) {
		$("#m"+id).hide();
		$("#"+id).show();
		$("#"+id).focus();
	} else {
		$("#m"+id).show();
		$("#"+id).hide();
	}
}
function voteCritica(id, voto, tipo, showid) {
	if (tipo == false) {
		$("#criticas_list").load("/criticas_p.php?id="+id+"&voto="+voto+"&showid="+showid);
	} else {
		$("#criticas_list").load("/criticas_s.php?id="+id+"&voto="+voto+"&episodio="+showid);
		
	}
}
function timerLoader() {
	if (window.frames["player_frame"].document.getElementById("player_frame_hide").style.display == "block") {
		window.frames["player_frame"].document.getElementById("player_frame_hide").innerHTML = "<img src='/img/loader_video.gif' border='0' /><br /><br />"+lang["load_msg"];
	}
}
var lastBotmenu = "";
function blankBotMenu() {
	$("#fav_link").removeClass("selected");
	$("#des_link").removeClass("selected");
	$("#rep_link").removeClass("selected");
	$("#rep2_link").removeClass("selected");
	$("#botmenu_block").hide();
}
function botmenuTab(id, serie, id2) {
	if (lastBotmenu != id2) {
		blankBotMenu();
		$("#"+id2+"_link").addClass("selected");
		if (serie == true) {
			id += "&serie=true";
		}
		$("#botmenu_block").html(lang["cargando"]).slideDown("fast").load("/botlink_"+id2+".php?id="+id);
		lastBotmenu = id2;
	} else {
		blankBotMenu();
		lastBotmenu = "";
	}
}
function resizeFrame(cond) {
	var el = document.getElementById("player_frame");
	var el2 = document.getElementById("player");
	if (el.width == 640 || cond == false) {
		el.width = 900;
		el.height = 500;
		el2.style.width = "900px";
		el2.style.height = "500px";
	} else if (cond == true) {
		el.width = 640;
		el.height = 360;
		el2.style.width = "640px";
		el2.style.height = "360px";
	}
}
function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		 return window.frames["player_frame"].window[movieName];
	 } else {
		 return window.frames["player_frame"].document[movieName];
	 }
 }
function toolSubtitulador() {
	if (window.frames["player_frame"].document.getElementById("playerSWF")) {
		resizeFrame(false);
		thisMovie("playerSWF").openTool("subtitulador");
		thisMovie("playerSWF").width = 900;
		thisMovie("playerSWF").height = 500;
		window.frames["player_frame"].document.getElementById("playerSWF").width = 900;
		window.frames["player_frame"].document.getElementById("playerSWF").height = 500;
	} else {
		alert(lang["sub_error1"]);
	}
	$("#player_tools_menu").slideToggle("fast");
}

function toolsMenu() {
	$("#player_tools_menu").slideToggle("fast");
}
function getTrailer(yid) {
	$(".trailer_block").html('<object width="640" height="375"><param name="movie" value="http://www.youtube.com/v/'+yid+'&hl=es_ES&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+yid+'&hl=es_ES&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="375"></embed></object>');	
}
function langMenu() {
	var loff = $("#langbut").offset();
	if (document.getElementById("langchoose").style.display != "block") {
		$("#langchoose").css("top", loff.top+17+"px").css("left", loff.left+"px").show("fast");
		var nclick = 0;
		function bb() {
			nclick++;
			if (nclick > 1) {
				$("#langchoose").hide("fast");
				$(this).unbind("click", bb);
				nclick=0;
			}
		}
		$(document).bind("click", bb);
	} else {
		$("#langchoose").hide("fast");
	}
}