$(document).ready(function() {
	var showNotification = IGA.utils.cookie.readCookie('justinbieber_notify');
	if (showNotification == "true") {
		$('#notify-table').slideDown('slow');
	}

	var fansLatestTweets = IGA.twitter();

	//update resulting div container id and template path
	fansLatestTweets.setTemplateUrl('#Tweet_Container', '/templates/tweet.htm');
	//update query name and number of tweets to display on page
	fansLatestTweets.getLatestTweets('thejennaandrews', 3);
	$('#tweet_text').twitterCounter({
		limit: 108,
		counter: '#tweet_char_left',
		okSize: 108,
		okStyle: '.ok',
		watchSize: 20,
		watchStyle: '.watch',
		warningSize: 10,
		warningStyle: '.warning',
		errorSize: 0,
		errorStyle: '.twit_error'
	});
});

function displayFollowerCountProgressBar(followerCount) {
	$("#progressbar").progressbar({
		value: followerCount / 15000
	});
};
$(document).ready(function() {
	$("#twitterPost").bind("click", function() { postTweet(); return false; });

	var showNotification = IGA.utils.cookie.readCookie('justinbieber_notify');
	if (showNotification == "true") {
		$('#notify-table').slideDown('slow');
	}

});
function displayFollowerCountProgressBar(followerCount) {
	$("#progressbar").progressbar({
		value: followerCount / 15000
	});
};

function postTweet() {
	var tweet = $("#tweet_static").html() + " " + $("#tweet_text").val() + $("#tweet_static_url").html();
	var tweetToken = getCookieValue("oauth_token");
	var tweetSecret = getCookieValue("oauth_tokenSecret");
	if (tweetToken == null) {
		var newLocation = encodeURI("/Login.aspx?tweet=") + encodeURIComponent(tweet.toString());
		document.location = newLocation;
		return false;
	}
	var postUrl = "http://att.jennaandrews.idjmg.com/twitter.asmx/PostTweet";
	$.post(postUrl
, {
	token: tweetToken, secret: tweetSecret, message: tweet
}
	, function(data) { });
}

function getCookieValue(key) {
	var pattern = key + "=[^;]*;?"
	var regCookie = new RegExp(pattern);

	var myCookie = null;
	if (regCookie.test(document.cookie)) {
		myCookie = regCookie.exec(document.cookie)[0];
	}
	else
	{ return null; }

	var myCookieValue = myCookie.toString().slice(myCookie.indexOf(key) + key.length + 1, (myCookie.indexOf(";") > 0) ? myCookie.indexOf(";") : myCookie.length);

	return myCookieValue;
}
