/**
 * jQuery Gallery (for Mighty myT) plugin
 * 
 * 
 * @name jquery-mm-gallery.js
 * @author Mighty myT
 * @version 0.5
 * @date November 17, 2010
 * @category jQuery plugin
 * @copyright (c) 2010 Mighty myT (mighty2.com)
 * @license -
 * @example -
 */
(function($) {

	var G = {};

	G.options = {
		url: '',
		id: '',
		stayInterval: 5000,
		fadeInterval: 500
	};

	G._holder = new Array();
	G._current   = 0;

	var isLoaded = false;

	// Functions ///////////////////////////
	/**
	 * 
	 * 
	 */
	G.init = function(options) {
		if(options) {
			applyOption(G.options, options);
		}

		$(function() {
			G.setup(G.options.list);
		});
	};

	/**
	 *
	 *
	 */
	G.setup = function(list) {
		$('#'+G.options.id).empty();
		for (var i=0; i<list.length; i++) {
			var item = $('<li><a href="' + list[i].url + '">' + list[i].date + '&nbsp;' + list[i].title + '</a></li>').css('display', 'none');
			G._holder.push(item);
			$('#'+G.options.id).append(item);
		}

		G.dispContent();
	};

	G.dispContent = function() {
		G._holder[G._current].fadeIn(G.options.fadeInterval, G.stayContent);
	};

	G.stayContent = function() {
		setTimeout('MmProgramInfo.hideContent()', G.options.stayInterval);
	}

	G.hideContent = function() {
		G._holder[G._current].fadeOut(G.options.fadeInterval, function() {
			G._current++;
			if (G._current >= G._holder.length)
				G._current = 0;
			G.dispContent();
		});
	};


	// Common Function ///////////////////////////////////////////////////////////
	/**
	 * Marge Option
	 *
	 */
	function applyOption(original, extension) {
		for(var property in extension) {
			original[property] = extension[property];
		}

		return original;
	}

	/**
	 *
	 *
	 */
	function each(obj,callback) {
		var i=0,len=obj.length;

		for(var value=obj[0]; i<len&&callback.call(value,i,value)!==false; value=obj[++i]) {
		}
	}

	function trim(str) {
		return str?str.replace(/(^\s+)|(\s+$)/g, ''):'';
	}

	window.MmProgramInfo = G;
})(jQuery);




