$(document).ready(function(){
	
	/*-------------------------------------------------------
		Modificacion de la estructura del template para
		el home de valles.
	-------------------------------------------------------*/
	if($('.bloqueVinedo').length){
		$('#columnaIzquierda').addClass('columnaIzquierdaVinedo');
		$('#columnaDerecha').addClass('columnaDerechaVinedo');
	}
	
	/*-------------------------------------------------------
		Evento para el resize del fondo
	-------------------------------------------------------*/
	if ($.browser.msie && ($.browser.version < '7')) {
		$(window).wresize(function(){
			$('#bgContenedor').resizeFondo();
		});
	}
	else{
		$('#bgContenedor').resizeFondo();
		$(window).bind("resize", function(){
			$('#bgContenedor').resizeFondo();
		});
	}

	/*-------------------------------------------------------
		Inicializa las validaciones
	-------------------------------------------------------*/
	iniciaValidacionesInput();

	/*-------------------------------------------------------
		Inicializa pngfix para IE6
	-------------------------------------------------------*/
	if($.browser.msie && $.browser.version < 7){
		if (DD_belatedPNG) {
			DD_belatedPNG.fix('.pngfix');
		}
	}
	
	/*-------------------------------------------------------
		Asignar ancho al paginador
	-------------------------------------------------------*/
	if ($('.wp-pagenavi').length){
		if ($('.wp-pagenavi').children().length) {
			var w = 0;
			var i = 0;
		
			$('.wp-pagenavi').children().each(function(){
				w = w + parseInt($(this).innerWidth());
				i++;
			});
			$('.wp-pagenavi').css({
				'width': (w + (i - 1) * 2) + 5
			});
		}
	}

	/*-------------------------------------------------------
		Inicializa estilo para Select
	-------------------------------------------------------*/
	if ($('.selectBox').length > 0) {
		$('.selectBox').selectBox();
		correccionZIndex();
	}
	
	/*-------------------------------------------------------
		Hack safari para botones
	-------------------------------------------------------*/
	if ( $.browser.safari && ($.browser.version == '525.28') ){
		$('.btnNormal,.btnComoLlegar,.btnVerGaleria,.btnVerVideo,.btnComentarios,.btnContacto').find('span:first').css({
			'padding-top'		: '11px',
			'padding-bottom'	: '13px'
		});
	}

	/*-------------------------------------------------------
		Inicializa fuente en flash
	-------------------------------------------------------*/	
	if ($('.tituloFlash38').length) {
		$('.tituloFlash38').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold.swf',
			w: 360,
			h: 40,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash38Vinedo').length) {
		$('.tituloFlash38Vinedo').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold.swf',
			w: 170,
			h: 40,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash20').length) {
		$('.tituloFlash20').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold.swf',
			w: 360,
			h: 25,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash24').length) {
		$('.tituloFlash24').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold_2.swf',
			w: 330,
			h: 25,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash16').length) {
		$('.tituloFlash16').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold_2.swf',
			w: 330,
			h: 19,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash50').length) {
		$('.tituloFlash50').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold_2.swf',
			w: 330,
			h: 40,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash500').length) {
		$('.tituloFlash500').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold_2.swf',
			w: 500,
			h: 25,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlashCorto500').length) {
		$('.tituloFlashCorto500').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold_2.swf',
			w: 180,
			h: 25,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash712').length) {
		$('.tituloFlash712').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold_2.swf',
			w: 700,
			h: 25,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash350').length) {
		$('.tituloFlash350').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold_2.swf',
			w: 350,
			h: 25,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash135').length) {
		$('.tituloFlash135').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold_2.swf',
			w: 135,
			h: 25,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash400').length) {
		$('.tituloFlash400').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold_2.swf',
			w: 472,
			h: 25,
			textcolor: '#222222',
			textalign: 'left'
		});
	}
	
	if ($('.tituloFlash400B').length) {
		$('.tituloFlash400B').tituloFlash({
			swfURL: urlGlobal + '/swf/walkway_semibold_2.swf',
			w: 472,
			h: 25,
			textcolor: '#ffffff',
			textalign: 'left'
		});
	}

});

function iniciaValidacionesInput(){
	/*-------------------------------------------------------
		Valida que solo se ingresen caracteres numericos
	-------------------------------------------------------*/
	$(".inputNumerico").keypress(function(evt){
		var key = evt.keyCode ? evt.keyCode : evt.which ;
		return (key <= 27 || (key >= 48 && key <= 57)); 
	});	

	/*-------------------------------------------------------
		Valida que solo se ingresen caracteres alfabeticos
	-------------------------------------------------------*/
	$(".inputAlfabetico").keypress(function(evt){
		var key = evt.keyCode ? evt.keyCode : evt.which ;
		return (key <= 32 || (key >= 65 && key <= 90) || (key >= 97 && key <= 122) || key >= 128 ); 
	});

	/*-------------------------------------------------------
		Valida que solo se ingresen caracteres email
	-------------------------------------------------------*/
	$(".inputEmail").keypress(function(evt){
		var key = evt.keyCode ? evt.keyCode : evt.which ;
		return (key <= 27 || key == 45 || key == 46 || (key >= 48 && key <= 57) || (key >= 64 && key <= 90) || (key >= 97 && key <= 122) ); 
	});
}

/*-------------------------------------------------------
	Funcion que corrige los z-index de los select con 
	estilos.
-------------------------------------------------------*/
function correccionZIndex() {
	var zIndex = 500;
	$('.formItem').each(function() {
		$(this).css({
			position	: 'relative',
			zIndex		: zIndex--
		});
 	});
}

/*-------------------------------------------------------
	Funcion que redimensiona la imagen de fondo, segun
	la resolucion de la ventana.
-------------------------------------------------------*/
$.fn.resizeFondo = function() {
  	return this.each(function() {
  		
		var r = 1080 / 1440;
		
		var windowWidth = $(window).width();
		var windowHeight = $(window).height();

		if ((windowHeight/windowWidth) > r){
		    $(this).height(windowHeight);
		    $(this).width(windowHeight / r);
		    $(this).children().height(windowHeight);
		    $(this).children().width(windowHeight / r);
		} 
		else {
		    $(this).width(windowWidth);
		    $(this).height(windowWidth * r);
		    $(this).children().width(windowWidth);
		    $(this).children().height(windowWidth * r);
		}
		
		$(this).children().css({
			'left'	: (windowWidth - $(this).width())/2,
			'top'	: (windowHeight - $(this).height())/2
		});
		
		return false;
	});
};
