

$(document).ready( function() {
    $.get(window.location.protocol+'//'+window.location.hostname +'/simple/tweet.php', function(data) {
        var tweet = data
        if(data!=""){
        $("#tweet").html("@<a href='http://twitter.com/ice_puntoes'>ice_puntoes</a>: "+tweet);  
        }else{
          $("#tweet").html("ICE Comunicaci&#243;n ofrece, en todo el &#225;mbito nacional, servicios de publicidad, dise&#241;o gr&#225;fico, multimedia, comunicaci&#243;n institucional y gabinete de prensa, adem&#225;s de desarrollar proyectos comoexposiciones tem&#225;ticas o la organizaci&#243;n de eventos.");
        }
        
    }); 

  
  $("#irarriba a").click(function(e){
    
    e.preventDefault();
    $('html, body').animate({scrollTop:0}, 'slow');
  })

    var t=100;

    $('#slider').nivoSlider({
        effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
        slices:15,
        animSpeed:500, //Slide transition speed
        pauseTime:10000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:true, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:true, //1,2,3...
        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:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
        beforeChange: function() {
            $(".nivo-caption").animate({
                "height":"0px"
            });
        },
        afterChange: function() {
            $(".nivo-caption").animate({
                "height":"116px"
            });
        },
        slideshowEnd: function() {
        }, //Triggers after all slides have been shown
        lastSlide: function() {
        }, //Triggers when last slide is shown
        afterLoad: function() {
        } //Triggers when slider has loaded
    });

    if($(".l3").length>0) {
        $(".l3:first").addClass("enfocado").addClass("primero");//.attr("id","primero");
        
        $(".l3").each(function(i,e){
          if($(e).find(".l3cuerpo a:first").length>0){
            $(e).addClass("mano");
            
            
            
            //$(e).find(".l3cuerpo .l3img").addClass
            $(e).bind("click", function(){
              window.location=$(e).find(".l3cuerpo a:first")[0];
            })
          }
        })
        
        
        
        
        
        
        $(".l3").hover(function () {
          if(!$(this).hasClass("enfocado")){
          $(".enfocado").removeClass("enfocado");
          $(this).addClass("enfocado");
          }

        }, function () {
          if(!$(this).hasClass("primero")){
           $(this).removeClass("enfocado");           
           setTimeout(function(){
             if($(".enfocado").length==0){
               $(".l3:first").addClass("enfocado")
             }
             
           },t);
          }else{
           if(!$(this).hasClass("primero")){ 
           setTimeout(function(){
             if($(".enfocado").length>0){
               $(".l3:first").removeClass("enfocado")
             }
             
           },t);
           }else{
             
           }
          }


        }
        );

    }
    
    
    /*+++++++++++*/
        var opacidadoverlay=0.8;
    var images = $(".l3img img");
    var title = $("title").text() || document.title;
    var url="";
    
    images.draggable({
      helper: function() {
        title=$(this).attr("alt");
        url=$(this).parent().attr("href");
        url=location.hostname+"/index.php"+ url.substr(url.lastIndexOf("?"));
        return $("<div>").attr("id", "helper").html("<span>Compartir "+$(this).attr("alt")+"</span>").appendTo("body");
      },
      cursor: "pointer",
      cursorAt: { left: -10, top: 20 },
      zIndex: 99999,
      start: function() {
        $("<div>").attr("id", "overlay").css("opacity", opacidadoverlay).appendTo("body");
        $("#tip").remove();
        $(this).unbind("mouseenter");
        $("#targets").css("left", ($("body").width() / 2) - $("#targets").width() / 2).slideDown();
      },
      stop: function() {
        $("#targets").slideUp(500,function(){
                  $(".share", "#targets").remove();
                  $("#overlay").animate({"opacity":"0"},800,function(){
                    $(this).remove();
                  })
        });

        $(this).bind("mouseenter", createTip);
      }
    });
    
    $("#targets li").droppable({
      tolerance: "pointer",    
      over: function() {
        $(".share", "#targets").remove();
        $("<span>").addClass("share").text("Compartir  en " + $(this).attr("id")).addClass("active").appendTo($(this)).fadeIn();
      },    
      drop: function() {
        var id = $(this).attr("id"),
          //url = window.location.href;
          base = $(this).find("a").attr("href");

        if (id.indexOf("twitter") != -1) {
      window.open(base + "/home?status=" + title + ": " + url, '_blank');
        } else if (id.indexOf("facebook") != -1) {
      window.open(base + "/sharer.php?u=" + url + "&t=" + title, '_blank');          
        }
      }     
    });
  
    var createTip = function(e) {
      //create tool tip if it doesn't exist
      ($("#tip").length === 0) ? $("<div>").html("<span>arrastra para compartir<\/span><span class='arrow'><\/span>").attr("id", "tip").css({ left:e.pageX + 30, top:e.pageY - 16 }).appendTo("body").fadeIn(500) : null;
    };
    
    images.bind("mouseenter", createTip);
    
    images.mousemove(function(e) {
    
      //move tooltip
      $("#tip").css({ left:e.pageX + 30, top:e.pageY - 16 });
    });
  
    images.mouseleave(function() {
    
      //remove tooltip
      $("#tip").remove();
    });
    
    
    

})


