// Google Maps 
	
function initialize() {
	var myLatlng = new google.maps.LatLng(-23.530861, -46.736936);
    var myOptions = {
		zoom: 16,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("googleMaps"), myOptions);
}
  
function loadScript() {
	var script = document.createElement("script");
	script.type = "text/javascript";	
	script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
	document.body.appendChild(script);
	
	/*height:280px; width:480px;*/
}
	  



$(document).ready(function(){

	// Google Maps
	if($('#googleMaps')[0]){
		window.onload = loadScript;
	}

	if($('#hs_container')[0]){
	
		$('#preloader').css('height',$('body').height());
	
		//custom animations to use
		//in the transitions
		var animations		= ['right','left','top','bottom','rightFade','leftFade','topFade','bottomFade'];
		var total_anim		= animations.length;
		
		//just change this to one of your choice
		var easeType		= 'swing';
		
		//the speed of each transition
		var animSpeed		= 850;
		
		//caching
		var $hs_container	= $('#hs_container');
		var $hs_areas		= $hs_container.find('.hs_area');
		
		//first preload all images
		$hs_images          = $hs_container.find('img.item');
		var total_images    = $hs_images.filter('img').length;
		var cnt             = 0;
		
		loadImages	= function() {
			return $.Deferred(
				function(dfd) {
					
					loaded = 0;
					$hs_images.each(function(){
					
						var $this = $(this);
						
						if (!$this.html()) {
						
							$('<img/>').load(function(){
								++cnt;

								if(cnt == total_images){
								
									$hs_areas.each(function(){
										
										var $area 		= $(this);
										
										$area.data('over',true).bind('teste',function(){
										
											if($area.data('over')){
												$area.data('over',false);
												
												var total		= $area.children().filter('img').length;
												
												var $current 	= $area.find(':visible').filter('img');

												var idx_current = $current.index();

												var $next		= (idx_current == total-1) ? $area.children(':first').filter('img') : $current.next('img');

												$next.show();
												
												var anim		= animations[Math.floor(Math.random()*total_anim)];
												switch(anim){

													case 'right':
														$current.animate({
															'left':$current.width()+'px'
														},
														animSpeed,
														easeType,
														function(){
															$current.hide().css({
																'z-index'	: '1',
																'left'		: '0px'
															});
															$next.css('z-index','9999');
															$area.data('over',true);
														});
														break;

													case 'left':
														$current.animate({
															'left':-$current.width()+'px'
														},
														animSpeed,
														easeType,
														function(){
															$current.hide().css({
																'z-index'	: '1',
																'left'		: '0px'
															});
															$next.css('z-index','9999');
															$area.data('over',true);
														});
														break;

													case 'top':
														$current.animate({
															'top':-$current.height()+'px'
														},
														animSpeed,
														easeType,
														function(){
															$current.hide().css({
																'z-index'	: '1',
																'top'		: '0px'
															});
															$next.css('z-index','9999');
															$area.data('over',true);
														});
														break;

													case 'bottom':
														$current.animate({
															'top':$current.height()+'px'
														},
														animSpeed,
														easeType,
														function(){
															$current.hide().css({
																'z-index'	: '1',
																'top'		: '0px'
															});
															$next.css('z-index','9999');
															$area.data('over',true);
														});
														break;

													case 'rightFade':
														$current.animate({
															'left':$current.width()+'px',
															'opacity':'0'
														},
														animSpeed,
														easeType,
														function(){
															$current.hide().css({
																'z-index'	: '1',
																'left'		: '0px',
																'opacity'	: '1'
															});
															$next.css('z-index','9999');
															$area.data('over',true);
														});
														break;

													case 'leftFade':
														$current.animate({
															'left':-$current.width()+'px','opacity':'0'
														},
														animSpeed,
														easeType,
														function(){
															$current.hide().css({
																'z-index'	: '1',
																'left'		: '0px',
																'opacity'	: '1'
															});
															$next.css('z-index','9999');
															$area.data('over',true);
														});
														break;

													case 'topFade':
														$current.animate({
															'top':-$current.height()+'px',
															'opacity':'0'
														},
														animSpeed,
														easeType,
														function(){
															$current.hide().css({
																'z-index'	: '1',
																'top'		: '0px',
																'opacity'	: '1'
															});
															$next.css('z-index','9999');
															$area.data('over',true);
														});
														break;

													case 'bottomFade':
														$current.animate({
															'top':$current.height()+'px',
															'opacity':'0'
														},
														animSpeed,
														easeType,
														function(){
															$current.hide().css({
																'z-index'	: '1',
																'top'		: '0px',
																'opacity'	: '1'
															});
															$next.css('z-index','9999');
															$area.data('over',true);
														});
														break;		
													default:
														$current.animate({
															'left':-$current.width()+'px'
														},
														animSpeed,
														easeType,
														function(){
															$current.hide().css({
																'z-index'	: '1',
																'left'		: '0px'
															});
															$next.css('z-index','9999');
															$area.data('over',true);
														});
														break;
												}	
											}
										});
										
										
										
										$area.hover(function(){
																
											$(this).siblings().stop(false,false).fadeTo('fast',0.4);
											$(this).append('<p id="hoverTxt" class="noCufon"><a href="portfolio" title="Lorem Ipsum" class="noCufon"><strong>'+$(this).find('img:visible').attr('title')+'</strong>'+$(this).find('img:visible').attr('alt')+'<span>&nbsp;veja mais +</span></a></p>');
											
										},function(){
											
											$(this).siblings().stop(false,false).fadeTo('fast',1);
											$('#hoverTxt').remove();
											
										});
										
										loaded++;
										if(loaded === total_images/2){
											dfd.resolve();
										}
										
									});
									

									
								}
							}).attr('src',$this.attr('src'));
							
						}
								
					});
					
				}
			).promise();
		}				
		
		$.when(loadImages()).done(function(){
			$('#preloader').fadeOut(1000);
			$('.preloader').fadeIn(800);
			$('#preloader').remove();
		});

		function initAnim(){
			$hs_areas.trigger('teste');
		}

		var interval = setInterval(initAnim,8000);	
		
		$hs_container.hover(
			function(){
				clearInterval(interval);
			},
			function(){
				initAnim();
				interval = setInterval(initAnim,8000);
			}
		);
		
	}else{
		$('#preloader').remove();
		$('.preloader').show();
	}
	
	$('#slider .slider').jcarousel({
    	wrap: 'circular',
		auto: 5,
		animationStepCallback: function() {
		
			Cufon.replace('h5',{textShadow: '#000 1px 1px 1px'});
		}
    });
	

	
	// insere logo uti no rodapé
	$('#ass p a').html('<img class="pngFix" src="img/uti-das-ideias.png" alt="Uti das Ideias | Web e Design"/>');
	
	// cufon
	
	Cufon.replace('h1',{textShadow: '#4c4233 -1px -1px 1px'});
	
	Cufon.replace('h3',{textShadow: '#444 -1px -1px 1px'});
	Cufon.replace('#news h3',{textShadow: '#4c4233 -1px -1px 1px'});
	Cufon.replace('.mainNews h3',{textShadow: '#4c4233 -1px -1px 1px'});
	Cufon.replace('.noticias .absContainer ul li h3',{textShadow: '#4c4233 -1px -1px 1px'});
	
	Cufon.replace('.date',{textShadow: '#4c4233 -1px -1px 1px'});
	Cufon.replace('.mainNews .date',{textShadow: '#4f090a -1px -1px 1px'});
	Cufon.replace('p:not(.noCufon)');
	Cufon.replace('label');
	Cufon.replace('.title p strong',{textShadow: '#4c4233 -1px -1px 1px'});
	Cufon.replace('h2',{textShadow: '#a0988a 1px 1px 1px'});
	Cufon.replace('h4',{textShadow: '#e4babe 1px 1px 1px'});
	//Cufon.replace('h5',{textShadow: '#000 1px 1px 1px'});
	Cufon.replace('#top ul li a',{textShadow: '#830a0b 0px 1px 1px',hover: true});
	Cufon.replace('#footer ul li a',{textShadow: '#830a0b 0px 1px 1px',hover: true});

	// fx
	
	$('#main').append('<div class="fx-main"></div>');
	$('#news').append('<div class="fx-news"></div>');
	
	// fancybox
	if($('.iframe')[0]){
	
		if($('.iframe').hasClass('noticia')){
			var w = 700;
			var h = 500;
		} else if($('.iframe').hasClass('servico')) {
			var w = 600;
			var h = 250;
		} else {
			var w = 900;
			var h = 572;
		}
	
		$('.iframe').fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	400, 
			'speedOut'		:	200, 
			'width'			:	w,
			'height'		:	h
		});
	}
	
	if($('.flashMsg')[0]){
		var $html = $('#flashMessage').html();
		$('#flashMessage').remove();
		$('.flashMsg').html($html);
	}
	
});



