/****************************************************************************************
*	file		: clientscript/index.js
*
*	Only load this on the index page
*
****************************************************************************************/
largebox = new Move( getbyid('largebox') , 30 );
largebox.element.currimg = 0;

feeds = new Move( getbyid('feeds') , 30 );
feeds.element.currimg = 0;

box = new Array();
for( i = 1; i < 6; i++ )
{
	box[i] = new Move( getbyid('imagebox'+i) , 50 );
	box[i].element.currimg = 0;
}

opener = setInterval( function(){ openrandom() }, 5000 );

function openrandom()
{

	for( a = 1; a < 6; a++ )
	{
		
		if( box[a].element.currimg == 1 )
		{
			rotate( box[a] );
			latest = a;
		}
	}

	randvalue = Math.round(Math.random()*5)+1

	rotate( box[randvalue] );

}

function rotate( obj )
{
	if( typeof(obj) == "undefined" )
	{
		return false;
	}
	if( !obj.element.currimg )
	{
		obj.element.currimg = 1;
	}
	else
	{
		obj.element.currimg++;
	}
	
	height = obj.element.parentNode.clientHeight;
	
	nextvalue = height * obj.element.currimg

	if( nextvalue >= obj.element.clientHeight )
	{
		nextvalue = 0;
		obj.element.currimg = 0;
	}

	obj.set( 'x', 0 );
	obj.set( 'y', -(nextvalue) );
	obj.init();
}

social = new Socialplugin();
social.set( 'feed', { 'identifier':'twitter', 'url':'output.php?url=twitter', 'tag':'item', 'sourceurl':'https://www.twitter.com/#!/thq1beije' });
social.set( 'feed', { 'identifier':'youtube', 'url':'output.php?url=youtube', 'tag':'item', 'sourceurl':'http://www.youtube.com/user/thq1beije' });
social.set( 'feed', { 'identifier':'vimeo', 'url':'output.php?url=vimeo', 'tag':'item', 'sourceurl':'http://www.vimeo.com/beije' });
social.set( 'feed', { 'identifier':'flickr', 'url':'output.php?url=flickr', 'tag':'entry', 'sourceurl':'http://www.flickr.com/beije' });
social.set( 'feed', { 'identifier':'xbox live', 'url':'output.php?url=xbox live', 'tag':'Game', 'sourceurl':'http://live.xbox.com/Profile?gamertag=thq1%20beije' });
social.set( 'removeword', 'thq1beije: ');
social.set( 'destination', 'socialfeeds');
social.set( 'linelength', 35);
social.set( 'publishamount', 0);
social.set( 'useicons', true);
social.set( 'usesource', false);
social.set( 'showdate', false);
social.set( 'publish', false);

pageloadchecker = setInterval( function(){ haspageloaded(); }, 100);

function checkfeeds()
{
if( social.done )
{
	socialmedia = social.fetchdata()
	getbyid('latestfeeditem').innerHTML = '<span class="quote">&#147;</span><a href="'+socialmedia[0]['link']+'" target=*_blank*>'+socialmedia[0]['short_title']+'</a><span class="quote">&#148;</span>';
	getbyid('latestfeeditemsource').innerHTML = socialmedia[0]['RSSPARSER_ID'];
	rotate( feeds );
	
	flickrimages = new Array();
	imgcounter = 0;
	for(z=0;z<socialmedia.length;z++)
	{
		if( socialmedia[z]['RSSPARSER_ID'] == 'flickr' )
		{
			getbyid('largebox').innerHTML += '<div style="width:370px; height:410px; background:url(\''+socialmedia[z]['link']+'\') center center;"></div>';
			flickrimages.push( socialmedia[z]['link'] );
			imgcounter++;
		}
		
		if( imgcounter >= 4 )
		{
			break;
		}
	}
	
	if( flickrimages.length > 0 )
	{
		largeboxtimer = setInterval( function(){ rotate( largebox ) }, 10000 );
	}
	
	clearInterval( feedchecker );
}
}

function haspageloaded()
{
if( typeof(pagehasloaded) != undefined )
{
	if( pagehasloaded )
	{
		clearInterval( pageloadchecker );
		feedchecker = setInterval( function(){ checkfeeds(); }, 1000);
		social.build();
	}
}
}

