/*@cc_on(function(a,b){function r(a){var b=-1;while(++b<f)a.createElement(e[b])}if(!(!window.attachEvent||!b.createStyleSheet||!function(){var a=document.createElement("div");a.innerHTML="<elem></elem>";return a.childNodes.length!==1}())){a.iepp=a.iepp||{};var c=a.iepp,d=c.html5elements||"abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",e=d.split("|"),f=e.length,g=new RegExp("(^|\\s)("+d+")","gi"),h=new RegExp("<(/*)("+d+")","gi"),i=/^\s*[\{\}]\s*$/,j=new RegExp("(^|[^\\n]*?\\s)("+d+")([^\\n]*)({[\\n\\w\\W]*?})","gi"),k=b.createDocumentFragment(),l=b.documentElement,m=l.firstChild,n=b.createElement("body"),o=b.createElement("style"),p=/print|all/,q;c.getCSS=function(a,b){if(a+""===undefined)return"";var d=-1,e=a.length,f,g=[];while(++d<e){f=a[d];if(f.disabled)continue;b=f.media||b,p.test(b)&&g.push(c.getCSS(f.imports,b),f.cssText),b="all"}return g.join("")},c.parseCSS=function(a){var b=[],c;while((c=j.exec(a))!=null)b.push(((i.exec(c[1])?"\n":c[1])+c[2]+c[3]).replace(g,"$1.iepp_$2")+c[4]);return b.join("\n")},c.writeHTML=function(){var a=-1;q=q||b.body;while(++a<f){var c=b.getElementsByTagName(e[a]),d=c.length,g=-1;while(++g<d)c[g].className.indexOf("iepp_")<0&&(c[g].className+=" iepp_"+e[a])}k.appendChild(q),l.appendChild(n),n.className=q.className,n.id=q.id,n.innerHTML=q.innerHTML.replace(h,"<$1font")},c._beforePrint=function(){o.styleSheet.cssText=c.parseCSS(c.getCSS(b.styleSheets,"all")),c.writeHTML()},c.restoreHTML=function(){n.innerHTML="",l.removeChild(n),l.appendChild(q)},c._afterPrint=function(){c.restoreHTML(),o.styleSheet.cssText=""},r(b),r(k);if(c.disablePP)return;m.insertBefore(o,m.firstChild),o.media="print",o.className="iepp-printshim",a.attachEvent("onbeforeprint",c._beforePrint),a.attachEvent("onafterprint",c._afterPrint)}})(this,document);@*/


$(function(){

	// window adjust
	alignCenter();
	
	$(window).resize(function(){
		alignCenter();
	});
	
	// molecula prepare
	window.setTimeout(function(){
	
		var startPosition = $("nav a.selected").position().left + ( $("nav a.selected").width() / 2 ) -  ( $("#molecula").width() / 2 ) + 5;

		$("#molecula").css({ "left": startPosition  }).show();
		$("nav a.selected").css("color","#454142");
	
	}, 1000);
	
	
	// molecula animate
	$("nav a").mouseover(function(){

		var _self = $(this);
		
		var _x = _self.width() / 2;
		var _left = _self.position().left + _x - ( $("#molecula").width() / 2 ) + 5;

		if( _self.not('.selected') )
			$("nav a").css("color", "#fff");				

		$("#molecula").stop().animate({ "left": _left  }, 300, function(){
			_self.css("color","#454142");	
		});

	});
	
	$("nav").mouseleave(function(){
		var _self = $(this);
		
		var startPosition = $("nav a.selected").position();
		var _left = startPosition.left + ( $("nav a.selected").width() / 2 ) -  ( $("#molecula").width() / 2 ) + 5;

		$("nav a").css("color", "#fff");
		
		$("#molecula").stop().animate({ "left": _left  }, 300, function(){
			$("nav a.selected").css("color","#454142");
		});	
	});

	if( $("#localizacao").length > 0 ) map();

	if( $("#contato").length > 0 ){

		$(".data").mask("99/99/9999");
  		$(".telefone").mask("(99) 9999.9999");

		var escreva = $("#escreva");
		escreva.unbind("submit").bind("submit", function(){
			
			var data = escreva.serializeArray();
			
			$(".ops").removeClass("ops");

			$.each( data, function(i, item){
				
				var field = $("#" + item.name );

				if( item.name == "nome" && $.trim( item.value ) == "" || 
				    item.name == "email" && $.trim( item.value ) == "" || 
				    item.name == "evento" && $.trim( item.value ) == "" || 
					item.name == "telefone" && $.trim( item.value ) == "" || 
				    item.name == "qtde" && $.trim( item.value ) == "" || 
				    item.name == "tipo" && $.trim( item.value ) == "" || 
				    item.name == "mensagem" && $.trim( item.value ) == "" )
					field.addClass("ops");

				if( item.name == "data" && $.trim( item.value ).length < 10 || 
                                    item.name == "evento" && $.trim( item.value ).length < 10)
					field.addClass("ops");

			});

			if( $(".ops").length > 0 ){			
				
				showMessage( "Preencha corretamente os campos (*)" );			

			} else {

				showMessage( "Aguarde, enviando mensagem..." );

				$.ajax({
					url: escreva.attr("action"),
					type: escreva.attr("method"),
					data: data,
					success: function( retorno ){

						alert(retorno);
					
						showMessage( "Mensagem enviada com sucesso!" );
						
						$(".entry").val("");

						window.timeout(function(){
							if( $("#message").is(":visible") ){
								$("#message").hide().html("");
								$("#outer").hide();
							}


						}, 3000);
					}							
				});

			}

			return false;

		});
		
	}

	if( $("#banner").length > 0 ){

		$('#banner').cycle({ fx:'fade', timeout:5000, delay:-5000 });
	
	}
	

	if( $("#espaco").length > 0 ){

		var where = $(".fotos:visible").attr("id");
		$("."+where).eq(1).find(".titulo").addClass("off");

		$(".fotos:visible").cycle({ fx:'fade', speed: 500, timeout: 0, prev:'.nav-left', next:'.nav-right' });

		// titulo		
		$(".titulo").unbind("click").bind("click", function(){

			if( $(".box-show").length > 0 ) $(".box-show").remove();
		
			var _self = $(this);
			var _index = _self.parent().index();
			var _clone = _self.parent().clone();
			
			$(".titulo").removeClass("off");
			_self.addClass("off");

			$(".imagem:visible").hide();			
			$(".content:visible").hide();

			$("#barra-direita").prepend( _clone );
						
			_clone.css("top", "20px").show();
			_clone.find( ".imagem" ).removeClass("hide").show();
			_clone.find( ".content" ).removeClass("hide").show();
			_clone.addClass("box-show");
			
			$(".fotos").hide().removeClass("hide");
			$(".fotos").eq( _index ).show();

			$(".fotos:visible").cycle({ fx:'fade', speed: 500, timeout: 0, prev:'.nav-left', next:'.nav-right' });
			
		});




	}

});

var trava = 0;

var showMessage = function( message ){

	$("#message").hide().html("");
	$("#outer").hide();

	$("#outer").css("opacity", 0.7).show();		
	$("#message").html("<p>"+ message +"</p>");
	var left = $("#outer").width() / 2 - $("#message").width() / 2;
	var top = $("#outer").height() / 2 - $("#message").height() / 2;
	$("#message").css({ "top": top+"px", "left":left+"px" }).show();

	$("#outer, #message").unbind("click").bind("click", function(){
		$("#message").hide().html("");
		$("#outer").hide();
	});

}

var alignCenter = function(){

		var windowHeight = $(window).height();
		var allHeight = $("#all").height();
		
		var adjust = ((windowHeight / 2) - (allHeight / 2)) - $("footer").height();
		
		if( adjust > 0 )
			$("#all").css("margin-top", adjust);

}

var map = function() {

	var latlng = new google.maps.LatLng( -23.54836, -46.527336 );

	var myOptions = {
		zoom: 17,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
	    	disableDefaultUI: true,
		scaleControl: false
	};

	var map = new google.maps.Map(document.getElementById("mapa"), myOptions);

	var marker = new google.maps.Marker({
		position: latlng, 
		map: map, 
		title:"Buffet Trianon"
	});
}

