  /**
 * jQuery Content Fader
 * @name Thomas A. Bibb (bibb.thomas@googlemail.com)
 * @author Premier Software Solutions - http://www.premiersoftware.co.uk/
 * @version 0.3 stable
 * @date May 13, 2009
 * @category jQuery plugin
 * @copyright (c) 2009 Premier Software Solutions (www.premiersoftware.co.uk)
 * 
		For this pluging to work correctly you must have the following divs;
		* %instance%			(The div which the content is loaded into)
		*  %instance%Link 		(This div which the links are loaded into)
		*  %instance%Content 		(Which contains many Divs)
		*  for each instance of the fader you must do the following;
		* $(document).ready(function() {
			$("#myDiv1").contentFader();  	//instance one
			$("#myDiv2").contentFader(); 	//instance two
			$("#myDiv3").contentFader();		//instance three
		});
 */
 
(function($) {
 	/**
	 * $ is an alias to jQuery object
	 *
	 */
	$.fn.contentFader = function(settings) {
		settings = jQuery.extend({
			//settings and stuff here
		},settings);
		
		var objContentHolder = this;
		var objContentHolderID = "#"+$(objContentHolder).attr('id');
		var objLink = "#"+$(objContentHolder).attr('id')+"Link";
		var objContent = "#"+$(objContentHolder).attr('id')+"Content";
		
		/**
		 * Initializing the plugin calling the start function
		 *
		 * @return boolean false
		 */
		
		 //create some vars
		 var arrItems = new Array();
		 var i=0;
		 
		 //Hide Content Holder
		$(objContentHolder).hide();
		  $(objContent+" > div").each(
			function(intIndex, strValue) {  
			i++;
				// put the Div Elements into an Array
				arrItems[intIndex] = strValue.innerHTML;
		    });
			// we did not find any Content Holders
			if (i <=0) {
				$(objContentHolder).text("Content was not found, you must declare "+objContentHolderID+"Content").effect('highlight',{},1500);
			}
			
			//create a list
			
			
			$(objLink).append("<ul>");
			$(objLink).append("<p>«</p>");
			for (i=1; i<arrItems.length; i++) {
				$(objLink).append("<li>"+i+"</li>");
			}
			$(objLink).append("<p>»</p>");
			$(objLink).append("</ul>");
			
			//Load the first div element & change css state of ul
			$(objContentHolder).fadeIn("slow").html(arrItems[1]);
			$(objContentHolderID+" img").fadeTo("slow", 0.66);
			$(objLink+" li:first").addClass("activeToggle").fadeIn("slow");
			
			//Change content when clicking Index
			$(objContentHolder).attr('id')
			
			//allow scroll through content 
			//setInterval("fadeToNext()", 5000);
			
			$(objLink+" li").click(function () { 
			 			$(objLink+" li").removeClass("activeToggle");
						$(this).addClass("activeToggle");
						//store the li which was clicked
						var objLinkCliked = this;
				 //Check if Reception Div is Hidden
				 if ($(objContentHolder).is(":hidden")) {
					 //get the arrayIndex
					 var data = this.value();
					 $(objContentHolder).fadeIn("slow").html(arrItems[data]);
				 } else {
					$(objContentHolder).fadeOut("slow", function () {
						//get around the passing of the ArrayIndex
						var data = $(objLinkCliked).text();
						//finally load the content
						$(objContentHolder).html(arrItems[data]).fadeIn("slow");
					})	
				} 
			});

		//enable alpha change on mouseover
		$(objContentHolderID+" img").mouseover(function () {
			$(this).fadeTo("slow", 1.00);
		}).mouseout(function () {
			$(this).fadeTo("slow", 0.66);
		});
		
		//lightbox workaround
		$(objContentHolder).mouseover(function () { 
			$("#"+$(objContentHolder).attr('id')+" a").lightBox();
			return false;
		});
		
		
		
		
		}
}) (jQuery);