urlWithoutLang = function( url) {
  return url.sub( /\/[a-z]{2}\//, '/').sub( /\/[a-z]{2}$/, '').sub( /\?.*/, '');
}

// Inicio de los javascripts
function init ()
{
  startList ('nav');
  var request_uri = urlWithoutLang( document.URL);
  // document.observe( "dom:loaded", function( ) { 
  $$('ul#secondary_menu li, ul.children li').each( function( element) {
    element.select( 'a').pluck('href').each( function( href) {
      if ( urlWithoutLang( href) == request_uri)  { element.addClassName( 'current');}
    });
  });
}

Event.observe (window, 'load', init, false);


//Aumentar y reducir el tamaño del texto
function changeFontSize (node_div_id, value, stylesheet_id) 
{
	node_div = $(node_div_id);
	for (i = 0; i < node_div.childNodes.length; i++)
	{
		node = node_div.childNodes[i];
		if (node.nodeName == 'LI' || node.nodeName == 'P')
		{
			
			if (value == '+')
			{
				CURRENT_KEY_SIZE = CURRENT_KEY_SIZE + 1;
				if (CURRENT_KEY_SIZE > 5) CURRENT_KEY_SIZE = 5;
			}
			else
			{
				CURRENT_KEY_SIZE = CURRENT_KEY_SIZE - 1;
				if (CURRENT_KEY_SIZE < 0) CURRENT_KEY_SIZE = 0;
			}
			node.style.fontSize = BRANCH_FONT_SIZE [stylesheet_id][CURRENT_KEY_SIZE] + "px";
		}
	}
}


//Activacion de los submenus en IE
function startList (id_node)
{
  if (document.all&&document.getElementById) {
	var lis = document.getElementById(id_node).getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" over";
			selects = document.getElementsByTagName('select');
			for(i = 0; i < selects.length; i++) {
				selects[i].style.visibility = 'hidden';
			}
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over"), "");
			selects = document.getElementsByTagName('select');
			for(i = 0; i < selects.length; i++) {
				selects[i].style.visibility = 'visible';
			}
		}
	}
	}
}

function add_photo_to_tiny (photo, classCSS)
{
	if (tinyMCE)
	tinyMCE.execCommand('mceInsertContent',false,'<img class="' + classCSS + '" src="' + photo  + '" />');
}

function input_search (input, text, current_event, inactive_class)
{
	if (current_event == 'focus')
	{
		if (input.value == text)
		{
			input.value = '';
			input.className = '';
		}
	}
	else if (current_event == 'blur')
	{
		if (input.value == '')
		{
			input.value = text;
			input.className = inactive_class;
		}
	}
}
function openWindow(url,name,width,height) {
  window.open(url,name,"menubar=1,resizable=1,scrollbars=yes,width=" + width + ",height=" + height);
}

function createBigWindow () {
	window_id = 'bigWindow';
	if ($(window_id)) {
		$(window_id).show().focus();
	} else {
		 new UI.Window({theme:  'black_hud', 
			               shadow: false,
										 id: window_id,
			               width:  600,
										 close: "hide",
										 footer: false,
										 resizable: false,
			               height: 550}).center().setContent('<div id=\'gallery_big_wrapper\'></div>').show().focus();
		$('gallery_big_wrapper').insert ( {top: $('gallery_big')})
	}
}

function moveNode (node, wrapper, position)
{
	if ($(node) && $(wrapper)) {
		eval ('$(wrapper).insert ({' + position + ': $(node)})');
	}
}

