// Reverse hack
jQuery.fn.reverse = [].reverse;
var Facultades = {
    // roundedCorners: Adds four spans to the elements collection
    // to style them for rounded corners
    roundedCorners: function(collection){
        // generate html for spans
        var spans = "<span class='rc ne'></span>";
        spans += "<span class='rc nw'></span>";
        spans += "<span class='rc se'></span>";
        spans += "<span class='rc sw'></span>";
        $(collection).reverse().each(function(){
            $(this).html( $(this).html() + spans );
        });
    }
},
SOCIAL = {

	init : function(clase) {
		$(clase).each(function(e){
			$(this).click(function(e){
			  e.preventDefault();
				if($("#social_" + this.id).css("display") == "none") {
					SOCIAL.reset(clase);
					$("#social_" + this.id).slideDown();
					$(this).parents('li:first').addClass("active_list");
				} else {
					SOCIAL.reset(clase);
				}
			}); // click
		}); // each
	},
	
	reset: function(clase){
		$(clase).each(function(){
				$("#social_" + this.id).slideUp();
				$(".degree_lists li").removeClass("active_list");
		})
	}

}


$(function(){
  
  //modal popup provisional de la home
  $('.new_instalations_modal a:first').trigger('click');
  
  // rounded corners
  Facultades.roundedCorners('.rounded_corners');
  SOCIAL.init(".social_box ul li a.flickr_box");
  SOCIAL.init(".foldable .list a");
    

  if($('#s4').length>0) {
	
		$('#s4') 
		.before('<div id="nav">') 
		.cycle({ 
		    fx:     'fade', 
		    speed:   600, 
				timeout: 12000, 
				next:   '#s4', 
				pause:   1,
				before:  onBefore,
		    pager:  '#nav'
		});
	}

  $('.diary_list').jScrollPane({
    		showArrows:true	,
    		scrollbarWidth:25
    	});
  
  
	
	function onBefore() { 
		  var href = this.rel; 
	    $('#home_intro').html('<h2>'+ this.title.split("|")[0] + '</h2>');
			$('#home_intro').append('<p>' + this.title.split("|")[1] + '</p>');
			$('.home_more_info a').attr("href", this.rel);
	}



});