$(document).ready(function () {
    // Start Load Google+
    window.___gcfg = {lang: 'es'};

    (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    })();
    // End Load Google+
    
    //Start Load Facebook
    
    //End Load Facebook
    
    $(".nav").bind("click", function (e) {
        $('.dropdown-toggle, .menu').parent("li").removeClass("open");
    });
    $("#menu").click(function (e) {
        var $li = $(this).parent("li").toggleClass('open');
        return false;
    });
    
    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 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;
    }
    
    $(".close").click(function (e) {
        var id = $(this).parent("div").attr("id");
        createCookie(id, "true", 1);
        var $li = $(this).parent("div").fadeOut('fast'); 
        return false;
    });
    
    $(".ultima-hora").each(function(i) {
        var id = $(this).attr("id");
        var value = readCookie(id);
        if (value == null) {
            $(this).fadeIn('fast');
        }
    });
     
    $('#slider').nivoSlider({
        effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 2, // For box animations
        boxRows: 1, // For box animations
        animSpeed: 500, // Slide transition speed
        pauseTime: 8000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: true, // Next & Prev navigation
        directionNavHide: false, // Only show on hover
        controlNav: true, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel: false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav: false, // Use left & right arrows
        pauseOnHover: true, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        captionOpacity: 0.0, // Universal caption opacity
        prevText: 'Anterior', // Prev directionNav text
        nextText: 'Siguiente', // Next directionNav text
        randomStart: false, // Start on a random slide
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });
    
    $(".spoiller-alert").children("p").css("display", "none");
    
    $(".spoiller-alert").click(function(e) {
       if ($(this).children("p").css("display") == "none"){
           $(this).children("p").css("display", "block");
       }
       else {
           $(this).children("p").css("display", "none");
       }
       $(this).children("p").css("width", "680px");
    });
    
    $(".thdrpy").children("a").click(function (e) {
        $('#cancel_reply').addClass("btn");
        $('#cancel_reply').addClass("danger");
        $('#cancel_reply').children("a").css('color', '#ffffff');   
        $('#cancel_reply').css('display', 'inline');
    });
	
		window.___gcfg = {lang: 'es'};

	(function(){

		var po = document.createElement("script");

		po.type = "text/javascript"; po.async = true;po.src = "http://apis.google.com/js/plusone.js";

		var s = document.getElementsByTagName("script")[0];

		s.parentNode.insertBefore(po, s);

	})();

	(function() {

        var twitterScriptTag = document.createElement('script');

        twitterScriptTag.type = 'text/javascript';

        twitterScriptTag.async = true;

        twitterScriptTag.src = 'http://platform.twitter.com/widgets.js';

        var s = document.getElementsByTagName('script')[0];

        s.parentNode.insertBefore(twitterScriptTag, s);

	})();
	
	jQuery.getScript('http://connect.facebook.net/es_ES/all.js', function() {
    FB.init({appId: '200685519991858', status: true, cookie: true, xfbml: true});
  });
});
