﻿$(document).ready(function () {

    //get first one

    doAnimation(1);

});

function doAnimation(rel) {

    var total = parseInt($('.SCCIPBanner').size());

    var obj = $('.SCCIPBanner[rel="' + rel + '"]');

    //alert(1);

    obj.children('.trans').hide();
    obj.children('.transInner').children('.caption').hide();
    obj.children('.transInner').children('.SCCIPBannerFindOutMore').hide();
    obj.children('.SCCIPBannerDocumentImage').hide();

    //alert(2);

    $('.SCCIPBanner').hide();

    //alert(3);

    //fade in background

    obj.fadeIn(1000, function () {

        //fade in transparent overlay

        var BannerType = obj.children('#ctl00_ctl00_Banner_rptBanner_ctl01_hfBannerType').val();

        if (BannerType != "Blank") {

            obj.children('.trans').fadeTo(750, 0.7, function () {

                // fade in document image
                obj.children('.SCCIPBannerDocumentImage').fadeIn(500);

                //fade in text
                obj.children('.transInner').children('.caption').fadeIn(500, function () {

                    //show find out more link

                    obj.children('.transInner').children('.SCCIPBannerFindOutMore').fadeIn(100, function () {

                        //var obj = $('.SCCIPBanner[rel=2]');

                        if ((parseInt(rel) + 1) <= total) {

                            rel = rel + 1;
                        }
                        else {

                            rel = 1;
                        }

                        if (total > 1) {

                            window.setTimeout("doAnimation(" + parseInt(rel) + ")", 8000);

                        }

                    });
                });

            });

        }

    });

}

(function ($) {
    $.fn.customFadeIn = function (speed, callback) {
        $(this).fadeIn(speed, function () {
            if (!$.support.opacity)
                $(this).get(0).style.removeAttribute('filter');
            if (callback != undefined)
                callback();
        });
    };
    $.fn.customFadeOut = function (speed, callback) {
        $(this).fadeOut(speed, function () {
            if (!$.support.opacity)
                $(this).get(0).style.removeAttribute('filter');
            if (callback != undefined)
                callback();
        });
    };
    $.fn.customFadeTo = function (speed, to, callback) {
        return this.animate({ opacity: to }, speed, function () {
            if (to == 1 && jQuery.browser.msie)
                this.style.removeAttribute('filter');
            if (jQuery.isFunction(callback))
                callback();
        });
    };
})(jQuery);
