var $j = jQuery.noConflict();
var FFESDetailPage = '';
var LastSlide = 1;
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel(
    {
        auto: 3
        , scroll: 1
        , wrap: 'circular'
        , prev: ''
        , itemFirstInCallback: ffes_itemFirstInCallback
        , itemFirstOutCallback: ffes_itemFirstOutCallback
        , itemVisibleInCallback: { onBeforeAnimation: mycarousel_itemVisibleInCallback }
        , itemVisibleOutCallback: { onAfterAnimation: mycarousel_itemVisibleOutCallback }
    }
    );
});

//jQuery(document).ready(function() {
//    jQuery('.slideshow').cycle({
//        startingSlide: 0, timeout: 0, fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
//    });
//});
jQuery(document).ready(function() {
    if (document.getElementById('SlideShow1') != null) {
        var SlideArray = document.getElementById('SlideShow1').childNodes;
        for (var i = 1; i < SlideArray.length; i++) {
            jQuery(SlideArray[i]).css("filter", "none");
        };
        //hide all elements, but first one
        for (var i = 1; i < SlideArray.length; i++) {
            jQuery(SlideArray[i]).hide();
        };
    }
});
function ffes_itemFirstInCallback(carousel, item, itemIndex) {
    var locIndex = carousel.first % mycarousel_itemList.length; //handle issue where array max exceeded
    if (locIndex < 0) locIndex = mycarousel_itemList.length + locIndex; //handle if goes negative
    if (locIndex == 0) locIndex = mycarousel_itemList.length; //handle wrap around
    item.className += ' on';

    if (jQuery("#SlideShow1").height() != 0) {
        var height = (jQuery("#SlideShow1").height() + 'px');
        document.getElementById('SlideShow1').style.height = height;
    }    

    var SlideArray = document.getElementById('SlideShow1').childNodes;
    jQuery(SlideArray[LastSlide]).fadeOut(0, function() {        
        jQuery(SlideArray[locIndex - 1]).fadeIn(500);
    });
//    jQuery(SlideArray[LastSlide]).hide();
//        
//    jQuery(SlideArray[locIndex - 1]).fadeIn(2000);
    
    LastSlide = locIndex - 1;    
};

function ffes_itemFirstOutCallback(carousel, item, itemIndex) {
    item.className = item.className.replace(' on', '');
};

function mycarousel_itemVisibleInCallback(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.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
    item.className = item.className.replace(' on', '');
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
    item.className = item.className.replace(' on', '');
};

/**
* Item html creation helper.
*/
function mycarousel_getItemHTML(item) {

    if (LoadTargetInPage) {
        
        var SepKey = '?';
        if (FFESDetailPage.indexOf("?") >= 0) {
            SepKey = '&';
        }
        //alert(SepKey);
        return '<a href="' + FFESDetailPage + SepKey + 'page=featuredetails&FFESID=' + item.databaseId + '#seasonalwidget"><img src="' + item.url + '" alt="' + item.title + '" height="57px" width="57px" border="0"/></a>';
    }
    else {
        return '<a href="http://www.familyfeatures.com/ifsjs/theme/FeatureDetailFull.aspx?ID=' + item.databaseId + '"><img src="' + item.url + '" alt="' + item.title + '" height="57px" width="57px" border="0"/></a>';
    }
};


    
