// JavaScript Document
$(document).ready(function() {

    //Funcőes Básicas

    /* Target hack - para Strict */
    $('a.blank').click(function() {
        $(this).attr("target", "_blank");
    });

    $('a.self').click(function() {
        $(this).attr("target", "_self");
    });

    $('a.parent').click(function() {
        $(this).attr("target", "_parent");
    });

    /* Limpa o Input ao clicar */
    $('input:text').focus(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
            if ($(this).hasClass("password")) {
                $(this).attr("type", "password");
            }
            $(this).bind("blur", function() {
                if ($(this).val() == '') {
                    if ($(this).hasClass("password")) {
                        $(this).attr("type", "text");
                    }
                    $(this).val($(this).attr("title"));
                }
            });
        }
    });

    // Ancoras
    $("#divAncoras a").click(function() {
        var e = $(this).attr("href");
        $(window).scrollTop($(e).offset().top + 30)
        return false;
    });
	
	// SIMPLE MODAL JQUERY
	$('a[name=modal]').click(function(e) {
		e.preventDefault();
		
		var id = $(this).attr('href');
	
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		$('#mask').css({'width':maskWidth,'height':maskHeight});
 
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		$(id).fadeIn(2000); 
		
		$("#estado").hide();
	
	});
	
	$('.window .close').click(function (e) {
		e.preventDefault();
		$("#estado").show();
		$('#mask').hide();
		$('.window').hide();
	});		
	
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});	
	
	
	/*______________________________ TROCAR IMAGENS DA FICHA ___________________________________________*/
	$('div.fotoEmpreendimento div.empreendimento').click(function(){
		var newSrc = $(this).parent().find('img').attr('src').replace('/thumbs','/large');
		newSrc = $('div.imgGrande div.empreendimento img').attr('src', newSrc);
		
	});
	

});

function getFlashMovieObject(movieName) {
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movieName]) return document.embeds[movieName]; 
	}
	else {
		return document.getElementById(movieName);
	}
}

function toggle(i) {
	if($(i).is(":hidden")) $(i).show();
	else $(i).hide();
}

$(document).ready(function() {
    var imgdim_a_options = {
        'width': 158,
        'height': 158,
        'constrain': 'height',
        'focus': 'mid'
    };

    $('.foto').imageDimensions(imgdim_a_options);

    var imgdim_b_options = {
        'width': 288,
        'height': 386
    };

    $('.fotogrande').imageDimensions(imgdim_b_options);

    var imgdim_c_options = {
        'width': 42,
        'height': 62,
        'constrain': 'height',
        'focus': 'right'
    };

    $('.fotopeq').imageDimensions(imgdim_c_options);
});

function validaForm(){
		//validar nome
		d = document.cadastro;
		if (d.nome.value == ""){
			alert("O campo " + d.nome.name + " deve ser preenchido!");
			d.nome.focus();
			return false;
		}
		
		//validar email
		if (d.email.value == ""){
			alert("O campo " + d.email.name + " deve ser preenchido!");
			d.email.focus();
			return false;
		}
		//validar email(verificao de endereco eletronico)
		parte1 = d.email.value.indexOf("@");
		parte2 = d.email.value.indexOf(".");
		parte3 = d.email.value.length;
		if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
			alert("O campo " + d.email.name + " deve ser conter um endereco eletronico!");
			d.email.focus();
			return false;
		}
		
		if (d.mensagem.value == ""){
			alert("O campo " + d.mensagem.name + " deve ser preenchido!");
			d.mensagem.focus();
			return false;
		}
		
		return true;
	}
	
	jQuery(document).ready(function() {
    jQuery('#carrosselLancamentos').jcarousel();
});
	
		jQuery(document).ready(function() {
    jQuery('#carrosselProdutos').jcarousel();
});
