// vars
var tweets;
var index = 0;
var pages = 20;
var pageInterval = 5000;
// social button hover effect
$(".socialbutton img").hover(
	function(){this.src = this.src.replace("_n","_h");},
	function(){this.src = this.src.replace("_h","_n");}
);
// get data
function getSocialData(count){
	// fetch data from php
	var data = 'count='+count;
	$.ajax({
        url: "assets/twitterfetcher/socialprinter.php",
        type: "GET",
		dataType:'json',
        data: data,
        cache: true,
        success: function (json){
			// save data
			tweets = json;
			// show next tweet
			showTweets();
        },
		error: function(jqxhr, textstatus, errorthrown){
			// error occurred
			var output = '<img src="assets/img/tw_in.jpg"/>' + '<a href="http://www.twitter.com/sevenedge" target="_blank">Oops, something went wrong. Click here to check our Twitter feed</a>' + '<img src="assets/img/tw_out.jpg"/>';
			$('#socialtwmessage').html(output);
		}
    });
}
function showTweets(){
	showNextTweet();
	//
	setInterval(function(){
		index++;
		showNextTweet();
	}, pageInterval);
}
function showNextTweet(){
	// hide current data
	$('#socialtwmessage').hide();
	// show new tweet
	var output = '<img src="assets/img/tw_in.jpg"/>' + tweets[index % pages] + '<img src="assets/img/tw_out.jpg"/>';
	$('#socialtwmessage').html(output);
	//display the body with fadeIn transition
	$('#socialtwmessage').fadeIn('fast');
}
// fetch items
getSocialData(pages);
