runOnLoad(function () {
	$('#loading-full').hide();
});

/**
FADE OVERWRITE
**/
jQuery.fn.fadeIn = function(speed, callback) { 
	// Hack for IE:
	var obj_id = this.attr('id');
	if (jQuery.browser.msie && $('#'+obj_id+'.pics img').length > 0) 
		$('#'+obj_id+'.pics img').css({position: 'static'});
		
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  {
			if ($('#'+obj_id+'.pics img').length > 0) 
				$('#'+obj_id+'.pics img').css({position: 'absolute'});
            this.style.removeAttribute('filter');  
        }
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
	// Hack for IE:
	var obj_id = this.attr('id');
	if (jQuery.browser.msie && $('#'+obj_id+'.pics img').length > 0) 
		$('#'+obj_id+'.pics img').css({position: 'static'});

    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie) {
			if ($('#'+obj_id+'.pics img').length > 0) 
				$('#'+obj_id+'.pics img').css({position: 'absolute'});
            this.style.removeAttribute('filter');  
		}
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
/**
**/

// Ini values
left_pos2 = $('.content-2').css('margin-left');
ini_pos2 = '-' + (($('.content-2').width()*1)+20)+'px';
ini_width2 = $('.content-2').width();

left_pos3 = $('.content-3_3').css('margin-left');
ini_pos3 = '-' + (($('.content-3_3').width()*1)+20)+'px';
ini_width3 = $('.content-3_3').width();

function quitaacentos(t){
	á="a";é="e";í="i";ó="o";ú="u";à="a";è="e";ì="i";ò="o";ù="u";ñ="n";ä="a";ë="e";ï= "i";ö="o";ü="u";
	acentos=/[áéíóúàèìòùñäëïöü]/g;
	return t.replace(acentos, function($1){return eval($1)})
}

// Reurns the div id of of the content from link title
function getContentId(opt_title) {
	opt_name = opt_title.replace(' y ','-');
	opt_name = opt_name.replace(' ','-');

	opt_name = opt_name.toLowerCase();
	opt_name = quitaacentos(opt_name);
	
	return opt_name;	
}

// Reurns the first class of the html class attribute
function getClassId(class_names) {
        opt_name = class_names;
        css_a = class_names.split(' ');

	if (css_a.length > 0) {
          css_a = class_names.split(' ');
	  opt_name = css_a[0];
        }

	opt_name = opt_name.toLowerCase();
	opt_name = quitaacentos(opt_name);
	
	return opt_name;	
}

function scrollToTop(opt_name) {
	if ($('#'+opt_name+' .scroll-pane').length > 0 && typeof($('#'+opt_name+' .scroll-pane')[0].scrollTo) == "function") 
		$('#'+opt_name+' .scroll-pane')[0].scrollTo(0);
}

function simpleToggleContent(opt_name) {

	var ini_width = ini_width2;
	if ($('#' +opt_name).hasClass('content-3_3'))
		ini_width = ini_width3;
	
	if ($('#'+opt_name).width() > "0") {
		// slide off content
		$('#'+opt_name+' div').hide();
		$('#'+opt_name).animate({width: "0px", paddingLeft: '0', paddingRight: '0'}, 'slow');
	} else {
		$('#' +opt_name).animate({width: ini_width, paddingLeft: '10', paddingRight: '10'}, 'slow', function () {
		 	scrollToTop(opt_name);
			$('#' +opt_name+' div').show();
		});
	}
};

// Toggle contents
function toggleContent(opt_title, url) {
	
	// disable article container
	$('.mod_article').each(function () {

		// id the article is visible then hide
		if ($(this).css('top') == "0px") {
			var hide = true;
			$('#' +this.id+' .ce_text').each(function () {
				// if has content then slide off
				if ($(this).css('width') != "0px") {	
					// if has content then slide off		
					if (($('#' +this.id).hasClass('content-2') || $('#' +this.id).hasClass('content-3_3'))) {
						// slide off content and show the new article
					    scrollToTop(this.id);
						$('#'+this.id+' div').hide();
						$('#'+this.id).animate({width: 0, paddingLeft: '0', paddingRight: '0'}, 'slow', function(content_id) {
						showNewArticle($(this).parent(), opt_name, url);
						});
						hide = false;				
						return false;
					}
				}
			}); 

			if (hide) {
				// Si hay contenido - area cliente - fijo lo quitamos antes d mostrar el nuevo
				if ($('#' +this.id+' div:first').hasClass('content-4')) {
					$('#' +this.id+' div:first').css({display: 'none'});
					$('#' +this.id+' #login-form').css({display: 'none'});
				}
				showNewArticle($(this), opt_name, url);

				return false;
			}
 		}
	});
};

function toggleInnerContent(opt_title, url) {
	var opt_text_name = opt_name + '-text';

	// Si vienes de galeria recargar articulo y mostrar texto seleccionado
	if ($('#gallery-contents div').length > 0 /*|| $("#main-content #loading").css('display') != 'none'*/) {
		showNewArticle2($('#gallery-contents'), opt_name);
	}

	// Si se viene de presupuesto recargar articulo y mostrar texto seleccionado
	if ($('#solicitud-presupuesto').css('top') == "0px") {
		showNewArticle2($('#solicitud-presupuesto'), opt_name);
	}
	

	// disable article container
	$('.mod_article').each(function () {

		// id the article is visible then hide
		if ($(this).css('top') == "0px") {
			var hide = true;
			$('#' +this.id+' .ce_text').each(function () {
				// if has content then slide off
				if ($(this).css('width') != "0px") {	
					if (($('#' +this.id).hasClass('content-2') || $('#' +this.id).hasClass('content-3_3'))) {
						// slide off content and show the new article
					    scrollToTop(this.id);
						$('#'+this.id+' div').hide();
						$('#'+this.id).animate({width: 0, paddingLeft: '0', paddingRight: '0'}, 'slow', function(content_id) 
						{
							// slide in new content
							var ini_width = ini_width2;
							if ($('#' +opt_text_name).hasClass('content-3_3'))
								ini_width = ini_width3;
		
							if (($('#' +opt_text_name).hasClass('content-2') || $('#' +opt_text_name).hasClass('content-3_3'))) {
								$('#' +opt_text_name).animate({width: ini_width, paddingLeft: '10', paddingRight: '10'}, 'slow', function () {
									$('#' +opt_text_name+' div').show();
								});
							}
		
		//					showNewArticle($(this).parent(), opt_name, url);
						});
						hide = false;
						return false;
					}
				}
			}); 
			if (hide) {
				// slide in new content
				var ini_width = ini_width2;
				if ($('#' +opt_text_name).hasClass('content-3_3'))
					ini_width = ini_width3;

				if (($('#' +opt_text_name).hasClass('content-2') || $('#' +opt_text_name).hasClass('content-3_3'))) {
					$('#' +opt_text_name).animate({width: ini_width, paddingLeft: '10', paddingRight: '10'}, 'slow', function () {
						$('#' +opt_text_name+' div').show();
					});				
				}
				return false;
			}
 		}
	});
}


function showNewArticle(current_article, opt_name, url) {
			
	// if nothing to show let current content	
	//if ($('#' +opt_name).length == 0)
	//	return;
					

	// If is gallery
	if (url) {
		// hide current article
		$('#' +current_article.attr('id') +' .pics').cycle('pause');
		$(current_article).css({top:"-1000px", left:"-1000px"});
		
		// Clear catalog contents
		$('#gallery-contents').html("");
		$.ajax({
			url : url,
			beforeSend : function() {
				$("#gallery-contents").html('<div id="loading"></div>');
				$("#gallery-contents").css({ top:"0px", left:"0px", marginTop: "69px" });
//				$("#loading").show();
			},
			complete : function () {
//				$("#loading").hide();
//				setTimeout('$("#loading").hide()',2000);
				// load content out of the screen to avoid fliking		
			},
			success : function (data) {
//				$("#loading").hide();
				$("#gallery-contents").css({ top:"0px", left:"0px", marginTop: "69px" });
				$('#gallery-contents').html(data);
//				setTimeout('$("#gallery-contents").css({ top:"0px", left:"0px", marginTop: "69px" })',2000);
			}
		});
		return false;
	} else {	
		if ($('#gallery-contents div').length > 0/* || $("#loading").css('display') != 'none'*/) {
//			$("#loading").hide();
			$('#gallery-contents').html("");
			$('#gallery-contents').css({top:"-1000px", left:"-1000px"});
		}
		
		// Si hay contenido - area cliente - fijo lo mostramos antes d posicionarlo por is ha sido ocultado anteriormente.
		if ($('#' +opt_name+' div:first').hasClass('content-4')) {
			$('#' +opt_name+' div:first').css({display: 'block'});
			$('#' +opt_name+' #login-form').css({display: 'block'});
		}
		
		// show new article
		// if change section fadeout old one and fedin new one if same section just show contents
		//if ($(current_article).attr('id') != opt_name) {
			// hide current article

		$('#' +current_article.attr('id') +' .pics').cycle('pause');

		if ($('#' +current_article.attr('id') +' .pics').length > 0 && $('#' +opt_name +' .pics').length > 0) {
			
			if ($(current_article).attr('id') != opt_name) {
				// Hack to avoid 2 contents visibles at same time during fadeOut delay.
				$('#' +current_article.attr('id')).css({top:"-1px", marginTop:"70px"}); 
				$('#' +current_article.attr('id') +' .pics').fadeOut("slow");
			}			
			// $('#' +current_article.attr('id') +' .pics').fadeOut("slow");
			$('#' +opt_name).css({ top:"0px", left:"0px", marginTop: "69px" });

			if ($(current_article).attr('id') != opt_name) {
				$('#' +opt_name +' .pics').css({ display: "none" });
		 		$('#' +opt_name +' .pics').fadeIn("slow", function () {
					$(current_article).css({top:"-1000px", left:"-1000px"});
				});
			}
			
			$('#' +opt_name +' .pics').cycle('resume', true);

		} else {
			$(current_article).css({top:"-1000px", left:"-1000px"});
		
			$('#' +opt_name).css({ top:"0px", left:"0px", marginTop: "69px" });
			$('#' +opt_name +' .pics').css({ display: "none" });
	 		$('#' +opt_name +' .pics').fadeIn("slow");
			$('#' +opt_name +' .pics').cycle('resume', true);
		}

		//}		

		// slide in new content
		var ini_width = ini_width2;
		if ($('#' +opt_name+' div:first').hasClass('content-3_3'))
			ini_width = ini_width3;

		if (($('#' +opt_name+' div:first').hasClass('content-2') || $('#' +opt_name+' div:first').hasClass('content-3_3'))) {
			$('#' +opt_name+' div:first').animate({width: ini_width, paddingLeft: '10', paddingRight: '10'}, 'slow', function () {
				$('#' +opt_name+' div:first div').show();
			});
		}
	}	
}

function showNewArticle2(current_article, opt_name) {

	if ($('#gallery-contents div').length > 0 /* || $("#main-content #loading").css('display') != 'none' */) {
//		$("#main-content #loading").hide();
		$('#gallery-contents').html("");
		$('#gallery-contents').css({top:"-1000px", left:"-1000px"});
	}
		
	// Cargamos el articulo seleccionado de nivel 1
	var selected = $(".mod_navigationMain li.active");
	selected = getClassId($(selected).attr('class'));
	var article = $('#' +selected+'-text').parent();
	
	// Si hay contenido - area cliente - fijo lo mostramos antes d posicionarlo por is ha sido ocultado anteriormente.
	if ($('#' +$(article).attr('id')+' div:first').hasClass('content-4')) {
		$('#' +$(article).attr('id')+' div:first').css({display: 'block'});
		$('#' +$(article).attr('id')+' #login-form').css({display: 'block'});
	}
	
	// show new article
	// if change section fadeout old one and fedin new one if same section just show contents
	//if ($(current_article).attr('id') != opt_name) {
		// hide current article

	$('#' +current_article.attr('id') +' .pics').cycle('pause');

	if ($('#' +current_article.attr('id') +' .pics').length > 0 && $('#' +opt_name +' .pics').length > 0) {
		
		if ($(current_article).attr('id') != opt_name) {
			// Hack to avoid 2 contents visibles at same time during fadeOut delay.
			$('#' +current_article.attr('id')).css({top:"-1px", marginTop:"70px"}); 
			$('#' +current_article.attr('id') +' .pics').fadeOut("slow");
		}			
		// $('#' +current_article.attr('id') +' .pics').fadeOut("slow");
		$('#' +$(article).attr('id')).css({ top:"0px", left:"0px", marginTop: "69px" });

		if ($(current_article).attr('id') != opt_name) {
			$('#' +$(article).attr('id') +' .pics').css({ display: "none" });
	 		$('#' +$(article).attr('id') +' .pics').fadeIn("slow", function () {
				$(current_article).css({top:"-1000px", left:"-1000px"});
			});
		}
		
		$('#' +$(article).attr('id')+' .pics').cycle('resume', true);

	} else {
		$(current_article).css({top:"-1000px", left:"-1000px"});
	
		$('#' +$(article).attr('id')).css({ top:"0px", left:"0px", marginTop: "69px" });
		$('#' +$(article).attr('id') +' .pics').css({ display: "none" });
 		$('#' +$(article).attr('id') +' .pics').fadeIn("slow");
		$('#' +$(article).attr('id') +' .pics').cycle('resume', true);
	}

	//}		

	// slide in new content
	var ini_width = ini_width2;
	if ($('#' +opt_name+'-text').hasClass('content-3_3'))
		ini_width = ini_width3;

	if (($('#' +opt_name+'-text').hasClass('content-2') || $('#' +opt_name+' div:first').hasClass('content-3_3'))) {
		$('#' +opt_name+'-text').animate({width: ini_width, paddingLeft: '10', paddingRight: '10'}, 'slow', function () {
			$('#' +opt_name+'-text div').show();
		});
}
}

// Toggle navigation options submenu level1
function toggleOptions1(opt_title) {
	// opt_name = getContentId(opt_title);
	

//	var disable_toggle = $('.mod_navigationMain li.'+opt_name).hasClass('active') && opt_name == 'estudio';

	$('.mod_navigationMain a').removeClass('active');
	$('.mod_navigationMain li').removeClass('active');

//	if (!disable_toggle) {
	$('.mod_navigationMain li.'+opt_name).addClass('active');
	$('.mod_navigationMain a.'+opt_name).addClass('active');	
	
	$('.mod_customnav a').removeClass('active');
	$('.mod_customnav li').removeClass('active');
	
	$('.nav-hidden a').removeClass('active');
	$('.nav-hidden li').removeClass('active');
	
	// Hack Safari: show the element before hide.
    $('.mod_customnav').show();
	$('.nav-hidden').show();
	$('.nav-hidden2').show();

    $('.mod_customnav').hide();
	$('.nav-hidden').hide();
	$('.nav-hidden2').hide();
	if ($('#nav-'+opt_name).length > 0) {
		$('#nav-'+opt_name).show();
	}
//	}
};

// Toggle navigation options submenu level2
function toggleOptions2(opt_title) {
	// opt_name = getContentId(opt_title);

	$('.mod_customnav a').removeClass('active');
	$('.mod_customnav li').removeClass('active');
		
	$('.mod_customnav li.'+opt_name).addClass('active');
    $('.mod_customnav a.'+opt_name).addClass('active');	
	
	$('.nav-hidden a').removeClass('active');
	$('.nav-hidden li').removeClass('active');
	
	// Hack Safari: show the element before hide.
   	$('.nav-hidden').show();
	$('.nav-hidden2').show();

   	$('.nav-hidden').hide();
	$('.nav-hidden2').hide();
	if ($('#nav-'+opt_name).length > 0) {
    	$('#nav-'+opt_name).show();
    }
};

// Toggle navigation options submenu level3
function toggleOptions3(opt_title) {
	// opt_name = getContentId(opt_title);

	$('.nav-hidden a').removeClass('active');
	$('.nav-hidden li').removeClass('active');
	
	$('.nav-hidden li.'+opt_name).addClass('active');
    $('.nav-hidden a.'+opt_name).addClass('active');	

	// Hack Safari: show the element before hide.
	$('.nav-hidden2').show();

	$('.nav-hidden2').hide();
	if ($('#nav-'+opt_name).length > 0) {
    	$('#nav-'+opt_name).show();
    }
};

// Toggle navigation options submenu level3
function toggleOptions4(opt) {
	$(opt).parent().addClass('active');
    $(opt).parent().addClass('active');	

	$(opt).addClass('active');
    $(opt).addClass('active');	
};

$(document).ready(function () {

	sel_id = 'estudio';
	ini_width2 = $('.content-2:first').width();
	ini_width3 = $('.content-3_3:first').width();

	// Setup menus level1
    $('a.estudio').removeClass('active');
    $('li.estudio').removeClass('active');

	// Hide contents
	$('.content-2').css({width: '0', paddingLeft: '0', paddingRight: '0'});
	$('.content-3_3').css({width: '0', paddingLeft: '0', paddingRight: '0'});

	$('.content-2 .content-text').hide();
	$('.content-3_3 .content-text').hide();
	
	// Stop rotators
	$('.pics').cycle('pause'); 
	
	// Hide menus
	$('.mod_customnav').hide();
	$('.mod_cataloglist').hide();

	// Set menu links
    $('.mod_navigationMain a').each(function () {
    	this.href = "javascript://";
    	$(this).click(function () {
    		opt_name = getClassId($(this).attr('class'));
    		toggleOptions1(opt_name); 
     		toggleContent(opt_name);
	   	});
    });
    
    $('.mod_customnav a').each(function () {
    	this.href = "javascript://";
    	$(this).click(function () {
   			opt_name = getClassId($(this).attr('class'));
     		toggleOptions2(opt_name); 
//    		toggleContent(opt_name);
			if (opt_name != 'solicitud-presupuesto')
	    		toggleInnerContent(opt_name);
	    	else
	    		toggleContent(opt_name);
    	});
    });
    
    $('.nav-hidden a').each(function () {
    	this.href = "javascript://";
    	$(this).unbind("click");
    	$(this).click(function () {
   			opt_name = getClassId($(this).attr('class'));
    		toggleOptions3(opt_name); 
//    		toggleContent(opt_name);
    		toggleInnerContent(opt_name);
    	});
    });
    
    $('.nav-hidden2 a').each(function () {
    	if (!$(this).hasClass('jScrollArrowUp') && !$(this).hasClass('jScrollArrowDown')) {
   			var href = this.href;
    		this.href = "javascript://";
    		$(this).unbind("click");
    		$(this).click(function () {
   				opt_name = getClassId($(this).attr('class'));
    			toggleOptions4($(this)); 
    			toggleContent(opt_name, href);
    		});
    	}
    });
    
	// Forms validation
	$("#f3").RSV({
		onCompleteHandler: myOnCompleteF3,
		rules: [
			"required,ctrl_22,Por favor entra tu email.",
			"required,ctrl_16,Por favor entra tu nombre.",
			"required,ctrl_19,Por favor escribe un comentario.",
			"valid_email,ctrl_22,Por favor entra un email válido."		]
		});

	// Forms validation
	$("#f5").RSV({
		onCompleteHandler: myOnCompleteF5,
		rules: [
			"required,ctrl_44,El camp email es requerit.",
			"required,ctrl_41,El camp nom es requerit.",
			"required,ctrl_47,Escriu un comentari.",
			"valid_email,ctrl_44,Direcció d'email incorrecte."		]
		});
          
	// Forms validation
	$("#f1").RSV({
		onCompleteHandler: myOnCompleteF1,
		rules: [
			"required,ctrl_5,Por favor entra tu email.",
			"required,ctrl_1,Por favor entra tu nombre.",
			"required,ctrl_8,Por favor escribe un comentario.",
			"valid_email,ctrl_5,Por favor entra un email válido."		]
		});
		
	// Forms validation
	$("#f4").RSV({
		onCompleteHandler: myOnCompleteF4,
		rules: [
			"required,ctrl_30,El camp email es requerit.",
			"required,ctrl_26,El camp nom es requerit.",
			"required,ctrl_33,Escriu un comentari.",
			"valid_email,ctrl_30,Direcció d'email incorrecte."		]
		});
		
	// Forms roll-over
	$('#f1 #ctrl_10').hover(
		function (){
			$(this).attr('src', 'tl_files/bg/img/enviar3_on.gif');
		},
		function (){
			$(this).attr('src', 'tl_files/bg/img/enviar3.gif');
		}
	);
    $('#f3 #ctrl_20').hover(
		function (){
			$(this).attr('src', 'tl_files/bg/img/enviar3_on.gif');
		},
		function (){
			$(this).attr('src', 'tl_files/bg/img/enviar3.gif');
		}
	);
	$('#f4 #ctrl_10').hover(
		function (){
			$(this).attr('src', 'tl_files/bg/img/enviar3_on.gif');
		},
		function (){
			$(this).attr('src', 'tl_files/bg/img/enviar3.gif');
		}
	);
	$('#f5 #ctrl_20').hover(
		function (){
			$(this).attr('src', 'tl_files/bg/img/enviar3_on.gif');
		},
		function (){
			$(this).attr('src', 'tl_files/bg/img/enviar3.gif');
		}
	);
	$('#login-form #login').hover(
		function (){
			$(this).attr('src', 'tl_files/bg/img/login2_on.gif');
		},
		function (){
			$(this).attr('src', 'tl_files/bg/img/login.gif');
		}
	);
          
    // Form textarea re-set for chrome
    var isChrome = /Chrome/.test(navigator.userAgent);
    if (isChrome) {
		$('#f1 .textarea').css({height: '95px'});
		$('#f3 .textarea').css({height: '35px'});
		$('#f4 .textarea').css({height: '95px'});
		$('#f5 .textarea').css({height: '35px'});
    }          

	// Show selected content
	if (location.hash != '' && $(location.hash).length > 0) {
		$(location.hash).css({ top:"0px", left:"0px", marginTop: "69px" });
		toggleContent(location.hash.substring(1));
	} else {
		$('#estudio').css({ top:"0px", left:"0px", marginTop: "69px" });
		$('#estudio .pics').cycle('resume');
	}	
	
	// Append close button to content blocks
	$('.content-2, .content-3_3').each(function() {
		//$arrowDown = $(this).find('.jScrollArrowDown');
		//$container = $arrowDown.parent();
		$container = $(this).find('.jScrollPaneContainer');
//		var x = $(this).parent().attr('id');
		var x = $(this).attr('id');

		$container.append(
			jQuery('<a></a>')
				.attr({'href':'javascript:;', 'className':'jScrollClose'})
				.css({'width':'15px'})
				.html('Close')
				.bind('mousedown', function()
				{
					simpleToggleContent(x);
					this.blur();
					return false;
				})		
		);
	});

	// Hack... avoid overflow: auto in ie
	$('.jScrollPaneContainer').each(function () {
		if ($(this).find('.jScrollArrowUp').length == 0 && $(this).find('.scroll-pane').css('overflow') == 'auto') 		{
			$(this).parent().css('overflow', 'hidden');
			$(this).css('overflow', 'hidden');
			$(this).find('.scroll-pane').css('overflow', 'hidden');
			$(this).find('.scroll-pane').css('width', $(this).find('.scroll-pane').width()-15);
			if ('.jScrollClose') {
				$(this).find('.jScrollClose').css({right: '10px'});
				// Hack IE6
				if (jQuery.browser.msie) {
  					if(parseInt(jQuery.browser.version) == 6) {
				      $(this).find('.jScrollClose').css({bottom: '20px'});
 					 }
				} 
			}
			$(this).find('.content-text').css('height', '310px');
		} 
	});
});


function myOnCompleteF3()
{
 	ajaxSubmit($('#f3'));
 	return false;
}

function myOnCompleteF1()
{
 	ajaxSubmit($('#f1'));
 	return false;
}


function myOnCompleteF4()
{
 	ajaxSubmit($('#f4'));
 	return false;
}

function myOnCompleteF5()
{
 	ajaxSubmit($('#f5'));
 	return false;
}

function ajaxSubmit(form) {
	var params = {}; 
	$(form).find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea").filter(":enabled").each(function() { 
		params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
	});
	$(form).find('input[@type="image"]').attr('src','tl_files/bg/img/loading2.gif');
	$(form).find('input[@type="image"]').attr('disabled','true');
		 
	$.post($(form).attr("action"), params, function(xml){ 
		if ($(form).attr("id") == "f4" || $(form).attr("id") == "f5")
			alert('Gracies per contactar amb nosaltres.');
		else
			alert('Gracias por contactar con nosotros.');
		resetForm($(form));
		$(form).find('input[@type="image"]').attr('src','tl_files/bg/img/enviar3.gif');
		$(form).find('input[@type="submit"]').attr('disabled','false');
	});
	return false; 
} 

function resetForm(form) {
	$(form).each(function(){
	        this.reset();
	});
}

/****
* OLD FUNCTIONS MULTIPLE SLIDESHOW
*****/
/*
function simpleToggleContentOld(opt_name) {

	var ini_width = ini_width2;
	if ($('#' +opt_name+' div:first').hasClass('content-3_3'))
		ini_width = ini_width3;
	
	if ($('#'+opt_name+' div:first').width() > "0") {
		// slide off content
		$('#'+opt_name+' div:first div').hide();
		$('#'+opt_name+' div:first').animate({width: "0px", paddingLeft: '0', paddingRight: '0'}, 'slow');
	} else {
		$('#' +opt_name+' div:first').animate({width: ini_width, paddingLeft: '10', paddingRight: '10'}, 'slow', function () {
		 	scrollToTop(opt_name);
			$('#' +opt_name+' div:first div').show();
		});
	}
};

// Toggle contents
function toggleContentOld(opt_title, url) {
	
	// disable article container
	$('.mod_article').each(function () {

		// id the article is visible then hide
		if ($(this).css('top') == "0px") {

			// if has content then slide off		
			if (($('#' +this.id+' div:first').hasClass('content-2') || $('#' +this.id+' div:first').hasClass('content-3_3'))) {
				// slide off content and show the new article
			    scrollToTop(this.id);
				$('#'+this.id+' div:first div').hide();
				$('#'+this.id+' div:first').animate({width: 0, paddingLeft: '0', paddingRight: '0'}, 'slow', function(content_id) {
					showNewArticle($(this).parent(), opt_name, url);
				});
				return false;				
			} 
			// Si hay contenido - area cliente - fijo lo quitamos antes d mostrar el nuevo
			if ($('#' +this.id+' div:first').hasClass('content-4')) {
				$('#' +this.id+' div:first').css({display: 'none'});
				$('#' +this.id+' #login-form').css({display: 'none'});
			}

			showNewArticle($(this), opt_name, url);

			return false;
 		}
	});
};

*/



