 /* jTwitter 1.1.1 - Twitter API abstraction plugin for jQuery*/
(function( $ ){
	$.extend( {
		jTwitter: function( username, numPosts, fnk ) {
			var info = {};
			
			// If no arguments are sent or only username is set
			if( username == 'undefined' || numPosts == 'undefined' ) {
				return;
			} else if( $.isFunction( numPosts ) ) {
				// If only username and callback function is set
				fnk = numPosts;
				numPosts = 1;
			}
			
			var url = "https://twitter.com/status/user_timeline/" +
				username + ".json?count="+numPosts+"&callback=?";

			$.getJSON( url, function( data ){
				if( $.isFunction( fnk ) ) {
					fnk.call( this, data );
				}
			});
		}
	});
})( jQuery );
/* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& */
//set data arrays
var tPost = [];
var fPost = [];
//var thisDate = [];

/*Enter user info here  */
var twitter_icon = "/ot-images/ico_twitter_32x32.png";
var twitterLink = "https://twitter.com/#!/outdoortech";
var twitterNumOfPosts = 2;

var facebook_icon = "/ot-images/ico_facebook_32x32.png";
var facebookLink = "https://www.facebook.com/OutdoorTechnology";

var totalNumOfPosts = 2;
var finalPostArray = [];
var finalIconArray =[];
var finalLinkArray = [];

var fbtwUpdate =
{
	init: function()
	{
			//get twitter 
			fbtwUpdate.twitterPost();
			//get facebook 
			fbtwUpdate.facebookPost();
	},
	
	twitterPost: function()
		{
		
		/* Twitter Javascript **************************************************************************************************   **************************************************************************************************
			JTwitter() takes 2 arguments  
			Twitter account name & Number of posts
			go to the folowing url to see the possible return data: http://jquery-howto.blogspot.com/2009/11/jquery-twitter-plugin-update-jtwitter.html
		*/
    // Get latest 1 tweets by outdoortech
    $.jTwitter('outdoortech', twitterNumOfPosts, function(data){
        $('#posts').empty();
        $.each(data, function(i, post){
      //  alert(post.text);
        tPost.push(post.text);
        //don't need to compare dates anymore
        //thisDate.push(post.created_at);
        });
    });
   },

	facebookPost: function()
	{
	/* Face Book Function **************************************************************************************************************************************************************************************************** */
    $.ajax({
        type:"GET",
        url:"https://graph.facebook.com/42260100207/feed",
        data:"access_token=191727675663|6c09ddf48de994698cfb24eeb4af3501&format=jsonp",
        success:function(feed) {
		for(y=0, yy = feed.data.length; y<yy; y++){
			if (feed.data[y].message !== undefined && feed.data[y].from.id == "42260100207"){
					fPost.push(feed.data[y].message);
					//don't need to compare dates anymore
					//thisDate.push(feed.data[y].created_time);
			}
		}
			//don't need to compare dates anymore
			//fbtwUpdate.recentPost(thisDate[0],thisDate[1]);

			//update webpage
			fbtwUpdate.postToweb();
        },
        dataType:"jsonp"
    });
	},
	//don't need to compare dates anymore
	/*recentPost: function(twitter,facebook){
				var twitterDate = new Date(twitter);
				var facebookDate = new Date(facebook.replace(/\-/g,'\/').replace(/T/,' ').replace(/\+/,' -0'));
					if(twitterDate > facebookDate){
							fbtwUpdate.postToweb(twitterLink,thisPost[1],twitter_icon);
					}else{
							fbtwUpdate.postToweb(facebookLink,thisPost[1],facebook_icon);
					};
	},*/
	
	postToweb: function(){
	//(sociallink, socialText, image){
				//don;t need to restrict size anymore
				//find out length of text and edit text
				/*if(socialText.length > 70 && socialText.length < 120 ){
					socialText = "<span style='font-size:small'>"+socialText+"</span>";
				} else if(socialText.length > 120){
					socialText = socialText.substr(0,120);
					socialText = socialText.substr(0, socialText.lastIndexOf(' '));
					socialText += "...";
					socialText =  "<span style='font-size:small'>"+socialText+"</span>";
				}*/
				
				//place list of posts in alternating array
				for(ot = 0, otot = totalNumOfPosts; ot<otot; ot++){
					finalPostArray.push(tPost[ot]);
					finalIconArray.push(twitter_icon);
					finalLinkArray.push(twitterLink);

					finalPostArray.push(fPost[ot]);
					finalIconArray.push(facebook_icon);
					finalLinkArray.push(facebookLink);

				}
				var html="<div id='socialcontainer'  class='TCfullscreen'><ul>";
				for(hi = 0; hi< finalPostArray.length; hi++){

				//customize this area for print out for customer	
				

				html += "<li class='socialupdate'><a href='"+finalLinkArray[hi]+"' target='_blank'>"+
				"<div><img width='28' src='"+finalIconArray[hi]+"'/></div>"+
				"&nbsp;<div class='socialtext'>";
				if(finalPostArray[hi].length > 100){
				html+= "<marquee behavior='scroll' direction='left' scrollamount='3' width='900'>"+finalPostArray[hi]+"</marquee>";
				}else{
				html += finalPostArray[hi];
				}
				html += "</div></a></li>";
				
					}
				html += "</ul></div><!-- end of social container-->";
				$('#social-bubble').html(html);
				$(function(){
					$("#socialcontainer > ul").anythingSlider({ 
						theme : 'ot', 
						vertical: true, 
						buildNavigation : false, 
						buildStartStop : false, 
						autoPlay : true, 
						autoPlayLocked : true, 
						delay : 15*1000, 
						expand : true, 
						buildArrows: false
					});

				});

				$('marquee').marquee('.activePage').mouseover(function () {
					$(this).trigger('stop');
					}).mouseout(function () {
					$(this).trigger('start');
					});
				
				/* Post to web w/JQuery 
				$('.social-image').attr('src',image);
				$('#social-bubble').html(socialText);
				$('.update-bubble').click(function(){
						window.location = sociallink; */
	
	}
	
};
$(function(){
fbtwUpdate.init();
});
