


        
/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        var idx = jQuery(this).attr("id").replace("navigatorItem_", "");
        carousel.scroll(jQuery.jcarousel.intval(idx));
        return false;
    }); 
}

// Used to mark the currently selected "page" dot 
function mycarousel_itemFirstInCallback(carousel, item, index, state)
{      
    var idx = carousel.first; // Will not be correct if more than 1 item is visible  
    var activeElement=jQuery('.sel');
    activeElement.removeClass('sel');
    activeElement.addClass('unsel');
       
    var selected = jQuery('#navigatorItem_' + idx);
    selected.removeClass('unsel');
    selected.addClass('sel');
    return false;
}


// Ride the carousel...


jQuery(document).ready(function() 
{
    // Find the li-element that contains the link to the current page. Start the carousel at this li.
    var location = document.location.pathname;
    var items = jQuery('.carouselListItem');
    var bestLinkIndex = 1;
    var bestLinkLength = 0;
    for (var i = 0; i < items.length; i++) 
    {
       var item = items.get(i);
       var links = jQuery('a', item);
       for (var j = 0; j < links.length; j++)
       {
           var link = links.get(j);
           var href = link.pathname; 
           if (location.indexOf(href) != -1 && location.length > bestLinkLength)
           { 
               bestLinkIndex = i + 1;
               bestLinkLength = href.length;
           }
       }
    }

    jQuery("#mycarousel").jcarousel({
        scroll: 1,
        start : bestLinkIndex,
        initCallback: mycarousel_initCallback,
        itemFirstInCallback : mycarousel_itemFirstInCallback
    });
    
    jQuery("#mycarousel .jcarousel-next").click(function()
    {
		return disablemorefeatures();
    });
   
   jQuery("#mycarousel .jcarousel-prev").click(function()
    {
		return disablemorefeatures();	
   });
   
   jQuery("#mycarousel .unsel").click(function()
    {
		return disablemorefeatures();	
   });
   
   
   function disablemorefeatures() 
   {
	
		setTimeout(function()
		{
			if ( jQuery("div.jcarousel-next-disabled").length > 0 )
			{
			   	jQuery(".xcapMoreFeatures").css("color", "#7abfc2");
			   	return stopPulser();
			
			}
			else
			{
				jQuery(".xcapMoreFeatures").css("color", "#fff");
			}
		}, 500); 

		return false;	  
   }
   
   
   jQuery(".xcapMoreFeatures").click(function()
   {
    	jQuery("#mycarousel .jcarousel-next").click();
   });
  
	
    
});

