﻿(function($) {
    $.anim_list = {
        parent: null,
        data_layers: ["section-animated", "section-layer01", "section-layer03", "section-layer02", "section-people", "section-layer04", "section-text"],
        text: {
            list: ["images/text01.png", "images/text03.png", "images/text02.png"],
            animation: function(obj, selector) { (selector.length > 0 ? selector.first().fadeIn(3000, function() { obj.text.animation(obj, $(".section-text img:hidden")) }) : ""); },
            init: function(obj, selector) { if (obj.parent.find(".section-text img").length == 0) { $(obj.text.list).each(function(i, item) { $("<img src=\"" + item + "\"/>").appendTo(selector).hide(); }); obj.text.animation(obj, obj.parent.find("img:hidden")); } else { obj.parent.find(".section-text img").remove(); obj.text.init(obj, selector); } }
        },
        counter: 0,
        data: [{ img: 'images/bg_gorvern.jpg', p: 'images/people_govern.png', offset: 240 }, { img: 'images/bg_commercial.jpg', p: 'images/people_commercial.png', offset: 300 }, { img: 'images/bg_consumer.jpg', p: 'images/people_consumer.png', offset: 240}],
        static_setting: { preload_name: "preload" },
        util: {
            test: function(obj) { },
            reset: function(obj) { var selector = obj.parent.find(".section-people"); if (selector.css("opacity") == 1) { selector.animate({ opacity: 0 }, function() { obj.parent.find(".section-animated").animate({ marginLeft: 0 }).end().find(".section-people").css({ marginLeft: 0 }); }); } },
            preload: function(obj, callback) { $("<div id=\"" + obj.static_setting.preload_name + "\"></div>").appendTo("body"); $.each(obj.data, function(i, item) { $("<img src=\"" + item.img + "\"/><img src=\"" + item.p + "\"/>").appendTo("#" + obj.static_setting.preload_name).hide().ready(function() { (obj.data.length == (i + 1) ? (typeof callback == "function" ? callback() : void (0)) : ""); }); }); },
            placeholder: function(obj) { $("<div></div>").insertAfter(obj.parent).height(obj.parent.height()); },
            buildlayers: function(obj) { $(obj.data_layers).each(function(i, item) { obj.parent.append("<div class=\"" + item + "\"></div>"); }); }
        },
        init: function() {
            var obj = this;
            obj.parent.show();
            obj.util.reset(obj);
            obj.parent
                .find(".section-animated")
                .css({
                    marginLeft: -20,
                    opacity: 0,
                    backgroundImage: "url(" + obj.data[obj.counter].img + ")"
                })
                .animate({ opacity: 1, marginLeft: '+=20' }, 400, function() {
                    obj.parent.find(".section-people")
                        .css({ marginLeft: obj.data[obj.counter].offset, opacity: 0, backgroundImage: "url(" + obj.data[obj.counter].p + ")" })
                        .animate({ opacity: 1, marginLeft: '-=100' }, 1000, function() {
                            $.anim_list.counter++;
                            if ($.anim_list.counter == $.anim_list.data.length) {
                                $.anim_list.counter = 0;
                            };
                            window.setTimeout(function() { obj.init() }, 6000);
                        });
                });
        }
    };
    $.fn.anim = function(callback) {
        var obj = $.anim_list;
        obj.parent = $(this).hide();
        obj.util.buildlayers(obj);
        //obj.util.placeholder(obj);
        obj.text.init(obj, obj.parent.find(".section-text"));
        obj.util.preload(obj, function() { obj.init() }); return this;
    };
})(jQuery);

$(document).ready(function() {
    var isFlash;
    try {
        x = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
        isFlash = true;
    }
    catch (e) {
        isFlash = false;
    }
    if (document.all && isFlash) {
        $("#drx_flash,#drx_header_flash").show();
        $("#drx_animation_placeholder, #drx_header, #drx_tabs").hide();
    }
    else {
        $("#drx_flash,#drx_header_flash").hide();
        $("#drx_animation_placeholder").css({ backgroundImage: 'none' })
        $("#drx_animation").anim();
        //    $("#drx_tabs a").mouseover(function(e) {
        //        $(this).animate({ marginTop: 5, height: 36 }, 100, function() { });
        //    }).mouseout(function(e) {
        //        $(this).animate({ marginTop: 10, height: 31 }, 100, function() { });
        //    });
    }
    $("#divCompositeLayer").delay(1000).fadeIn();
});
