$(document).ready(function()  {
	$(function() {
		$(".external").attr("target","_blank");
	});

	$("a").focus(function() {
		$(this).blur();
	});

	/*menu idiomes*/
	$("#btnLang").click(function(){
		$("#lang").toggle();
		return false;
	}); 							 

	/*menu principal*/
	var active = $("body").attr("class");
	$("#menu a." + left(active,3)).addClass("active");

	$("#menu span").css("opacity","0");
	$("#menu span").hover(function(){
		$(this).stop().animate({opacity: 1}, 125);
	},
	// on mouse out
	function(){
		$(this).stop().animate({opacity: 0}, 75);
		});	
	
	/*menu serveis*/
	$("#intro li a:not('.active')").css("opacity","0.5");
	$("#intro li a:not('.active')").hover(function(){
		$(this).stop().animate({opacity: 1}, 100);
	},
	// on mouse out
	function(){
		$(this).stop().animate({opacity: 0.5}, 125);
		});	
	
	$("#credits").click(function(){
		$("p.credits").toggle();
		return false;
	}); 							 

	//$('a.lightbox').lightBox();
    $(function() {
        var boxen = [];
        //find all links w/ rel="lightbox[gallery_name]" or just rel="lightbox" it works both ways
        $('a[rel*=lightbox]').each(function() {
        //push only unique lightbox[gallery_name] into boxen array
        if ($.inArray($(this).attr('rel'),boxen)) boxen.push($(this).attr('rel'));
    });
    //for each unique lightbox group, apply the lightBox
    $(boxen).each(function(i,val) { $('a[rel='+val+']').lightBox(); });
    });	
	
}); 


function left(str, n){
	if (n <= 0)     // Invalid bound, return blank string
			return "";
	else if (n > String(str).length)   // Invalid bound, return
			return str;                // entire string
	else // Valid bound, return appropriate substring
			return String(str).substring(0,n);
}

