//background position fix plugin
(function($){if(!document.defaultView||!document.defaultView.getComputedStyle){var oldCurCSS=jQuery.curCSS;jQuery.curCSS=function(elem,name,force){if(name==='background-position'){name='backgroundPosition'}if(name!=='backgroundPosition'||!elem.currentStyle||elem.currentStyle[name]){return oldCurCSS.apply(this,arguments)}var style=elem.style;if(!force&&style&&style[name]){return style[name]}return oldCurCSS(elem,'backgroundPositionX',force)+' '+oldCurCSS(elem,'backgroundPositionY',force)}}var oldAnim=$.fn.animate;$.fn.animate=function(prop){if('background-position'in prop){prop.backgroundPosition=prop['background-position'];delete prop['background-position']}if('backgroundPosition'in prop){prop.backgroundPosition='('+prop.backgroundPosition}return oldAnim.apply(this,arguments)};function toArray(strg){strg=strg.replace(/left|top/g,'0px');strg=strg.replace(/right|bottom/g,'100%');strg=strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");var res=strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);return[parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]]}$.fx.step.backgroundPosition=function(fx){if(!fx.bgPosReady){var start=$.curCSS(fx.elem,'backgroundPosition');if(!start){start='0px 0px'}start=toArray(start);fx.start=[start[0],start[2]];var end=toArray(fx.options.curAnim.backgroundPosition);fx.end=[end[0],end[2]];fx.unit=[end[1],end[3]];fx.bgPosReady=true}var nowPosX=[];nowPosX[0]=((fx.end[0]-fx.start[0])*fx.pos)+fx.start[0]+fx.unit[0];nowPosX[1]=((fx.end[1]-fx.start[1])*fx.pos)+fx.start[1]+fx.unit[1];fx.elem.style.backgroundPosition=nowPosX[0]+' '+nowPosX[1]}})(jQuery);
			
$(document).ready(function(){
						   
	$('#ft_bt_bx').show();
	
	//navegacao sonhos
	$('#next').click(function(){
							  var count = 0;
							  $('.bounce').animate( {opacity: 0}, 500, function(){
																				if(count == 0){
																					$('.bounce').animate( {opacity: 1}, 500);
																					count++;
																				} else {	
																					count++;
																				}
																				if(count == 4){
																					avanca();
																				}
																			});				  
																		});	
	$('#previous').click(function(){ 
								  var count = 0;
								  $('.bounce').animate( {opacity: 0}, 500, function(){
																				   if(count == 0){
																						$('.bounce').animate( {opacity: 1}, 500);
																						count++;
																				   } else {
																					   count++;
																				   }
																					if(count == 4){	
																						retrocede();
																					}
								   											});	
								  										});

	$('#logo').ready(function(){
		if (!jQuery.browser.msie) {
			animaHeader();
		}				  	  
	});
	
});

function bounce(object, oldx, oldy) {
	newx = oldx + Math.floor(5*Math.random());
	newy = oldy + Math.floor(5*Math.random());
	newspeed = 400 + Math.floor(10*Math.random());
	$(object).animate({top: newx + 'px ', left: newy + 'px'}, newspeed, function() { bounce(object, oldx, oldy);});
}

function animaHeader(){
	$('#nuvem1').css('opacity', 0);
	$('#nuvem2').css('opacity', 0);
	$('#nuvem3').css('opacity', 0);
	$('#nuvem4').css('opacity', 0);
	
	$('#nuvem1').animate({opacity: 1}, 1000,function(){
			 bounce('#nuvem1', 160, 75);
			 $('#nuvem3').animate({opacity: 1}, 800,function(){
						  bounce('#nuvem3', 280, 580);
						  $('#nuvem2').animate({opacity: 1}, 600,function(){
									   bounce('#nuvem2', 252, 254);
									   $('#nuvem4').animate({opacity: 1}, 500,function(){
												   bounce('#nuvem4', 160, 746);
												   });
									   });
						  });
			 });
	

	$('#menina').css('top', '-217px');
	$('#menina').css('left', '842px');
	
	function animaMenina(){
		$('#menina').animate({top: 0, 'left': '625'}, 1000, function(){});
	}	
}

//FUN��ES DE CONTROLE DA NAVEGA��O
	var grupoAtual = 1;
	$(document).ready(function(){
		$('.grupo1').addClass('on');
	});
	
	function avanca(){	
		$('.grupo' + grupoAtual).removeClass('on');
		$('.grupo' + grupoAtual).css('display', 'none');
		if(grupoAtual < 4){
			grupoAtual++;	  
		} else {		
			grupoAtual = 1;				  
		}		
		$('.grupo' + grupoAtual).addClass('on');				
	}
	
	function retrocede(){
		$('.grupo' + grupoAtual).removeClass('on');
		$('.grupo' + grupoAtual).css('display', 'none');	
		
		if(grupoAtual > 1){
			grupoAtual--; 
		} else {
			grupoAtual = 4;
		}
		$('.grupo' + grupoAtual).addClass('on');
	}	

//PRELOAD IMAGES
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
