$(function(){
    initsidebarmenu();
});

// Flash Separados por ie
var swfobject_params = {
    wmode:'transparent'
};

// Estaticos
swfobject.embedSWF(URLBASE+"content/flash/logo.swf", "swf_logo", "200", "140", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/bandeiras.swf", "swf_bandeiras", "160", "60", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/fone.swf", "swf_fone", "210", "40", "9.0.0", null, null, swfobject_params, null);

// Conforme linguagem
swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_localizacao.swf", "swf_titu_localizacao", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_pacotes.swf", "swf_titu_pacotes", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_infraestrutura.swf", "swf_titu_infraestrutura", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_apartamentos.swf", "swf_titu_apartamentos", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_atendimento.swf", "swf_titu_atendimento", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_indique.swf", "swf_titu_indique", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_reservas.swf", "swf_titu_reservas", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_eventos.swf", "swf_titu_eventos", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_gastronomia.swf", "swf_titu_gastronomia", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_health_club.swf", "swf_titu_health_club", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/menu.swf", "swf_menu", "180", "255", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/frase.swf", "swf_frase", "550", "60", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_hotel.swf", "swf_titu_hotel", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/bt_voltar.swf", "swf_voltar", "70", "30", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_politica.swf", "swf_titu_politica", "200", "40", "9.0.0", null, null, swfobject_params, null);

swfobject.embedSWF(URLBASE+"content/flash/"+IDIOMA+"/titu_norma.swf", "swf_titu_norma", "200", "40", "9.0.0", null, null, swfobject_params, null);

//Links do site
function portugues(){
    location.href=URLBASE+"idioma/troca_idioma/pt_BR";
}

function espanhol(){
    location.href=URLBASE+"idioma/troca_idioma/es_ES";
}

function ingles(){
    location.href=URLBASE+"idioma/troca_idioma/en_US";
}

function menu_localizacao(){
    location.href=URLBASE+"localizacao";
}
 
function menu_infra_estrutura(){
    location.href=URLBASE+"infraestrutura";
}

function menu_pacotes_promocao(){
    location.href=URLBASE+"pacote";
}

function menu_apartamentos(){
    location.href=URLBASE+"apartamento";
}

function menu_atendimento(){
    location.href=URLBASE+"contato";
}

function menu_indique(){
    location.href=URLBASE+"indique";
}

function menu_reservas(){
    location.href=URLBASE+"reserva";
}

function menu_eventos(){
    location.href=URLBASE+"evento";
}

function menu_gastronomia(){
    location.href=URLBASE+"gastronomia";
}

function menu_health_club(){
    location.href=URLBASE+"club";
}

function menu_nosso_hotel(){
    location.href=URLBASE+"empresa";
}

function ajeitaData(d) {
    if ( (d.length==2) || (d.length==5) ) {
        d += "/";
    }
    return d;
}

$.fn.bg = (function(){
    //    if($.browser.msie){
    //        return function(img){
    //            this.css("background", "url("+img+") no-repeat top center");
    //            this.css("background", "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='scale')");
    //            this.css("background", "-ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='scale')");
    //            return this;
    //        }
    //    }else{
    return function(img){
        this.css("background", "url("+img+") no-repeat top center");
        this.css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='scale')");
        this.css("-ms-filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='scale')");
        return this;
    }
//    }
})();

// Efeitos fundo
(function($){
    
    if(_key_.indexOf('tarifas') == 0){
    	_key_ = 'tarifas';
    }
    
    if(_key_ != 'index') {
        
        var _imgs_ = {
            "hotel": ['hotel/1.jpg', 'hotel/2.jpg', 'hotel/3.jpg'/*, 'hotel/4.jpg', 'hotel/5.jpg', 'hotel/6.jpg'*/],
            "apartamentos/ver/2/luxo": ['luxo/1.jpg', 'luxo/2.jpg'/*, 'luxo/3.jpg', 'luxo/4.jpg', 'luxo/5.jpg'*/],
            "apartamentos/ver/3/suite-luxo": ['suite/1.jpg', 'suite/2.jpg', 'suite/3.jpg'/*, 'suite/4.jpg', 'suite/5.jpg'/*, 'suite/6.jpg', 'suite/7.jpg'*/],
            "apartamentos/ver/4/suite-especial": ['suite_especial/1.jpg', 'suite_especial/2.jpg', 'suite_especial/3.jpg'/*, 'luxo/4.jpg', 'suite/1.jpg', 'suite/2.jpg', 'suite/3.jpg', 'suite/4.jpg'*/],
            "apartamentos/ver/5/super-luxo": ['super_luxo/1.jpg', 'super_luxo/2.jpg', 'super_luxo/3.jpg'/*, 'super_luxo/4.jpg'*/],
            "apartamentos/ver/6/super-suite": ['super_suite/1.jpg', 'super_suite/2.jpg', 'super_suite/3.jpg'/*, 'super_suite/4.jpg'*/],
            "health": ['health/1.jpg', 'health/2.jpg', 'health/3.jpg'/*, 'health/4.jpg', 'health/5.jpg'*/],
            "gastronomia": ['gastronomia/1.jpg', 'gastronomia/2.jpg', 'gastronomia/3.jpg'/*, 'gastronomia/4.jpg'*/],
			"fale_chef": ['gastronomia/1.jpg', 'gastronomia/2.jpg', 'gastronomia/3.jpg'/*, 'gastronomia/4.jpg'*/],
            "evento": ['evento/1.jpg', 'evento/2.jpg', 'evento/3.jpg'/*, 'evento/4.jpg', 'evento/5.jpg', 'evento/6.jpg', 'evento/7.jpg'*/],
			"agenda_evento": ['evento/1.jpg', 'evento/2.jpg', 'evento/3.jpg'/*, 'evento/4.jpg', 'evento/5.jpg', 'evento/6.jpg', 'evento/7.jpg'*/],
			"fotos_evento": ['evento/1.jpg', 'evento/2.jpg', 'evento/3.jpg'/*, 'evento/4.jpg', 'evento/5.jpg', 'evento/6.jpg', 'evento/7.jpg'*/],
			"monte_evento": ['evento/1.jpg', 'evento/2.jpg', 'evento/3.jpg'/*, 'evento/4.jpg', 'evento/5.jpg', 'evento/6.jpg', 'evento/7.jpg'*/],
			"evento/ver/1": ['evento/1.jpg', 'evento/2.jpg', 'evento/3.jpg'/*, 'evento/4.jpg', 'evento/5.jpg', 'evento/6.jpg', 'evento/7.jpg'*/],
            "tarifas": ['tarifario/1.jpg', 'tarifario/2.jpg', 'tarifario/3.jpg'/*, 'tarifario/4.jpg'*/],
            "pacotes/ver/2/nupcias": ['nupcias/1.jpg', 'nupcias/2.jpg', 'nupcias/3.jpg'/*, 'nupcias/4.jpg', 'nupcias/5.jpg', 'nupcias/6.jpg', 'nupcias/7.jpg'*/],
            "pacotes/ver/6/relax": ['relax/1.jpg', 'relax/2.jpg', 'relax/3.jpg'/*, 'relax/4.jpg', 'relax/5.jpg'*/],
           	"pacotes/ver/7/comemoracao-especial": ['comemoracao-especial/1.jpg', 'comemoracao-especial/2.jpg'/*, 'comemoracao-especial/3.jpg'*/],
           	"pacotes/ver/5/final-de-semana-romantico": ['romantico/1.jpg', 'romantico/2.jpg', 'romantico/3.jpg'],
			"pacotes/ver/4/final-de-semana": ['finaldesemana/1.jpg'/*, 'finaldesemana/2.jpg', 'finaldesemana/3.jpg'*/],
           	"reserva": ['hotel/2.jpg', 'gastronomia/3.jpg', 'relax/6.jpg'], 
           	"localizacao": ['localizacao/1.jpg', 'localizacao/2.jpg', 'localizacao/3.jpg'],
           	"politica": [],
           	"normas": []
        };
    
        var jfundo = {
            images : _imgs_[_key_],
            timeout : 5000,
            troca : function(next){
                var nex = 0;
                nex = next;
                var $A = $("#jfundoA");
                var $B = $("#jfundoB");

                var prev = (nex==0)? jfundo.images.length-1 : nex-1;

                var $img = $(jfundo.images);

                $A.bg(URLBASE+'content/image/'+$img.get(nex)).show();
                $B.fadeOut(3000, function(){
                    $B.bg(URLBASE+'content/image/'+$img.get(nex)).show();
                    $A.hide().bg(URLBASE+'content/image/'+$img.get(prev));

                    if(++next == jfundo.images.length){
                        setTimeout(function(){
                            jfundo.troca(0)
                        }, jfundo.timeout);
                    }else{
                        setTimeout(function(){
                            jfundo.troca(next)
                        }, jfundo.timeout);
                    }
                });
            },
            init : function(){
                if (document.images){
                    preload_image_object = new Image();
                    var i = 0;
                    for(i=0; i<=jfundo.images.length; i++)
                        preload_image_object.src = jfundo.images[i];
                }

				$("#jfundoB").bg(URLBASE+'content/image/'+jfundo.images[0]);

				setTimeout(function(){
					jfundo.troca(1);
				}, jfundo.timeout); 
					
            }
        };
        $(function(){
				//inicia o troca fundo
				jfundo.init();
        });
    }
})(jQuery);
// fim Efeitos fundo

$(document).ready(function(){
    $("#form_novidades").validar({
        before: function(){
        //if($("#nNome").val()=='Nome') $("#nNome").val('');
        //if($("#nEmail").val()=='E-mail') $("#nEmail").val('');
        },
        end : function(){
            var notify = new Notify('Aguarde...', {
                "hide":false
            });
            $.post( URLBASE+'index/novidade', $("#form_novidades").serialize(), function(data){
                if(data.result){
                    notify.text('Cadastrado com sucesso!', true);
                    document.getElementById('form_novidades').reset();
                }else{
                    notify.text('Não foi possivel cadastra-lo(a), por favor tente mais tarde!', true);
                }
            }, 'json' );
            return false;
        }
    });

    $("#nNome").focus(function(){
        if($(this).val()=='Nome')
            $(this).val('').css('color', '#000');
    }).blur(function(){
        if($(this).val()=='')
            $(this).val('Nome').css('color', '#ccc');
    }).css('color', '#ccc');

    $("#nEmail").focus(function(){
        if($(this).val()=='E-mail')
            $(this).val('').css('color', '#000');
    }).blur(function(){
        if($(this).val()=='')
            $(this).val('E-mail').css('color', '#ccc');
    }).css('color', '#ccc');

    $("#banners").cycle({
        fx: 'fade'
    });
})

var notifys = 0;

var Notify = function(message, options){
    var self = this;
    var el = false;
    var modal = false;
    var opts = {};
    var defaults = {
        "show":true,
        "hide":true,
        "delay":2000,
        "modal":false
    };

    this.show = function(){
        if(el){
            el.animate({
                top: 0
            }, 200, '', function(){
                if(opts.hide) setTimeout(self.hide, opts.delay);
            })

            if(opts.modal){
                var id = el.attr('id')+'_over';
                $(document.body).prepend($('<div>').css({
                    'position':'fixed',
                    'width':'100%',
                    'height':'100%',
                    'background-color':'#FFF',
                    'display':'none',
                    'z-index':'9',
                    "opacity":0.5,
                    "-khtml-opacity":0.5,
                    "-moz-opacity":0.5,
                    "filter": "alpha(opacity=50)"
                }).attr('id', id));
                modal = $('#'+id).fadeIn();
            }
        }
    };

    this.text = function(text, hide){
        if(text) el.find('div').html(text);
        if(hide) setTimeout(self.hide, opts.delay);
        el.css('left', ($(document.body).width()/2) - (el.width()/2) )

        return el.find('div').html(text);
    }

    this.hide = function(){
        if(el){
            el.animate({
                top: el.height()*-2
            }, 1000, function(){
                el.remove();
                el = false;
            })
            if(opts.modal && modal){
                modal.fadeOut('', function(){
                    modal.remove();
                    modal = false;
                });
            }
        }
    };

    this.init = function(){
        $.extend(opts, defaults, options);

        $(document.body).prepend($('<div/>')
            .attr('id', 'jquery_plugin_notify_'+notifys)
            .html( $('<div/>').addClass('jquery_plugin_notify').html(message).css('padding', '20px 60px') )
            .css({
                'display': 'none',
                'position':'fixed',
                'top':'0',
                'left':'0',
                'z-index':'10',
                'background-color':'#1D1E1F',
                'border':'3px solid #000000',
                'color': '#FFF',
                'font-size':'13px',
                "opacity":0.85,
                "-khtml-opacity":0.85,
                "-moz-opacity":0.85,
                "filter": "alpha(opacity=85)",
                "-o-box-shadow": "#B4B8C1 0 1px 6px",
                "-webkit-box-shadow": "#B4B8C1 0 1px 6px",
                "-moz-box-shadow": "#B4B8C1 0 1px 6px"
            })
            );

        el = $('#jquery_plugin_notify_'+notifys)
        el.css({
            'left': (($(document.body).width()/2) - (el.width()/2)),
            'top': (el.height()*-2)
        }).show('fast', function(){
            if(opts.show)
                self.show();
        });
        notifys++;
    };

    //    new Observer({
    //        "fn": function(){
    //            return $('.jquery_plugin_notify').size() == 0
    //        },
    //        "call": self.init
    //    });

    self.init();
}

//var observers = new function(){
//    var ar = new Array();
//
//    this.add = function(obs){
//        obs.index(ar.length);
//        ar.push(obs);
//    }
//}

var Observer = function(options){
    var self = this;
    var hasNotify = false;
    var opts = {};
    var defaults = {
        "fn":function(){},
        "call":function(){},
        "timeout":11
    };
    var index = 0;

    this.index = function(i){
        if(i) index = i;
        return index;
    }

    $.extend(opts, defaults, options);

    this.robot = function(){
        if(! opts.fn() && ! hasNotify){
            setTimeout(self.robot, opts.timeout, opts);
        }else{
            opts.call();
        }
    };
    
    this.notify = function(){
        hasNotify = true;
        opts.call();
    }

    this.cancel = function(){
        hasNotify = true;
    }

    this.robot();
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}

$(window).load(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 2,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});

$(function() {
    $("a#example1").fancybox({
        'padding'       : 1,
        'titleShow'	    : false,
        'transitionIn'	: 'fade',
        'transitionOut'	: 'fade'
    });

    $("#previsao").fancybox({
        'titleShow'	        : false,
        'padding'			: 1,
        'transitionIn'		: 'fade',
        'height'			: '180px',
        'width'		        : '150px',
        'transitionOut'		: 'fade'
    });

    $("#varios1").fancybox({
        'titleShow'	        : false,
        'padding'			: 1,
        'transitionIn'		: 'fade',
        'transitionOut'		: 'fade'
    });

    $("#varios2").fancybox({
        'titleShow'	        : false,
        'padding'			: 1,
        'transitionIn'		: 'fade',
        'transitionOut'		: 'fade'
    });

    $("a[rel=grupo_imagens]").fancybox({
        'padding'		: 1,
        'transitionIn'		: 'fade',
        'transitionOut'		: 'fade',
        'titlePosition' 	: 'over',
        'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });
});

function menu_meteorologia(){
    // <a id="varios1" href="#medidas" title="Medidas">Medidas</a>
    $("body").prepend('<a href="#metereologia" id="various1"></a>');
    $("#various1").fancybox().click();
//console.log($("#varios1")[0]);
}

$(function(){
    $("#tg_menu").toggle(function(){
        var el = $("#sidebarmenu1");
        el.slideDown("slow");
        el.fadeIn("fast");
    }, function(){
        var el = $("#sidebarmenu1");
        el.slideUp("slow");
        el.fadeOut("fast");
    });
});
