
(function($) {
    window.initCarousels = function() {

	    // count to mark each element with a unique #
	    var carousel_count = 1;
        
        // for each carousel instance, we want to 
        // add a class to uniquely identify each by
        $(".module-carousel").each(function(){
        	
		    var $this = $(this),
				 this_length = $this.find("li").length;
				 
			if ( this_length > 1 ) {
			
				// set up unique class using the count 
				var carousel_class = "carousel" + carousel_count,
				    // add unique class to this carousel
				     $this_carousel = $this.addClass(carousel_class);
				     
			     // add unique calss to the next/prev buttons
			     $this.parent().find(".next").addClass("next" + carousel_count);
			     $this.parent().find(".prev").addClass("prev" + carousel_count);
	
			    // using the unique class call jCarouselLite
			    $this_carousel.jCarouselLite({
	        	    btnNext: ".next" + carousel_count,
	        	    btnPrev: ".prev" + carousel_count,
	        	    visible: 2
	    	    });

				if ( this_length == 2 ) {
        			$(".middleWidgetColumn .next" + carousel_count + ", .middleWidgetColumn .prev" + carousel_count).hide();
        		}

	    	    // +1 for next instance
	    	    carousel_count++;

        	} else {
        		
        		$this.parent().find(".next, .prev").hide();
        		
        	}
        	
        });

        $('.widget.photos .module-carousel a, .quickLinksModule.photos a').fancybox({
            "type": "image",
            "titlePosition" : "inside",
            "transitionIn" : "elastic",
            "transitionOut" : "none"
        });

        $('.widget.video .module-carousel a, .quickLinksModule.video a').fancybox({
            "type": "iframe",
            "titlePosition" : "inside",
            "transitionIn" : "elastic",
            "transitionOut" : "none",
            "width" : 600,
            "height" : 400
        });
        
    }
    
})(this.jQuery);

jQuery(function($) {
    if(typeof Blackboard == "undefined" || !("WidgetManager" in Blackboard)) {
        window.initCarousels();
    }
});



