﻿var is_image_loaded = function (img) {
    // IE
    if (!img.complete) {
        return false;
    }
    // Others
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }
    return true;
}

$(document).ready(function () {
    var first_slide = $('.tickerFeatured img:first');
    if (is_image_loaded(first_slide.get(0))) {
        $('.tickerFeatured').cycle({
            fx: 'scrollHorz',
            delay: 1000,
            timeout: 8000,
            pause: 1,
            speed: 1400,
            next: '#featuredNext',
            prev: '#featuredPrev',
            pager: '#featuredPager',
            sync: 1,
            autostopCount: 5
        });
    } else {
        first_slide.load(function (e) {
            //$('#loading').hide();
            //$('#slideshow').show().cycle();
            $('.tickerFeatured').cycle({
                fx: 'scrollHorz',
                delay: 1000,
                timeout: 8000,
                pause: 1,
                speed: 1400,
                next: '#featuredNext',
                prev: '#featuredPrev',
                pager: '#featuredPager',
                sync: 1,
                autostopCount: 5
            });
        });
        //$('#slideshow').hide();
        // I'll handwave the display of a loading indicator, since
        // it's covered in the tutorial linked in the question.
        //$('#loading').show();
    }
});

//$(document).ready(function () {
function pageLoad(sender, args) {
    //alert('go');
    $('.myticker').cycle({
        fx: 'scrollUp',
        after: adDisplayCallback,
        timeout: 6000,
        pause: 1,
        speedIn: 800,
        speedOut: 1200,
        easeIn: 'easeInCirc',
        easeOut: 'easeInCirc',
        next: '#next',
        sync: 0,
        fastOnEvent: 1
    });

    //            $('.tickerFeatured').cycle({
    //                fx: 'scrollHorz',
    //                delay:         1000,
    //                timeout: 8000,
    //                pause: 1,
    //                speed: 1400,
    //                next: '#featuredNext',
    //                prev: '#featuredPrev',
    //                pager: '#featuredPager',
    //                sync: 1,
    //                autostopCount: 5,
    //                requeueOnImageNotLoaded: true,
    //                requeueTimeout: 500
    //            });
}
//});
