jQuery(function(){
	// Submenus
	jQuery('#menu li').live('mouseenter', function(){
		jQuery(this).siblings('li').children('.submenu').hide();
		jQuery(this).children('.submenu').show();
	});
	jQuery('#menu .submenu').live('mouseleave', function(){
		jQuery(this).hide();
	});
	
	// Selector de mapa
	jQuery('#map-tabs li').live('click', function(){
		if (jQuery(this).hasClass('active')) {
		} else {
			jQuery(this).toggleClass('active').siblings('li').toggleClass('active');
			jQuery('#maps .map').toggleClass('active');
		};
	});
	
	// Selector de idioma
	jQuery('.dropdown-selector').click(function(){
		jQuery(this).children('.dropdown-list').toggle();
	});
	
	// Scrollable
	if ($('.scroll-list').width() > 0) {
		$('.scroll-list').scrollable();
	};
	
	// Cita aleatoria en Premsa
	jQuery.fn.random = function(num) {
	    num = parseInt(num);
	    if (num > this.length) return this.pushStack(this);
	    if (! num || num < 1) num = 1;
	    var to_take = new Array();
	    this.each(function(i) { to_take.push(i); });
	    var to_keep = new Array();
	    var invert = num > (this.length / 2);
	    if (invert) num = this.length - num;
	    for (; num > 0; num--) {
	      for (var i = parseInt(Math.random() * to_take.length); i > 0; i--)
	        to_take.push(to_take.shift());
	      to_keep.push(to_take.shift());
	    }
	    if (invert) to_keep = to_take;
	    return this.filter(function(i) { return $.inArray(i, to_keep) != -1; });
	  };
	
	$('.quote').random().css({ display: 'block' });
});



// funcions google translate

function openInNewWindow(l) {
	var newWindow = window.open(l, '_blank');
	newWindow.focus();
	return false;
 }
 
 function tradueixMe(lang){
	var e=(document.charset||document.characterSet);				
	var urlTrad = 'http://translate.google.com/translate?u='+encodeURIComponent(document.location.href)+'&hl=ca&langpair=auto|'+lang+'&tbb=1&ie='+e;				
	openInNewWindow(urlTrad);
 }
