$(document).ready(function() {
	
	
	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});

	$('#ordenar').change(function() {
		  
		window.location=baseUrl+'/noticias/ordenar/termo/'+$(this).val();
	});
	
	addMascara = function() {
		$('<div class="ui-widget-overlay" id="mascara"></div>')
		.css({
			width: $(window).width(),
			height: $(window).height(),
			position: 'fixed'
		})
		.insertAfter('#wrap');
		
		$('<img src="'+baseUrl+'/default/imagens/ajax-loader.gif" id="ajax-loader" alt="Carregando...">')
		.css({
			position: 'fixed',
			left:($(window).width()/2 - $('#ajax-loader').width() / 2),
			top:($(window).height()/2 - $('#ajax-loader').height() / 2)
		})
		.insertAfter('.ui-widget-overlay');
	};
	removeMascara = function() {
		$('#mascara, #ajax-loader').remove();
	};
	
    $('#menu_empresa_box li,#menu_empreendimento_box li').hover(
        function() {
            vPos = $(this).hasClass('first') ? 'top' : $(this).hasClass('last') ? 'bottom' : 'center';
            $(this).css({
                backgroundPosition: 'right '+vPos
                });
        },
        function() {
            vPos = $(this).hasClass('first') ? 'top' : $(this).hasClass('last') ? 'bottom' : 'center';
            if(!$(this).hasClass('active'))
                $(this).css({
                    backgroundPosition: 'left '+vPos
                    });
        }
        );
	
    $("#tabs").tabs();
    $("#telefone").mask("(99) 9999-9999");
    $("#celular").mask("(99) 9999-9999");
    $("#nascimento").mask("99/99/9999");
    $("#cpf").mask("999.999.999-99");
    $("#cep").mask("99.999-999");
    
    $('input[prompt]').each(function() {
        $(this).val($(this).attr('prompt'));
    }).focus(function() {
        if($(this).val()==$(this).attr('prompt'))$(this).val('');
    }).blur(function() {
        if($(this).val() == '')
            $(this).val($(this).attr('prompt'));
    });

    if($('#thumbs_comerciais li').length) {
        $('#thumbs_comerciais').jcarousel({
            wrap: 'circular'
        });
    }
    


    if($('#thumbs_lalec li').length) {
        $('#thumbs_lalec').jcarousel({
            wrap: 'circular'
        });
    }
    
    $("#unidade_portfolio").change(function(){
    	window.location= $(this).val();	
    });
    

	$('#thumbs_comerciais a').click(function(event) {
		event.preventDefault();
		$('#foto_comercial img').remove();
		$('#foto_comercial img').css('vertical-align', 'middle');
		$('<img />')
		.attr('src', $(this).attr('href'))
		.css('opacity', '0.3')
		.prependTo('#foto_comercial')
		.animate({opacity: 1}, 2000);
	});
	
	$('#thumbs_lalec a').click(function(event) {
		event.preventDefault();
		$('#imagem_social img').remove();
		$('#imagem_social img').css('vertical-align', 'middle');
		$('<img />')
		.attr('src', $(this).attr('href'))
		.css('opacity', '0.3')
		.prependTo('#imagem_social')
		.animate({opacity: 1}, 2000);
	});
	
	$('#thumbs a').click(function(event) {
		event.preventDefault();
		$('#foto_lancamento img').remove();
		$('#foto_lancamento img').css('vertical-align', 'middle');
		$('<img />')
		.attr('src', $(this).attr('href'))
		.css('opacity', '0.3')
		.prependTo('#foto_lancamento')
		.animate({opacity: 1}, 2000);
	});
	
	$('#img_planta a').click(function(event) {
		event.preventDefault();
		$('.planta_zoom img').remove();
		$('.planta_zoom img').css('vertical-align', 'middle');
		$('<img />')
		.attr('src', $(this).attr('href'))
		.css('opacity', '0.3')
		.prependTo('.planta_zoom')
		.animate({opacity: 1}, 2000);
	});
	
		
    // Funcao que faz aparecer o submenu

    if($.browser.msie && parseInt($.browser.version) < 8) {
        //$('#bannerFlashTopo *').hide();
        $('#menu .item-menu').mouseenter(function() {
            $('#menu .hover').removeClass('hover');
            if($(this).find('li').length > 2)
                $(this).addClass('hover');
        }).mouseleave(function() {
            //$('#menu .hover').removeClass('hover');
        });

        $('#conteudo').mouseenter(function() {
            $('#menu .hover').removeClass('hover');
        });
    }
    else {
        $("#menu .item-menu").hover(function(){

            if($(this).find('li').length > 2)
                $(this).addClass('hover');

        }, function(e){

            $(this).removeClass('hover');

            if($.browser.webkit || $.browser.safari || $.browser.msie ) {
                    $('#FlashID').show();
            }
        });
    }
    $("#menu ul li ul li.top,#menu ul li ul li.bottom").each(function() {
        $(this).append('<span class="l"></span><div></div><span class="r"></span>');
    });
    $('.abas_detalhes a').each(function() {
        $(this).css({left: ($(this).index() * 81) + 'px'});
    });
    
    $('.abas_detalhes a').click(function(){
        if(!$(this).hasClass('active')) {
            $('.conteudo_abas div.container').hide();
            $('.conteudo_abas #'+$(this).attr('class')).show();
            active = $(this).parent().find('.active');
            active.removeClass('active')
            if(active.index() != 0)
                active.css({left:(parseInt(active.css('left'))+4)+'px'});

            if($(this).index() != 0)
                $(this).css({left:(parseInt($(this).css('left'))-4)+'px'});

            $(this).addClass('active');

        }
        return false;
    });

    $('.abas_indices a').click(function(){
        if(!$(this).hasClass('active')) {
            $('.conteudo_abas div.container').hide();
            $('.conteudo_abas #'+$(this).attr('class')).show();
            active = $(this).parent().find('.active');
            active.removeClass('active')

            $(this).addClass('active');
        }
        return false;
    });
        /*
    //Funcao para marcar o menu principal dos imveis comerciais
    $("#submenu_comercial li,#menu ul li #imo_comercial").hover(function(){
        $("#menu ul li #imo_comercial").css({
            backgroundPosition: 'center top '
        });
    }, function(){       
        $("#menu ul li #imo_comercial").css({
            backgroundPosition: 'center bottom '
        });
    });
	*/
    ///////////////////////////
	
    $('#empreendimento_select').change(function(e) {
        e.preventDefault();
			
        $.ajax({
            url: $('.form #caminho').val(),
            dataType: 'html',
            type: 'post',
            data: $('#empreendimento_select').serialize(),
			
            success: function(data) {
                $('#unidade_select').html(data);

            },
            error: function(xhr, er) {
                alert('Error ' + xhr.status + ' - ' + xhr.statusText);
            }
        });
		
    });


     $('#form_canall').live('submit', function(e) {
        e.preventDefault();
        var cont = $(this);
        $.ajax({
            url: $(cont).attr('action'),
            dataType: 'html',
            type: 'post',
            data: $('#form_canall').serialize(),
			
            success: function(data) {
                if(data==1){
                    alert('Mensagem enviada com sucesso.');
                    $("#form_canall")[0].reset();
                }else{
                    alert('Houve falha ao tentar enviar a mensagem.');
                }
            },
            error: function(xhr, er) {
                alert('Error ' + xhr.status + ' - ' + xhr.statusText);
            }
        });
		
    });
	
    $('#form_canall').validate({
        rules: {
            nome: {
                required : true,
                maxlength: 50
            },
            email: {
                required : true,
                email: true,
                maxlength: 50
            },
            empreendimento: {
                required : true
            },
            unidade: {
                required : true
            }
        }
    });
    
    
    $('#form_news_rodape').live('submit', function(e) {
        e.preventDefault();
        var cont = $(this);
        
        if($("#nome_rodape").val()=="- Seu nome -"){
        	alert('Digite seu nome.');
        }else if($("#email_rodape").val()=="- Seu email -"){
            alert('Digite seu e-mail.');	
        }else{
	        $.ajax({
	            url: $(cont).attr('action'),
	            dataType: 'html',
	            type: 'post',
	            data: $('#form_news_rodape').serialize(),
				
	            success: function(data) {
	                if(data==1){
	                    alert('Dados gravados com sucesso.');
	                    $("#form_news_rodape")[0].reset();
	                }else{
	                    alert('Houve falha ao tentar gravar seus dados.');
	                }
	            },
	            error: function(xhr, er) {
	                alert('Error ' + xhr.status + ' - ' + xhr.statusText);
	            }
	        });
        }   
		
    });
	

    ///////////////////////////
	
    $('#form_boleto').live('submit', function(e) {
        e.preventDefault();
        var cont = $(this);
        $.ajax({
            url: $(cont).attr('action'),
            dataType: 'html',
            type: 'post',
            data: $('#form_boleto').serialize(),
			
            success: function(data) {
                if(data==1){
                    alert('Mensagem enviada com sucesso.');
                    $("#form_boleto")[0].reset();
                }else{
                    alert('Houve falha ao tentar enviar a mensagem.');
                }
            },
            error: function(xhr, er) {
                alert('Error ' + xhr.status + ' - ' + xhr.statusText);
            }
        });
		
    });
	
    $('#form_boleto').validate({
        rules: {
            nome: {
                required : true,
                maxlength: 50
            },
            email: {
                required : true,
                email: true,
                maxlength: 50
            },
            empreendimento: {
                required : true
            },
            unidade: {
                required : true
            }
        }
    });
	
    ///////////////////////////
	
    /*$('#form_obra').live('submit', function(e) {
        e.preventDefault();
        var cont = $(this);
        $.ajax({
            url: $(cont).attr('action'),
            dataType: 'html',
            type: 'post',
            data: $('form_obra').serialize(),
			
            success: function(data) {
                if(data==1){
                    alert('Mensagem enviada com sucesso.');
                    $("#form_obra")[0].reset();
                }else{
                    alert('Houve falha ao tentar enviar a mensagem.');
                }
            },
            error: function(xhr, er) {
                alert('Error ' + xhr.status + ' - ' + xhr.statusText);
            }
        });
		
    });
	
    $('#form_obra').validate({
        rules: {
			
            empreendimento: {
                required : true
            },
            unidade: {
                required : true
            }
        }
    });*/
	
	
    ///////////////////////////
	
    $('#form_atualizacao').live('submit', function(e) {
        e.preventDefault();
        var cont = $(this);
        $.ajax({
            url: $(cont).attr('action'),
            dataType: 'html',
            type: 'post',
            data: $('#form_atualizacao').serialize(),
			
            success: function(data) {
                if(data==1){
                    alert('Mensagem enviada com sucesso.');
                    $("#form_atualizacao")[0].reset();
                }else{
                    alert('Houve falha ao tentar enviar a mensagem.');
                }
            },
            error: function(xhr, er) {
                alert('Error ' + xhr.status + ' - ' + xhr.statusText);
            }
        });
		
    });
	
    $('#form_atualizacao').validate({
        rules: {
            nome: {
                required : true,
                maxlength: 60
            },
            email: {
                required : true,
                email: true,
                maxlength: 60
            },
            telefone: {
                required : true
            },
            celular: {
                required : true
            },
            cidade: {
                required : true,
                maxlength: 60
            },
            cep: {
                required : true
            },
            endereco: {
                required : true,
                maxlength: 60
            },
            numero: {
                required : true
            },
            bairro: {
                required : true,
                maxlength: 30
            },
            empreendimento: {
                required : true
            },
            unidade: {
                required : true
            }
        }
    });
    
    
    $('#bt_enviar_amigo').click(function(e){
		
    	e.preventDefault();
		var cont = $(this);
				
		$('#dialog_indique').dialog({
			modal: true,
			resizable : false,
			width: 300,
			height: 250,
			title: 'Indicação'
		});
		
		$('#form_indique').live('submit', function(e) {		
			e.preventDefault();
				
			$.ajax({
				url: $('#bt_indique').attr('href'),
				dataType: 'html',
				type: 'post',
				data: $('#form_indique').serialize(),
				
				success: function(data) {				
					if(data==1){
						$("#form_indique")[0].reset();
						$('#dialog_indique').dialog('close');
                                                alert('Mensagem enviada com sucesso.');
						
					}else{
						alert('Erro ao enviar a mensagem,tente novamente.');
					}	
				},
				error: function(xhr, er) {
					alert('Error ' + xhr.status + ' - ' + xhr.statusText);
				}
			});
			
		});		
		
		$('#form_indique').validate({
			rules: {
				indicador: {
					required : true,
					maxlength: 50
				},
				indicado: {
					required : true,
					maxlength: 50
				},
				email_indicado: {
					required : true,
					email: true,
					maxlength: 50
				}
			}
		});
		
	});
    
    
    
    $('#bt_interesse_imovel').click(function(e){
		e.preventDefault();
		var cont = $(this);
				
		$('#dialog_interesse').dialog({
			modal: true,
			resizable : false,
			width: 300,
			height: 250,
			title: 'Interesse no Imóvel'
		});
		
		$('#form_interesse').live('submit', function(e) {		
			e.preventDefault();
				
			$.ajax({
				url: $('#bt_interesse_imovel').attr('href'),
				dataType: 'html',
				type: 'post',
				data: $('#form_interesse').serialize(),
				
				success: function(data) {				
					if(data==1){
						alert('Mensagem enviada com sucesso.');
						$("#form_interesse")[0].reset();
						$('#dialog_interesse').dialog('close');
					}else{
						alert('Erro ao enviar a mensagem,tente novamente.');
					}	
				},
				error: function(xhr, er) {
					alert('Error ' + xhr.status + ' - ' + xhr.statusText);
				}
			});
			
		});		
		
		$('#form_interesse').validate({
			rules: {
				nome_interesse: {
					required : true,
					maxlength: 50
				},
				email_interesse: {
					required : true,
					maxlength: 50
				},
				telefone: {
					required : true,
					maxlength: 14
				}
			}
		});
		
	});
    

    
    $('#form_contato').live('submit', function(e) {
        e.preventDefault();
        var cont = $(this);
        $.ajax({
            url: $(cont).attr('action'),
            dataType: 'html',
            type: 'post',
            data: $('#form_contato').serialize(),
			
            success: function(data) {
                if(data==1){
                    alert('Agradecemos o seu contato! Responderemos a sua mensagem o mais breve possível.CEGG preendimentos');
                    $("#form_contato")[0].reset();
                }else{
                    alert('Houve falha ao tentar enviar a mensagem.');
                }
            },
            error: function(xhr, er) {
                alert('Error ' + xhr.status + ' - ' + xhr.statusText);
            }
        });
		
    });
	
    $('#form_contato').validate({
        rules: {
	    	setor: {
	        required : true
	    	},    
    		nome: {
                required : true,
                maxlength: 60
            },
            email: {
                required : true,
                email: true,
                maxlength: 60
            },
            telefone: {
                required : true
            },
            
            cidade: {
                required : true,
                maxlength: 60
            },
            cliente: {
                required : true
            },
            mensagem: {
                required : true,
                maxlength: 500
            }
           
        }
    });
    
    
    
    $('#form_interesse').live('submit', function(e) {
        e.preventDefault();
        var cont = $(this);
        $.ajax({
            url: $(cont).attr('action'),
            dataType: 'html',
            type: 'post',
            data: $('#form_interesse').serialize(),
			
            success: function(data) {
                if(data==1){
                    alert('Mensagem enviada com sucesso.');
                    $("#form_interesse")[0].reset();
                }else{
                    alert('Houve falha ao tentar enviar a mensagem.');
                }
            },
            error: function(xhr, er) {
                alert('Error ' + xhr.status + ' - ' + xhr.statusText);
            }
        });
		
    });
	
    $('#form_interesse').validate({
        rules: {
	    	setor: {
	        required : true
	    	},    
    		nome: {
                required : true,
                maxlength: 60
            },
            email: {
                required : true,
                email: true,
                maxlength: 60
            },
            telefone: {
                required : true
            },
            cliente: {
                required : true
            },
            mensagem: {
                required : true,
                maxlength: 500
            }
           
        }
    });
    
    $('#form_receba').live('submit', function(e) {
        e.preventDefault();
        var cont = $(this);
        $.ajax({
            url: $(cont).attr('action'),
            dataType: 'html',
            type: 'post',
            data: $('#form_receba').serialize(),
			
            success: function(data) {
                if(data==1){
                    alert('Dados enviados com sucesso.');
                    $("#form_receba")[0].reset();
                }else{
                    alert('Houve falha ao tentar enviar a mensagem.');
                }
            },
            error: function(xhr, er) {
                alert('Error ' + xhr.status + ' - ' + xhr.statusText);
            }
        });
		
    });
	
    $('#form_receba').validate({
        rules: {
	    	   
    		nome_receba: {
                required : true,
                maxlength: 60
            },
            email_receba: {
                required : true,
                email: true,
                maxlength: 60
            }
           
        }
    });
    
    
 	$('#img_video').click(function(e){
						
		$('#dialog_video').dialog({
			modal: true,
			resizable : false,
			width: 680,
			height: 470,
			title: 'Vídeo',
			close:function(){
				$('#FlashID').show(); 
			},
			buttons:{"Close": 
				function() { 
					$(this).dialog("close"); 				 
				} 
			}
		});
		$('#FlashID').hide();
	
	});
 	
 	$('#img_video1').click(function(e){
		
		$('#dialog_video1').dialog({
			modal: true,
			resizable : false,
			width: 680,
			height: 470,
			title: 'Vídeo',
			close:function(){
				$('#FlashID').show(); 
			},
			buttons:{"Close": 
				function() { 
					$(this).dialog("close"); 				 
				} 
			}
		});
		$('#FlashID').hide();
	
	});
 	
 	$('#img_video2').click(function(e){
		
		$('#dialog_video2').dialog({
			modal: true,
			resizable : false,
			width: 680,
			height: 470,
			title: 'Vídeo',
			close:function(){
				$('#FlashID').show(); 
			},
			buttons:{"Close": 
				function() { 
					$(this).dialog("close"); 				 
				} 
			}
		});
		$('#FlashID').hide();
	
	});
 	
 	$('#img_video3').click(function(e){
		
		$('#dialog_video3').dialog({
			modal: true,
			resizable : false,
			width: 680,
			height: 470,
			title: 'Vídeo',
			close:function(){
				$('#FlashID').show(); 
			},
			buttons:{"Close": 
				function() { 
					$(this).dialog("close"); 				 
				} 
			}
		});
		$('#FlashID').hide();
	
	});
 	
 	$('#img_video4').click(function(e){
		
		$('#dialog_video4').dialog({
			modal: true,
			resizable : false,
			width: 680,
			height: 470,
			title: 'Vídeo',
			close:function(){
				$('#FlashID').show(); 
			},
			buttons:{"Close": 
				function() { 
					$(this).dialog("close"); 				 
				} 
			}
		});
		$('#FlashID').hide();
	
	});
 	
 	
 	$('.obra').live('click', function(e){
 		
		e.preventDefault();
		var cont = $(this);	
				
			$.ajax({
				url: $(cont).attr('rel'),
				dataType: 'html',
				type: 'post',				
				
				success: function(data) {
				
				   $('#dialog_fotosobra').html(data).dialog({
				      title: 'Fotos da Obra',
				      modal: true,
				      draggable: false,
				      resizable: false,
				      closeOnEscape: true,
				      width: 590,
				      height: 355
				     });
				}
				
			});
			
			
	});

	
});


			
	
