/// <reference name="MicrosoftAjax.js" />
/// <reference path="jquery-1.3.2-vsdoc2.js" />
/// <reference path="EICv3.js" />
var common = function() {

    this.formatSelects = function() {
        //criar método na classe layout
        $('div.select').click(function() {
            $(this).find("ul").toggle("normal");
            $(this).find("ul > li").click(function() {
                $(this).parent().prev().text($(this).text());
                $(this).parent().prev().attr("id", $(this).attr("id"));
            });
        });
    };

    this.animateFooter = function() {
        $('.rodape ul.f_l li > a').mouseover(function() {
            $(this).find('span.ico').animate({ height: '32px' }, 200);
        }).mouseleave(function() {
            $(this).find('span.ico').animate({ height: '19px' }, 200);
        });
    };

    this.ToolTipPremio = function() {
        setTimeout(function() {
            for (i = 0; i < $(".lista_premios li").length; i++) {
                $(".lista_premios li #span_" + i).wTooltip({
                    content: $(".lista_premios li #div_" + i).html(),
                    className: "tooltip",
                    fadeIn: 400,
                    fadeOut: 400
                });
            }
        }, 500);
    };

    this.Layout = function() {
        /*Formata os elementos input para ficar customizavel*/
        this.formatInputsBorder = function() {
            /*formata input text*/
            $('input[type=text], input[type=password]').wrap('<span class="input"></span>');
            $('textarea').wrap('<span class="textarea"></span>');
        };

    };

    this.ReservaListAno = function(count) {
        for (var index = 0; index < count; index++) {
            $(".reserva_form .select > ul").append("<li>" + (parseInt($("#genSelectedValue").text()) + index) + "</li>");
        }
    };

    this.reservar = function(urlReserva, language) {

        if (language == 'en-US')
            language = 1;
        else
            language = 4;

        var arguments = new Array();
        arguments[0] = language;
        arguments[1] = $('#txtAdultos').val();
        arguments[2] = $('#txtCriancas').val();
        arguments[3] = $('#txtDias').val();
        arguments[4] = $('#txtMes').val() + '/' + $('#txtDia').val() + '/' + $('.selectedValue').text();

        for (index = 0; index < arguments.length; index++) {
            urlReserva = urlReserva.replace('{' + (index) + '}', arguments[index]);
        }

        window.open(urlReserva, 'Reserva', 'status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes');
    };

    this.sendNomeDest2 = function(sender, args) {
        if ($('#txtNomeDest2').val() == '' && $('#txtEmailDes2').val() != '')
            args.IsValid = false;
    }

    this.sendEmailDest2 = function(sender, args) {
        if ($('#txtNomeDest2').val() != '' && $('#txtEmailDes2').val() == '')
            args.IsValid = false;
    }

    this.sendNomeDest3 = function(sender, args) {
        if ($('#txtNomeDest3').val() == '' && $('#txtEmailDes3').val() != '')
            args.IsValid = false;
    }

    this.sendEmailDest3 = function(sender, args) {
        if ($('#txtNomeDest3').val() != '' && $('#txtEmailDes3').val() == '')
            args.IsValid = false;
    }

    this.viewPhoto = function(ImageLoading) {
        $('.lista_fotos li').find('a:first').lightBox({ imageLoading: ImageLoading, containerBorderSize: '3', containerResizeSpeed: '400' });

        $('.lista_fotos li').find('a:first').click(function() {
            $('#lightbox-nav').remove();
            $('#lightbox-image-details-currentNumber').remove();
        });
    }
};

var Common = new common();

this.layout = new Common.Layout();

window.alert = function(txt) {
    eic.alertDebug(txt);
};

$(document).ready(function() {
    eic.createExternalLinks();
    eic.blockContextMenu();
    layout.formatInputsBorder();
    Common.formatSelects();
    fixContentHeight('.cont_mid', '.rodape_bg');
    Common.animateFooter();
    
    //IE6 check
    if(jQuery.browser.msie && jQuery.browser.version == "6.0"){
		var str_aviso = "<div style='border: 1px solid #F7941D; background: #FEEFDA; text-align: center; clear: both; height: 75px; position: relative;'><div style='position: absolute; right: 3px; top: 3px; font-family: courier new; font-weight: bold;'><a href='#' onclick='javascript:this.parentNode.parentNode.style.display=\"none\"; return false;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-cornerx.jpg' style='border: none;' alt='Fechar'/></a></div><div style='width: 640px; margin: 0 auto; text-align: left; padding: 0; overflow: hidden; color: black;'><div style='width: 75px; float: left;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-warning.jpg' alt='AVISO!'/></div><div style='width: 275px; float: left; font-family: Arial, sans-serif;'><div style='font-size: 14px; font-weight: bold; margin-top: 12px;'>Voc&ecirc; est&aacute; usando um navegador desatualizado!</div><div style='font-size: 12px; margin-top: 6px; line-height: 12px;'>Para navegar melhor neste site, por favor, atualize seu navegador.</div></div><div style='width: 75px; float: left;'><a href='http://pt-br.www.mozilla.com/pt-BR/' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-firefox.jpg' style='border: none;' alt='Get Firefox 3.5'/></a></div><div style='width: 75px; float: left;'><a href='http://www.microsoft.com/downloads/details.aspx?FamilyID=341c2ad5-8c3d-4347-8c03-08cdecd8852b&DisplayLang=pt-br' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-ie8.jpg' style='border: none;' alt='Get Internet Explorer 8'/></a></div><div style='width: 73px; float: left;'><a href='http://www.apple.com/br/safari/download/' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-safari.jpg' style='border: none;' alt='Get Safari 4'/></a></div><div style='float: left;'><a href='http://www.google.com/chrome?hl=pt-BR' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-chrome.jpg' style='border: none;' alt='Get Google Chrome'/></a></div></div></div>";
		$('body').prepend(str_aviso);
    }
});


/*
|---------------------------------------------------------------------------------------------------------------------------------------|
| Descrição: Fixa a altura do div de conteúdo para rodapé fixar no fim da página.           											|
| Criado: 12/11/2009 | Por: Rafael F. Silva																								|
| Modificado: __/__/____ | Por:																											|
|---------------------------------------------------------------------------------------------------------------------------------------|
*/
function fixContentHeight(content, footer){
    var remainingHeight = $(window).height() - ($(content).offset().top + getCalcHeight(content) + getCalcHeight(footer))
    if(remainingHeight > 0)
        $(content).height($(content).height() + remainingHeight);
}

/*
|---------------------------------------------------------------------------------------------------------------------------------------|
| Descrição: Pega o valor calculado da altura do elemento.																				|
| Criado: 02/09/2009 | Por: Rafael F. Silva																								|
| Modificado: __/__/____ | Por:																											|
|---------------------------------------------------------------------------------------------------------------------------------------|
*/
function getCalcHeight(obj)
{
	return parseInt($(obj).height()) +
			parseInt($(obj).css('margin-top')) +
			parseInt($(obj).css('margin-bottom')) +
			parseInt($(obj).css('padding-top')) +
			parseInt($(obj).css('padding-bottom')) +
			parseInt($(obj).css('border-top-width')) +
			parseInt($(obj).css('border-bottom-width'));
}

function fctCortina(){
    if ($('.cortina').html() == null) {
        $('body').append("<div class='cortina'></div>");
        $('.cortina').css({ height: $('body').height(), opacity: '0.8' });
    }
    
    $('.cortina').toggle('fast');
}


function limitChars(texto, limite){
	var text = $('#'+texto).val();
	var textlength = text.length;
	
	if (textlength > limite) {
	    document.getElementById(texto).value = document.getElementById(texto).value.substring(0, limite);
	}
	
	return true;
}


