/*!
*Autor: Alexandre do Prado Servian
*Data:30/08/2011
*email:alexandreservian@gmail.com
*/
$(document).ready(function(){
    zoom();
    dialog();
    menu();
    menu_lateral();
    voltar_top();
    abas();
    mascaras();
    gal_fornecedor();
    gal_empresa();
    gal_informativo();
    gal_relacionado();
    add_favorito();
    tooltip();
    maps();
    fancybox();
})
function zoom(){
    $('.fotozoom').jqzoom({
        zoomType: 'standard',
        lens:true,
        preloadImages: false,
        alwaysOn:false
    });
}
function dialog(){
    $(".dialog").dialog({ 
        bgiframe: true,
        modal: true,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });
    $(".dialog-info").dialog({
        bgiframe: true,
        modal: true,
        autoOpen: false,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });
}
function menu(){
    menu=$('.pt_1 ul:nth-child(2) li:nth-child(3) .submenu');
    $(menu).css({
        'display':'none'
    });
    $('.pt_1 ul:nth-child(2) li:nth-child(3)').hover(function(){
        $(menu).css({
            'display':'block'
        });
    },function(){
        $(menu).css({
            'display':'none'
        });
    }
    )
}
function menu_lateral(){
    $('.menu_lateral .main_ul li div').hover(function(){		
        $(this).toggleClass('div1');
    }) 	
    $('.menu_lateral .main_ul > li > ul').css({
        'display':'none'
    });
    $('.menu_lateral .main_ul > li').hover(function(){	
        icon= $(this).find('div').addClass('div2');
        $(this).find('ul:first').css({
            'display':'block'
        });
    },function(){
        $(this).find('ul:first').css({
            'display':'none'
        });
        icon= $(this).find('div').removeClass('div2');
    }
    )
}	
function voltar_top(){
    $('footer .container div:first-child div:last-child').click(function(){
        $('html, body').animate({
            scrollTop:0
        }, 'slow');
    });
}
function abas(){
    $('.abas_ul li a').click(function(){
        return false;
    })
		
    $('#tal_cont').hide();
    var noticia;	
    var hash = window.location.hash;
    if (hash !='')
    {
        noticia = $(hash).html();
        $('.abas_ul li a[href="' + hash + '"]').parent().addClass('ativo');		
    } else {
        noticia = $('#tal_cont div:first-child').html();			
        $('.abas_ul li:first-child').addClass('ativo');		
    }	
    $('#info').append('<div>' + noticia + '</div>').find('div').slideDown();
    $('.abas_ul li a').click(function(){
        $('.abas_ul li').removeClass('ativo');
        $(this).parent().addClass('ativo');
        var ancora = $(this).attr('href');
        var nome = ancora.substr(1, ancora.length);
        noticia = $('#tal_cont div[id="' + nome + '"]').html();
        $('#info').empty();
        $('#info').append('<div>' + noticia + '</div>').find('div').slideDown();
        return false;
    })	
}
function mascaras(){
    $('.tel').mask('(99) 9999-9999');
    $('.cep').mask('99999-999');
    $('.data').mask('99/99/9999');
    $('.cnpj').mask('99.999.999/9999-99');
    $('.cpf').mask('999.999.999-99');  
}
function gal_fornecedor(){
    $('.gal_fornecador').carouFredSel({
        items: 7,
        height: 150,
        direction: "left",
        prev : {   
            button  : "#prev",
            key     : "left"
        },
        next : {
            button  : "#next",
            key     : "right"
        },
        scroll : {
            items: 1,
            effect: "easeOutBounce",
            duration: 800,                        
            pauseOnHover: true
        }
    });
}
function gal_empresa(){
    $('.gal_empresa').carouFredSel({
        items: 6,
        direction: "left",
        prev : {   
            button  : "#prev",
            key     : "left"
        },
        next : {
            button  : "#next",
            key     : "right"
        },
        scroll : {
            items: 1,
            effect: "easeOutBounce",
            duration: 800,                        
            pauseOnHover: true
        }
    });
}
function gal_informativo(){
    $('.gal_informativo').carouFredSel({
        items: 5,
        direction: "left",
        prev : {   
            button  : "#prev",
            key     : "left"
        },
        next : {
            button  : "#next",
            key     : "right"
        },
        scroll : {
            items: 1,
            effect: "easeOutBounce",
            duration: 800,                        
            pauseOnHover: true
        }
    });
}
function gal_relacionado(){
    $('.gal_relacionado').carouFredSel({
        items: 4,
        direction: "left",
        prev : {   
            button  : "#prev",
            key     : "left"
        },
        next : {
            button  : "#next",
            key     : "right"
        },
        scroll : {
            items: 1,
            effect: "easeOutBounce",
            duration: 800,                        
            pauseOnHover: true
        }
    });
}
function add_favorito() {
    $("#add_favorito").click(function(e) {
        e.preventDefault();
        // aqui deve definir o endereço do site
        var url = 'http://www.cemaco.com.br';
        // aqui deve definir o titulo do site
        var title = 'Cemaco | Aqui você constrói';
        // mozilla firefox          
        if ($.browser.mozilla == true) {
            window.sidebar.addPanel(title, url, '');
            return false;
        // internet explorer
        } else if ($.browser.msie == true) {
            window.external.AddFavorite(url, title);
            return false;
        // outros navegadores
        } else {
            alert('Pressione as teclas CTRL + D para adicionar aos favoritos.');
        }
    });
}
function tooltip() {
    $('.medida').mouseenter(function(e) {
        x = e.pageX - $(this).offset().left;
        y = e.pageY - $(this).offset().top;
        $(this).css('z-index','15')
        .children(".tooltip")
        .css({
            'top': y + 10,
            'left': x + 20,
            'display':'block'
        });
    }).mousemove(function(e) {
        x = e.pageX - $(this).offset().left;
        y = e.pageY - $(this).offset().top;
        $(this).children(".tooltip").css({
            'top': y + -35,
            'left': x + -70
        });
    }).mouseleave(function() {
        $(this).css('z-index','1')
        .children(".tooltip")
        .animate({
            "opacity": "hide"
        }, "fast");
    });
  
}
function maps(){
    $("#maps").goMap({ 
        markers: [{  
            latitude: -16.675829, 
            longitude: -49.306317,			
            html: { 
                content: 'Cemaco Pio XII', 
                popup: true 
            } 
        },{  
            latitude: -16.675829, 
            longitude: -49.306317, 
            html: '' 
        }],
        zoom: 18,
        maptype: 'HYBRID',
        hideByClick: false
    });
    
    $("#maps1").goMap({ 
        markers: [{  
            latitude: -16.732438, 
            longitude: -49.271555,			
            html: { 
                content: 'Cemaco Parque Amazônia', 
                popup: true 
            } 
        },{  
            latitude: -16.732438, 
            longitude: -49.271555,
            html: '' 
        }],
        zoom: 18,
        maptype: 'HYBRID',
        hideByClick: false
    });
    
    $("#maps2").goMap({ 
        markers: [{  
            latitude: -16.780696, 
            longitude: -49.276907,			
            html: { 
                content: 'Cemaco Mansões Paraíso', 
                popup: true 
            } 
        },{  
            latitude: -16.780696, 
            longitude: -49.276907,	 
            html: '' 
        }],
        zoom: 18,
        maptype: 'HYBRID',
        hideByClick: false
    });
}
function fancybox() {
    $("a.group").fancybox({
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'elastic',
        'speedIn'		:	600, 
        'speedOut'		:	200, 
        'overlayShow'	:	false
    });
}
