	// makeClass - By John Resig (MIT Licensed)

	function makeClass() {
		return function(args) {
			if (this instanceof arguments.callee) {
				if (typeof this.init == "function")
					this.init.apply(this, args.callee ? args : arguments);
			} else
				return new arguments.callee(arguments);
		};
	}
	
	function log (){
		console.log.apply(this, arguments)
	}

	/**
	 * VHImgCycler - reusable class that wraps jQuery Cycle Plug-in for multiple image cyclers on one page
	 * 
	 * requires ;
	 * 		- jquery.js
	 * 		- jquery.cycle.lite.min.js
	 */
	
	var VHImgCycler = makeClass();
	
	VHImgCycler.prototype = {

		divId: '',
		magnifyBtn: '',
		prevCountTxt: '',
		Cycler: '',

		defaultOptions: {	
			fx:			   'scrollHorz',
		    sync:          1,     // true if in/out transitions should occur simultaneously 
		    fit:           0,     // force slides to fit container 
		    pause:         1,     // true to enable "pause on hover" 
		    delay:         0,     // additional delay (in ms) for first transition (hint: can be negative) 
		    slideExpr : 'li a img',
			continuous:		0
		}

	};

	VHImgCycler.prototype.init = function(divId, cycleTime, width, height) {

	    // set default properties
	    this.divId = divId;
	    this.magnifyBtn = $(divId + " .icMagnify");
	    this.prevCountTxt = $(divId + " .icPrevCount");
	    var self = this;

	    var opts = {}
	    $.extend(opts, this.defaultOptions, {
	        timeout: 0,
	        speed: cycleTime,  // speed of the transition (any valid fx speed value)
	        width: width,
	        height: height,
	        next: divId + " .icNext",
	        prev: divId + " .icPrev",
	        before: function(curr, next, opts) {
	            self.onBefore(curr, next, opts, self);
	        },
	        after: function(curr, next, opts) {
	            self.onAfter(curr, next, opts, self);
	        },
	        prevNextClick: function(isNext, slideNo, slideElement) {
			   self.onPrevNextClick(isNext, slideNo, slideElement, self);
	        }
	    });

	    this.Cycler = $(divId + " .icImages ul");

	    // initialize all buttons in div
	    this.initControls();

	    // disable all links if only one photo
	    this.imgCount = $(divId).find("li a img").length;

	    if (this.imgCount == 1) {

	        self.UpdateDisplayForOneImage( $(divId + " .icNext") , $(divId + " .icPrev") , $(divId + " .icPhotos"), self )

	    }

	    // start the cycler
	    self.Cycler.cycle(opts);
	    	    
	    
	};


	VHImgCycler.prototype.initControls = function() {

	    // ref to all image hrefs
	    var ahrefs = $(this.divId + " ul li a");
	    var self = this;

	    self.Cycler.hover(
			function() { self.Cycler.cycle('pause'); },
			function() { self.Cycler.cycle('resume'); }
		);

	    self.magnifyBtn.hover(
			function() { self.Cycler.cycle('pause'); },
			function() { self.Cycler.cycle('resume'); }
		);

	    self.magnifyBtn.click(function() {
	        self.showLightBox(self);
	    });

	    ahrefs.click(function(e) {
	        e.preventDefault();
	        self.showLightBox(self);
	    });

	    

	};

	VHImgCycler.prototype.showLightBox = function(self) {

	    // get the current image index
	    var slideIndex = self.prevCountTxt.html();

	    // get the img paths and convert to new array
	    var originalImgs = $(self.divId).find("li a img");
	    var newImgs = [];
	    originalImgs.each(function() {
	        var newImageSrc = $(this).attr("src").replace(/width=\d+/i, "width=600").replace(/height=\d+/i, "height=400");
	        newImgs.push(newImageSrc);
	    });

	    // update gallery index
	    $("#icTBContent li.pages").html(slideIndex + " of " + newImgs.length);

	    // clear contents and add new images
	    $(".icTBImg").empty();
	    for (var i = 0; i < newImgs.length; i++) {
	        $(".icTBImg").append("<img src=" + newImgs[i] + " />");
	    }

	    // create options for cycler inside gallery
	    var galleryOptions = {
	        sync: 1,
	        fit: 0,
	        delay: 0,
	        continuous: 0,
	        width: 600,
	        height: 400,
	        timeout: 0,
	        speed: 500,
	        startingSlide: slideIndex - 1,
	        next: "#icTBContent li.next",
	        prev: "#icTBContent li.prev",
	        prevNextClick: function(isNext, slideNo, slideElement) {
	            $("#icTBContent li.pages").html((slideNo + 1) + " of " + newImgs.length);
	        }
	    };

	    // init cycler
	    $(".icTBImg").cycle(galleryOptions)

	    // show thickbox
	    tb_show("", "#TB_inline?height=470&width=610&inlineId=icTBGallery", false);

	    
	    if (self.imgCount == 1) {
	        self.UpdateDisplayForOneImage($("#icTBContent li.next"), $("#icTBContent li.prev"), null, self)
	    } else {
	        $("#icTBContent li.next").attr("style", "")
	        $("#icTBContent li.prev").attr("style", "");
	    }

	};
	
	VHImgCycler.prototype.onBefore = function(curr, next, opts, self) {
		// nothing yet	
	};

	VHImgCycler.prototype.onPrevNextClick = function(isNext, slideNo, slideElement, self) {
	
	};
	
	VHImgCycler.prototype.onAfter = function(curr, next, opts, self ){
		self.prevCountTxt.html( (opts.currSlide+1) );
    };

    VHImgCycler.prototype.UpdateDisplayForOneImage = function(prev, next, photosText, self) {

        // disable click and hide next
        next.click(function(e) {
            e.preventDefault();
        }).attr("style", "display:none !important");

        // disable click and hide prev
        prev.click(function(e) {
            e.preventDefault();
        }).attr("style", "display:none !important")

        // update photos text
        if (photosText != null) {
            photosText.html("photo");
        }
        

    }
	
	