// JavaScript Document
$(document).ready(function(){
	//if($('#logger').css({display:'block'})){
//		$('#jquery-overlay2').delay(1000).fadeOut(2000);
//		$('#logger').delay(1000).fadeOut(2000);
//	}
	$('#indique').css({display:'none'});
	$('#indique2').css({display:'none'});
	$('.fancy').css({display:'none'});
	$( "#cycle_tab1" ).tabs({
			ajaxOptions: {
				error: function( xhr, status, index, anchor ) {
					$( anchor.hash ).html(
						"Nao da pra abrir" );
				}
			},
			spinner: 'Retrieving data...'
	});
		$('.cc').click(function(){
			window.open('http://www.strengenharia.com.br/chatlive/chat.php?code=U0VSVkVSUEFHRQ__','','width=590,height=610,left=0,top=0,resizable=yes,menubar=no,location=yes,status=yes,scrollbars=yes');
		});
		$( "#allow" ).tabs();
		$('#slide_imoveis1').jcarousel({
			scroll:1,
			wrap: 'circular', 
			start: 1	
		});
		$('#slide_imoveis2').jcarousel({
			scroll:1,
			wrap: 'circular',
			start: 1	
		});
		$('#slide_imoveis3').jcarousel({
			scroll:1,
			wrap: 'circular',
			start: 1	
		});
		$('#slide_imoveis4').jcarousel({
			scroll:1,
			wrap: 'circular',
			start: 1	
		});
		//Corrigir BUG no tamanho da listagem gerado pelo UI TAB ;)
		$('.jcarousel-list-horizontal').css({'width':'1189px'});			
		
		
		$('#slider_home').before('<ul id="nav">').cycle({
		fx: 'fade',
		speedIn:1000,  
   		speedOut:500,  
		timeout:9000,
		pager:'#nav',
		slideExpr:'img',
		pagerAnchorBuilder:function(idx, slide){
			return '<li><a href="#">'+slide.alt+'</a></li>';
		},
		cleartype: true, 
		cleartypeNoBg: true,
		fit:0,
		containerResize:1
		});

	$('#emailfeed').blur(function(){
		var valor = $(this).val();
		$('#cad_email').val(valor);	
	});	

	function Prog(id, val){
		$(".dash #"+id).progressbar({
			value: val
		});		
	}

	Prog("inf", eval($("#infVal").text()));
	Prog("sup", eval($("#infSup").text()));
	Prog("alv", eval($("#infAlv").text()));
	Prog("ins", eval($("#infIns").text()));
	Prog("revin", eval($("#infRevin").text()));
	Prog("revex", eval($("#infRevex").text()));
	Prog("acb", eval($("#infAcb").text()));
	Prog("ent", eval($("#infEnt").text()));
	
	for(i=1; i<=3; i++){
		Prog("inf"+[i]+"", eval($("#infVal"+[i]+"").text()));
		Prog("sup"+[i]+"", eval($("#infSup"+[i]+"").text()));
		Prog("alv"+[i]+"", eval($("#infAlv"+[i]+"").text()));
		Prog("ins"+[i]+"", eval($("#infIns"+[i]+"").text()));
		Prog("revin"+[i]+"", eval($("#infRevin"+[i]+"").text()));
		Prog("revex"+[i]+"", eval($("#infRevex"+[i]+"").text()));
		Prog("acb"+[i]+"", eval($("#infAcb"+[i]+"").text()));
		Prog("ent"+[i]+"", eval($("#infEnt"+[i]+"").text()));	
	}
	
	$(".obrasTable tr:even").css({background:"#dddddd"});
	$('#empre').change(function(){
		var valor = $(this).val();
		window.location.href = "http://www.strengenharia.com.br/cliente/acompanhe/"+valor;
	});
	$('#cep').mask("99999-999");
	$("#ddd").mask("(99)");
	$("#tel").mask("9999-9999");
	$("#ddd").keydown(function(){
		var ddd = $("#ddd").val();
		if(ddd.length >= 6){
		$("#tel").focus();	
		}
	});
	$('.btn_enviarEmail').click(function(){
		var email = $('#cad_email').val();
		var nome = $('#cad_nome').val();
		if( (email =='')  || (email.indexOf("@")<2) || (email.indexOf(".")<1) ){
			$('.errno').text('Por favor, digite um email válido');
		}
		else if(nome == ''){
			$('.errno').text('Por favor, digite seu nome');	
		}
		else{
		$('#frm_indique2').slideUp();
		$('#indiquesucess').fadeIn();
		$('#frm_indique2').submit();
		}
	});
	$('.generic_search').click(function(){
		var estagio = $('#estagio_obra').val();	
		var local = $('#localidade').val();
		var num = $('#num_quartos').val();
		
		window.location.href = "http://www.strengenharia.com.br/buscar/"+estagio+"/"+local+"/"+num;
	});
	$('.bt_imovel').click(function(){
		var frmType = $('#frmType').val();
		var nome = $('#nome').val();
		var email = $('#email').val();
		var ddd = $('#ddd').val();
		var tel = $('#tel').val();
		var msg = $('#msg').val();
		var imv = $('#imovel').val();
		//$('#shown_info').html('Carregando...');
		$('#shown_info').load("response1.php",{frmType : frmType, imovel:imv, nome : nome, email : email, ddd : ddd, tel : tel, msg : msg}, function(){
			$('#shown_info').html('Sua mensagem foi enviada com sucesso!');	
		});
		$('#frm_info').submit();		
	});
	$("#frm_indique").validate(
	{
            rules:{
               	cad_nome:{
                    required: true,
					minlength:2
                },
                cad_email: {
                    required: true,
                    email: true
                }
            },
            messages:{
               cad_nome:{
                    required: "O campo nome é obrigatorio.",
					minlength: "O campo nome deve conter no mínimo 2 caracteres."
                },
                cad_email: {
                    required: "O campo email é obrigatorio.",
                    email: "O campo email deve conter um email válido."
                }
            }
 
        }
		);	
		
		$('#ender').focus(
		function(){
			$('#cep').val('').attr('readonly',true);
			$(this).removeAttr('readonly');	
			$('#bt_comochegar').attr('name','endereco');
		}
		);
		$('#cep').focus(function(){
			$('#ender').val('').attr('readonly',true);	
			$(this).removeAttr('readonly');	
			$('#bt_comochegar').attr('name','cep');
		})
		
		/*PERIODO*/
		
		$('#periodo').change(function(){
			$('#thumbs3').html('Carregando...');
			$('#frm_periodo').submit();
		});
		
	
	$('.wt input').focus(function(){	
	var Bag = $(this).attr('id');
	var selfValue = Bag.substr(0);	
		if($(this).val() == selfValue){
			$(this).val('');
		}
	}).blur(function(){
	var Bag = $(this).attr('id');
	var selfValue = Bag.substr(0);
		if($(this).val() == ''){
			$(this).val(selfValue);
		}	
	});

		
	/*SLIDES*/
		// We only want these styles applied when javascript is enabled
				$('div.navigation').css({'width' : '330px', 'height' : '260px', 'float' : 'right', 'margin-right' : '10px', 'margin-top' : '17px' });
				//$('div.content').css('display', 'block');
//
//				// Initially set opacity on thumbs and add
//				// additional styling for hover effect on thumbs
//				var onMouseOutOpacity = 0.67;
//				$('#thumbs ul.thumbs li').opacityrollover({
//					mouseOutOpacity:   onMouseOutOpacity,
//					mouseOverOpacity:  1.0,
//					fadeSpeed:         'fast',
//					exemptionSelector: '.selected'
//				});
				
				// Initialize Advanced Galleriffic Gallery
				
	var gallery = $('#gallery').galleriffic('#navigation', {
		delay:                2000,
		numThumbs:            9,
		imageContainerSel:    '#slideshow',
		//controlsContainerSel: '#controls',
		titleContainerSel:    '#image-title',
		descContainerSel:     '#image-desc',
		downloadLinkSel:      '#download-link',
		fixedNavigation:	   true,
		galleryKeyboardNav:	   false,
		autoPlay:			   false,
		enableBottomPager:         true,
		nextPageLinkText:          'Próxima >',
		prevPageLinkText:          '< Anterior',
	});
	
	gallery.onFadeOut = function() {
		$('#details').fadeOut('fast');
	};
	
	gallery.onFadeIn = function() {
		$('#details').fadeIn('fast');
		$('#slideshow').append('<span class="lupaRoof"></span>');
	};
	
	
	var gallery2 = $('#gallery2').galleriffic('#navigation2', {
		delay:                2000,
		numThumbs:            9,
		imageContainerSel:    '#slideshow2',
		//controlsContainerSel: '#controls',
		titleContainerSel:    '#image-title2',
		descContainerSel:     '#image-desc',
		downloadLinkSel:      '#download-link',
		fixedNavigation:	   true,
		galleryKeyboardNav:	   false,
		autoPlay:			   false,
		enableBottomPager:         true,
		nextPageLinkText:          'Próxima >',
		prevPageLinkText:          '< Anterior',
	});
	
	gallery2.onFadeOut = function() {
		$('#details2').fadeOut('fast');
	};
	
	gallery2.onFadeIn = function() {
		$('#details2').fadeIn('fast');
		$('#slideshow2').append('<span class="lupaRoof"></span>');
	};
	
	
	var gallery3 = $('#gallery3').galleriffic('#navigation3', {
		delay:                2000,
		numThumbs:            9,
		imageContainerSel:    '#slideshow3',
		//controlsContainerSel: '#controls',
		titleContainerSel:    '#image-title3',
		descContainerSel:     '#image-desc',
		downloadLinkSel:      '#download-link',
		fixedNavigation:	   true,
		galleryKeyboardNav:	   false,
		autoPlay:			   false,
		enableBottomPager:         true,
		nextPageLinkText:          'Próxima >',
		prevPageLinkText:          '< Anterior',
	});
	
	gallery3.onFadeOut = function() {
		$('#details3').fadeOut('fast');
	};
	
	gallery3.onFadeIn = function() {
		$('#details3').fadeIn('fast');
		$('#slideshow3').append('<span class="lupaRoof"></span>');
	};
			
});
