$(document).ready(function(){
  //FONDO
  var fondoImg = $("span.fondoImg").attr("rel");
  if(fondoImg != ""){
    $("body").css({
      "background-image":"url("+fondoImg+")"
    })
  }

  
  
  //CONTENT BOTTOM TIGHT//
  $("#ContentRightTopR ul li").each(function(e){
  
       $(this).prepend("<span>"+(e+1)+". </span>")
  });   
    
  //MAIN BANNER
    

  
  /*GALERIA DE FOTOS*/
  
  $("div#ContentRight div#galeria ul li").css("cursor","pointer").hover(function(){
    var este = $(this)  
      $(this).find("img").stop().fadeTo(300,"1",function(){
          este.find("div.title").fadeIn(500)
        })
      
    },function(){
      var este = $(this)  
      $(this).find("img").stop().fadeTo(300,".2",function(){
          este.find("div.title").fadeOut(300)
        })
      
      });
      
      
    /*SCROLLBAR*/
    var a, c
  $("#ContentRight div.controlGallery a").hover(function(){
      $(this).stop().fadeTo(300,"1")  
      if($(this).attr("class")=="move_up"){
        a = $("#ContentRight div.contentGallery").scrollTop();
        b = setInterval(function(){
        a-=1;
        $("#ContentRight div.contentGallery").scrollTop(a);
        },10)
      } else{
        c = $("#ContentRight div.contentGallery").scrollTop();
        b = setInterval(function(){
        c+=1;
        $("#ContentRight div.contentGallery").scrollTop(c);
        },10)
      }
      
    },function(){
      clearInterval(b)
      $(this).stop().fadeTo(300,".2")  
      
    }).click(function(){
      return false;
         
    }).mousedown(function(){
          
      if($(this).attr("class")=="move_up"){
        a = $("#ContentRight div.contentGallery").scrollTop();
        w = setInterval(function(){
        a-=5;
        $("#ContentRight div.contentGallery").scrollTop(a);
        },10)
      } else{
        c = $("#ContentRight div.contentGallery").scrollTop();
        w = setInterval(function(){
        c+=5;
        $("#ContentRight div.contentGallery").scrollTop(c);
        },10)
      }
      
      }).mouseup(function(){
        clearInterval(w)
        
      })
          
          $(".contentGallery li, #ContentCenter div.mini_imagenes ul li").click(function(){
            /*APAGANDO Y ENCENDIENDO LI'S*/
          if($(this).attr("class") == "active"){
              return false;
          }
          $("#ContentCenter div.mini_imagenes ul li").each(function(){
              if($(this).attr("class") == "active"){
                  $(this).css("border","1px solid #525252")
                  $(this).find("div.titulo").stop().animate({"bottom":"-30px"},200);
                  $(this).find("img").stop().fadeTo(500,".3")
                  $(this).attr("class","")
                    
              }
          }) 
           
           $(this).css("border","1px solid #fff");
           $(this).css("cursor","pointer").find("div.titulo").stop().animate({"bottom":"0"},300);
           $(this).find("img").stop().fadeTo(500,"1")
           $(this).attr("class","active")

             $("div#ContentRightTop").html('<iframe style="background:#000;" width="550" height="534" scrolling="NO" frameborder="0" src="/'+$(this).attr("rel")+'/index.html"></iframe>')
             
             $("ul#Menu > li").each(function(){
               $(this).attr("class","")
             })
             $("ul#Menu > li:eq(2)").attr("class","active")
          })
               
      
        

})
