var $j = $j || jQuery.noConflict();


/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
var visibleSlide = 0; 
function mycarousel_initCallback(carousel) {
	var totalSlides = $j('#heroCarousel').find('ul li').length;
	var startPosition = 1;
	for(i=1; i<=totalSlides;i++){
		$j('#heroCarouselControl').append('<a class="heroPagination" href="#" title="Slide '+i+' of '+totalSlides+'">'+i+'</a>');
	}
	$j('#heroCarouselControl').children('a:eq(0)').addClass('highLighted')
	$j('#heroCarouselControl a').bind('click', function() {
        carousel.scroll($j.jcarousel.intval($j(this).text()));
		$j('#heroCarouselControl a').removeClass('highLighted')
		$j(this).addClass('highLighted');
        return false;
    });
}

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered after animation.
 */
function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
	visibleSlide = idx;
};

function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
	$j('#heroCarouselControl a').removeClass('highLighted')
	$j('#heroCarouselControl').children('a').eq(idx-1).addClass('highLighted');
};


/* code for branch locater dropdown end */
$j(document).ready(function() {

	if ($j("#heroCarousel").length){ 
	    $j('#heroCarousel').jcarousel({
			auto: 12,
			scroll:1,
			animation: 'slow',
		wrap: 'last',
			// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null,
			itemFirstInCallback:  mycarousel_itemFirstInCallback,
		itemVisibleInCallback: {
		    onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
		},
		initCallback: mycarousel_initCallback				  
		});
	}
// My HiSave Carosuel init function
	if ($j("#myHiSaveCarosuel").length){ 
		$j("#myHiSaveCarosuel").jcarousel({	
			scroll:1,
			 auto: 12,
			animation: 'slow'
		});
	}
	
// Testimonial Carosuel init function
	if ($j("#testimonialCarousel").length){ 
		$j("#testimonialCarousel").jcarousel({	
			scroll:1,
			animation: 'slow'
		});
	}
	
	
});
