function artsSpotlight(inelement,inparams,inevents){
	var params = {
		'Discap': 'Y',		    // Controls whether the caption (heading) will be shown ('Y','N')
		'Bshape': 'R',		    // Controls the shape of the buttons ('R' = rounded, 'S' = square)
		'Oshape': 'R',        // Controls whether the background and overlay should use rounded or square corners ('R','S')
    'Oopacity': .5,       // Controls the opacity of the overlay (0 to 1)
		'Color': '#FFFF00',   // Controls the background color of the overlay (Hex value starting with #)
		'Interval': 5,        // Controls the number of seconds between automatic advancement
		'Fade': 'M',          // Controls the speed of the fade effect ('N' = no fade, 'S' = slow, 'M' = medium, 'F' = fast)
		'Imgsize': 'L',       // Controls whether the event image should be shown outside or inside the overlay box ('S' = inside, 'L' = outside)
		'Imgalign': 'L',      // Control whether the vent image is left aligned or right aligned ('L' = left, 'R' = right)
    'OTmargin': 40,       // Space between the top of the background and the top of the overlay
    'OLmargin': 10,       // Space between the left of the background and the left of the overlay
    'ORmargin': 10,       // Space between the right of the background and the right of the overlay
    'OBmargin': 10,       // Space between the bottom of the background and the bottom of the overlay
    'IMargin': 10,        // Space between the event image and the event text, the text and the overlay and the image and the overlay
    'Width': 450,         // Width of the total box
    'Height': 150,        // Height of the total box
    'Bcolor': '#EEEEEE',  // Background color of the selector buttons (Hex value starting with #)
    'BHcolor': '#FF9900', // Background color of the selector buttons when highlighted (Hex value starting with #)
    'BBcolor': '#EEEEEE'  // Border color of the selector buttons when highlighted (Hex value starting with #)
	};
	
  // Keep track of the events to display
	var events = inevents;
  
  // Image preload
  //var imgPreload;
  for(key in events){
    //imgPreload = new Image();
    //imgPreload.src = events[key].Img;
    $("body").append("<img src='"+events[key].Img+"' style='visibility: hidden; height: 1px; width: 1px;' />");
  }
  
  // Holds the # of the currently displayed event
  var curEvent = null;
  
  // Increment by one to keep the spotlight paused on the current slide, decrement by one to release the hold
  var pauseAuto = 0;
  
  // Set to 1 if the manual pause button is pressed
  var pauseManual = 0;
  
  // Holds the original position data of the overlay box
  var overlayAnchor = 0;
	
  // Load parameters
	for(key in inparams){
		if(params[key]){
			params[key] = inparams[key];	
		}	
	}
  
  // Convert the fade parameter into the proper notation
  if(params['Fade'] == 'S'){
    params['Fade'] = 'slow';
  }else if(params['Fade'] == 'M'){
    params['Fade'] = 'normal';
  }else if(params['Fade'] == 'F'){
    params['Fade'] = 'fast';
  }
  
  // Load the spotlight HTML code
  $(inelement).html("<div class='arts-spotlight' style='width: "+params['Width']+"px; height: "+params['Height']+"px;'><div class='arts-spotlight-bg'></div><div class='arts-spotlight-selectors'></div><div class='arts-spotlight-caption'>&nbsp;</div><div class='arts-spotlight-overlay-bg'></div><div class='arts-spotlight-image'></div><div class='arts-spotlight-text'></div></div>");
	
  // A function for generating a button image
  function generateButton(label,id,clickEvent){
    var button = $("<div class='arts-spotlight-selector'>"+label+"</div>");
    button.addClass("arts-spotlight-selector-"+id);
    if(clickEvent){
      button.bind('click',{paneNum: id},clickEvent);
    }
    button.bind('mouseenter',{button: id},function(e){
      button = e.data.button;
      highlightButton(button);
    });
    button.bind('mouseleave',{button: id},function(e){
      button = e.data.button;
      unhighlightButton(button);
    });
    $(inelement).find(".arts-spotlight-selectors").append(button);
    unhighlightButton(id);
    return button;
  }
  
  // Create the selection buttons
  var count = inevents.length;
  for(var i = 1; i <= count; i++){
    generateButton(i,i,function(eve){
        pauseAuto++;
        loadPane(eve.data.paneNum);
        setTimeout(function(){
          pauseAuto--;
        },15000);
    });
  }
  
  // Create the pause button
  var pb = generateButton('||','pause',function(){
    if(pauseManual){
      pauseManual = 0;
      pauseAuto--;
    }else{
      pauseManual = 1;
      pauseAuto++;
    }
  });
  
  // Get the total width and height of the spotlight box
  var totalWidth = $(inelement).find(".arts-spotlight").width();
  var totalHeight = $(inelement).find(".arts-spotlight").height();
  
  // Position the overlay window
  function positionElements(){
    var overlay = $(inelement).find(".arts-spotlight-overlay-bg");
    var caption = $(inelement).find(".arts-spotlight-caption");
    var txt = $(inelement).find(".arts-spotlight-text");
    var img = $(inelement).find(".arts-spotlight-image");
    var imgWidth = img.width();
    
    var widthMod = 0;
    var inWidthMod = 0;
    var inLeftMod = 0;
    var outLeftMod = 0;
    
    if(params['Imgalign'] == 'L'){
      if(params['Imgsize'] == 'L'){
        outLeftMod += imgWidth+params['IMargin'];
        widthMod += outLeftMod;
      }else{
        inLeftMod += imgWidth+params['IMargin'];
      }
    }else{
      if(params['Imgsize'] == 'L'){
        widthMod += imgWidth+params['IMargin'];
      }else{
        inWidthMod += imgWidth+params['IMargin'];
      }
    }
    
    overlay.css('position','absolute');
    overlay.css('z-index','4');
    overlay.css('top',(params['OTmargin'])+'px');
    overlay.css('left',(params['OLmargin']+outLeftMod)+'px');
    overlay.css('width',(totalWidth-params['OLmargin']-params['ORmargin']-widthMod)+'px');
    overlay.css('height',(totalHeight-params['OTmargin']-params['OBmargin'])+'px');
  
    var pos = overlay.position();
    
    img.css('position','absolute');
    img.css('z-index','5');
    if(params['Imgsize'] == 'S'){
      img.css('top',(params['OTmargin']+params['IMargin'])+'px');
    }else{
      img.css('top',(params['OTmargin'])+'px');
    }
    if(params['Imgalign'] != 'R'){
      if(params['Imgsize'] == 'S'){
        img.css('left',(params['OLmargin']+params['IMargin'])+'px');
      }else{
        img.css('left',(params['OLmargin'])+'px');
      }
    }else{
      if(params['Imgsize'] == 'S'){
        img.css('right',(params['ORmargin']+params['IMargin'])+'px');
      }else{
        img.css('right',(params['ORmargin'])+'px');
      }
    }
	
	// Scale images to fit in box
	var imgMaxWidth = 250;
	var imgMaxHeight;
	if(params["Imgsize"] == "L") {
		imgMaxHeight = totalHeight;
	} else {
		imgMaxHeight = overlay.height()-2*params["IMargin"];
	}
	$(img).find("img").each(function(index, imgEl) {
		if(imgEl.width > imgMaxWidth) {
			imgEl.height *= imgMaxWidth/imgEl.width;
			imgEl.width = imgMaxWidth;
		}
		if(imgEl.height > imgMaxHeight) {
			imgEl.width *= imgMaxHeight/imgEl.height;
			imgEl.height = imgMaxHeight;
		}
	});
	
	// Resize overlay to work with scaled image size
	if(params["Imgsize"] == "L") {
		if(params["Imgalign"] == "L") {
			overlay.css("left", params["OLmargin"]+img.width()+params["IMargin"]+"px");
		}
		overlay.css("width", totalWidth-params["OLmargin"]-params["ORmargin"]-img.width()-params["IMargin"]+"px");
	}
    pos = overlay.position();
	
	// Scale text box based on image size
    txt.css('position','absolute');
    txt.css('z-index','5');
    txt.css('top',(pos.top+params['IMargin'])+'px');
	if(params["Imgalign"] == "L") {
		if(params["Imgsize"] == "L") {
			txt.css("left", pos.left+params["IMargin"]+"px");
			txt.css("width", overlay.width()-2*params["IMargin"]);
		} else {
			txt.css("left", pos.left+img.width()+2*params["IMargin"]+"px");
			txt.css("width", overlay.width()-img.width()-3*params["IMargin"]);
		}
	} else {
		if(params["Imgsize"] == "L") {
			txt.css("left", pos.left+params["IMargin"]+"px");
			txt.css("width", overlay.width()-2*params["IMargin"]);
		} else {
			txt.css("left", pos.left+params["IMargin"]+"px");
			txt.css("width", overlay.width()-img.width()-3*params["IMargin"]);
		}
	}
    txt.css('height',(overlay.height()-params['IMargin']-params['IMargin'])+'px');
    
    if(params['Color']){
      overlay.css('background',params['Color']);
    }
      
    // Round the outside box
    //if(params['Oshape'] == 'R'){
    //  overlay.css('border-radius','5px');
    //  overlay.css('-moz-border-radius','5px');
    //  overlay.css('-webkit-border-radius','5px');
    //}

    overlay.fadeTo(1,params['Oopacity']);

    // Generate the caption
    if(params['Discap'] == 'Y'){
      $(inelement).find(".arts-spotlight-caption").css('display','block');
    }else{
      $(inelement).find(".arts-spotlight-caption").css('display','none');
    }
    var height = caption.height();
    caption.css('position','absolute');
    caption.css('z-index','6');
    caption.css('top',(pos.top-height)+'px');
    caption.css('left',(pos.left)+'px');
  }

  // Round the outside box
  //if(params['Oshape'] == 'R'){
  //  $(inelement).find(".arts-spotlight-bg").css('border-radius','5px');
  //  $(inelement).find(".arts-spotlight-bg").css('-moz-border-radius','5px');
  //  $(inelement).find(".arts-spotlight-bg").css('-webkit-border-radius','5px');
  //}
  
  setTimeout(function(){
    // Initiate the pane
    positionElements();
    loadPane(1);
  },250);
  
  // Start the auto-scroll
  setInterval(function(){
    if(pauseAuto == 0){
      loadPane(curEvent+1);
    }
  },params['Interval']*1000);
  
  // Auto-pause on mouse enter
  $(inelement).bind('mouseenter',function(){
    pauseAuto++;
  });
  
  // Auto-pause on mouse exit
  $(inelement).bind('mouseleave',function(){
    pauseAuto--;
  });
  
  // Highlight a selector button
  function highlightButton(num){
    var button = $(inelement).find('.arts-spotlight-selector-'+num);
    if(button){
      if(params['Bshape'] == 'R'){
        button.css('background','url(/site/spotlight_box/shapes.php?template=selector_circle_on&bgcolor='+params['BHcolor'].replace('#','')+'&bordercolor='+params['BBcolor'].replace('#','')+')');
        button.css('background-repeat','no-repeat');
        button.css('color','white');
      }else{
        button.css('border',"1px solid "+params['BBcolor']);
        button.css('background',params['BHcolor']);
        button.css('height',"16px");
        button.css('color','white');
      }
    }
  }

  // Unhighlight a selector button
  function unhighlightButton(num){
    if(curEvent == num) return;
    if(num == 'pause' && pauseManual) return;
    var button = $(inelement).find('.arts-spotlight-selector-'+num);
    if(button){
      if(params['Bshape'] == 'R'){
        button.css('background','url(/site/spotlight_box/shapes.php?template=selector_circle_off&bgcolor='+params['Bcolor'].replace('#','')+')');
        button.css('background-repeat','no-repeat');
        button.css('color','black');
      }else{
        button.css('border',"1px solid "+params['Bcolor']);
        button.css('background',params['Bcolor']);
        button.css('height',"16px");
        button.css('color','black');
      }
    }
  }
  
  // Load a new pane
  function loadPane(paneNum){
  
    // Check bounds on the pane number
    if(paneNum > events.length){
      paneNum = 1;
    }else if(paneNum < 1){
      paneNum = events.length;
    }
    
    // Prevent automatic scrolling during animations
    pauseAuto++;
    
    // Copy the current window to the top and fade it out
    if(curEvent && params['Fade'] != 'N'){
    
      var toFadeOut = $(inelement).find('.arts-spotlight').clone();
      toFadeOut.addClass('arts-spotlight-clone');
      toFadeOut.find('.arts-spotlight-caption').addClass('arts-spotlight-caption-clone');
      toFadeOut.find('.arts-spotlight-caption').removeClass('arts-spotlight-caption');
      toFadeOut.find('.arts-spotlight-text').removeClass('arts-spotlight-text');
      toFadeOut.find('.arts-spotlight-image').removeClass('arts-spotlight-image');
      toFadeOut.find('.arts-spotlight-bg').addClass('arts-spotlight-bg-cloned');
      toFadeOut.find('.arts-spotlight-bg').removeClass('arts-spotlight-bg');
      toFadeOut.css('z-index',100);
      $(inelement).append(toFadeOut);
      toFadeOut.fadeOut(params['Fade'],function(){
        $(inelement).find('.arts-spotlight-clone').remove();
        pauseAuto--;
      });
      
    }else{
      pauseAuto--;
    }
  
    $(inelement).find('.arts-spotlight-caption').html(events[paneNum-1].Caption);
    $(inelement).find('.arts-spotlight-text').html(events[paneNum-1].Html);
    if(events[paneNum-1].Img){
      $(inelement).find('.arts-spotlight-image').html("<a href='"+events[paneNum-1].Link+"'><img src='"+events[paneNum-1].Img+"' /></a>");
    }else{
      $(inelement).find('.arts-spotlight-image').html(events[paneNum-1].Img);
    }
    if(events[paneNum-1].Bgimg.substring(0,1) == '#'){
      $(inelement).find('.arts-spotlight-bg').css('background',events[paneNum-1].Bgimg);
    }else{
      $(inelement).find('.arts-spotlight-bg').css('background',"url("+events[paneNum-1].Bgimg+")");
    }
    positionElements();
  
    var oldCurEvent = curEvent;
    curEvent = paneNum;
    if(oldCurEvent) unhighlightButton(oldCurEvent);
    highlightButton(curEvent);
  }
  
}

// Register handler with jQuery
$.fn.spotlight = function(inparams,inevents){
  return this.each(function(){
    artsSpotlight(this,inparams,inevents);
  });
};

