/* Author: 
   Mikko Tikkanen
   mikko.tikkanen@gmail.com
*/

var gLocations = {
	tampere: {
		username: 'FGJTampere'
	},
	turku: {
		username: 'FGJTurku'
	},
	oulu: {
		username: 'FGJOulu'
	},
	kajaani: {
		username: 'FGJKajaani'
	},
	helsinki: {
		username: 'HelsinkiGameJam'
	},
	kouvola: {
		username: 'FGJKouvola'
	}
};


/**
 * Set column
 * 
 * @param {Number} _id			Column id number
 * @param {String} _query		Twitter query
 * @param {String} _header		Column header
 */
function setColumn(_id, _query, _header) {
	var column = $("#column"+_id);
	column.liveTwitter(_query, {
		limit: 10,
		rate: 15000
	});
	column.find('.column_header span').eq(0).html(_header);
} 

/**
 * Set header
 * 
 * @param {Object} _query		Twitter query
 * @param {Object} _name		(Optional) Username
 */
function setLocal(_query, _username) {
	// If no name is set, use the query
	_username = (_username === undefined) ? _query : _username; 
	
	$("#local_status #text").liveTwitter(_query, {
		limit: 1,
		rate: 30000,
		mode: 'user_timeline'
	});
	$('#local_status #user span').html(_username);
}

// If location has username, set the header
if(gLocations[loc] !== undefined && gLocations[loc].username !== undefined) {
	setLocal(gLocations[loc].username);
}

// Set the columns
setColumn(1, '#ggj12', '#GGJ12');
setColumn(2, '#fgj12', '#FGJ12');




/**
 * Set ustream video feeds
 */
function setVideoFeeds() {
	if(typeof(gUstreamFeeds) == 'undefined') {
		return false;
	}
	
	// Set stream refreshtime
	var timeout = window.setTimeout(timedOut, timeoutLength);
	
	// Loop through feeds
	var num = 4;
	while(num--) {
		if(gUstreamFeeds[num] === undefined) {
			continue;
		}		
		// Set stream 
		$('#ustream'+(num+1)).attr({src: gUstreamFeeds[num]});
	}
	
	
}
// Try to set the video feeds
setVideoFeeds();


// Ugly globals
var timeoutLength = 100000;
var timeout = null;
var refreshNum = 1;

/**
 * Ustream refresh timer
 */
function timedOut() {
	$('#ustream'+refreshNum).attr({src: gUstreamFeeds[refreshNum-1]});

    refreshNum++;

    // If we are over the feed count, go back to first
    if(refreshNum > gUstreamFeeds.length) {
        refreshNum = 1;
    }

    // Repeat the timeout
    timeout = window.setTimeout(timedOut, timeoutLength);
}



$('#flickr').jflickrfeed({
	qstrings: {
		id: '46847823@N07'
	},
	itemTemplate: '<img src="{{image}}" alt="{{title}}" style="bottom: 0px; right: 0px;" /></a>'
});
$.fn.cycle.defaults.speed   = 900;
$.fn.cycle.defaults.timeout = 6000;
$.fn.cycle.defaults.containerResize = false;
$.fn.cycle.defaults.fit = 1;
$.fn.cycle.defaults.random = 1;
setTimeout(function() {
	$('#flickr').css({
		'visibility': 'visible'
	}).cycle();
}, 2000);



