/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
	//alert(carousel.attr("id"));
    jQuery('#mycarousel .jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		//alert(jQuery(this));
		 jQuery('#mycarousel .jcarousel-control .control-width').removeClass("btn-active").addClass("btn-inactive");
		 
		 jQuery(this).find(".control-width").removeClass("btn-inactive").addClass("btn-active");
		 //alert(jQuery(this).find(".control-width").attr("class"));
		
        return false;
    });

    jQuery('#mycarousel .jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

// Ride the carousel...
jQuery(document).ready(function() {
	jQuery(".picshow").show();					
    jQuery("#mycarousel").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
	
	

});

function mycarousel_initCallback2(carousel) {
	//alert(carousel.attr("id"));
    jQuery('#mycarouse2 .jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		//alert(jQuery(this));
		 jQuery('#mycarouse2 .jcarousel-control .control-width').removeClass("btn-active").addClass("btn-inactive");
		 
		 jQuery(this).find(".control-width").removeClass("btn-inactive").addClass("btn-active");
		 //alert(jQuery(this).find(".control-width").attr("class"));
		
        return false;
    });

    jQuery('#mycarouse2 .jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

// Ride the carousel...
jQuery(document).ready(function() {
	jQuery(".picshow").show();
	jQuery("#mycarouse2").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback2,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
});


var imgIdx = 0;


function mycarousel_initCallbackLead(carousel) {
	
    jQuery('#mycarouselAward .jcarousel-control a').bind('click', function() {
		//alert(jQuery.jcarousel.intval(jQuery(this).text()));															
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		//alert(jQuery(this));
		 jQuery('#mycarouselAward .jcarousel-control .control-width').removeClass("btn-active").addClass("btn-inactive");
		 
		 jQuery(this).find(".control-width").removeClass("btn-inactive").addClass("btn-active");
		 //alert(jQuery(this).find(".control-width").attr("class"));
		
        return false;
    });
	
    jQuery('#mycarouselAward .jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });
	

    
};



function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
	//alert(idx);
	carousel.length;
	imgIdx = idx + 1;
	//alert(imgIdx);
	
	var li = $("#mycarouselAward li").length;
	
	if(idx == li){
		//alert("test");
		//carousel.scroll(1);
	}
	//alert(imgIdx);
	

};


	

 //--------------click back change red botton-----------------------------//
function mycarousel_itemFirstOutCallback(carousel, item, idx, state) {
    //alert(idx);

	idx = idx ;

	jQuery('#mycarouselAward .jcarousel-prev').bind('click', function() {
		//alert(idx);															
        carousel.scroll(idx);
		//alert(jQuery(this));
		 jQuery('#mycarouselAward .jcarousel-control .control-width').removeClass("btn-active").addClass("btn-inactive");
		 $("#bullet"+idx).removeClass("btn-inactive").addClass("btn-active");
		 //alert(jQuery(this).find(".control-width").attr("class"));
		
        return false;
    });
	
};
 //--------------click back change red botton-----------------------------//
 
 
function mycarousel_itemLastInCallback(carousel, item, idx, state) {
    //alert(idx);
	//display('Item #' + idx + ' is now the last item');
};

function mycarousel_itemLastOutCallback(carousel, item, idx, state) {
    //alert(idx);
	//display('Item #' + idx + ' is no longer the last item');
};

function mycarousel_buttonNextCallback(carousel, button, enabled) {
    //display('Next button is now ' + (enabled ? 'enabled' : 'disabled'));
		//alert(imgIdx);
	 	
};

function mycarousel_buttonPrevCallback(carousel, button, enabled) {
    //display('Prev button is now ' + (enabled ? 'enabled' : 'disabled'));
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered before animation.
 */
function mycarousel_itemVisibleInCallbackAwardBeforeAnimation(carousel, item, idx, state) {
    // No animation on first load of the carousel
    if (state == 'init')
        return;
    jQuery('img', item).fadeIn('slow');
};



/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered after animation.
 */
 
 
 
 //--------------click next change red botton-----------------------------//
function mycarousel_itemVisibleInCallbackAwardAfterAnimation(carousel, item, imgIdx, state) {
    //alert('Item #' + idx + ' is now visible');
	//carousel.scroll(imgIdx);
	//alert(jQuery(this));
	//alert(imgIdx);
	
	
	 /*jQuery('#mycarouselAward .jcarousel-control .control-width').removeClass("btn-active").addClass("btn-inactive");
	 $("#bullet"+imgIdx).removeClass("btn-inactive").addClass("btn-active");*/
	 
	 
	 //alert(jQuery(this).find(".control-width").attr("class"));
};
 //--------------click next change red botton-----------------------------//



//------------------------circular----------------------------------//

/*var mycarousel_itemList_award = [
    {url: 'images/test01.jpg', title: 'Flower1'},
    {url: 'images/test02.jpg', title: 'Flower2'},
    {url: 'images/test03.jpg', title: 'Flower3'},
    {url: 'images/test04.jpg', title: 'Flower4'}
];*/

/*var mycarousel_itemList_award = [
    {html: '<a href="index_pic.php" target="_self"><img src="images/test01.jpg" width="960" height="400" alt="Flower1" /></a>'},
    {html: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="960" height="400"><param name="movie" value="imgUpload/LeadGraphic12_model02.swf"/><param name="quality" value="high"/><param name="wmode" value="transparent"/><embed src="imgUpload/LeadGraphic12_model02.swf" width="960" height="400" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent"></embed></object>'},
    {html: '<a href="newsandactivities.php" target="_self"><img src="images/test03.jpg" width="960" height="400" alt="Flower3" /></a>'},
    {html: '<a href="products.php" target="_self"><img src="images/test04.jpg" width="960" height="400" alt="Flower4" /></a>'}
];*/


function mycarousel_itemVisibleInCallbackAward(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList_award.length);
	//alert(mycarousel_itemList_award[idx - 1]);
	//alert(idx+"/"+mycarousel_itemList_award.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList_award[idx - 1]));
	carousel.add(i, mycarousel_itemList_award[idx - 1].html);
	
	
	
	//-------------------------- change red botton --------------------------//
	jQuery('#mycarouselAward .jcarousel-control .control-width').removeClass("btn-active").addClass("btn-inactive");
	jQuery("#bullet"+idx).removeClass("btn-inactive").addClass("btn-active");
	//alert($("#bullet"+idx));
	//$("#bullet"+idx).removeClass("btn-inactive").addClass("btn-active");
	//-------------------------- change red botton --------------------------//
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{	
    carousel.remove(i);
};

function mycarousel_getItemHTML(item)
{
    return '<img src="' + item.url + '" width="960" height="400" alt="' + item.title + '" />';
};
//------------------------circular----------------------------------//


// Ride the carousel...
jQuery(document).ready(function() {
	jQuery(".picshow").show();
	
	jQuery("#mycarouselAward").jcarousel({
		//------------------TEST Loop----------------------//
        /*auto:7,*/
		auto:5,
		scroll: 1,
		/*animation: 800,*/
		animation: 1500,
		wrap: 'circular',
		initCallback: mycarousel_initCallbackLead,
		itemVisibleInCallback: {
            onBeforeAnimation: mycarousel_itemVisibleInCallbackAwardBeforeAnimation,
			onBeforeAnimation: mycarousel_itemVisibleInCallbackAward,
            onAfterAnimation:  mycarousel_itemVisibleInCallbackAwardAfterAnimation
        },
        //itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallbackAward},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
		
		
		//------------------TEST Loop----------------------//
		
		//------------------use----------------------//
		
		/*scroll: 1,
		initCallback: mycarousel_initCallbackLead,
        itemVisibleInCallback: {
            onBeforeAnimation: mycarousel_itemVisibleInCallbackAwardBeforeAnimation,
            onAfterAnimation:  mycarousel_itemVisibleInCallbackAwardAfterAnimation
        },
		auto:2*/
		
		//------------------use----------------------//
		
		
		
		//itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
		//,buttonNextCallback:null
        // This tells jCarousel NOT to autobuild prev/next buttons
        /*buttonNextHTML: null,
        buttonPrevHTML: null*/
    });
	
	
	
	
});

