$(document).ready(function() {
	Fancybox.init();
	TabsContent.init();
	Tabs.init();
	Contacto.init();
	Trabajos.init();
});



var Fancybox = {
	init : function()
	{
		Fancybox._loadCss();
		if ($("a.fancybox").length > 0)
			$("a.fancybox").fancybox({
				'titleShow'     : false,
				"width"	: 900,
				"height" : 820,
				"autoScale" : false,
				"autoDimensions" : false

			});

		if ($("a.google-maps").length > 0)
			$("a.google-maps").fancybox( { width: 645, height: 475, 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"
		});
	}
}


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("");

				}
			});
		}

	}
}

