$(document).ready(function(){
	$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
});

jQuery.exists = function(selector) {return ($(selector).length > 0);}

if ($.exists($("#titleDireccion"))) { 
  $("#titleDireccion a").click(function(){
    $(".hideL").css("display", "none"); $(".direccionL").css("display", "block"); 
  });
}
if ($.exists($("#titleArtistico"))) { 
  $("#titleArtistico a").click(function(){ 
    $(".hideL").css("display", "none"); $(".artisticoL").css("display", "block");
  });
}
if ($.exists($("#titleComunicacion"))) { 
  $("#titleComunicacion a").click(function(){ 
    $(".hideL").css("display", "none"); $(".comunicacionL").css("display", "block");
  });
}
if ($.exists($("#titlePublicaciones"))) { 
  $("#titlePublicaciones a").click(function(){ 
    $(".hideL").css("display", "none"); $(".publicacionesL").css("display", "block");
  });
}
if ($.exists($("#titleEconomico"))) { 
  $("#titleEconomico a").click(function(){ 
    $(".hideL").css("display", "none"); $(".economicoL").css("display", "block");
  });
}
if ($.exists($("#titleGestion"))) { 
  $("#titleGestion a").click(function(){ 
    $(".hideL").css("display", "none"); $(".gestionL").css("display", "block");
  });
}


if ($.exists($("#igallery"))) {
  stepcarousel.setup({
    galleryid: 'igallery',
    beltclass: 'belt',
    panelclass: 'panel',
    autostep: { enable: false, moveby: 1, pause: 3000 },
    panelbehavior: { speed: 500, wraparound: false, persist: true },
    defaultbuttons: { enable: false },
    contenttype: ['inline']
  });
  
  $(function() { $('#igallery a').lightBox(); });
};

if ($.exists($("#organigrama"))) { $(function() { $('.lightorg a').lightBox(); }); };

$(document).ready(function() {

  $("ul#top li a.fold").hover(function() {
    var sub = $(this).parent().find("ul.sub");
    
    if (sub.css('height') == 'auto') { sub.stop(true, true).slideDown('fast'); };
    
    $(this).parent().hover(function() {},
    function() {
      sub.stop(true, true).slideUp('fast');
    });
  }).hover(function() {
    // Manipulate HTML
    $(this).addClass("subhover");
  },
  function() {
    $(this).removeClass("subhover");
  });
  
  
  // Facebox
  $('a[rel*=facebox]').facebox();

  //
	$('.inlineRadios input[type=radio]').prettyCheckboxes();
  $('.inlineCheckbox input[type=checkbox]').prettyCheckboxes();
  
  
  // Publications LaziLoad
  // if ($.exists($("#publications"))) {
  //   $("img").lazyload({ placeholder : "/images/publications_grey.jpg" });
  // }
  
  $("#squares a:not(.revert)").bind("click",function(){
    var id = $(this).attr('id').split('_')[1];
    
    $("#square_image_"+id).flip({
      direction: $(this).attr("rel"),
      color: $(this).attr("rev"),
      content: $(this).attr("title"),
      
      onBefore: function(){
        $("#am_"+id).hide();
        $("#al_"+id).show(); }
    });
    return false;
  });
  
  $("#squares a.revert").bind("click",function(){
    var id = $(this).attr('id').split('_')[1];
    
    $("#square_image_"+id).revertFlip();
    
    $("#al_"+id).hide();
    $("#am_"+id).show();
    
    return false;
  });
  
  
    
});

jQuery(function($){//on document ready
  //autocomplete
  $('input.autocomplete').each(function(){
    var $input = $(this);
    $input.autocomplete($input.attr('autocomplete_url'));
  });
});

