jQuery.fn.init_carousel = function() {


	// set globals
	$.yuna_carousel = {};
	$.yuna_carousel.intCurrentIndex = 0;
	$.yuna_carousel.intDelay = 5000; // (milisec)
	first = true;

	$('.imageSliderLink').show();

 	// set handlers on the navigation
 	$('.imageSliderLink').each(function(intIndex){
 		$(this).click(function(){
 			$.yuna_carousel.intCurrentIndex = intIndex;
 			show_content();
 			return false;
 		});
 	});

 	// show the first box
	show_content($.yuna_carousel.intCurrentIndex);
	return(this);
}


// show the content for the given index
function show_content(){

	 // loop through the navigation
	 // edit the active link
	 // remember the correct one
	 $('.imageSliderLink').each(function(intIndex){
	 	if(intIndex==$.yuna_carousel.intCurrentIndex){
			$(this).attr("class","imageSliderLink active");
			$.yuna_carousel.jqActiveLink = $(this);
	 	} else {
	 	    $(this).attr("class","imageSliderLink inactive");
	 	}
	 });



	  // get the rel item from the active link
	 var strBoxId = $.yuna_carousel.jqActiveLink.attr("rel");



	 // loop through the content boxes, turn them all off
	 $('.headerContentBox').each(function(intIndex){
	 	$(this).css("position","absolute");
	 	if ($(this).attr('id') != strBoxId) {
			if(first == true) {
				$(this).css('display', 'none');
			}else {
	 			$(this).fadeOut('slow');
			}
	 	}

	 });
	 first = false;

	 // set the active content parts
	 var objContentBox =  $('#'+strBoxId);
	 var objContentText =  $('#'+strBoxId+' .textPart')
	 var objContentImage =  $('#'+strBoxId+' .imagePart')



	 //display the entire box
	 objContentBox.css("display","block");
	 // display the text part
	 objContentText.css("display","block");
	 // fade in the image

	 objContentImage.css("display","none");
	 objContentImage.css({ opacity:0, visibility:'visible' })
//	 objContentImage.fadeIn('slow');
	objContentImage.css("display","block");
	 objContentImage.animate( {opacity:1}, 2000 );

	 // set a new interval
	 clearInterval($.yuna_carousel.intTimeoutId);
	 $.yuna_carousel.intTimeoutId= setInterval("show_next_content();",$.yuna_carousel.intDelay);
}


/*
* circulate
* called from interval
*/
function show_next_content(){
	// get the total amount of boxes
	var arrContent = $('.imageSliderLink');
	var intCarouselLength = arrContent.length;

	// increment the index
	$.yuna_carousel.intCurrentIndex++;

	// circulate the index
	if($.yuna_carousel.intCurrentIndex >= intCarouselLength){
		$.yuna_carousel.intCurrentIndex = 0;
	}
	//set the active one
	show_content();
}
