
$(document).ready(function() {
	Home.init();
	Productos.init();
	Fancybox.init();
	Cabeceras.init();
	Formularios.init();
});
var Productos = {
	init : function()	{
		Productos.caracteristicas();
		$("#caracteristicas a:first").click();
		Productos.fotos();
		Productos.tabs();
		$("#tabs-marcas a:first").click();
	},

	caracteristicas : function() {
		$("#caracteristicas a").bind("click", function() {
			var valores = $(this).parent().parent().find(".valores")
			var simbolo = $(this).parent().find(".simbolo")
			if (valores.css("display") == "none") {
				simbolo.html("[-]");				
			} else {
				simbolo.html("[+]");				
			}
			valores.toggle("slow");
			
			return false; 
		});
	}, 
	fotos : function() {
		
		if ($(".scroll li").length > 3) {
			$(".scroll").jCarouselLite({
				btnNext: ".next",
				btnPrev: ".prev",
				visible: 3,
				scroll : 3	
			});
		}
	},
	tabs : function() {
		$("a.tabs").bind("click", function() {
			$("#tabs-marcas li").removeClass("selected");
			$("div.contenido-tabs-marcas").hide("slow");
			$(this).parent().parent().parent().addClass("selected");
			var href = $(this).attr("href");
			$(href).show("slow");
		});
	}
}


var Fancybox = {
	init : function()
	{
		if ($.fancybox) {
			Fancybox._loadCss();
			if ($("a.fancybox").length > 0)
				$("a.fancybox").fancybox();

			if ($("a.google-maps").length > 0)
				$("a.google-maps").fancybox( { width: 645, height: 475, hideOnContentClick: false, 'type'	: 'iframe'});
			if ($("a.video-link").length > 0)
				$("a.video-link").fancybox( { width: 645, height: 375, hideOnContentClick: false, 'type'	: 'iframe'});

		}
	},

	_loadCss : function()
	{
		$("head").append("<link>");
		css = $("head").children(":last");
		css.attr({
			rel:  "stylesheet",
			type: "text/css",
			href: "/resources/js/jquery/fancybox/jquery.fancybox-1.3.1.css"
		});

		$("head").append("<link>");
		css = $("head").children(":last");
		css.attr({
			rel:  "stylesheet",
			type: "text/css",
			href: "/css/css3.css"
		});
	}
}


var Trabajos = {
	init : function()
	{
		if (jQuery().tinycarousel) {
			$("#slider-code").tinycarousel({ pager: true,
				callback: function(element, index){
					//console.log(element, index);
				}
			});
		}
	}
}


var Tabs = {

	init: function () {
		$(".form").hide();
		$("#formulario-contacto").show();

		$("ul.tabs a").click(function() {
			$("ul.tabs li").removeClass("selected");

			$(this).parent().addClass("selected");

			id = $(this).attr("href");
			$(".form").hide();
			$(id).show();

			return false;
		});

	}
}


var TabsContent = {
	init: function() {
		$(".tabs-content-div").hide();
		if (self.document.location.hash && $("#tab-" + self.document.location.hash.substring(1)).length > 0) {
			$("ul.tabs-content li").removeClass("selected");
			$("#tab-" + self.document.location.hash.substring(1)).addClass("selected");
			$(self.document.location.hash).show();

		} else {
			$(".tabs-content-div.selected").show();
		}
		$("ul.tabs-content a").click(function() {
			$("ul.tabs-content li").removeClass("selected");

			$(this).parent().addClass("selected");

			id = $(this).attr("href");
			$(".tabs-content-div").hide();
			$(id).show();

			return false;
		});
	}
}

var Contacto = {
	vacios : false,
	init : function() {
		if ($("#formulario-contacto").length > 0) {
			$("#form-contacto").validate();
			$("#form-presupuesto").validate();
			$("#form-soporte").validate();
			$(".texto").bind("click", function() {
				if (!Contacto.vacios) {
					Contacto.vacios = true;
					$(".texto").val("");

				}
			});
		}

	}
}


var Home = { 
	init : function() {
		Home.productos();
	},
	productos : function() {
		if ($("#marcador-visual > li").size() > 3) {
			$(".scroll-home").jCarouselLite({
				btnNext: ".next-home",
				btnPrev: ".prev",
				visible: 3,
				scroll : 3,
				auto: 3000,
				speed: 800,
				afterEnd: function(a) {
					$("#marcador-visual > li")
						.removeClass("marcador-on")
						.addClass("marcador-off");

					a.map(function() {
						$("#marcador-" + this.id.split("-")[1]).removeClass("marcador-off").addClass("marcador-on");
					});
				}
			});
		}
	}
}

var Cabeceras = {
	init : function()
	{
		if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
		} else {

			if ($("#cabeceras1 img").length > 1) {
				$('#cabeceras1').jqFancyTransitions({
					width: 602,
					height: 408,
					titleOpacity: 0.0,
					direction: 'right',
					position: 'up',
					stripDelay: 150					
				});
			}

			if ($("#cabeceras2 img").length > 1) {
				$('#cabeceras2').jqFancyTransitions({
					height: 418,
					width: 394,
					titleOpacity: 0.0,
					direction: 'left',
					position: 'bottom',
					stripDelay: 150
				});
			}

			if ($("#mini-cabeceras1 img").length > 1) {
				$('#mini-cabeceras1').jqFancyTransitions({
					width: 602,
					height: 226,
					titleOpacity: 0.0,
					direction: 'right',
					position: 'up',
					stripDelay: 250					
				});
			}
			
			if ($("#mini-cabeceras2 img").length > 1) {
				$('#mini-cabeceras2').jqFancyTransitions({
					height: 211,
					width: 373,
					titleOpacity: 0.0,
					direction: 'left',
					position: 'bottom',
					stripDelay: 250
				});
			}
			
		}
	}
}



Formularios = {
	
	init : function() {
		Formularios.contacto();
	},
	contacto : function() {
		if ($("#formulario-contacto").length > 0) {
			$("#formulario-contacto").validate();
		}
	}
}
