Common = function() {
	var link = "/ba/";
	
	var _currentSection = '';

	var _init = function(alreadyLoaded) {
		
		if(!alreadyLoaded){
			/** Preload Images **/
			$.preLoadImages("images/ambientaciones_background.jpg");
			
			/** Intro Animations **/
			$("#header_logo").animate({width:"452px"},500, function(){$("#header_buttons_container").fadeIn(500)} );
			// $("#header_buttons_container").fadeIn(500);
			$("#button_ambientaciones_header").fadeIn(500);
			$("#button_productos_header").fadeIn(500);
			$("#top_search_bar").fadeIn(4000);
			$("#footer").fadeIn(2000);
			$("#hometext").fadeIn(1000,function(){$("#hometext").fadeOut(5000)} );
		}

		$('#header_logo').click(function(event){
			// event.preventDefault();
			window.location.replace("index.php");
			return false;
		});
		
		/** Menu **/
		$('.header_submenu_button').hover(
			function() {
				if($(this).hasClass('selected')) return;
				$(this).addClass('active');
			},
			function() {
				if($(this).hasClass('selected')) return;
				$(this).removeClass('active');
			}
		);
		
		$('.header_submenu_button').click(function(event){
			event.preventDefault();
			// if($(this).hasClass('selected')) return;
			
			$('.header_submenu_button.selected').removeClass('active selected');
			
			$(this).addClass('active selected');
			
			var section = $(this).attr('id');
			
			// update breadcrum
			updateBreadCrumbBySection(section);
			
			_openSection(section,{clearMarca: true});
			// _blockUIOpaque(true);
			// _openSectionNoFade(section);
			// _blockUIOpaque(false);
			
			// left menu update
			$('.menu').initMenu();
			
			return false;
		});
		
		$('.footer_menu_item').hover(
			function() {
				if($(this).hasClass('selected')) return;
				$(this).addClass('active');
			},
			function() {
				if($(this).hasClass('selected')) return;
				$(this).removeClass('active');
			}
		);
		
		$('.footer_menu_item').click(function(event){
			event.preventDefault();
			if($(this).hasClass('selected')) return;
			
			$('.footer_menu_item.selected').removeClass('active selected');
			
			$(this).addClass('active selected');
			
			var section = $(this).attr('id');
			
			// update breadcrum
			updateBreadCrumbBySection(section);
			
			_openSection(section);
			
			
			hideAmbientacionesHeaderButton();
			hideProductosHeaderButton();
			
			return false;
		});
		
		/** Menú :: Ambientaciones **/
		$("#button_ambientaciones_header").click(function () {
				
				// hide buscador
				$(".seachBoxContainer").fadeOut(500);
			
				hideProductosHeaderButton();
			  	
				// container
				$('#button_ambientaciones_header').animate({
					height: "20px",
					backgroundColor: "#0079c2;"
				}, 200, function() {
					// Animation complete.
					$("#button_ambientaciones_header_submenu").fadeIn(1000);
					// Show page background
					$("#content_background_image").fadeIn(1500);

				});
			  
			  	// text "AMBIENTACIONES"
				$('#button_ambientaciones_header_text').animate({
					marginTop: "2px"
				}, 200, function() {
					// Animation complete.
				});
				
				// page contents
				/*
				$('#contents').animate({
					marginTop: "2px"
				}, 200, function() {
					// Animation complete.
				});
				*/
				
				// show ambientaciones body
				var section = "ambientaciones_banos";
				_openSection(section);
				
				
				// Breadcrumb text
				updateBreadCrumb("Ambientaciones / Ba&ntilde;os");
				
				return false;
				
		    });
		
		/** Menú :: Productos **/
		$("#button_productos_header").click(function () {
			
			$(".seachBoxContainer").fadeIn(1000);
			
			hideAmbientacionesHeaderButton();
			
			// Breadcrumb text
			updateBreadCrumb("Productos");
			
			
			  	// container
				$('#button_productos_header').animate({
					height: "20px",
					backgroundColor: "#0079c2;"
				}, 200, function() {
					// Animation complete.
					$("#button_productos_header_submenu").fadeIn(1000);
					// Show page background
					//TODO: La imagen tiene que ser random, una llamada a un url code igniter que retorne un path se me ocurre
					$("#content_background_image").fadeIn(1500);
					

				});
			  
			  	// text "PRODUCTOS"
				$('#button_productos_header_text').animate({
					marginTop: "2px"
				}, 200, function() {
					// Animation complete.
				});
				
				// page contents
				/*
				$('#contents').animate({
					marginTop: "2px"
				}, 200, function() {
					// Animation complete.
				});
				*/
				
				// show productos body
				var section = "productos_categoria";
				_openSection(section);
				return false;
				
		    });
		
			// init drow down menu
			dropdownmenu();
			catmenu();
			
		/*
		 * Event cuando una cat se selecciona del 
		 * menu categoria, top-right
		 */
		$(".cat").click(function () {
				// event.preventDefault();
				var section = "productos_categoria";
				
				// update breadcrum
				updateBreadCrumbBySection(section);
				
				// Categoria seleccionada
				var cat = $(this).attr("href");
				
				_openSection(section,{cate: cat, clearMarca: true});
				
				
				return false;

		    });
		
		/*
		 * Event cuando una cat se selecciona del 
		 * menu categoria, top-right
		 */
		$(".marca").click(function () {
			
				// event.preventDefault();
				var section = "productos_categoria";
				
				// update breadcrum
				updateBreadCrumbBySection(section);
				
				// Categoria seleccionada
				var cat = $(this).attr("href");
				
				_openSection(section,{marca: cat});
				
				
				return false;

		    });
		
		/*
		 * BUSCAR!
		 */
		$(".searchButton").click(function () {
			
			var section = "buscar_productos";
			var ptn = $(".searchInput").val();
			
			// reset offest
			var of = 0;
			
			// open section
			_openSection(section,{pattern: ptn, offset: of});
			
			hideAmbientacionesHeaderButton();
			hideProductosHeaderButton();
			return false;

		    });
		
		
		
	};
	
	var hideAmbientacionesHeaderButton = function(){
		$('#button_ambientaciones_header').animate({
			height: "35px",
			backgroundColor: "#0079c2;"
		}, 200, function() {
			// Animation complete.
			$("#button_ambientaciones_header_submenu").fadeOut(1000);
			// Show page background
			$("#content_background_image").fadeOut(1500);
		});
		
		$('.button_header_text').animate({
			marginTop: "10.5px"
		}, 200);
	}
	
	var hideProductosHeaderButton = function(){
		$('#button_productos_header').animate({
			height: "35px",
			backgroundColor: "#0079c2;"
		}, 200, function() {
			// Animation complete.
			$("#button_productos_header_submenu").fadeOut(1000);
			// Show page background
			$("#content_background_image").fadeOut(1500);
		});
		
		$('.button_header_text').animate({
			marginTop: "10.5px"
		}, 200);
	}
	
	var _blockUI = function(value) {
		if(value) {
			$('#page_data').block({
				message: $('#preloader'),
				css: {
					border:'none',
					backgroundColor:'none',
					padding:50
				}
			});
		}else{
			$('#page_data').unblock();
		}
	}
	
	var _blockUIOpaque = function(value) {
		if(value) {
			$('#page_data').block({
				message: $('#preloader'),
				css: {
					border:'none',
					backgroundColor:'none',
					padding:500
				}
			});
		}else{
			$('#page_data').delay(1000).unblock();
		}
	}
	
    
	/** Secciones **/
	var _openSectionNoFade = function(sectionId, data) {
		// if(_currentSection == sectionId ) return;
		_currentSection = sectionId;
		// _blockUI(true);
		$('#contents').load(Data.secciones[sectionId].template, data, function(response, status, xhr) {
			// _blockUI(false);
			if (!status || status == "error") {
				$('#contents').html('');
			}
		});
	}
	
	var _openSection = function(sectionId, data) {
		// if(_currentSection == sectionId ) return;
		_currentSection = sectionId;
		_blockUI(true);
		$('#contents').load(Data.secciones[sectionId].template, data, function(response, status, xhr) {
			_blockUI(false);
			if (!status || status == "error") {
				$('#contents').html('');
			}
		});
		// $('#loaddiv').fadeOut('slow').load('reload.php').fadeIn("slow");
	}
	
	var _openSubSection = function(sectionId, data) {
		// if(_currentSection == sectionId ) return;
		_currentSection = sectionId;
		_blockUI(true);
		$('#subSection').load(Data.secciones[sectionId].template, data, function(response, status, xhr) {
			_blockUI(false);
			if (!status || status == "error") {
				$('#subSection').html('');
			}
		});
	}
	
	var _openSection1 = function(sectionId, data) {
		if(_currentSection == sectionId ) return;
		_currentSection = sectionId;
		_blockUI(true);
		$('#contents').post(Data.secciones[sectionId].template, data, function(response, status, xhr) {
			_blockUI(false);
			if (!status || status == "error") {
				$('#contents').html('');
			}
		});
	}
	var _initBanos = function() {
		$("#carousel").css({display: 'none'})
		
		$("#carousel").CloudCarousel( { 
			reflHeight: 56,
			reflGap:0,
			titleBox: $('#carousel-title'),
			altBox: $('#carousel-alt'),
			buttonLeft: $('#but1'),
			buttonRight: $('#but2'),
			yRadius:80,
			xPos: 450,
			yPos: 50,
			speed:0.15,
			mouseWheel:true,
			bringToFront:true,
			minScale:0.10,
			FPS:40
		});
		
		
		
		$(".amblink").click(function () {
			
			// event.preventDefault();
			var section = "ambientacion_imagen";
			
			// update breadcrum
			updateBreadCrumbBySection(section);
			
			// Categoria seleccionada
			var cat = $(this).attr("id");
			
			_openSection(section,{cate: cat});
			
			return false;

	    });
		
		$("#carousel").fadeIn(2000);
	}
	
	var _initBanos2 = function() {
		$('#flip').jcoverflip();
	}
	
	var _initBanos3 = function() {
		
		$("#slider").easySlider({
			auto: false, 
			continuous: false,
			speed: 1000,
			prevId: 'prevBtn',
			prevText: '',
			nextId: 'nextBtn',	
			nextText: '' });
		
		$("#nextBtn").click(function(event){
			$('.ambientacionNombreBox').fadeOut(100);
			$('.ambientacionNombreBox').fadeIn(2000);
			
			// set current slide
			var currentSlide = $('#currentSlide').val();
			currentSlide++;
			$('#currentSlide').val(currentSlide);
			
			$(".ambientacionCotizacionTable").fadeOut(500);
			$(".ambientacionDetailTable").fadeOut(500);
			return false;
		});
		
		$("#prevBtn").click(function(event){
			$('.ambientacionNombreBox').fadeOut(100);
			$('.ambientacionNombreBox').fadeIn(2000);
			
			// set current slide
			var currentSlide = $('#currentSlide').val();
			currentSlide--;
			$('#currentSlide').val(currentSlide);
			
			$(".ambientacionCotizacionTable").fadeOut(500);
			$(".ambientacionDetailTable").fadeOut(500);
			return false;
		});
		
	}
	
	var _initEmpresa = function() {
		// $('#scrollbar1').tinyscrollbar({ sizethumb: 15 });
		$("#scr1").jScrollPane();
	}
	
	var _initNovedades = function() {
		$("#novedades_text_1").jScrollPane();
		$("#novedades_text_2").jScrollPane();
		$("#novedades_text_3").jScrollPane();
	}
	
	/*
	var _initNovedades = function() {
		$('#scrollbar1').tinyscrollbar({ sizethumb: 15 });
		$('#scrollbar2').tinyscrollbar({ sizethumb: 15 });
	}
	*/
	
	var _initLocales = function() {
		
		var showLocal = function(localId) {
			var imagen = Data.secciones.footer_menu_item_locales.imagenes[localId];
			var html = Data.secciones.footer_menu_item_locales.locales[localId];
			var mapa = Data.secciones.footer_menu_item_locales.mapas[localId];
			$('#local_description').html(html);
			$("#localImage").attr("src",imagen);
			$("#localMapa").attr("src",mapa);

		}
	
		$('.trigger_locales').hover(
			function() {
				if($(this).hasClass('selected')) return;
				$(this).addClass('active');
			},
			function() {
				if($(this).hasClass('selected')) return;
				$(this).removeClass('active');
			}
		);
		
		$('.trigger_locales').click(function(event){
			event.preventDefault();
			if($(this).hasClass('selected')) return;
			
			$('.trigger_locales.selected').removeClass('active selected');
			
			$(this).addClass('active selected');
			
			showLocal($(this).attr('id'));
			
			return false;
		});
		
		$('.trigger_locales').eq(0).addClass('active selected');
		showLocal($('.trigger_locales').eq(0).attr('id'));
		
	}
	
	var _initServicios = function() {
		var showServicio = function(id) {
			var titulo = Data.secciones.footer_menu_item_servicios.titulos[id];
			var texto = Data.secciones.footer_menu_item_servicios.texto[id];
			var imagenI = Data.secciones.footer_menu_item_servicios.imagenI[id];
			var imagenA = Data.secciones.footer_menu_item_servicios.imagenA[id];
			$('#servicio_titulo').html(titulo);
			$("#servicio_texto").html(texto);
			$("#imagenIzquierda").attr("src",imagenI);
			$("#imagenAbajo").attr("src",imagenA);
		}
	
		$('.trigger_servicios').hover(
			function() {
				if($(this).hasClass('selected')) return;
				$(this).addClass('active');
			},
			function() {
				if($(this).hasClass('selected')) return;
				$(this).removeClass('active');
			}
		);
		
		$('.trigger_servicios').click(function(event){
			event.preventDefault();
			if($(this).hasClass('selected')) return;
			
			$('.trigger_servicios.selected').removeClass('active selected');
			
			$(this).addClass('active selected');
			
			showServicio($(this).attr('id'));
			
			$("#imagenTopServicios").fadeOut(1000);
			
			return false;
		});
		
		// $('.trigger_servicios').eq(0).addClass('active selected');
		showServicio($('.trigger_locales').eq(0).attr('id'));
		
	}

	var _initContactenos = function() {
		var showServicio = function(id) {
			var titulo = Data.secciones.footer_menu_item_contactenos.titulos[id];
			var texto = Data.secciones.footer_menu_item_contactenos.texto[id];
			var body = Data.secciones.footer_menu_item_contactenos.body[id];
			var imagenI = Data.secciones.footer_menu_item_contactenos.imagenI[id];
			$('#servicio_titulo').html(titulo);
			$("#servicio_texto").html(texto);
			$("#imagenIzquierda").attr("src",imagenI);
			$("#body").load(body);
		}
	
		$('.trigger_contactenos').hover(
			function() {
				if($(this).hasClass('selected')) return;
				$(this).addClass('active');
			},
			function() {
				if($(this).hasClass('selected')) return;
				$(this).removeClass('active');
			}
		);
		
		$('.trigger_contactenos').click(function(event){
			event.preventDefault();
			if($(this).hasClass('selected')) return;
			
			$('.trigger_contactenos.selected').removeClass('active selected');
			
			$(this).addClass('active selected');
			
			showServicio($(this).attr('id'));
			
			$("#imagenTopContactenos").fadeOut(1000);
			
			return false;
		});
		
		// $('.trigger_servicios').eq(0).addClass('active selected');
		showServicio($('.trigger_locales').eq(0).attr('id'));
		
	}

	/* PRODUCTOS MENU */
	var _initProductos = function(href) {
		
		if(href.lastIndexOf("/", href.length)){	
			href = href.substring(href.lastIndexOf("/")+1);
		}
		// just get the if from the href
		// href = href.substr(href.lastIndexOf("/")+1);
		// event.preventDefault();
		var section = "productos_list";

		// update breadcrum
		// updateBreadCrumbBySection(section);
		_openSubSection(section,{cate: href});
		
		return false;
	}
	
	var _detalleProducto = function(some_href) {
		
		// just get the if from the href
		if(some_href.lastIndexOf("/", some_href.length)){	
			some_href = some_href.substring(some_href.lastIndexOf("/")+1);
		}
		
		// event.preventDefault();
		var section = "producto_detalle";
		
		// update breadcrum
		updateBreadCrumbBySection(section);
		
		// _openSubSection(section,{productoID: some_href});

		var ajaxTarget = Data.secciones[section].template + '/' + some_href;
		// $('#ex2').jqm({ajax: ajaxTarget, trigger: "a.productoGridLink"});
		$('#ex2').jqm({ajax: ajaxTarget, trigger: false});
		$('#ex2').jqmShow(); 
		return false;
	}
	
	var _detalleProductoSearchResult = function(some_href) {
		// just get the if from the href
		if(some_href.lastIndexOf("/", some_href.length)){	
			some_href = some_href.substring(some_href.lastIndexOf("/")+1);
		}
		
		// event.preventDefault();
		var section = "search_producto_detalle";
		
		// update breadcrum
		updateBreadCrumbBySection(section);
		_openSection(section,{productoID: some_href});
		
		return false;
	}
	
	/* END PRODUCTOS MENU */
	
	/*
	 * Updates breadcrum text
	 */
	var updateBreadCrumb = function(some_text){
		// update breadcrum
		$('#breadcrumb').fadeOut(1500, function () {
			$('#breadcrumb').html(some_text);
			$('#breadcrumb').fadeIn(1500);
		});
		
	}
	
	/*
	 * Updates breadcrum based on section
	 */
	var updateBreadCrumbBySection = function(some_text, data){
		if(some_text == 'productos_marca'){
			
		}
		
		else{
			updateBreadCrumb('');
		}
	}
	
	/*
	 * Displays drop down menu for categorias / productos
	 */
	var dropdownmenu = function(){
		$(" #nav ul ").css({display: "none"});
		$(" #nav li").hover(function(){
			$(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).slideDown(400);
			},function(){
				$(this).find('ul:first').slideUp(400);
			});
	}
	
	
	var catmenu = function(){
		$(" #catnav ul ").css({display: "none"});
		$(" #catnav li").hover(function(){
			$(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).slideDown(400);
			},function(){
				$(this).find('ul:first').slideUp(400);
			});		
	}
	
	var _initProductosGrid = function(){
		$('.productoGridLink').click(function(event){
			event.preventDefault();
			_detalleProducto(this.href);
			return false;
		});
	}

	var _initProductosSearchResultsGrid = function(){
		
		/* Dont think this is usefull anymore...
		$('#prevBtnProductosLink').click(function(event){
			var count = $('#count').val();
		});
		*/
		
		// whait for images being loaded
        $('body').waitForImages(function() {
           
        	// create the slider with ul contents
    		$("#productosSlider").easySlider({
    			prevId: 'prevBtnProductos',
    			prevText: '',
    			nextId: 'nextBtnProductos',	
    			nextText: '',
    			orientation: 'horizontal'
    		});
    		
        }, function() {
        	
        	// set link on every image
    		$('.productoGridLink').click(function(event){
    			event.preventDefault();
    			_detalleProductoSearchResult(this.href);
    			return false;
    		});
        	
        });
		
	}
	
	var _initProductosSearchResultsGrid2 = function(){
		/* Dont think this is usefull anymore...
		$('#prevBtnProductosLink').click(function(event){
			var count = $('#count').val();
		});
		*/
		
		// whait for images being loaded
        // $('body').waitForImages(function() {
           
        	$('#prevBtnProductosLink').click(function(event){
    			event.preventDefault();
    			
    			// load previous data if available.
    			var section = "buscar_productos";
    			
    			var ptn = $("#searchPattern").val();
    			
    			// reset offest
    			var currentOffset = $("#offset").val();
    			var of = 0;
    			
    			if(currentOffset > 0){
    				of = parseInt(currentOffset) - 10;
    			}
    			
    			// open section
    			_openSection(section,{pattern: ptn, offset: of});
    				
    			hideAmbientacionesHeaderButton();
    			hideProductosHeaderButton();
    			
    			// return false;
    		});
    		
        	$('#nextBtnProductosLink').click(function(event){
    			event.preventDefault();
    			
    			// load previous data if available.
    			var section = "buscar_productos";
    			
    			var ptn = $("#searchPattern").val();
    			
    			// reset offest
    			var currentOffset = $("#offset").val();
    			var of = 0;
    			
    			// TODO: check por el max de results.
    			if(currentOffset >= 0){
    				of = parseInt(currentOffset) + 10;
    			}
    			
    			// open section
    			_openSection(section,{pattern: ptn, offset: of});
    		
    			hideAmbientacionesHeaderButton();
    			hideProductosHeaderButton();
    			
    			// return false;
    		});
        	
        // }, function() {
        
        	// set link on every image
    		$('.productoGridLink').click(function(event){
    			event.preventDefault();
    			_detalleProducto(this.href);
    			// _detalleProductoSearchResult(this.href);
    			return false;
    		});
        	
        // });
		
	}

	var _initProductosPorCategoriaResultsGrid = function(){
		/* Dont think this is usefull anymore...
		$('#prevBtnProductosLink').click(function(event){
			var count = $('#count').val();
		});
		*/
		
		// whait for images being loaded
        // $('body').waitForImages(function() {
           
        	$('#prevBtnProductosLink').click(function(event){
    			event.preventDefault();
    			
    			// load previous data if available.
    			var section = "productos_list";
    			
    			// var ptn = $("#searchPattern").val();
    			
    			// reset offest
    			var currentOffset = $("#offset").val();
    			var of = 0;
    			
    			if(currentOffset > 0){
    				of = parseInt(currentOffset) - 8;
    			}
    			
    			// open section
    			_openSubSection(section,{offset: of});
    				
    			hideAmbientacionesHeaderButton();
    			hideProductosHeaderButton();
    			
    			// return false;
    		});
    		
        	$('#nextBtnProductosLink').click(function(event){
    			event.preventDefault();
    			
    			// load previous data if available.
    			var section = "productos_list";
    			
    			// var ptn = $("#searchPattern").val();
    			
    			// reset offest
    			var currentOffset = $("#offset").val();
    			var of = 0;
    			
    			// TODO: check por el max de results.
    			if(currentOffset >= 0){
    				of = parseInt(currentOffset) + 8;
    			}

    			// open section
    			_openSubSection(section,{offset: of});
    		 
    			hideAmbientacionesHeaderButton();
    			hideProductosHeaderButton();
    			
    			// return false;
    		});
        	
        // }, function() {
        
        	// set link on every image
    		$('.productoGridLink').click(function(event){
    			event.preventDefault();
    			_detalleProducto(this.href);
    			// _detalleProductoSearchResult(this.href);
    			return false;
    		});
        	
        // });
		
	}
	
	var _verProductosLinksUpdate = function(){
		/*
		 * Volver a la lista de productos desde producto detalle
		 */
		$("#prod_detalle_back").click(function () {
				// event.preventDefault();
				var section = "productos_list";
				
				// update breadcrum
				updateBreadCrumbBySection(section);
				
				// Categoria seleccionada
				var cat = $(this).attr("href");
				
				_openSubSection(section,{cate: cat});
				
				
				return false;

		    });
	}
	
	var _verProductosSearchDetalleLinksUpdate = function(){
		/*
		 * Volver a la lista de productos desde producto detalle
		 */
		$("#prod_detalle_back").click(function () {
				
				var section = "buscar_productos";
				var ptn = $(this).attr("href");
				
				// if empty pattern display categorias
				_openSection(section,{pattern: ptn});
				return false;
		    });
	}
	
	var _initDetalleAmbientacion = function(){
		
		// scrollpane settings
		var spSettings = {
				// autoReinitialise: true
			};

		// Initialize scroll pane
		$(".scroll-pane").jScrollPane(spSettings);
		
		// hide descripcion/cotizacion on prev press
		$('#prevBtn').click(function(event){
			$(".ambientacionCotizacionTable").fadeOut(500);
			$(".ambientacionDetailTable").fadeOut(500);
			return false;
		});
		
		// hide descripcion/cotizacion on next press
		$('#nextBtn').click(function(event){
			$(".ambientacionCotizacionTable").fadeOut(500);
			$(".ambientacionDetailTable").fadeOut(500);
			return false;
		});
		
		
		$('#verDescripcionButton').click(function(event){
			event.preventDefault();
			$(".ambientacionCotizacionTable").fadeOut(1500);
			
			// $(".ambientacionDetailTable").fadeIn(1500);
			// current slide
			var current =  "#ambientacionDetailTable_" + $('#currentSlide').val();
			
			$(current).fadeIn(1500);
			
			$("div.nights h5 div.num").text()
			
			// Initialize scroll pane
			$(".scroll-pane").jScrollPane(spSettings);
			
			return false;
		});
		
		$('.verCotizacionButton').click(function(event){
			event.preventDefault();
			
			$('#prsonalInfoError').fadeOut(50);
			var current =  "#ambientacionCotizacionTable_" + $('#currentSlide').val();
			$(current).fadeIn(1500);
			// $(".ambientacionCotizacionTable").fadeIn(1500);
			$(".ambientacionDetailTable").fadeOut(1000);
			$(".scroll-pane-cotizacion").jScrollPane(spSettings);
			return false;
		});
		
		$('.enviarCotizacionButton').click(function(event){
			event.preventDefault();
			
			// form selecccionado
			var formId = $(this).attr("href");
			
			if($('#usertel_'+formId).val() == '' && !isValidEmail($('#usermail_'+formId).val())){
				// alert('Por favor ingrese un email valido o un numero telefonico.');
				$('#prsonalInfoError_'+formId).fadeIn(600);
				return false;
			}
			
			
			// Serialize form data
		    var values = $('#'+formId).serialize();

			$(".ambientacionCotizacionTable").fadeOut(1500);
			$(".ambientacionDetailTable").fadeOut(1500);
			
			// send email
			 $.post('/ba/enviarInformacionAmbientacionPorEmail',values);
			 
			 
			// clear form data
			$('#usertel_'+formId).val('');
			$('#usermail_'+formId).val('');
			$('#username_'+formId).val('');
			$('#usernewsletter_'+formId).val('');
			
			return false;
		});
		
		
		$('.ambientacionesCloseDetails').click(function(event){
			event.preventDefault();
			$(".ambientacionDetailTable").fadeOut(1500);
			$(".ambientacionCotizacionTable").fadeOut(1500);
			
			
			return false;
		});
		
		
		
	}
	
	//function to check valid email address
	var isValidEmail = function(strEmail){
	  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

	   // search email text for regular exp matches
	    if (strEmail.search(validRegExp) == -1) 
	   {
	      return false;
	    } 
	    return true; 
	}

	
	var _initContactenosPostventa = function(){
		$('#enviarButton').click(function(event){
			event.preventDefault();
		
			// check pedido and email are completed
			if(!isValidEmail($('#email').val())){
				$('#faltaEmail').fadeIn(100);
				
				return false;
				
			}
			
			if($('#numeroPedido').val() == ''){
				$('#faltaPedido').fadeIn(100);
				
				return false;
				
			}
			
			
			// form values
		    var values = $('#envio').serialize();

		    // append email
		    values = values + "&email=" + $('#email').val();
		    
			// send email
			 $.post('/ba/enviarContactenosPostventaPorEmail',values);
			 
			 var section = "contactenos_envio_exitoso";
			 
			 _openSection(section);
			 
			return false;
		});
	}
	
	var _initContactenosLocales = function(){
		$('#enviarButton').click(function(event){
			event.preventDefault();
		
			// check email
			if(!isValidEmail($('#email').val())){
				$('#faltaEmail').fadeIn(100);
				return false;
			}
			
			// form values
		    var values = $('#envio').serialize();

		    // append email
		    values = values + "&email=" + $('#email').val();
		    
			// send email
			 $.post('/ba/enviarContactenosLocalesPorEmail',values);
			 
			 var section = "contactenos_envio_exitoso";
			 
			 _openSection(section);
			 
			return false;
		});
	}
	
	var _initContactenosObras = function(){
		$('#enviarButton').click(function(event){
			event.preventDefault();
		
			// check email
			if(!isValidEmail($('#email').val())){
				$('#faltaEmail').fadeIn(100);
				return false;
			}
			
			// form values
		    var values = $('#envio').serialize();
		 
		    // append email
		    values = values + "&email=" + $('#email').val();
			
		    // send email
			 $.post('/ba/enviarContactenosObrasPorEmail',values);
			 
			 var section = "contactenos_envio_exitoso";
			 
			 _openSection(section);
			 
			return false;
		});
	}
	
	var _initContactenosRRHH = function(){
		$('#enviarButton').click(function(event){
			event.preventDefault();
		
			// check email
			if(!isValidEmail($('#email').val())){
				$('#faltaEmail').fadeIn(100);
				return false;
			}
			
			// form values
		    var values = $('#envio').serialize();

		    // append email
		    values = values + "&email=" + $('#email').val();
		    
			// send email
			 $.post('/ba/enviarContactenosRRHHPorEmail',values);
			 
			 var section = "contactenos_envio_exitoso";
			 
			 _openSection(section);
			 
			return false;
		});
	}
	
	var _initContactenosCompras = function(){
		$('#enviarButton').click(function(event){
			event.preventDefault();
		
			// check email
			if(!isValidEmail($('#email').val())){
				$('#faltaEmail').fadeIn(100);
				return false;
			}
			
			// form values
		    var values = $('#envio').serialize();

		    // append email
		    values = values + "&email=" + $('#email').val();
		    
			// send email
			 $.post('/ba/enviarContactenosComprasPorEmail',values);
			 
			 var section = "contactenos_envio_exitoso";
			 
			 _openSection(section);
			 
			return false;
		});
	}
	
	var _initContactenosMarketing = function(){
		$('#enviarButton').click(function(event){
			event.preventDefault();
		
			// check email
			if(!isValidEmail($('#email').val())){
				$('#faltaEmail').fadeIn(100);
				return false;
			}
			
			// form values
		    var values = $('#envio').serialize();
		    
		    // append email
		    values = values + "&email=" + $('#email').val();

			// send email
			 $.post('/ba/enviarContactenosMarketingPorEmail',values);
			 
			 var section = "contactenos_envio_exitoso";
			 
			 _openSection(section);
			 
			return false;
		});
	}
	
	var _initContactenosGeneral = function(){
		$('#enviarButton').click(function(event){
			event.preventDefault();
		
			// check email
			if(!isValidEmail($('#email').val())){
				$('#faltaEmail').fadeIn(100);
				return false;
			}
			
			// form values
		    var values = $('#envio').serialize();

		    // append email
		    values = values + "&email=" + $('#email').val();
		    
			// send email
			 $.post('/ba/enviarContactenosGeneralPorEmail',values);
			 
			 var section = "contactenos_envio_exitoso";
			 
			 _openSection(section);
			 
			return false;
		});
	}
	
	var _initContactenosCobranzas = function(){
		$('#enviarButton').click(function(event){
			event.preventDefault();
		
			// check email
			if(!isValidEmail($('#email').val())){
				$('#faltaEmail').fadeIn(100);
				return false;
			}
			
			// form values
		    var values = $('#envio').serialize();

		    // append email
		    values = values + "&email=" + $('#email').val();
		    
			// send email
			 $.post('/ba/enviarContactenosCobranzasPorEmail',values);
			 
			 var section = "contactenos_envio_exitoso";
			 
			 _openSection(section);
			 
			return false;
		});
	}
	
	var _initContactenosPostventaExito = function(){
		$('#evioExitoOtraConsultaButton').click(function(event){
			event.preventDefault();

			 var section = "footer_menu_item_contactenos";
			 
			 _openSection(section);
			 
			return false;
		});
	}
	
	/* FUNCTION MAPPINGS*/
	return {
		init:_init,
		initBanos:_initBanos,
		initBanos2:_initBanos2,
		initBanos3:_initBanos3,
		initLocales:_initLocales,
		initEmpresa:_initEmpresa,
		initNovedades:_initNovedades,
		initServicios:_initServicios,
		initContactenos:_initContactenos,
		openSection:_openSection,
		initProductos:_initProductos,
		initProductosGrid:_initProductosGrid,
		detalleProducto:_detalleProducto,
		detalleProductoSearchResult:_detalleProductoSearchResult,
		updateDropDowns:dropdownmenu,
		initDetalleAmbientacion:_initDetalleAmbientacion,
		initProductosSearchResultsGrid:_initProductosSearchResultsGrid,
		initProductosSearchResultsGrid2:_initProductosSearchResultsGrid2,
		verProductosSearchDetalleLinksUpdate:_verProductosSearchDetalleLinksUpdate,
		initContactenosPostventa:_initContactenosPostventa,
		initContactenosLocales:_initContactenosLocales,
		initContactenosObras:_initContactenosObras,
		initContactenosRRHH:_initContactenosRRHH,
		initContactenosMarketing:_initContactenosMarketing,
		initContactenosGeneral:_initContactenosGeneral,
		initContactenosCobranzas:_initContactenosCobranzas,
		initContactenosPostventaExito:_initContactenosPostventaExito,
		initContactenosCompras:_initContactenosCompras,
		verProductosLinksUpdate:_verProductosLinksUpdate,
		initProductosPorCategoriaResultsGrid:_initProductosPorCategoriaResultsGrid
	}
	/* END FUNCTION MAPPINGS*/
}();
