var v3_url="http://www.aunder.org";
var modalWindow = {  
    parent:"body",  
    windowId:null,  
    content:null,  
    width:null,  
    height:null,  
    close:function()  
    {  
        $(".modal-window").remove();  
        $(".modal-overlay").remove();  
    },  
    open:function()  
    {  
        var modal = "";  
   	modal += "<div class=\"modal-overlay\"></div>";
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";  
        modal += this.content;  
        modal += "</div>";      


        $("#contenido").append(modal);  
  
        $(".modal-window").append("<a class=\"close-window\"></a>");  
        $(".close-window").click(function(){modalWindow.close();});  
        $(".modal-overlay").click(function(){modalWindow.close();});  
    }  
};

var previewWeb = function(id) 
{
 	var modal = "";
	modal+= "<div id=\"webshot\"><img src=\"http://imagenes.aunder.org/webcache/cache.php?dir="+id+"\"/></div>";  
	$("#webshot").remove();
        $("#webSnap").append(modal);
};

var cargaContactanos = function()  
{  
    source=v3_url+"/contact_form.html";
    modalWindow.windowId = "Cont&atilde;ctanos";  
    modalWindow.width = 480;  
    modalWindow.height = 405;  
    modalWindow.content = "<iframe width='480' height='405' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";  
    modalWindow.open();  
};

var cargaEnlace = function()  
{  
    source=v3_url+"/enlaces_form.html";
    modalWindow.windowId = "Unete";  
    modalWindow.width = 480;  
    modalWindow.height = 405;  
    modalWindow.content = "<iframe width='480' height='405' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";  
    modalWindow.open();  
};

var cargaPersonalizar = function()  
{  
    source=v3_url+"/personalizaRSS.php";
    modalWindow.windowId = "Personalizar";  
    modalWindow.width = 480;  
    modalWindow.height = 405;  
    modalWindow.content = "<iframe width='480' height='405' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";  
    modalWindow.open();  
};

$(document).ready(function() {


 /*$(".nombre_enlace").mouseover(function () {
	var text=$(this).parent().parent().children(".comentario_enlace").html(); 
	alert(text);
	 $("#contenido").append(text); 
	});
*/


 $("#tabs").stop().animate({opacity: "0.6"},0);  
 
 $("#header").hover(function () {
    $("#tabs").stop().animate({opacity: "0.9"},200);},
			function () { $("#tabs").stop().animate({opacity: "0.6"},200); });

 $("#au_recomienda_data").stop().animate({height: "20px"},0);
 $("#au_recomienda_data2").stop().animate({height: "0px"},0);  
 
 $("#indice_au_recomienda").hover(function () {
    $("#au_recomienda_data").stop().animate({height: "40px"},200);
        $("#au_recomienda_data2").stop().animate({height: "0px"},200);
	},
			function () { $("#au_recomienda_data").stop().animate({height: "20px"},200); 
				        $("#au_recomienda_data2").stop().animate({height: "0px"},200);			
});


/*$("#footer").click(function(){
 if ($("#footer").height() != 1) {
 $("#footer").animate({  height: "1px", borderWidth: "2px" }, 1500 );
 }
 else {
 $("#footer").animate({  height: "60px", borderWidth: "1px" }, 1500 );
 }

});*/

 $(".img_serie").hide();  
 
 $(".serie").dblclick(function () {
    $(this).children(".img_serie").slideToggle("fast"); });

$("#avatar").show();
$("#datos_user_posts").show();
$("#datos_user_pms").show();

$("#avatar").animate({left: "60px", top: "60px"},0);
$("#datos_user_posts").animate({left: "-180px", top: "60px"},0);
$("#datos_user_pms").animate({left: "300px", top: "60px"},0);



var X,r;
$("#avatar_contenido").mouseenter(function(e) {
X=e.pageX;
r=1;
});

$("#avatar_contenido").mouseover(function(e) {
var mov=e.pageX-X;
if (mov<-60 && r>0){
	var avl=$("#avatar").position().left;
	var pol=$("#datos_user_posts").position().left;
	var pml=$("#datos_user_pms").position().left;
	
	if (avl<=-180){
	avl=-180; 
	pml=20;
	pol=-420;
	}
	else if (avl>=200){
	avl=60;
	pol=-180;
	pml=300;
	}
	else {
	avl=-180;
	pml=20;
	pol=-420;
	}
	$("#avatar").animate({left: avl-10+"px"},200);
	$("#datos_user_posts").animate({left: pol-10+"px"},200);
	$("#datos_user_pms").animate({left: pml-10+"px"},200);

	$("#avatar").animate({left: avl+5+"px"},100);
	$("#datos_user_posts").animate({left: pol+5+"px"},100);
	$("#datos_user_pms").animate({left: pml+5+"px"},100);

	$("#avatar").animate({left: avl+"px"},100);
	$("#datos_user_posts").animate({left: pol+"px"},100);
	$("#datos_user_pms").animate({left: pml+"px"},100);

	X=e.pageX;
	mov=0;
	r=0;
}
else if (mov>60 && r>0){
	var avl=$("#avatar").position().left;
	var pol=$("#datos_user_posts").position().left;
	var pml=$("#datos_user_pms").position().left;
	
	if (avl>=300){
	avl=300;
	pml=440;
	pol=60;
	}
	else if (avl<=0){
	avl=60;
	pol=-180;
	pml=300;
	}
	else {
	avl=300;
	pol=60;
	pml=440;
	}
	$("#avatar").animate({left: avl+10+"px"},200);
	$("#datos_user_posts").animate({left: pol+10+"px"},200);
	$("#datos_user_pms").animate({left: pml+10+"px"},200);

	$("#avatar").animate({left: avl+5+"px"},100);
	$("#datos_user_posts").animate({left: pol+5+"px"},100);
	$("#datos_user_pms").animate({left: pml+5+"px"},100);

	$("#avatar").animate({left: avl+"px"},100);
	$("#datos_user_posts").animate({left: pol+"px"},100);
	$("#datos_user_pms").animate({left: pml+"px"},100);
	X=e.pageX;
	mov=0;
	r=0;
}

});



/* $("#datos_user").hide();  


 $("#datos_nick").click(function() {
	$("#datos_user").slideToggle("fast");});
*/

$("#fo_busqueda_serie").keyup(function(e) {
if(e.keyCode == 13) {
	$("#fo_busqueda_serie").submit();
}
});


$("#f_busqueda_serie").autocomplete("http://www.aunder.org/series.php", {
		width: 350,
		max: 12,
		highlight: false,
		scroll: true,
		scrollHeight: 500,
		formatItem: function(data, i, n, value) {
			var nombre =value.split(";")[1].replace(/\s/g,"_");
			return "<a href='http://www.aunder.org/Serie/"+nombre+"'><img src='http://www.aunder.org/au/Imagenes/" + value.split(";")[0] + "' /> " + value.split(";")[2]+"</a>";
		},
		formatResult: function(data, value) {
			return value.split(";")[1];
		}
	});

function findValueCallback(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	
function formatItem(row) {
		return row[0] + " (<strong>id: " + row[1] + "</strong>)";
	}
function formatResult(row) {
		return row[0].replace(/(<.+?>)/gi, '');
	}





});



function get_rss_feed(url) {
	//clear the content in the div for the next feed.
	$("#feedContent").empty();
 	
	//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
	$.get(url, function(d) {
 
		//find each 'item' in the file and parse it
		
 
		//name the current found item this for this particular loop run
		var $item = $(d).find('item');
		// grab the post title
		var title = $item.find('title').text();
		// grab the post's URL
		var link = $item.find('link').text();
		// next, the description
		var description = $item.find('description').text();
		//don't forget the pubdate
		var pubDate = $item.find('pubDate').text();
		// now create a var 'html' to store the markup we're using to output the feed to the browser window
		var html = "<div class=\"entry\"><h2 class=\"postTitle\">" + title + "<\/h2>";
		html += "<em class=\"date\">" + pubDate + "</em>";
		html += "<p class=\"description\">" + description + "</p>";
		html += "<a href=\"" + link + "\" target=\"_blank\">Read More >><\/a><\/div>";

		//put that feed content on the screen!
		$('#feedContent').append($(html));  

	 $('.blog').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 500;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('#feedContent', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: -90,
                        left: -33,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
	});
 
};

function buscarNoti(){
document.getElementById("f_busqueda_noticia").submit();
}

function buscarSerie(){
document.getElementById("f_busqueda_serie").submit();
}
    