Shout 						= 	new Object;
Shout.Init					=		function() {
	//Shout.GetTweets();
	// shake!!
	window.setTimeout('Shout.Shake.Anim()', 3000);
	
	// social clicks	
	$('#social li a.twitter').bind('mouseover', 		function() { Shout.MOver({c:'twitter',x:'0', y:'-26px'}); });
	$('#social li a.twitter').bind('mouseout', 			function() { Shout.MOut({c:'twitter',x:'0', y:'0'}); });
	$('#social li a.twitter').bind('click', 				function() { Shout.MClick({c:'twitter'}); });
	$('#social li a.facebook').bind('mouseover', 	function() { Shout.MOver({c:'facebook',x:'-30px', y:'-26px'}); });
	$('#social li a.facebook').bind('mouseout', 	function() { Shout.MOut({c:'facebook',x:'-30px', y:'0'}); });
	$('#social li a.facebook').bind('click', 			function() { Shout.MClick({c:'facebook'}); });

}
//		shake thing
//		shake thing
//		shake thing
Shout.Shake			=		new Object;
Shout.Shake._x 		= 	['+=3', '-=5', '+=7', '=2', '-=2', '+=7' , '-=5', '0'];
Shout.Shake._y 		= 	['-=2', '+=7' , '-=5', '+=3', '+=3', '-=5', '+=7', '0'];
Shout.Shake._t 		= 	[10, 15, 20, 5, 10, 15, 20, 5];
Shout.Shake._c		= 	0;
Shout.Shake.Anim 	= 	function(q) {
	if (q) Shout.Shake._c=0;
	$('#shout').animate({
		left: Shout.Shake._x[Shout.Shake._c],
		top: Shout.Shake._y[Shout.Shake._c],
	}, Shout.Shake._t[Shout.Shake._c], function() {
		Shout.Shake.N();
  });
	
 }
Shout.Shake.N = function() { 
	if (this._c < this._x.length) { 
		if (this._c==3) window.setTimeout('Shout.Shake.Anim()', 7000);
		else Shout.Shake.Anim();
	}
		else window.setTimeout('Shout.Shake.Anim("r")', 7000);
	this._c++;
	
}



//		twitter widget
Shout.GetTweets	=	function() {
	$.jTwitter('festashout', 5, function(data){
		Shout._d			 	= data;
		Shout._t 				= Shout._d.length;
		Shout.Controller();				
	});
}
Shout.Controller			=		function() {
	this.Count();
	this.View();
}
Shout.View					=		function() {
	$('#twitter div').fadeOut('slow', function() {
				
		$('#twitter div').html('<p>'+ Shout.LinkRegex(Shout._d[Shout._n].text) + '</p> <span class="author">' + Shout._d[Shout._n].created_at + '</span>');		
		$('#twitter div').fadeIn('slow');
		Shout.Cycle();
	});
}
Shout.LinkRegex				=		function(t) {
	var rp1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
	var rp = t.replace(rp1, '<a href="$1" target="_blank">$1</a>');
	var rp2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
	var rp = rp.replace(rp2, '$1<a href="http://$2" target="_blank">$2</a>');
	var rp3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
	var rp = rp.replace(rp3, '<a href="mailto:$1">$1</a>');
	return rp;
}
Shout.Cycle				=		function() {
	window.setTimeout('Shout.Controller()', 7000);
}
Shout.Count				= function() {
		if ((this._n+1) < this._t) this._n++;
		else this._n =0;
}
	
		
// social buttons
Shout.MOver		=	 function(o){
	$('#social li a.'+o.c)
		.stop()
		.animate({backgroundPosition:'"('+o.x+' '+o.y+')"'}, {duration:200});
}
Shout.MOut		=	 function(o){
	$('#social li a.'+o.c)
		.stop()
		.animate({backgroundPosition:'"('+o.x+' '+o.y+')"'}, {duration:200});
}		
Shout.MClick	=	 function(o){
	$('#social li a.'+o.c)
		.stop()
			.unbind('mouseout')
			.unbind('mouseover'); 
}
	
			
$(document).ready(function() { Shout.Init(); });
