var gwJcarousel = new Object();

/*
 * itemLoadCallback
 * starts just before a new item moves into the first position
 * BTW - jquery.jcarousel.js had to be modified 
 * (line 236 "$(window).unbind('resize.jcarousel..." commented out) 
 * to remove issue with browser resizing making images bounce.
*/

gwJcarousel.itemLoadCallback = function(carousel, state) {

	//test for whether the currentImage var is set already 
	//if it is we need to make sure the previous image is scaled
	//back to previously set imgHeight and imgWidth properties
	if(window.currentImage) {
		$(currentImage).animate({ 
	    	height: '150px', 
	    	width: currentImage.attr('width')*.75, 
	    	marginTop: '30', 
	    	marginLeft: '0' }, 
	    	300 
	    );
	 }
	
	    
	//make sure any other content that has been displayed is hidden
	$('.homeBubble').fadeOut(1000).hide();
    
	//find the item furthest to the left (gives us the index number only)
    firstCarouselItem = carousel.first;  
   
   //look for the carousel li with that index ( in attr "jcarouselindex")
    activeCarouselItem = $('#gwCarousel').find('li[jcarouselindex ='+firstCarouselItem+']');
    
    //get the id of that carousel item
    firstCarouselItemId = $(activeCarouselItem).attr('id');
    
    //get the unique part of that li id string
    uniquePart = firstCarouselItemId.slice(8);
    
    //doing the actions to the objects within the carousel based on our selection
    window.currentImage = $(activeCarouselItem).children(':first-child')
    imgWidth = currentImage.attr('width');
    imgHeight = currentImage.attr('height');
    
    $(currentImage).animate({ 
    	height: '200px', 
    	width: imgWidth/.75, 
    	marginTop: '-20px', 
    	marginLeft: '0'
    	}, 300, function() {
	    	// Animation complete.
	    	$("#homeBubble"+uniquePart).fadeIn(500);
	});

}

/*
* standard jcarousel init function
*/
$(document).ready(function() {

	$('.carouselMainImg').each(function() {
		$(this).animate({ 
	    	height: '150px', 
	    	width: $(this).attr('width')*.75, 
	    	marginTop: '30', 
	    	marginLeft: '0'},
	    	0
		);
	});

    $('#gwCarousel').jcarousel({
    	//only advance 1 item at a time
        scroll: 1,
        auto: 8,
        animation: 'slow',
        wrap: 'circular',
        //callback functions to relate items with content that gets faded in
        itemLoadCallback: {onBeforeAnimation: gwJcarousel.itemLoadCallback}
    });
});

