window.onerror=handleErr;
function handleErr(msg,url,l){
	return true;
}


$(document).ready(function(){
	// therror does not <3 frames
	if (top.location != location) {
		top.location.href = document.location.href;
	}
	/* Búsqueda */
	if($("#buscador").attr("id")){
		$("#buscador .inputtext").focus(function(){
			$(this).unbind("focus");
			$(this).attr("value", "");
		});
	}

	/* Compárteme */
	$(".meneame, .enchilame").click(function(){
		try {
			urchinTracker("/sharethis");
		} catch(e){	}
		$(this).animate({opacity:1.0}, 250, function(){
			window.location = $(this).attr("href");
		});
		return false;
	});

	$(".videofaqlink").click(function(){
		$(this).parents(".videofaq:eq(0)").children("p.noV:eq(0)").slideDown("slow");
		$(this).unbind("click");
		return false;
	});

	$(".addrss").click(function(){
		if(!$("#addrssHold").attr("id")){
			$("#main").before('<div id="addrssHold"><div id="addrss"></div></div>');
			$("#addrssHold").addClass("noV");
		}

		$.ajax({
			type: "GET",
			url: "/files/addrss.htm",
			cache: false,
			dataType: "html",
			success: function(html){
				$("#addrss").html(html);
			}
		});
		tb_show("Suscribir", "#TB_inline?height=300&width=600&inlineId=addrssHold&modal=false", "");
		return false;
	});

	/* GetFirefox */
	if($(".adverttop").attr("id")){
		var adverttop = $(".adverttop").attr("id");

		var cookie = $.cookie(adverttop);
		/* No hay cookie, perhaps first time */

		if(!cookie){
			$("#"+adverttop).animate({opacity: 1.0}, 1500).slideDown("slow");
			$.cookie(adverttop, 'notfirsttime', {expires:7});
		} else if(adverttop=='notfirsttime'){
			$("#"+adverttop).removeClass("noV");
		}

		$("#"+adverttop+" span.yup").click(function(){
			$("#"+adverttop+" .info").slideUp("slow");
			$("#"+adverttop+" .getit").animate({opacity: 1.0}, 700).slideDown("slow");
			//$("#"+adverttop+" .holder").after("<iframe src=\"/files/firefox.htm\" allowtransparency=\"true\" frameborder=\"0\" scrolling=\"no\" style=\"background:transparent; display:block; border:0; margin:0 auto; width:468px; height:60px;\"></iframe>");
		});

		$("#"+adverttop+" span.nope").click(function(){
			$("#"+adverttop).animate({opacity: 1.0}, 400).slideUp("slow");
			$.cookie("#"+adverttop, 'noshow', {expires:7});
		});
	}
	$("object").attr("allowNetworking", "internal");
	
	/* Hotlink */
	$("#hotlinkimage img").each(function(){
		var max_width = 600;
		var width = $(this).width();
		var height = $(this).height();
		if (width > max_width) {
			//Set variables	for manipulation
			var ratio = (height / width );
			var new_width = max_width;
			var new_height = (new_width * ratio);
			
			//Shrink the image and add link to full-sized image
			$(this).height(new_height).width(new_width);
			$(this).css("cursor","pointer");
			$(this).click(function(){
				window.location = $(this).attr("src");
			});
		} //ends if statement
	});
	
	if($(".video").length){
		$(".video span.hold").each(function(){
			var h = $(this).siblings("img").attr("height");
			var w = $(this).siblings("img").attr("width");

			$(this).siblings("img").css({display:"block"});

			$(this).css({width:w+"px",height:h+"px", marginBottom:-h+"px", display:"block"});
			$(this).children("span").css({display:"block", top:(h-80)+"px", left:(w-85)+"px"});
		});
	}
});

function showvid(t,loc,w,h){

	try {
		urchinTracker("/verVideo");
	} catch(e){	}

	var loc = loc.split("").reverse().join("");
	var num = Math.round(Math.random()*99999);
	var so = new SWFObject(loc, "swf_"+num, w, h, "7", "#ffffff");

	$(t).parent().attr("id", "vid_"+num);

	so.addParam("allowScriptAccess", "never");
	so.addParam("allowNetworking", "internal");
	so.addParam("enableJSURL", "false");
	so.write("vid_"+num);
	
	if($("#vid_"+num).html().search(/<object/i) != -1 || $("#vid_"+num).html().search(/<embed/i) != -1){
		$(t).parent().attr("id", "");
		$(t).siblings("img").remove();
		$(t).remove();
	} else {
		try {
			urchinTracker("/verVideoFAIL");
		} catch(e){	}
		
		$("#vid_"+num).html('<object width="'+w+'" height="'+h+'"><param name="movie" value="'+loc+'"></param><param name="allowFullScreen" value="true"></param><embed src="'+loc+'" type="application/x-shockwave-flash" allowScriptAccess="never" allowNetworking="internal" enableJSURL="false" allowfullscreen="true" width="'+w+'" height="'+h+'"></embed></object>');
	}
	return;
}