
$(document).ready(function() {
	
	/* ALL PAGES 
	----------------------------------- */
	$("body").addClass("js_active");
	if($("#datepicker")[0]) {$( "#datepicker" ).datepicker();}
	
	$("ul.teachers li .icon").click( function(){
		var col = $(this).parents(".col");
		if ( col.hasClass("more") == true){ 
			col.toggleClass("more");
		}
		else{
			$("ul.teachers li .col").removeClass("more");
			col.toggleClass("more");
		}
		
	});
	/* SLIDERS
	---------------------------------- */
	if($(".slidetabs")[0]){
		
		$(function() {
  			$(".slidetabs").tabs(".images > div", {
  			  // enable "cross-fading" effect
  				effect: 'fade',
  				fadeOutSpeed: "slow",
  				// start from the beginning after the last tab
  				rotate: true
  			// use the slideshow plugin. It accepts its own configuration
  			}).slideshow({autoplay:true, interval: 4000, autopause: false});
		});
		
		var flashvars = {};
		var params = {};
		params.wmode = "transparent";
		var attributes = {};
		swfobject.embedSWF("swf/test2.swf", "flashBanner", "953", "346", "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
	}
	
	


	return false;	
});



/* GALLERIES
---------------------------------- */
var index = $(".thumbs li.el").index(this);

function loadGallery(){
	
	// hide loading
	if($('.loading')[0]){
		$('.loading').hide();
	}
	
	//fer apareixer les imatges
	$('body.gallery .thumbs').fadeIn('slow');
	
  	
  	// ordena per columnes 
  	$('ul.thumbs').isotope({
  		masonry : {
    		singleMode: true,
  	    	columnWidth: 240,
  	    	itemSelector: '.el'
  		}
	});
	
	Galleria.loadTheme('frontoffice/js/galleria/themes/classic/galleria.classic.js');
			$("#gallery").galleria({
			   	width: 955,
			   	height: 712,
			   	//show: 1,
			   	showCounter: false,
			   	extend: function(options) {
				    var gallery = this; // "this" is the gallery instance
    		        $('.thumbs li.el').click(function() {
						var index = $("#.thumbs li.el").index(this);
						gallery.show(index); // call the play method
    		        });
    		    }
			});
	
	$(".thumbs li.el").colorbox({
		inline:true, 
		href:"#gallery_wrapper"
	});
	
	
	/* COURSE
	---------------------------------- */
	$list = $('.subjects');
  	
  	$('#filter a').click(function(){
      var filterName = $(this).attr('data-filter');
      $list.isotope({ filter : filterName });
      return false;
    });
    
  	// switches selected class on buttons
    $('#filter').find('li a').click(function(){
        var $this = $(this);
        // don't proceed if already selected
        if ( !$this.hasClass('selected') ) {
          $this.parents('#filter').find('.selected').removeClass('selected');
          $this.addClass('selected');
        }

      });
    $(function(){
      
      $list.isotope({
        layoutMode : 'fitRows',
        itemSelector: 'li',
        masonry : {
          columnWidth: 220
        },
        getSortData : {
          index : function ( $elem ) {
      		return $elem.find('.index').text();
   		 }
        }
      });      
    });
	return false;
}

/* VALIDACION DE FORMULARIOS
-----------------------------------------*/
function validateForm (formId){
	var form = "#"+ formId;
	$(form).validate();
	$(form).submit();
}

  
 


// borrar texto por defecto en campo de texto
function removeinput(x) {
	if (x.value != '') {
	x.value = '';
	}
}





/* INFRAESTRUCTURES
---------------------------------- */
var index = $(".thumbs li.el").index(this);

function loadGallery(){
	
	// hide loading
	if($('.loading')[0]){
		$('.loading').hide();
	}
	
	//fer apareixer les imatges
	$('body.gallery .thumbs').fadeIn('slow');
	
  	
  	// ordena per columnes 
  	$('ul.thumbs').isotope({
  		masonry : {
    		singleMode: true,
  	    	columnWidth: 240,
  	    	itemSelector: '.el'
  		}
	});
	
	Galleria.loadTheme('frontoffice/js/galleria/themes/classic/galleria.classic.js');
			$("#gallery").galleria({
			   	width: 955,
			   	height: 712,
			   	//show: 1,
			   	showCounter: false,
			   	extend: function(options) {
				    var gallery = this; // "this" is the gallery instance
    		        $('.thumbs li.el').click(function() {
						var index = $("#.thumbs li.el").index(this);
						gallery.show(index); // call the play method
    		        });
    		    }
			});
	
	$(".thumbs li.el").colorbox({
		inline:true, 
		href:"#gallery_wrapper"
	});
	
	
	/* COURSE
	---------------------------------- */
	$list = $('.subjects');
  	
  	$('#filter a').click(function(){
      var filterName = $(this).attr('data-filter');
      $list.isotope({ filter : filterName });
      return false;
    });
    
  	// switches selected class on buttons
    $('#filter').find('li a').click(function(){
        var $this = $(this);
        // don't proceed if already selected
        if ( !$this.hasClass('selected') ) {
          $this.parents('#filter').find('.selected').removeClass('selected');
          $this.addClass('selected');
        }

      });
    $(function(){
      
      $list.isotope({
        layoutMode : 'fitRows',
        itemSelector: 'li',
        masonry : {
          columnWidth: 220
        },
        getSortData : {
          index : function ( $elem ) {
      		return $elem.find('.index').text();
   		 }
        }
      });      
    });
	return false;
}




/* VALIDACION DE FORMULARIOS
-----------------------------------------*/

function validateForm (formId){
	var form = "#"+ formId;
	$(form).validate();
	$(form).submit();
}

  
 


// borrar texto por defecto en campo de texto
function removeinput(x) {
	if (x.value != '') {
	x.value = '';
	}
}



