
(function($) {
	$.fn.homeimages = function(options) {
		
		
		return this.each(function() {
			$this = $(this);
			/* preload */
			var plis = new Array();
			for (var i in options){
				var tmpimg = new Image();
				tmpimg.src = options[i].PATH;
				tmpimg.alt = options[i].NAME;
				plis.push(tmpimg);
			}
			
			/* create object to track state */
			var sobj = {
				pli : plis,
				ref : $this,
				opts : options,
				move : function(dir){
					var c = this.getCurrent();
					if (c == -1 || c == this.opts.length-1) c = 0;
					else c++;

					$(".imageHolder img", this.ref).attr("src", this.pli[c].src);
					$(".imageHolder img", this.ref).attr("alt", this.pli[c].alt);
					if (this.opts[c].RELOCATE == '') {
						$(".imageHolder", this.ref).css("cursor", "default");
					}	else {
						$(".imageHolder", this.ref).css("cursor", "pointer");
					} 
				},
				go : function(){
					var c = this.getCurrent();
					if (this.opts[c].RELOCATE != "") location.href = this.opts[c].RELOCATE;
				},
				getCurrent : function(){
					var img = $(".imageHolder img", this.ref);
					var imgpath = img.attr("src");
					var c = -1;
					for (var i in this.opts){
						if (imgpath.indexOf(this.opts[i].PATH) != -1) c = i;
					}
					if (c == -1) c = 0;
					return c;
				}
			};
			
			/* add events */
			$("#controls a:first", $this).click(function(){sobj.move("+");return false;});
			$("#controls a:last", $this).click(function(){sobj.move("-");return false;});
			$(".imageHolder", $this).bind("click", function(){sobj.go();});
			/* setup first */
			//sobj.to($("#videolist .video", $this).eq(0));
			if (sobj.opts && sobj.opts[sobj.getCurrent()].RELOCATE != '') {
				$(".imageHolder", $this).css("cursor", "pointer");
			}
		});
	};

	$.fn.homeimages.defaults = {
	};

})(jQuery);