
var account = 'clatterbridge';
var seconds = 10;
var amount = 5;
var latest = "";

var birdObj;

window.addEvent('domready', function(){
	
	$('twitterBird').setStyle('background', 'none');
	
	birdObj = new Swiff('/_common/swf/twitter00.swf', {
		id: 'tweet',
		container: 'twitterBird',
		version: 8,
		width: '100%',
		height: '100%',
		params: {
			wMode: 'transparent'
		}
	});

	
    //myTwitterGitter.retrieve.periodical(seconds*1000, myTwitterGitter);
    getLatestTweets.periodical(seconds*1000);
    getLatestTweets();
    ///data/getData.asp
    
    var url = 'http://www.flickr.com/services/rest/?';
    	url += 'method=flickr.people.getPublicPhotos';
    	url += '&user_id=39774295@N04';
    	url += '&per_page=12';
    	url += '&format=json';
    	url += '&api_key=ea19004e8ba918dfede36a1189bd49e3';
    	url += '';
    	url += '';
    	url += '';
    
    new JsonP(url).request();
		
	
});

function tweetBird(){
	if($('tweet')){
		Swiff.remote(birdObj.toElement(), 'tweet', 0); 
	}
}

function getLatestTweets(){
	new TwitterGitter(account, {
    	count: amount,
    	onComplete: function(tweets, user){
    		$('tweetsContainer').set('html','');
    		//tweets.reverse();
    		tweets.each(function(tweet, i){
    			if(i == 0){
    				if(latest != tweet.created_at){
    					latest = tweet.created_at;
    					//console.log('call flash');
    					tweetBird.delay(500);
					}
				}
    			new Element('div', {
    				'class': i==0 ? 'whiteBoxItemFirst' : 'whiteBoxItem',
    				'html': '<p>'+tweet.text+'<br /><span class="greyTxt">'+Date.parse(tweet.created_at).toString('h:mm tt on d MMMM yyyy')+'</span></p>'
    			}).inject($('tweetsContainer'));
    			
    		});
    	}
    }).retrieve();
}

function jsonFlickrApi(rsp){
	var images = rsp.photos.photo;
	images.each(function(el, i){
		//console.log('http://farm'+el.farm+'.static.flickr.com/'+el.server+'/'+el.id+'_'+el.secret+'.jpg');
		var cls = '';
		if((i%4) == 3){
			cls = 'end';
		}
		/*new Element('div', {
			styles: {
				background: 'url(http://farm'+el.farm+'.static.flickr.com/'+el.server+'/'+el.id+'_'+el.secret+'_t.jpg) no-repeat center'
			},
			'class': cls
		}).inject($('flickrContainer'));*/
		new Element('img', {
			src: 'http://farm'+el.farm+'.static.flickr.com/'+el.server+'/'+el.id+'_'+el.secret+'_s.jpg',
			'class': cls
		}).inject($('flickrContainer'));
	});
}

