$(document).ready(function() {
	function loadingOverlay(){
		$("#loading_overlay .loading_message").delay(500).fadeOut(function(){});
		$("#loading_overlay").delay(700).fadeOut();
	}

	window.onload = function () {
		loadingOverlay();
	};

	$(".img").hover(function(){
		$(this).fadeTo(400, 0.6);
	},function(){
		$(this).fadeTo(400, 1.2);
	});

    $(".img2").fadeTo(400, 0.6);
	$(".img2").hover(function(){
		$(this).fadeTo(400, 1.2);
	},function(){
		$(this).fadeTo(400, 0.6);
	});
    Cufon
    .set('fontSize', '15px')
    .replace('.status_row0, .status_row1', {
        hover: true,
        textShadow: '#000000 1px 1px'
    });
    Cufon
    .set('fontSize', '16px')
    .replace('#info_bg .menu a', {
        hover: true,
        textShadow: '#000000 1px 1px'
    });

    Cufon.replace('.search_title_mini',{
        hover: true,
        textShadow: '#000000 1px 1px'
    })

    Cufon
    .set('fontSize', '18px')
    .replace('.title_box ', {
        hover: true,
        textShadow: '#000000 1px 1px'
    });

    Cufon.replace('.content_title,.content_title_2-2,.content_title_date',{
        hover: true,
        textShadow: '#000000 1px 1px'
    });

    Cufon.replace('#title_center',{
        hover: true,
        textShadow: '#000000 1px 1px'
    });

    Cufon
    .set('fontSize', '12px')
    .replace('.medieval', {
        hover: true,
        textShadow: '#000000 1px 1px'
    });



    /***/
	$("a[rel^='modalImage']").prettyPhoto({
		autoplay_slideshow: false,
		theme: 'pp_l2_cl',
        social_tools: '',
        modal: true,
        deeplinking: false
	});

	$("a[rel^='modalImageGallery']").prettyPhoto({
		autoplay_slideshow: false,
		theme: 'dark_square',
        social_tools: '',
        modal: true,
        deeplinking: false
	});

	$("a[rel^='modalVideo']").prettyPhoto({
		autoplay_slideshow: false,
		theme: 'pp_l2_cl',
        social_tools: '',
        autoplay: true,
        modal: true,
		default_width: 750,
		default_height: 516,
        deeplinking: false
	});

	$("a[rel^='modalIframe']").prettyPhoto({
		theme: 'pp_l2_cl',
        social_tools: '',
        modal: true,
		default_width: 750,
		default_height: 516,
        deeplinking: false
	});

    /***/
   	$('.tooltip').tipsy({
	   gravity: jQuery.fn.tipsy.autoNS,
	   html: true
    });

   	$('.tooltip-n').tipsy({
	   gravity: 's',
	   html: true
    });

   	$('.tooltip-s').tipsy({
	   gravity: 'n',
	   html: true
    });

    /***/
    $(".video_play_slide").jCarouselLite({
        btnNext: ".video_next",
        btnPrev: ".video_prev",
        visible: 1,
        auto: 6000,
        speed: 1000
    });

    $(".gallery_play_slide").jCarouselLite({
        btnNext: ".gallery_next",
        btnPrev: ".gallery_prev",
        visible: 1,
        auto: 4500,
        speed: 500
    });

	/**	Panel de busqueda **/
	$("#l2cl_aportes_button").click(function () {
		if($("#loginBox").css("display") == "none")
		{
			$("#loginBox").slideDown("slow");
		}
		else if($("#loginBox").css("display") == "block")
		{
			$('#loginBox').slideUp('slow');
		}
	});

	/**	Form Search **/
	$("#status_mini").click(function () {
		if($("#SearchBox").css("display") == "none")
		{
			$("#SearchBox").slideDown("slow");
		}
		else if($("#SearchBox").css("display") == "block")
		{
			$('#SearchBox').slideUp('slow');
		}
	});

	/**	More Posts **/
	$("#forum_more").click(function () {
		if($("#MorePostBox").css("display") == "none")
		{
			$("#MorePostBox").slideDown("slow");
			$("#forum_go").hide();
			$('#forum_more_title').removeClass('more-down');
			$('#forum_more_title').addClass('more-up');
		}
		else if($("#MorePostBox").css("display") == "block")
		{
			$('#MorePostBox').slideUp('slow');
			$("#forum_go").show();
			$('#forum_more_title').removeClass('more-up');
			$('#forum_more_title').addClass('more-down');
		}
	});

	/**	More Posts **/
	$("#last_guides_more").click(function () {
		if($("#MoreGuidesBox").css("display") == "none")
		{
			$("#MoreGuidesBox").slideDown("slow");
			$("#last_guides_go").hide();
			$('#last_guides_more_title').removeClass('more-down');
			$('#last_guides_more_title').addClass('more-up');
		}
		else if($("#MoreGuidesBox").css("display") == "block")
		{
			$('#MoreGuidesBox').slideUp('slow');
			$("#last_guides_go").show();
			$('#last_guides_more_title').removeClass('more-up');
			$('#last_guides_more_title').addClass('more-down');
		}
	});


});


//"use strict";
function closeDiv() {
    $("#autoclose-message").fadeTo("slow",0.01,
        function(){$(this).slideUp("slow",
        function(){$(this).hide()})})
}
window.setTimeout("closeDiv();",2500);

function objetoAjax(){
    var xmlhttp=false;
    try
    {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
        try
        {
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E)
        {
            xmlhttp = false;
      	}
    }

    if (!xmlhttp && typeof XMLHttpRequest!='undefined')
    {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function sendRank(datos, resultado, borrar)
{
    divResultado = document.getElementById(resultado);
    if(divResultado.innerHTML=='' || borrar)
    {
        ajax = objetoAjax();
        if(datos!="")
        {
            divResultado.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='images/loader.gif'>";
            ajax.open("GET", datos);
            ajax.onreadystatechange=function()
            {
                if (ajax.readyState==4)
                {
                	if(ajax.responseText > 0) {
                		width = (ajax.responseText * 16);
                		divResultado.innerHTML = '<div style="float:right; margin-right:50px; color:#008000;">Voto realizado!</div>';

                		document.getElementById("current-rating").style.width = width+"px";
                		document.getElementById("media").innerHTML = ajax.responseText;
                	}
                	else
                	{
                		divResultado.innerHTML = '<div style="float:right; margin-right:50px; color:#FF0000;">Ya has votado hoy!</div>';
                	}
                }
            }
            ajax.send(null);
        }
        else
        	divResultado.innerHTML ="";
    }
}

function sendNavImageView(row, id){
	divContenido = document.getElementById('NavImageView');
	ajax=objetoAjax();
	ajax.open("GET", "galerias/g/nav/"+id+"/"+row+"/");
	divContenido.innerHTML= '<div class="loading2"></div>';
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divContenido.innerHTML = ajax.responseText
		}
	}
 ajax.send(null)
}

function sendNavVideoView(row, cid, id){
	divContenido = document.getElementById('NavVideoView');
	ajax=objetoAjax();
	ajax.open("GET", "videos/c/nav/"+cid+"/"+row+"/"+id+"/");
	divContenido.innerHTML= '<div class="loading2"></div>';
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divContenido.innerHTML = ajax.responseText
		}
	}
 ajax.send(null)
}

