window.console = (window.console !== undefined) ? window.console : {
	log: function(input) {},
	debug: function(input) {},
	info: function(input) {}
};




window.GDF = {
	application: {
		config: {
			//base_path: 'http://localhost/~george/work/justmusic-co-za/'
			//base_path: '/~justmus/'
			base_path: '/'
		}
	},
	helpers: {
		artists: function(artists) {
			var output = '';

			for (var i = 0, iLen = artists.length; i < iLen; i++) {
				var artist = artists[i];

				if (i == 0) {
					if (iLen > 1) {
						output += '<a href="'+ GDF.application.config.base_path +'artists/'+ artist.slug +'">'+ artist.name +'</a> Feat. ';
					} else {
						output += '<a href="'+ GDF.application.config.base_path +'artists/'+ artist.slug +'">'+ artist.name +'</a>';
					}
				} else {
					if (i > 1) {
						if ((i + 1) == iLen) {
							output += ' and <a href="'+ GDF.application.config.base_path +'artists/'+ artist.slug +'">'+ artist.name +'</a>';
						} else {
							output += ', <a href="'+ GDF.application.config.base_path +'artists/'+ artist.slug +'">'+ artist.name +'</a>';
						}
					} else {
						output += '<a href="'+ GDF.application.config.base_path +'artists/'+ artist.slug +'">'+ artist.name +'</a>';
					}
				}
			}

			return output;
		},
		formatTime: function(seconds, format) {
			if (format == null) {
				format = 'hh:mm:ss';
			}

			var hours = parseInt(Math.floor(seconds / 3600));

			seconds = seconds - (hours * 3600);

			var minutes = parseInt(Math.floor(seconds / 60));

			seconds = parseInt(Math.floor(seconds - (minutes * 60)));

			hours   = (hours <= 9)   ? '0' + hours.toString()   : hours.toString();
			minutes = (minutes <= 9) ? '0' + minutes.toString() : minutes.toString();
			seconds = (seconds <= 9) ? '0' + seconds.toString() : seconds.toString();

			if (format == 'hh:mm:ss') {
				return (hours +':'+ minutes +':'+ seconds);
			} else if (format == 'mm:ss') {
				return (minutes +':'+ seconds);
			}
		}
	}
}

String.prototype.strip_html = function()
{
	return this.replace(/<\/?[a-z][a-z0-9]*[^<>]*>/ig, '');
}

function start_banners() {
	// Fetch a list of banners and start the rotation
	$.getJSON(GDF.application.config.base_path + 'welcome/ajax?method=featured_banners', function(data){
		if (data.length < 1) {
			return;
		}

		// Start the rotation from the first banner
		var banners_wrapper      = $('#banners');
		var banner               = $('<img />');
		var current_banner_index = -1;
		var images               = [];
		var timer                = null;
		var intervalHandler = function() {
			++current_banner_index;

			if (data[current_banner_index] == undefined) {
				current_banner_index = 0;
			}

			banner.attr('src', images[current_banner_index].src);

			timer = setTimeout(intervalHandler, 8000);
		}

		banners_wrapper.append(banner);

		for (var i = 0, iLen = data.length; i < iLen; i++) {
			var img = new Image();

			img.src = GDF.application.config.base_path + 'uploads/banners/' + data[i].filename;

			images.push(img);
		}

		intervalHandler();
	});
}
