﻿var ASA_ABERTA = true;
var bate_asinha = function(){
    if(ASA_ABERTA){
        $(".twitter").css("background-position", "0 -42px");
        ASA_ABERTA = false;
    }else{
        $(".twitter").css("background-position", "0 0");
        ASA_ABERTA = true;
    }
}

var anota = {
	init : function(){
		this.buttons.init();
	},
	
	buttons : {
		init : function(){
			this.gimemore();
			this.callForm();
		},
		
		gimemore : function() {
			$('.gimmemore').unbind().bind({
				mouseenter : function(){
					//TODO: Fx
				},
				mouseout : function(){
					//TODO: Fx					
				},
				click : function(){
					//TODO: Call to action
				}
			});
			
		},
		
		callForm : function() {
			$('#send-phrase').unbind().bind({
				mouseenter : function(){
					//TODO: Fx
				},
				mouseout : function(){
					//TODO: Fx
				},
				click : function(){
					anota.modal.open();
				}
			});
			
		},
				
		sendForm : function(){
			$('.send-button').unbind().bind({
				click : function(){
					anota.form.send();
				}
			});
			
		},
		
		close : function(){
			$('.close').unbind().bind({
				click : function(){
					anota.modal.close();
				}
			})
		},		
	},

	modal : {
		isVisible : false,
		open : function() {
			var self = this;
			if(this.isVisible) 
				return;
			$('#modal').stop().fadeIn(200, function(){
				self.isVisible = true;
				anota.buttons.sendForm();
				anota.buttons.close();
			});
			$('.gimmemore').hide();
			$('.send-button').fadeIn(200);
		},
		
		close : function() {
			var self = this;
			$('.gimmemore').fadeIn(200);
			$('#modal').stop().fadeOut(200, function(){
				self.isVisible = false;
			});
			$('.send-button').stop().fadeOut(200);
		}		
	},
	
	form : {
		send : function(){
			//TODO: If success
			$('form', '#modal').animate({
				opacity:0
			}, 200, function(){
				$('#success').fadeIn(200);
			});
			setTimeout(function(){
				$('.close').trigger('click');
				$('.gimmemore a').trigger('click');
			},3000);
		}
	}
}

$(document).ready(function(){
	anota.init();
    $("#content figure")
        .animate({top:80}, 500)
        .animate({top:110}, 800);
    
    var voa_beja_flor = [{'left': 0, 'top': 0, 'speed': 500},
                         {'left': 0, 'top': 150, 'speed': 2000},
                         {'left': 240, 'top': 40, 'speed': 500},
                         {'left': 366, 'top': 69, 'speed': 1000},
                         {'left': 366, 'top': 65, 'speed': 500},
                         {'left': 366, 'top': 69, 'speed': 500},
                         {'left': 366, 'top': 65, 'speed': 500},
                         {'left': 500, 'top': 100, 'speed': 500},
                         {'left': 640, 'top': 60, 'speed': 1000},
                         {'left': 790, 'top': 200, 'speed': 500},
                         {'left': 870, 'top': 100, 'speed': 500},
                         {'left': 900, 'top': 400, 'speed': 500}]
    
    $(".twitter").click(function(){
        setInterval("bate_asinha();", 150);
        
        var n = $(".twitter").queue("fx");
        for(i=0;i<voa_beja_flor.length-1;i++){
            $(".twitter").animate({left:voa_beja_flor[i].left, top:voa_beja_flor[i].top}, {duration:voa_beja_flor[i].speed, specialEasing: {
                  width: 'easeOutBounce',
                  height: 'easeOutBounce' }})
        }
        setTimeout("window.location.href='"+$('#twitter_url').val()+"';", 4000);
        
    });
});