// action


//New website
var newSite = new jS('.Danny');
// Twitter
newSite.setSocial({social	:'twitter',user	:'48285316'})//user id NOT name
newSite.feedTwitter({element:'.Twitter .content',callback:'renderTwitter',callback2:'postTwitter',params:{test:'test'}});
// Flickr
newSite.setSocial({social:'flickr',user:'50029538%40N02'})
newSite.feedFlickr({element:'.Flickr .content',callback:'renderFlickr',callback2:'postFlickr',params:{test:'test'}});
// Last.fm
newSite.setSocial({social:'lastfm',user:'n0vus',key:'a357a4a0670251cee0f682659348cca3'})
newSite.feedLastfm({element:'.Lastfm .content',callback:'renderLastfm',callback2:'postLastFm',params:{test:'test'}});
// Daily mugshot
newSite.setSocial({social:'dailymugshot',user:'ddezeeuw',type:"main"}) //types are: thumb & main
newSite.feedDailymugshot({element:'.Dailymugshot .content',callback:'renderDailymugshot',callback2:'postDailyMugshot',params:{test:'test'}});
// Nike+
newSite.setSocial({social:'nikeplus',user:'1409766595'}) 
newSite.feedNikePlus({element:'.NikePlus .content',callback:'renderNikePlus',callback2:'postNikePlus',params:{test:'test'}});


//Post data rendering functions
postTwitter = function(obj){
	//alert('hellow Twitter w0rld')
}

postFlickr = function(obj){
	var items = obj.data.value.items[0].entry;
	
	var randItem = Math.floor(Math.random()*items.length);
	
	var img = obj.data.value.items[0].entry[randItem].link[2].href;
	setBackground(img);
	if(!$('body > .newBg').length){
		$('body').append('<div class="newBg">[ Switch Background ]</div>')
		$('body .newBg').data('obj',obj).click(function(){
			$('#fsBG img').fadeOut(500,function(){
				postFlickr($('body .newBg').data('obj'));
			});
		})
	}
}

postLastFm = function(obj){
	//alert('hellow LastFm w0rld')
}

postDailyMugshot = function(obj){
	//alert('hellow DailyMugshot w0rld')
}

postNikePlus = function(obj){
	//alert('hellow NikePlus w0rld')
}


/*
nike ID: 1409766595
nike FEED: http://nikeplus.nike.com/nikeplus/v1/services/widget/get_public_run_list.jsp?userID=<YOUR ID HERE>
run info: http://nikerunning.nike.com/nikeplus/v2/services/app/get_gps_detail.jsp?_plus=true&id=<YOUR RUN-ID HERE>&format=json
--
http://nikeplus.nike.com/nikeplus/v1/services/widget/get_public_run_list.jsp?userID=1409766595
http://nikerunning.nike.com/nikeplus/v2/services/app/get_gps_detail.jsp?_plus=true&id=299064666&format=json

http://nikerunning.nike.com/nikeplus/v2/services/app/run_list.jsp?userID=1409766595
*/



/*

dateArray = new Array('15/10/2000','28/05/1999',
'17/09/2005','06/12/2004','02/01/1998');
//dateArray.sort( newSite.sort(null,null,'A') );
//console.log('Ascending : ' + dateArray + '<br />');
*/
//set Interaction Tabs

$(document).ready(function(){

    setTabs();
    animateSite('About');
})

function animateSite(tab){
	$('h1, li.col > h2, strong, .content, .intro').hide();
	$('h1').fadeIn(1500);
	var n = 0;
	$('strong').delay(500).fadeIn(1000,function(){
		$.each($('li.col > h2'),function(){
			n++;
			$(this).delay(n*100).fadeIn(500);
		})

		var t = setTimeout(function(){
			$('.'+tab+' h2').click();
			
			$('.Dailymugshot .content').delay(1500).fadeIn(1,function(){
				$('.Dailymugshot').animate({'margin-left':'-200px'},500)
			});
			
		},n*300);
	});
}


function setTabs(){

   var i =101;
   $('.col h2')
       .click(function(){
       		$(this).parent().css({'z-index':i++});
       		$('.columns > ul > .active').removeClass('active').find('.content, .intro').fadeOut(500);
       		$(this).parent().addClass('active').find('.content, .intro').delay(500).fadeIn(500);
       	})       		
       .hover(function(){
       		if(!$(this).parent().hasClass('active'))$(this).addClass('hover')
       },function(){
       		
       		$(this).removeClass('hover')
       })
       .css({'cursor':'pointer'});
}

var reT;
$(window).resize(function(){
	clearTimeout(reT);
	reT = setTimeout(function(){setBackground()},100);
})

function setBackground(url){
	
	url = url || $('#fsBG img').attr('src');
	if(url == undefined || url == '')return;

	if(!$('#fsBG').length){$('body').append('<div id="fsBG"><img src="'+url+'" style="" /></div>')}else{
		
		$('#fsBG img').attr({'style':'','src':url});
	};
	
	(function setT(){
	var t = setTimeout(function(){if($('#fsBG > img').width() > 0){
			resizeBackground($('#fsBG > img'));
	}else{setT()}},50)})();
	
	var bg = $('#fsBG');
	var foto = bg.find('img');
	
	foto.attr('src',url);
}

function resizeBackground(element){
	var w = element.width(),
		h = element.height(),
		nh,nw;
	
	nh = $(window).height()/h;
	nw = $(window).width()/w; 

	if(nh >= 1){h*=nh; w*=nh}
	if(nw >= 1){h*=nw; w*=nw}
	
	nh = (h-$(window).height())/3;
	nw = (w-$(window).width())/3;
	
	element.css({'height':h,'width':w, 'margin-top': -nh, 'margin-left':-nw}).fadeIn(1000);
		
}





// Extra Info

//http://www.dailymugshot.com/openapis/get_sequence?userid=62462
 /* top albums: http://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=n0vus&api_key=a357a4a0670251cee0f682659348cca3
     recent tracks: http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=rj&api_key=a357a4a0670251cee0f682659348cca3*/

