// JavaScript Document
var facebookAppID = 191180567585311;
var XID = $('title').text().split(" ").join("");

function addTwitterFeed(twitterContainer, twitterID){
	if(twitterID.search("@") !== -1){
		twitterID=twitterID.split("@")[1];
	}
	twitterID = trimString(twitterID);
	var tweeturl = "http://twitter.com/statuses/user_timeline/"+twitterID+".json?count=10&callback=?";
		$(twitterContainer).html('');
				$.getJSON(tweeturl, function(data){
					$.each(data, function(i, item) {
						//var rtText = $.URLEncode(item.text);
                        var rtText =item.text;
						var link =  "http://twitter.com/home?status=RT @CaesarsPalace" + rtText;
	   					$('<div style="margin-bottom:15px;"></div>').html("<div class='tweetText '><!--<a class='tweetLink' href='http://twitter.com/"+twitterID+"/statuses/" + item.id + "'>-->" + item.text + "<!--</a>--></div><div class='retweet'><div class='tweetTime'>" + item.created_at + "</div>").appendTo(twitterContainer); 
	  				}); 
				});
}

function addComments(){
	$("#Comments").append("<fb:comments css='http://www.caesars.com/css_includes/2011_templates/comments.css?12' notify='true' simple='1' width='364' height='170' title='' url='' xid='"+XID+"'></fb:comments>");
}

function addSweeps(){
	$("#Sweeps").html('<div id="context_widget"></div>');
	$.getScript('http://grindle.contextoptional.com/plugin/loader.js');
}

function addLikeButton(action){
	var relPath;
	$(".facebookLB").each(function(){
		relPath = '';
		if($(this).find('a').attr('rel')){
			relPath = ($(this).find('a').attr('rel').length>0)?'href="'+$(this).find('a').attr('rel')+'"' : ''; 
		}
		
		$(this).html('<fb:like '+relPath+' layout="button_count" show_faces="false"  send="true" action="'+action+'" font="arial"></fb:like>');
	});
}

function addGooglePlusOne(){
		var relPath;
	$(".googlePO").each(function(){
		relPath = '';
		if($(this).find('a').attr('rel')){
			relPath = ($(this).find('a').attr('rel').length>0)?'href="'+$(this).find('a').attr('rel')+'"' : ''; 
		}
		$(this).html('<g:plusone annotation="bubble" width="150" '+relPath+' size="medium"></g:plusone>');
	});
	if($(".googlePO").length > 0){
		connectToGoogle();
	}
}

function addTwitterShare(){
		var dataUrl;
		var dataText;
		var dataCountUrl;
	$(".twitterShare").each(function(){
		if($(this).find('a').attr('rel')){
			dataUrl = ($(this).find('a:eq(0)').attr('rel').length>0)?'data-url="'+$(this).find('a:eq(0)').attr('rel')+'"' : '';
			dataCountUrl = ($(this).find('a:eq(0)').attr('rel').length>0)?'data-counturl="'+$(this).find('a:eq(0)').attr('rel')+'"' : ''; 
			dataText = ($(this).find('a:eq(1)').attr('rel').length>0)?'data-text="'+$(this).find('a:eq(1)').attr('rel')+'"' : '';
		}
		$(this).html('<a href="https://twitter.com/share" class="twitter-share-button" data-count="none"'+dataText+' '+dataUrl+' '+dataCountUrl+'>Tweet</a>');
	});
	if($(".twitterShare").length > 0){
		connectToTwitter();
	}
}

function connectToFacebook(){
	$('body').prepend('<div id="fb-root"></div>');
	$.getScript('http://connect.facebook.net/en_US/all.js#appId='+facebookAppID+'&xfbml=1', function() {
		 FB.init({
		  appId  : facebookAppID,
		  status : true, // check login status
		  cookie : true, // enable cookies to allow the server to access the session
		  xfbml  : true  // parse XFBML
		});
	});
}
function connectToGoogle(){
		$.getScript('https://apis.google.com/js/plusone.js');
}
function connectToTwitter(){
		$.getScript('http://platform.twitter.com/widgets.js');
}
