$(document).ready(function(){
	
	if (document.getElementById('indice_servicios')){
		indice_button();
	}
	
	//$("#navigation-continguts ul.small-menu>li:nth-of-type(2)").find("h2").addClass("on");
	//menu_bar();
	menu_hover();
	menu_click();
	table_rows();
	color_principal_nuevo();
	modificar_idioma();
	modifyHomeBlocks();
//	if($.browser.msie && $.browser.version == 6) { modifyHomeBlocks(); }
	
	//from prototype
	//if(document.getElementById('catalogo_prod')) generateCategories('l_1'); - descomentar cuando se decide lo que se va a utilizar
	if (document.getElementById('productBlock')) { productos_categorias(); }
	if (document.getElementById('info_1'))
	{
		$('#info_1').click(function(){
			popup('pop_1');
			return false;
		});
	}	
	
	if (document.getElementById('info_2')) 
	{
		$('#info_2').click(function(){
			popup('pop_2');
			return false;
		});
	}
	
	if (document.getElementById('modificar_datos')) 
	{
		$('#modificar_datos').click(function(){
			desbloquear();
			return false;
		});
	}
	
	if (document.getElementById('modificar_sector')) 
	{
		$('#modificar_sector').click(function(){
			desbloquear(this.id,'bloqueado_2');
			return false;
		});
	}
	
	if (document.getElementById('modificar_sector') && document.getElementById('bloqueado_2')) bloquear('modificar_sector','bloqueado_2');
	
	if (document.getElementById('modificar_datos')) bloquear();
	
});

function menu_bar() {
	var url = document.location.href;
	var parametro = url.substring(url.indexOf('?')+1,url.length);
	var arrayParams=parametro.split('&');
	
	for (var i=0;i<arrayParams.length;i++){
		if (arrayParams[i].substring(0,arrayParams[i].indexOf('=')) == 'categoria') {
			var numBer = (arrayParams[i].substring(arrayParams[i].indexOf('=')+1,arrayParams[i].length)-1);
			$("#navigation-continguts ul.small-menu>li:nth-of-type('"+numBer+"')").find("h2").addClass("on");
			$("#navigation-continguts ul.small-menu>li:nth-of-type('"+numBer+"')").find("div.menu_go_button").addClass("on");
		}
	}
}

function menu_hover() {
	$("#navigation-continguts div.box-title").hover(function(){
		$(this).find("div.menu_go_button").not(".on").css("background-color",colorPrincipal);
  		$(this).find("h2").not(".on").css("color",colorPrincipal);
		
	},function(){
 		$(this).find("div.menu_go_button").not(".on").css("background-color","#333");
 		$(this).find("h2").not(".on").css("color","#333");
				
	});
 $("a.button-servicios").hover(function(){
	//$(this).removeClass("off");
	$(this).css("background-color",colorPrincipal);
	$(this).find("span").css("color",colorPrincipal);
 	},function(){
		if (!document.getElementById('indice_servicios'))
			{
	$(this).css("background-color","#333");
	//$(this).addClass("off");
	$(this).find("span").css("color","#333");
			}
	});
}

function menu_click() {
	$(".box-title").click(function(){
		var aHref = $(this).find("a").get(0).href;
		return window.location=aHref;
	});
}

function table_rows() {
	$('table tbody tr:even').css('background-color','#fff');
	$('table tbody tr:odd').css('background-color','#f5f5f5');
}

function indice_button() {
	$("#navigation-right a").removeClass("off");
	$("#navigation-right a").addClass("on");
	$("#navigation-right span").css("color",colorPrincipal);
}

function modificar_idioma() {
	$('a.mod_link').click(function() {
		$('table.mod_idioma, table.mod_idioma_bottom').find("a").removeClass('actual').css('color',colorPrincipal);

		var thisID = this.id;
		var thisLEN = thisID.length-1;
		var secondLEN = thisID.substr(thisLEN);
		var idBottom = thisID+"2";
		var idtop = thisID.substr(0,thisLEN);

		if(secondLEN != 2) { $(this).addClass('actual').css('color','#000');
		$(document.getElementById(idBottom)).addClass('actual').css('color','#000');
		}
		else {
		$(this).addClass('actual').css('color','#000');
		$(document.getElementById(idtop)).addClass('actual').css('color','#000');
		}

	});
}

function productos_categorias() {
	$('#lista_disponibles li strong, #lista_disponibles li ul li span').hover(function() {
		$(this).css('text-decoration','underline');											   
	}, function() {
		$(this).css('text-decoration','none');
	});
	$('#lista_disponibles ul li ul li ul li span').hover(function() {
		$(this).css('text-decoration','none');											   
	}, function() {
		$(this).css('text-decoration','none');
	});
}

function modifyHomeBlocks() {
	var thisH1 = $(".small-boxes > li").eq(0).height();
	var thisH2 = $(".small-boxes > li").eq(1).height();
	var thisH3 = $(".small-boxes > li").eq(2).height();
	var thisH4 = $(".small-boxes > li").eq(3).height();

	if(parseInt(thisH2) < parseInt(thisH1)) {
		$(".small-boxes > li").eq(1).css("height",thisH1);
	}
	if(parseInt(thisH4) < parseInt(thisH3)) {
		$(".small-boxes > li").eq(3).css("height",thisH3);
	}
}

function color_principal_nuevo() {
	$('#header, span.fletxa, span.fletxa_arxiu, .go_button_on, div.menu_go_button.on, a.middle, a.on, ').css('background-color',colorPrincipal);
	$('.small-menu div.box-title h2.on, .cal .hour, .rounded-container h3.boxrounded-title, .contenido a, ul.subMenu li.current, ul.documentos a, #resultado a, .contenido div.lista a, ul.otrosElementos li div a, .contenido dl dd.data, #content-body p.fecha-limite a, div.contenido p span, #content-body .login_solicitud span a').css('color',colorPrincipal);
	if (document.getElementById('lang_cat')) { $('a#lang_cat').addClass('actual'); $('a#lang_cat2').addClass('actual'); $('table a.actual').css('color','#000'); }
	if (document.getElementById('go2home')) { $('div.small-confirm-box-container-middle .form_submit_left, div.small-confirm-box-container-middle .form_submit_right, div.small-confirm-box-container-middle input.form_submit_go').css('background-color','#333'); }
	if (document.getElementById('productBlock')) { $('#productBlock li#lista_anadidos p a').css('color','#999'); }
	
}