function initializeMap() {
	var myOptions = {
		zoom: 16,
		//		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var myGeocoder = new google.maps.Geocoder();
	myGeocoder.geocode({
		address:'Avenida Jabaquara, 1909, São Paulo'
	},function(results,status){
		if (status == google.maps.GeocoderStatus.OK) {
			var myLatlng = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
			map.setCenter(myLatlng);
			var marker = new google.maps.Marker({
				map: map, 
				position: myLatlng
			});
		}
	});
}

function loadMap() {
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initializeMap";
	document.body.appendChild(script);
}

$(function() {
	SI.Files.stylizeAll();

	$("#main-nav").jSlip();

	if ($("#slider").length > 0 ) {
		$("#slider").jPresenter({
			url: 'home/get_banners'
		});
	}

	// fade in / fade out links

	$("#social-media ul li a, .call").fadeTo("slow", 0.5); // This sets the opacity of the thumbs to fade down to 60% when the page loads

	$("#social-media ul li a, .call").hover(function(){
		$(this).stop().fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
	},function(){
		$(this).stop().fadeTo("slow", 0.5); // This should set the opacity back to 60% on mouseout
	});


	$("ul#clientes li").fadeTo("slow", 0.5); // This sets the opacity of the thumbs to fade down to 70% when the page loads

	$("ul#clientes li a").hover(function(){
		$(this).parents('li').stop().fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
	},function(){
		$(this).parents('li').stop().fadeTo("slow", 0.5); // This should set the opacity back to 70% on mouseout
	});

	// jquery do news

	$("section#news ul li a").live('mouseenter',function() {
		$(this).addClass("hover").stop()
		.animate({
			paddingBottom: '30px'
		}, 400);
	});
	$("section#news ul li a").live('mouseleave', function() {
		$(this).removeClass("hover").stop()
		.animate({
			paddingBottom: '6px'
		}, 200);
	});

	//  mouseover lista jobs

	$('.job li').live('mouseenter',function() {
		$(this).find('div.hidden').animate({
			top: 6,
			opacity: 1
		}).clearQueue();
	});
	$('.job li').live('mouseleave',function() {
		$(this).find('div.hidden').animate({
			top: '132px',
			opacity: 0.3
		}).clearQueue();
	});

	/*
	 * TOP PANEL - Contato
	 */

	if (jQuery.scrollTo) {
		var tpDuration = 600;

		// CONTATO - rodapé
		$('.contato').bind('click', function(e){
			e.preventDefault();
			tracker._trackPageview("/contato");
			$('#slider-contato header').attr('class','contato');
			if ($('div.wrap-mapa').is(':hidden')) $('div.wrap-mapa').show();
			$.scrollTo('#slider-contato',{
				duration: 800,
				onAfter: function(){
					if ($('#slider-contato div.contact').is(':hidden')) {
						$('#slider-contato div.work').hide();
						$('#slider-contato div.contact').show();
					}
					if ($('#slider-contato').css('height') == '10px') {
						$('#slider-contato').animate({
							height: '244px'
						},{
							duration: tpDuration,
							complete: function(){
								loadMap();
							}
						});
					}
				}
			});
		});

		// TRABALHE CONOSCO - rodapé
		$('.trabalhe').bind('click', function(e){
			e.preventDefault();
			tracker._trackPageview("/trabalhe-conosco");
			$('#slider-contato header').attr('class','trabalhe');
			if ($('div.wrap-mapa').is(':visible')) $('div.wrap-mapa').hide();
			$.scrollTo('#slider-contato',{
				duration: 800,
				onAfter: function(){
					if ($('#slider-contato div.work').is(':hidden')) {
						$('#slider-contato div.contact').hide()
						$('#slider-contato div.work').show();
					}
					if ($('#slider-contato').css('height') == '10px') {
						$('#slider-contato').animate({
							height: '244px'
						},{
							duration: tpDuration
//							complete: function(){
//								loadMap();
//							}
						});
					}
				}
			});
		});

		// CONTATO - menu
		$('#contato').bind('click', function(e){
			e.preventDefault();
			tracker._trackPageview("/contato");
			$('#slider-contato header').attr('class','contato');
			if ($('div.wrap-mapa').is(':hidden')) $('div.wrap-mapa').show();
			$.scrollTo('#slider-contato',{
				duration: 400,
				onAfter: function(){
					if ($('#slider-contato div.contact').is(':hidden')) {
						$('#slider-contato div.work').hide();
						$('#slider-contato div.contact').show();
					}
					if ($('#slider-contato').css('height') == '10px') {
						$('#slider-contato').animate({
							height: '244px'
						},{
							duration: tpDuration,
							complete: function(){
								loadMap();
							}
						});
					}
				}
			});
		});

		$('.fechar').bind('click', function(e){
			e.preventDefault();

			if ($('#slider-contato').css('height') == '244px') {
				$("#map_canvas").html('').removeAttr('style').css({
					'height': '125px',
					'width': '300px'
				});
				$('#slider-contato').animate({
					height: '10px'
				},{
					duration: tpDuration,
					complete: function(){
						if ($('div.wrap-mapa').is(':hidden')) $('div.wrap-mapa').show();
						$("#map-canvas").html('').removeAttr('style').css({
							'height'	: '125px',
							'overflow'	: 'hidden',
							'width'		: '300px'
						});
					}
				});
			}
		});

		$('#slider-contato input[type=submit]').parents('form').ajaxForm({
			dataType: 'json',
			success: function(response, status, xhr, form){
				if (response.error == false) {
					form.fadeOut('fast',function(){
						$(this).parent().append('<span class="mensagem-obrigado" style="display: none">'+response.message+'</span>').find('span.mensagem-obrigado').fadeIn();
					});
				}
			}
		});
	}
});
