﻿function open_tour() {
    $('div#tour_popup').overlay({
        mask: '#000', closeOnClick: false,
        //onLoad: tour_init() 
        onBeforeClose: function (event) {
            $('html').unbind("keypress");
        }
    });
    $('div#tour_popup').overlay().load();
}
function close_tour() {
    $('div#tour_popup').overlay().close();
}
function load_tour() {
    var html = $('div#tour_popup > div').html().replace(/ /g, "").replace(/[\t\n\r]/gi, "");
    if (html == "") {
        $.ajax({
            cache: false,
            async: true,
            type: "POST",
            //url: '<%= ResolveUrl("~/CMS.aspx/loadTour") %>',
            url: "/CMS.aspx/loadTour",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                $('div#tour_popup > div').html(msg.d);
                setTimeout("tour_init()", 500);
            }
        });
    }
    open_tour();
}
function tour_init() {
    $('div#tour_popup div.image_wrap img:first').show();
    $('div#tour_popup div.text_wrap div.text > div:first').show();
    $('html').bind("keypress", function (e) {
        if (e.keyCode == 37) {
            tour_transition('prev');
            return false;
        }
        else if (e.keyCode == 39) {
            tour_transition('next');
            return false;
        }
        else
        { return true; }
    });
}
function tour_transition(dir) {
    switch (dir) {
        case "next":
            var next;
            var current = $('div#tour_popup div.image_wrap img:visible');
            var last = $('div#tour_popup div.image_wrap img:last-child').index();
            if (current.index() != last) {
                next = current.next();
            }
            else {
                next = $('div#tour_popup div.image_wrap img:first-child');
            }
            current.fadeOut(300);
            $('div#tour_popup div.text > div:eq(' + current.index() + ')').fadeOut(300);
            next.fadeIn(500);
            $('div#tour_popup div.text > div:eq(' + next.index() + ')').fadeIn(500);
            break;
        case "prev":
            var prev;
            var current = $('div#tour_popup div.image_wrap img:visible');
            var first = $('div#tour_popup div.image_wrap img:first-child').index();
            if (current.index() != first) {
                prev = current.prev();
            }
            else {
                prev = $('div#tour_popup div.image_wrap img:last-child');
            }
            current.fadeOut(300);
            $('div#tour_popup div.text > div:eq(' + current.index() + ')').fadeOut(300);
            prev.fadeIn(500);
            $('div#tour_popup div.text > div:eq(' + prev.index() + ')').fadeIn(500);
            break;
    }
}
