
function myFlyerCarousel_initCallback(carousel) {
    //jQuery('.jcarousel-control a').bind('click', function() {
	jQuery("#homeFlyerCarouselNav a").bind("click", function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr("rel")));
        return false;
    });
};

function myFeaturedProductsCarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
};

function myFeaturedRecipesCarousel_initCallback(carousel) {
	jQuery("#homeRecipeCarouselNav a").bind("click", function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr("rel")));
        return false;
    });
};

function myFeaturedArticlesCarousel_initCallback(carousel) {
	jQuery("#homeArticleCarouselNav a").bind("click", function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr("rel")));
        return false;
    });
};

function myFlyerCarousel_updateView(carousel, listItem, listItemIndex, itemState) {
	jQuery("#GF_Home_Featured_Products #homeFeaturedProductsInfo span.content").css("display","none");
	jQuery("#GF_Home_Featured_Products #homeFeaturedProductsInfo span[rel='homeFeaturedProducts_" + listItemIndex + "']").css("display","block");
}

function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
	//;
};

function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
	var strCarouselID = jQuery(item).parent("ul").attr("id");
	var strParentID = jQuery("#"+strCarouselID).parent().parent().parent().parent().attr("id");
	var strIconSrc = jQuery("#"+strParentID + " div.carouselNav a").eq(idx-1).find("img").attr("src");
	strIconSrc = strIconSrc.replace("_off","_on");
	jQuery("#"+strParentID + " div.carouselNav a").eq(idx-1).find("img").attr("src",strIconSrc);
};

function mycarousel_itemVisibleOutCallbackBeforeAnimation(carousel, item, idx, state) {
	//;
};

function mycarousel_itemVisibleOutCallbackAfterAnimation(carousel, item, idx, state) {
	var strCarouselID = jQuery(item).parent("ul").attr("id");
	var strParentID = jQuery("#"+strCarouselID).parent().parent().parent().parent().attr("id");
	var strIconSrc = jQuery("#"+strParentID + " div.carouselNav a").eq(idx-1).find("img").attr("src");
	strIconSrc = strIconSrc.replace("_on","_off");
	jQuery("#"+strParentID + " div.carouselNav a").eq(idx-1).find("img").attr("src",strIconSrc);
};

function myFlyerCarousel_itemFirstInCallbackBeforeAnimation(carousel, item, idx, state) {
	//;
};

function myFlyerCarousel_itemFirstInCallbackAfterAnimation(carousel, item, idx, state) {
	var strCarouselID = jQuery(item).parent("ul").attr("id");
	var strParentID = jQuery("#"+strCarouselID).parent().parent().parent().parent().attr("id");
	jQuery("#"+strParentID + " div.carouselNav a img").each(function(){
		jQuery(this).attr("src", jQuery(this).attr("src").replace("_on","_off"));
	});
	jQuery("#"+strParentID + " div.carouselNav a").eq(parseInt(idx/4)).find("img").attr("src", jQuery("#"+strParentID + " div.carouselNav a").eq(parseInt(idx/4)).find("img").attr("src").replace("_off","_on"));
};

function myFlyerCarousel_itemVisibleOutCallbackBeforeAnimation(carousel, item, idx, state) {
	//;
};

function myFlyerCarousel_itemVisibleOutCallbackAfterAnimation(carousel, item, idx, state) {
	//;
};  


jQuery(document).ready(function(){
      doReady();
      
});

function doReady(){

    if (jQuery("#myFlyerCarousel").length > 0){
          jQuery("#myFlyerCarousel").jcarousel({
                //config
                initCallback: myFlyerCarousel_initCallback,
		  scroll: 4,
		itemFirstInCallback: {
			onBeforeAnimation: myFlyerCarousel_itemFirstInCallbackBeforeAnimation,
			onAfterAnimation:  myFlyerCarousel_itemFirstInCallbackAfterAnimation
		}
          });
    }

    if (jQuery("#homeFeaturedProductsCarousel").length > 0){
          jQuery("#homeFeaturedProductsCarousel").jcarousel({
                //config
                initCallback: myFlyerCarousel_initCallback,
		  scroll: 1,
		  itemVisibleInCallback: myFlyerCarousel_updateView
          });
    }
    if (jQuery("#homeFeaturedDepartmentsCarousel").length > 0){
          jQuery("#homeFeaturedDepartmentsCarousel").jcarousel({
                //config
                initCallback: myFlyerCarousel_initCallback,
		  scroll: 1
          });
    }
    
    if (jQuery("#homeRecipeCarousel").length > 0){
          jQuery("#homeRecipeCarousel").jcarousel({
                //config
                initCallback: myFeaturedRecipesCarousel_initCallback,
		  scroll: 1,
		itemVisibleInCallback: {
			onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation,
			onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
		},
		itemVisibleOutCallback: {
			onBeforeAnimation: mycarousel_itemVisibleOutCallbackBeforeAnimation,
			onAfterAnimation:  mycarousel_itemVisibleOutCallbackAfterAnimation
		}
          });
    }

    if (jQuery("#homeArticleCarousel").length > 0){
          jQuery("#homeArticleCarousel").jcarousel({
                //config
                initCallback: myFeaturedArticlesCarousel_initCallback,
		  scroll: 1,
		itemVisibleInCallback: {
			onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation,
			onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
		},
		itemVisibleOutCallback: {
			onBeforeAnimation: mycarousel_itemVisibleOutCallbackBeforeAnimation,
			onAfterAnimation:  mycarousel_itemVisibleOutCallbackAfterAnimation
		}
          });
    }
	
	// I'm not sure this section is used anymore ??
	jQuery("span.recoFlyerItemInfo").hover(
		function(){
			var thisItem = jQuery(this).attr("rel");
			var thisOffset = jQuery(this).offset();
			var carouselOffset = 0;
			if (jQuery("ul#myFlyerCarousel").css("left") <= -441){
				var carouselOffset = 30;
			}
			jQuery("span.recoFlyerItemInfoContents[rel='" + jQuery(this).attr("rel") + "']").css({
				"display":"block",
				"top":(0) + "px",
				"left": (parseInt(jQuery("ul#myFlyerCarousel").css("left")) + (jQuery("ul#myFlyerCarousel li").index(jQuery(this).parent()) * 157) - carouselOffset) + "px"
			});
			var thisPosition = jQuery(this).parent().position();
		},
		function(){
			jQuery("span.recoFlyerItemInfoContents[rel='" + jQuery(this).attr("rel") + "']").css("display","none");
		}
	);
	
	// I'm not sure this section is used anymore ??
	jQuery("span.recoFlyerItemInfoContents").hover(
		function(){
			jQuery(this).css("display","block");
		},
		function(){
			jQuery(this).css("display","none");
		}
	);


	jQuery("div#articleDetailContent ol.largeNumber li").each(function(){
		jQuery(this).css({
			"background": "transparent url(images/gf/article_bullet_styled_" + parseInt(jQuery("div#articleDetailContent ol.largeNumber li").index(this) + 1) + ".gif) no-repeat 0px 0px"
		});
	});
}

