﻿$(function () {   
 var DivHtml = new Array();
 var Flag = true;
 var SAccounts = [ "fb^unclebens^http://profile.ak.fbcdn.net/hprofile-ak-snc4/211069_114522715289111_1758054_s.jpg^Uncle Bens",
                   "fb^extraofficial^http://profile.ak.fbcdn.net/hprofile-ak-snc4/187881_120078638034364_5152727_s.jpg^Extra",
                   "fb^orbitgum^http://profile.ak.fbcdn.net/hprofile-ak-ash2/276443_10664469282_2297428_s.jpg^Orbit Gum",
                   "tt^theorbitgirl^^Orbit Gum",
                   "fb^5Gum^http://profile.ak.fbcdn.net/hprofile-ak-snc4/277064_288162265211_176205_s.jpg^5 Gum",
                   "fb^5GumUK^http://profile.ak.fbcdn.net/hprofile-ak-ash2/211105_188117167899871_1052866_s.jpg^5 Gum UK",
                   "fb^Skittles^http://profile.ak.fbcdn.net/hprofile-ak-snc4/277081_7914733474_1699749456_s.jpg^Skittles",
                   "tt^Skittles^^Skittles",
                   "fb^StarBurst^http://profile.ak.fbcdn.net/hprofile-ak-snc4/187908_130405304915_2181580_s.jpg^Star Burst",
                   "fb^Airwaves^http://profile.ak.fbcdn.net/hprofile-ak-snc4/276437_123069251050561_8236597_s.jpg^Airwaves",
                   "fb^lifesaversgummies^http://profile.ak.fbcdn.net/hprofile-ak-snc4/187772_106845072677908_462263_s.jpg^Life Savers Gummies",
                   "fb^altoids^http://profile.ak.fbcdn.net/hprofile-ak-snc4/195796_82862683534_1038458_s.jpg^Altoids",
				   "fb^chewing.gum.freedent^http://profile.ak.fbcdn.net/hprofile-ak-snc4/276677_119136338106958_7200576_s.jpg^Chewing Gum Freedent",
				   "fb^juicyfruit^http://profile.ak.fbcdn.net/hprofile-ak-ash2/188141_109191305769097_3628170_s.jpg^Juicy Fruit",
				   "fb^cesar^http://profile.ak.fbcdn.net/hprofile-ak-snc4/203525_236635545432_5309587_s.jpg^Cesar",
				   "tt^cesarcusine^^Cesar cusine",
				   "tt^pedigreeus^^Pedigree US",
				   "fb^pedigree^http://profile.ak.fbcdn.net/hprofile-ak-snc4/277102_19645788576_54564511_s.jpg^Pedigree",
				   "tt^pedigree^^Pedigree",
				   "tt^MarsDrinks_UK^^Mars Drinks UK",
				   "fb^Crave^http://profile.ak.fbcdn.net/hprofile-ak-snc4/187881_167543013306022_93243_s.jpg^Crave",
				   "fb^TheGoodlifeRecipe^http://profile.ak.fbcdn.net/hprofile-ak-ash2/276889_105296999477_180245924_s.jpg^The Good Life Recipe",
				   "fb^alterracoffee^http://profile.ak.fbcdn.net/hprofile-ak-snc4/211206_19310584836_4283190_s.jpg^Alterra Coffee",
				   "tt^alterracoffee^^ ALterra Coffee",
				   "tt^MMSGreen^^M&Ms Green",
				   "tt^MMSRed^^M&Ms Red",
				   "fb^MMS^http://profile.ak.fbcdn.net/hprofile-ak-snc4/276463_30634981956_1075151275_s.jpg^M&Ms",
				   "tt^snickers^^Snickers",
				   "fb^Snickers^http://profile.ak.fbcdn.net/hprofile-ak-snc4/195702_20645199461_2779147_s.jpg^Snickers",
				   "tt^snickersicecrm^^Snickers Ice Cream",
				   "tt^snickersla^^Snickers LA",
				   "fb^DoveChocolate^http://profile.ak.fbcdn.net/hprofile-ak-snc4/277078_352723179560_334303_s.jpg^Dove Chocolate",
				   "fb^dovediscoveries^http://profile.ak.fbcdn.net/hprofile-ak-snc4/203550_70752669789_5450684_s.jpg^Dove Discoveries",
				   "tt^dove_chocolate^^Dove Chocolate",
				   "tt^dcd_sweetie^^DCD Sweetie",
				   "fb^TwixItUp^http://profile.ak.fbcdn.net/hprofile-ak-ash2/187931_52535960977_3650208_s.jpg^Twix It Up",
				   "tt^cocoapro^^Cocoa Pro",
				   "fb^seramis.net^http://profile.ak.fbcdn.net/hprofile-ak-snc4/188060_122466173785_7053230_s.jpg^Saramis",
				   "tt^wisdompanel^^Wisdom Panel",
				   "fb^doggiedna^http://profile.ak.fbcdn.net/hprofile-ak-snc4/71156_70437008896_5966879_s.jpg^Doggie DNA",
				   "fb^MasterFoods^http://profile.ak.fbcdn.net/hprofile-ak-snc4/203516_187033474668373_6447565_s.jpg^Master Foods",
				   "tt^seedsofchange^^Seeds Of Change"];
				   
function FillDiv(Type,AccName,AccImg,DisName){
    
    var url="";
    if(Type==="fb"){
        url = "https://graph.facebook.com/"+AccName+"/posts?access_token=221239957925883|a9f3c76cd23dd24e73c97f526ff98dc2&limit=1&callback=?";
        $.getJSON(url,function(fbdata){
			if(!$.isEmptyObject(fbdata)){
				$.each(fbdata.data,function(i,fb){
				    var fbmsg = '';
				    if (fb.message != 'undefined'){
				        fbmsg = fb.message;
				    }				    
                    if(fbmsg && fbmsg.length>130){fbmsg = fbmsg.substring(0,130)+"....";}                                    
                    var fbtxt = "<div class='header'><div class='bc-icon'><a href='http://www.facebook.com/"+ AccName +"' target='_blank'><img height='30' width='30' src='"+ AccImg +"' alt='"+ DisName +"'><img height='30' width='30' src='./assets/images/center-content/fb-icon.png' alt='Facebook'></a></div><div class='source'></div><h6 class='darkblue'>" + DisName + "</h6></div><div class='bc-content grey'><p>" + fbmsg + "</p></div>";
				    DivHtml.push(fbtxt);
				});
			}
		});
    }
    else if(Type ==="tt"){
        url ="https://api.twitter.com/1/statuses/user_timeline.json?screen_name="+AccName+"&count=1&callback=?";
        $.getJSON(url,function(data){
			if(!$.isEmptyObject(data)){
				$(data).each(function(){
					var dt = new Date(this.created_at);
					//var tt = dt.getUTCFullYear()+"-"+strPad(dt.getUTCMonth(),2)+"-"+strPad(dt.getUTCDate(),2)+"T"+strPad(dt.getUTCHours(),2)+":"+strPad(dt.getUTCMinutes(),2)+":"+strPad(dt.getUTCSeconds(),2)+" +0000";
					var twmsg ='';
					if (this.text != 'undefined'){
					    twmsg =this.text;
					}
					if(twmsg && twmsg.length>130){twmsg=twmsg.substring(0,130)+"...";}
					var tttxt = "<div class='header'><div class='bc-icon'><a href='http://twitter.com/"+this.user.screen_name+"' target='_blank'><img height='30' width='30' src='"+this.user.profile_image_url_https+"' alt='"+ DisName +"'><img height='30' width='30' src='./assets/images/center-content/twitter-icon.png' alt='Twitter'></a></div><div class='source'></div><h6 class='darkblue'>"+ DisName +"</h6></div><div class='bc-content grey'><p>"+ twmsg +"</p></div>";
					DivHtml.push(tttxt);
				});
			}
		});
    }
  
    //return DivHtml;           
}





$.each(SAccounts,function(i){
var BrndName = SAccounts[i].split("^");
FillDiv(BrndName[0],BrndName[1],BrndName[2],BrndName[3]);
});

var auto_refresh_ttt = setInterval(
            function()
            {
                $.each(SAccounts,function(i){
                var BrndName = SAccounts[i].split("^");
                FillDiv(BrndName[0],BrndName[1],BrndName[2],BrndName[3]);
                });
                
            },3600000);

$('#brands-tweet-feeds').html("Loading Feeds...");
var auto_refresh = setInterval(
            function()
            {
                $('#brands-tweet-feeds').html("Loading Feeds...");
                var temp = DivHtml[Math.floor(Math.random() * DivHtml.length)];
                if(temp===""||temp==='undefined'){
                    temp = DivHtml[Math.floor(Math.random() * DivHtml.length)];
                }
                $('#brands-tweet-feeds').html(temp);
                                
            }, 10000);


//var dt = new Date("Tue Dec 27 20:34:02 +0000 2011");
//var stt =  "2011-12-29T07:33:27+0000";
//var tt = stt.split('+');
//var sdt = new Date(tt[0]);

//dd/mm/yyyy HH:mm:ss GMT
//var tt = Date.UTC(dt.getFullYear(),dt.getMonth(),dt.getDate(),dt.getHours(),dt.getMinutes(),dt.getSeconds(),dt.getMilliseconds());
//$('#div_feeds').html(dt.getUTCFullYear()+"-"+strPad(dt.getUTCMonth(),2)+"-"+strPad(dt.getUTCDate(),2)+"T"+strPad(dt.getUTCHours(),2)+":"+strPad(dt.getUTCMinutes(),2)+":"+strPad(dt.getUTCSeconds(),2)+" +0000");
//$('#div_feeds').html("First Date :"+relative_time(dt)+"<br/> Second Date:"+relative_time(sdt));
//alert(sdt.toUTCString());
//alert(dt);

});

