function menu_home(){
    location.href=URLBASE;
}

function menu_intro(){
    $("div#intro").hide();
}

function menu_diretoria(){
    location.href=URLBASE+"diretoria";
}


function mainmenu(){
    $(" #nav ul").css({
        display: "none"
    }); // Opera Fix
    $(" #nav li").hover(function(){
        $(this).find('ul:first').css({
            visibility: "visible",
            display: "none"
        }).show(400);
    },function(){
        $(this).find('ul:first').css({
            visibility: "hidden"
        });
    });
}

$(document).ready(function() {


    //----- INICIO - NAO MOSTRA SETAS SE CARROUSEL TIVER MENOS DE DUAS IMAGENS

    var n = $(".imgsJC").length;

    if(n <= 2){
        $(".bloco_home_cinema .jcarousel-next").hide();
        $(".bloco_home_cinema .jcarousel-prev").hide();
    }

    //----- FIM - NAO MOSTRA SETAS SE CARROUSEL TIVER MENOS DE DUAS IMAGENS

    //----- INICIO - MENU

    mainmenu();

    $("#menu").find('#shopping img').mouseover(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_1_on.png");
    }).mouseout(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_1.png");
    })

    $("#menu").find('#loja img').mouseover(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_2_on.png");
    }).mouseout(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_2.png");
    })

    $("#menu").find('#servico img').mouseover(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_3_on.png");
    }).mouseout(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_3.png");
    })

    $("#menu").find('#noticia img').mouseover(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_6_on.png");
    }).mouseout(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_6.png");
    })

    $("#menu").find('#contato img').mouseover(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_5_on.png");
    }).mouseout(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_5.png");
    })

    $("#menu").find('#trabalhe img').mouseover(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_7_on.png");
    }).mouseout(function(){
        $(this).attr("src", URLBASE+"content/image/bt_menu_7.png");
    })

    //----- FIM - MENU

    //----- INICIO - EVENTO DESTAQUE

    $('#mycarousel-evento').jcarousel();

    //----- FIM - EVENTO DESTAQUE

    //----- INICIO - VITRINE DESTAQUE

    $('#mycarousel-vitrine').jcarousel({
        vertical: true,
        scroll: 1
    });

    var n = $(".imgsV").length;

    if(n <= 1){
        $(".bloco_home_vitrine .jcarousel-next").hide();
        $(".bloco_home_vitrine .jcarousel-prev").hide();
    }

    //----- FIM - VITRINE DESTAQUE

    //----- INICIO - FILMES EM CARTAZ

    $('#mycarousel').jcarousel();

    //----- FIM - FILMES EM CARTAZ

    //----- INICIO - GALERIAS

    $(".maps").fancybox();

    $(".video").fancybox();

    $("a[rel=galeria]").fancybox({
        'transitionIn'      : 'elastic',
        'transitionOut'     : 'elastic',
        'titlePosition'     : 'over',
        'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
        return '<span id="fancybox-title-over">Imagem ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
        }
    });

    //----- FIM - GALERIAS

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

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: 200
            }, 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', '30px 150px') )
            .css({
                'display': 'none',
                'position':'fixed',
                'top':'0',
                'left':'0',
                'z-index':'10',
                'background-color':'#00923F',
                'border':'3px solid #89AF78',
                'color': '#FFF',
                'font-size':'13px',
                'font-weight':'bold'
//                "opacity":0.85,
//                "-khtml-opacity":0.85,
//                "-moz-opacity":0.85,
//                "filter": "alpha(opacity=85)",
//                "-o-box-shadow": "#999 0 1px 6px",
//                "-webkit-box-shadow": "#999 0 1px 6px",
//                "-moz-box-shadow": "#999 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();
}
