// JavaScript Document
function setUp(q) {
	switch(q) {
		case "index":
		$(document).ready(function(){
			
		$(".hover_fade").hover(function() { //On hover...
		//Animate the image to 0 opacity (fade it out)
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});
			
			$("ul.sf-menu").superfish(); 
			$('#slider').nivoSlider({ 
				effect: 'fade',
				// Specify sets like: 'fold,fade,sliceDown'
				slices: 15,
				// For slice animations
				boxCols: 8,
				// For box animations
				boxRows: 4,
				// For box animations
				animSpeed: 500,
				// Slide transition speed
				pauseTime: 7000,
				// How long each slide will show
				startSlide: 0,
				// Set starting Slide (0 index)
				directionNav: false,
				// Next & Prev navigation
				directionNavHide: false,
				// Only show on hover
				controlNav: false,
				// 1,2,3... navigation
				controlNavThumbs: false,
				// Use thumbnails for Control Nav
				controlNavThumbsFromRel: false,
				// Use image rel for thumbs
				controlNavThumbsSearch: '.jpg',
				// Replace this with...
				controlNavThumbsReplace: '_thumb.jpg',
				// ...this in thumb Image src
				keyboardNav: false,
				// Use left & right arrows
				pauseOnHover: false,
				// Stop animation while hovering
				manualAdvance: false,
				// Force manual transitions
				captionOpacity: 0.8,
				// Universal caption opacity
				prevText: '>',
				// Prev directionNav text
				nextText: '<',
				// Next directionNav text
				beforeChange: function() {},
				// Triggers before a slide transition
				afterChange: function() {},
				// Triggers after a slide transition
				slideshowEnd: function() {},
				// Triggers after all slides have been shown
				lastSlide: function() {},
				// Triggers when last slide is shown
				afterLoad: function() {} // Triggers when slider has loaded
	})	
			});
		break;	
		case "portada":
		$(document).ready(function(){
			setInterval('moverTira()',6000);
		});
		break;
		case "contacto":
		$(document).ready(function(){
			$("#form_contacto").validationEngine();
		});
		break;
		case "producto_categorias":
			$('.producto').colorbox({iframe:true, innerWidth:600,innerHeight:450, scrolling:false, close: 'X', innerWidth:"900px",innerHeight:"400px"});
		break;
		case "novedad.ampliada":
		$('#slider_novedades').nivoSlider({ 
				effect: 'fade',
				// Specify sets like: 'fold,fade,sliceDown'
				slices: 10,
				// For slice animations
				boxCols: 8,
				// For box animations
				boxRows: 4,
				// For box animations
				animSpeed: 300,
				// Slide transition speed
				pauseTime: 4000,
				// How long each slide will show
				startSlide: 0,
				// Set starting Slide (0 index)
				directionNav: true,
				// Next & Prev navigation
				directionNavHide: false,
				// Only show on hover
				controlNav: false,
				// 1,2,3... navigation
				controlNavThumbs: false,
				// Use thumbnails for Control Nav
				controlNavThumbsFromRel: false,
				// Use image rel for thumbs
				controlNavThumbsSearch: '.jpg',
				// Replace this with...
				controlNavThumbsReplace: '_thumb.jpg',
				// ...this in thumb Image src
				keyboardNav: false,
				// Use left & right arrows
				pauseOnHover: true,
				// Stop animation while hovering
				manualAdvance: false,
				// Force manual transitions
				captionOpacity: 0.8,
				// Universal caption opacity
				prevText: '>',
				// Prev directionNav text
				nextText: '<',
				// Next directionNav text
				beforeChange: function() {},
				// Triggers before a slide transition
				afterChange: function() {},
				// Triggers after a slide transition
				slideshowEnd: function() {},
				// Triggers after all slides have been shown
				lastSlide: function() {},
				// Triggers when last slide is shown
				afterLoad: function() {} // Triggers when slider has loaded
	})	
		break;
		case "servicios":
		$(document).ready(function(){
			$('#slider_controldemalezas').nivoSlider({ 
				effect: 'fold',
				// Specify sets like: 'fold,fade,sliceDown'
				slices: 10,
				// For slice animations
				boxCols: 8,
				// For box animations
				boxRows: 4,
				// For box animations
				animSpeed: 1000,
				// Slide transition speed
				pauseTime: 5000,
				// How long each slide will show
				startSlide: 0,
				// Set starting Slide (0 index)
				directionNav: true,
				// Next & Prev navigation
				directionNavHide: false,
				// Only show on hover
				controlNav: false,
				// 1,2,3... navigation
				controlNavThumbs: false,
				// Use thumbnails for Control Nav
				controlNavThumbsFromRel: false,
				// Use image rel for thumbs
				controlNavThumbsSearch: '.jpg',
				// Replace this with...
				controlNavThumbsReplace: '_thumb.jpg',
				// ...this in thumb Image src
				keyboardNav: false,
				// Use left & right arrows
				pauseOnHover: true,
				// Stop animation while hovering
				manualAdvance: false,
				// Force manual transitions
				captionOpacity: 0.8,
				// Universal caption opacity
				prevText: '>',
				// Prev directionNav text
				nextText: '<',
				// Next directionNav text
				beforeChange: function() {},
				// Triggers before a slide transition
				afterChange: function() {},
				// Triggers after a slide transition
				slideshowEnd: function() {},
				// Triggers after all slides have been shown
				lastSlide: function() {},
				// Triggers when last slide is shown
				afterLoad: function() {} // Triggers when slider has loaded
	})	
	
	$('#slider_administraciondecampos').nivoSlider({ 
				effect: 'fade',
				// Specify sets like: 'fold,fade,sliceDown'
				slices: 10,
				// For slice animations
				boxCols: 8,
				// For box animations
				boxRows: 4,
				// For box animations
				animSpeed: 300,
				// Slide transition speed
				pauseTime: 4000,
				// How long each slide will show
				startSlide: 0,
				// Set starting Slide (0 index)
				directionNav: true,
				// Next & Prev navigation
				directionNavHide: false,
				// Only show on hover
				controlNav: false,
				// 1,2,3... navigation
				controlNavThumbs: false,
				// Use thumbnails for Control Nav
				controlNavThumbsFromRel: false,
				// Use image rel for thumbs
				controlNavThumbsSearch: '.jpg',
				// Replace this with...
				controlNavThumbsReplace: '_thumb.jpg',
				// ...this in thumb Image src
				keyboardNav: false,
				// Use left & right arrows
				pauseOnHover: true,
				// Stop animation while hovering
				manualAdvance: false,
				// Force manual transitions
				captionOpacity: 0.8,
				// Universal caption opacity
				prevText: '>',
				// Prev directionNav text
				nextText: '<',
				// Next directionNav text
				beforeChange: function() {},
				// Triggers before a slide transition
				afterChange: function() {},
				// Triggers after a slide transition
				slideshowEnd: function() {},
				// Triggers after all slides have been shown
				lastSlide: function() {},
				// Triggers when last slide is shown
				afterLoad: function() {} // Triggers when slider has loaded
	})
	
			$('#slider_afmaderas_po').nivoSlider({ 
				effect: 'fade',
				// Specify sets like: 'fold,fade,sliceDown'
				slices: 10,
				// For slice animations
				boxCols: 8,
				// For box animations
				boxRows: 4,
				// For box animations
				animSpeed: 300,
				// Slide transition speed
				pauseTime: 4000,
				// How long each slide will show
				startSlide: 0,
				// Set starting Slide (0 index)
				directionNav: true,
				// Next & Prev navigation
				directionNavHide: false,
				// Only show on hover
				controlNav: false,
				// 1,2,3... navigation
				controlNavThumbs: false,
				// Use thumbnails for Control Nav
				controlNavThumbsFromRel: false,
				// Use image rel for thumbs
				controlNavThumbsSearch: '.jpg',
				// Replace this with...
				controlNavThumbsReplace: '_thumb.jpg',
				// ...this in thumb Image src
				keyboardNav: false,
				// Use left & right arrows
				pauseOnHover: true,
				// Stop animation while hovering
				manualAdvance: false,
				// Force manual transitions
				captionOpacity: 0.8,
				// Universal caption opacity
				prevText: '>',
				// Prev directionNav text
				nextText: '<',
				// Next directionNav text
				beforeChange: function() {},
				// Triggers before a slide transition
				afterChange: function() {},
				// Triggers after a slide transition
				slideshowEnd: function() {},
				// Triggers after all slides have been shown
				lastSlide: function() {},
				// Triggers when last slide is shown
				afterLoad: function() {} // Triggers when slider has loaded
	})				
			$('#slider_caracteristicas').nivoSlider({ 
				effect: 'fade',
				// Specify sets like: 'fold,fade,sliceDown'
				slices: 10,
				// For slice animations
				boxCols: 8,
				// For box animations
				boxRows: 4,
				// For box animations
				animSpeed: 300,
				// Slide transition speed
				pauseTime: 4000,
				// How long each slide will show
				startSlide: 0,
				// Set starting Slide (0 index)
				directionNav: true,
				// Next & Prev navigation
				directionNavHide: false,
				// Only show on hover
				controlNav: false,
				// 1,2,3... navigation
				controlNavThumbs: false,
				// Use thumbnails for Control Nav
				controlNavThumbsFromRel: false,
				// Use image rel for thumbs
				controlNavThumbsSearch: '.jpg',
				// Replace this with...
				controlNavThumbsReplace: '_thumb.jpg',
				// ...this in thumb Image src
				keyboardNav: false,
				// Use left & right arrows
				pauseOnHover: true,
				// Stop animation while hovering
				manualAdvance: false,
				// Force manual transitions
				captionOpacity: 0.8,
				// Universal caption opacity
				prevText: '>',
				// Prev directionNav text
				nextText: '<',
				// Next directionNav text
				beforeChange: function() {},
				// Triggers before a slide transition
				afterChange: function() {},
				// Triggers after a slide transition
				slideshowEnd: function() {},
				// Triggers after all slides have been shown
				lastSlide: function() {},
				// Triggers when last slide is shown
				afterLoad: function() {} // Triggers when slider has loaded
	})				
			$('#item_ControlDeMalezas').css('display', 'block');
			$("#lista_servicios a").click(function(){
				$(".servicio_oculto").fadeTo(500,0).css("display","none");
				$("#"+$(this).attr("rel")).stop(true,true).css("display","block").fadeTo(500,1);	
			});
			$('#menu_mostrar_servicios li').click(function(){
					$('#menu_mostrar_servicios li').removeClass('itemActivo');
					$(this).addClass('itemActivo');
				});
				$ ('.servicioConTexto').hover(
					function(){
							$(this).children('span').stop(true, true).fadeTo(500, 0.8);
					},
					function(){						
							$(this).children('span').stop(true, true).fadeTo(500, 0);
					}
				);
				
				$('.servicioConTexto').colorbox({iframe:true, scrolling:false, close: 'X', innerWidth:"700px",innerHeight:"300px"});
				$('.lbHtml').colorbox({iframe:true, scrolling:false, close: 'X', innerWidth:"700px",innerHeight:"300px"});		
				
			$.extend({
			  getUrlVars: function(){
				var vars = [], hash;
				var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
				for(var i = 0; i < hashes.length; i++)
				{
				  hash = hashes[i].split('=');
				  vars.push(hash[0]);
				  vars[hash[0]] = hash[1];
				}
				return vars;
			  },
			  getUrlVar: function(name){
				return $.getUrlVars()[name];
			  }
			});	
			
			var servicioViene = $.getUrlVar('s');
			try{console.debug(servicioViene)}catch(e){};
			if(servicioViene != undefined){
				$('.itemA').each(function(){
					if($(this).attr('rel') == servicioViene){
							$(this).click();
					}
				});
			}
		});		
		break;
	}
}
function contactoEnvia()
{
	
	s = $("#form_contacto").validationEngine('validate');
	if(s)
	{
		$('#form_contacto').find('.submitline').html('<p style="text-align:right"><img src="images/ajax-loader.gif" width="16" height="11"/></p>');
		$.post('index.php?mod=system&func=contacto', $("#form_contacto").serialize(), function(data) {
			//alert(data);
			if(data && data== 'ok')
			{
				$('#form_contacto').find('.submitline').html('<span class="retmsg"><strong>Gracias!</strong><br/>Su mensaje fue enviado correctamente.</span>');
			} else {
				$('#form_contacto').find('.submitline').html('<span class="retmsg"><strong>Error</strong><br/>No hemos podido procesar su mensaje, por favor inténtelo más tarde.</span>');
			}
			
		});
	}
	return false;
}
var contador = 1;
function moverTira(){
	if(contador != 3){
		contador ++;
		$('#slider_clientes').animate({marginLeft: '-=548px'}, 800);	
	}else{
		contador = 1;
		$('#slider_clientes').animate({marginLeft: '0px'}, 800);
	}
}
