	/** 
	 *	js-index.js
	 *
	 *	@version 1.0
	 *	@date 11/Marzo/2010, 4:25pm
	 *	@author Ralph Moran
	 *	@contact Ralph Moran
	 *			 ralphmoran@gmail.com
	 *
	 *	@Changelog
	 *	---------------------------------------------
	 *		@update 22/Abril/2010, 6:05pm
	 *		@author Ralph Moran
	 *		"Agrego accion para usar el FancyBox y Slider en galeria de Noticias."
	 *	---------------------------------------------
	 *		@update 26/Abril/2010, 11:58am
	 *		@author Ralph Moran
	 *		"Agrego acciones para el tinyTips."
	*/
	
	$(function()
	{		
		// Mostrar los BGs de cada item menu
		$(".menu li a").hover(
			function()
				{
					$li = $(this).parent();					
					
					if( $li.attr("class").indexOf("seccion-actual") == -1 )
						$li.addClass("item-activo");
				}, 
			function()
				{ 
					$li = $(this).parent();
					
					if( $li.attr("class").indexOf("seccion-actual") == -1 )
						$li.removeClass("item-activo");
				}
		); // Fin: $(".menu li a").hover({...});
		
		// Fix PNG en IE6
		//if( $.browser.version == "6.0" && $.browser.msie )				
			//$(document).pngFix();			
		
		
		$("#form_Contacto").validate(
		{						
			rules:{
					tfd_Nombre:{required:true},
					tfd_ApellidoPat:{required:true},
					tfd_ApellidoMat:{required:true},
					tfd_Calle:{required:true},
					tfd_Num:{required:true},
					tfd_Col:{required:true},  
					tfd_Cd:{required:true},
					tfd_Tel:{
						required:function(element) { return $("#tfd_Cel").val() == '';} 
						},
					tfd_Cel:{
						required:function(element) { return $("#tfd_Tel").val() == '';} 
						},
					sel_Destino:{required:true},
					tfd_Correo:{
						email: true
						},
					textA_Mnj:{required: true}
					
				},	
			messages:{
					tfd_Nombre:{required: "Obligatorio."},
					tfd_ApellidoPat:{required: "Obligatorio."},
					tfd_ApellidoMat:{required: "Obligatorio."},
					tfd_Calle:{required: "Obligatorio."},
					tfd_Num:{required: "Obligatorio."},
					tfd_Col:{required: "Obligatorio."},  
					tfd_Cd:{required: "Obligatorio."},
					tfd_Tel:{required: "Obligatorio."},
					tfd_Cel:{required: "Obligatorio."},
					sel_Destino:{required: "Obligatorio."},
					tfd_Correo:{
						email:"Por favor escribe un email valido!"
						},
					textA_Mnj:{required: "Obligatorio."}
				},
			submitHandler:function()
				{	$("#img_loaderContacto").show();
					$.post("controllers/controllerMails.php?tipoMail=contactos", $("#form_Contacto").serialize(), function(data)
					{
						$("#form_Contacto").resetForm();
						alert("Tomamos muy en cuenta tus comentarios, en breve nos pondremos en contacto.");
						$("#img_loaderContacto").hide();
					});
				}
		});
		
		// Agregar (*) a los campos requeridos
		$(".required").after(' <span class="error mini"> *</span>');
		
		// Los tips informativos
		$("a.tTip").tinyTips('title');
		
		$("#sel_Destino").change( function()
		{
			$("#sel_Destino option:selected").each(function()
			{
				$("a.tTip").attr({"title":$(this).attr("title")});
			});			
		});
		
		//#############################################
		// FancyBox
		$("a.fancy-box").fancybox({
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'titlePosition' 	: 'over',
			'onComplete'	:	function() 
			{
				$("#fancybox-wrap").hover(function() 
				{
					$("#fancybox-title").show();
				}, function() {
					$("#fancybox-title").hide();
				});
			},
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">' + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				// '  -  Imagen ' + (currentIndex + 1) + ' / ' + currentArray.length +
			}
		});
		
		//#############################################
		// Slider
		$("#div_ContenedorVideos").easySlider({
			auto: true, 
			continuous: true,
			prevText: '',
			nextText: '',
			speed:1000,
			pause:3800
		});
		
		//##############################################
		// Animacion portada					
		if( $("a.portada").length > 0 )
		{
			$("a.flv").fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'			: 680,
				'height'		: 495,
				'href'			: $("a.portada").attr("href").replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					 'wmode': 'transparent',
					'allowfullscreen': 'true'
				}
			});
						
			$("a.swf, a.img").fancybox({
			'titlePosition' 	: 'over',
			'onComplete'	:	function() 
				{
					$("#fancybox-wrap").hover(function() 
					{
						$("#fancybox-title").show();
					}, function() {
						$("#fancybox-title").hide();
					});
				},
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">' + (title.length ? ' &nbsp; ' + title : '') + '</span>';
					// '  -  Imagen ' + (currentIndex + 1) + ' / ' + currentArray.length +
				}
			});			
			
			$("a.live").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'     	: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("a.portada").trigger("click");
		}
		
		
		// Rubros
		$(".rubro + div").html("<em>Procesando...</em>").hide();
		$(".rubro").unbind("click").click(function()
		{
			var obj_Rubro = $(this);
			var arr_rubro = obj_Rubro.attr("group").split('-');
			
			if( !$("div",obj_Rubro.parent()).is(":visible") )
			{
				$.fancybox.showActivity();
				
				$.post("controllers/controllerBuscador.php?tipo="+arr_rubro[0]+"&cat="+arr_rubro[1],{x:1},function(result)
				{
					$.fancybox.hideActivity();
					$("div",obj_Rubro.parent()).html(result).toggle("slow");
				});
			}else
				$("div",obj_Rubro.parent()).toggle("slow");
			
			return false;
		});
		
	});
	
	
	/**
	 *	Slider de imagenes
	*/
	
	$(window).load(function() {
		$('#div_Slider').nivoSlider({
			effect:'fade',
			slices:15,
			animSpeed:2000,
			pauseTime:6000,
			directionNav:true, //Next & Prev
			directionNavHide:true, //Only show on hover
			controlNav:true, //1,2,3...
			pauseOnHover:true, //Stop animation while hovering
			beforeChange: function(){},
			afterChange: function(){}
		});
	});
	
	
	$(window).load(function() {
		$('#div_BannersT').nivoSlider({
			effect:'fade',
			slices:15,
			animSpeed:2000,
			pauseTime:6000,
			directionNav:true, //Next & Prev
			directionNavHide:true, //Only show on hover
			controlNav:true, //1,2,3...
			pauseOnHover:true, //Stop animation while hovering
			beforeChange: function(){},
			afterChange: function(){}
		});
	});
	
	$(window).load(function() {
		$('#div_BannersT_Lateral').nivoSlider({
			effect:'fade',
			slices:15,
			animSpeed:2000,
			pauseTime:6000,
			directionNav:true, //Next & Prev
			directionNavHide:true, //Only show on hover
			controlNav:true, //1,2,3...
			pauseOnHover:true, //Stop animation while hovering
			beforeChange: function(){},
			afterChange: function(){}
		});
	});	
	
	/**
	 *	$.resetForm();
	 *
	 *	"Resetea/limpia un formulario."
	 *
	 *	@access public
	 *	@usage $("form").resetForm();
	 *	@retun void
	*/
	
	jQuery.fn.resetForm = function()
	{
		$(this).each(function(){ this.reset(); });
	}
	
		
		
