$(document).ready(function() {
	$('ul.gallery').roundabout({
		shape: 'square',
		minScale: 0.2,
		minOpacity: 1,
		maxScale: 1,
		duration:1000,
		focusBearing:1,
		debug:false,
		clickToFocus:true
	});

	$("#lang_popup").tooltip({ effect: 'slide', delay: 700, position: 'bottom center', offset:	[13, 0]});
	$("#share_popup").tooltip({ effect: 'slide', delay: 700, position: 'bottom center', offset:	[13, 0]});
	markActiveLink();

});

//sets the new languaje
function chanegUrlLang(languaje){
	var currentUrl = location.href;
	if (gup('lang')!=''){ //lang parameter exists
		$partsArray = currentUrl.split('lang=');
		$newUrl = $partsArray[0]+'lang='+languaje;
		window.location = $newUrl;
	}
	else if (gup('id')!=''){
		window.location = currentUrl + "&lang=" + languaje;
	}
	else{//we need to add the lang parameter at the end of the url string
		window.location = currentUrl + "?lang=" + languaje;
	}
}

//returns the value of a parameter in the URL
function gup( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//adds the current class to the main menu
function markActiveLink() {
    $("ul.mainMenu a").filter(function() {
        var currentURL = window.location.toString().split("/");
        //delete extra parameters in the url
        var cleanURL = (currentURL[currentURL.length-1]).toString().split("?");
		if (currentURL[3]=="catalog")
			return $(this).attr("href") == "/catalog";
		if ( cleanURL.indexOf("#") > 0 )
			cleanURL = cleanURL.toString().split("#");
        if(cleanURL != '' && cleanURL != '#'){ //if the bit after the last slash is the current page name
			if(cleanURL[0] == "company.php")
				return $(this).attr("rel") == cleanURL[0];
			else if (cleanURL[0] == "services.php")
				return $(this).attr("rel") == cleanURL[0];
			else
				return $(this).attr("href") == cleanURL[0];
		}
        else{ //if the bit is empty we are at the root
            return $(this).attr("href") == "index.php";
		}
    }).addClass("current");

 }

/*

 function validacion(){

	valor = document.getElementById("nombreF").value;
	if( valor == null || valor.length == 0 || /^\s+$/.test(valor) ) {
	  alert('Nombre no es válido');
	  return false;
	}
}
window.onload = function() {
  validacion();
};*/
