$j(document).ready(function () {
    if (document.getElementById("slideshow")) {
        $j("#pictures li").hide();
		var total = $j("#menu2 li").length;
		var i = 0;
        $j("#menu2 li").each(function (a) {
			i++;
			if (i == 1) $j(this).addClass('first');
			if (i == total) $j(this).addClass('last');
            $j(this).click(function (b) {
                manageClick(a);
                return false
            })
        });
        $j("#pictures li").each(function (a) {
            $j(this).hover(function (b) {
                manageHover();
                return false
            })
        });
        manageAnimation()
    }
    if (document.getElementById("slideshow")) {
        $j("#close").click(function () {
            hideBanner();
            return false
        });
        setTimeout("showBanner()", 500)
    }
});
var frame = 0;
var timeout_id = null;
var nofferte = 1;

function showBanner()
{
    var c = $j("#flybanner");
    c.css("width", $j(window).width());
    c.css("height", $j(window).height());
    c.fadeTo("fast", 0.9);
    var b = $j("#banner");
    var g = ($j(window).height() - $j("#banner").height()) / 2;
    var f = ($j(window).width() - $j("#banner").width()) / 2;
    b.css("left", f);
    b.css("top", g);
    b.toggle("slow");
}
function hideBanner() {
    $j("#flybanner").hide();
    $j("#banner").hide();
    $j("#close").hide()
}
function manageAnimation() {
    var c = $j("#pictures li");
    var d = $j("#menu2 li");
    var b = frame;
    if (frame == 0) {
        c.eq(frame).fadeIn("slow");
        c.eq(c.length - 1).fadeOut("slow");
        d.eq(frame).addClass("current");
        d.eq(d.length - 1).removeClass("current")
    } else {
        if (frame == 1) {
            c.eq(frame).fadeIn("slow");
            c.eq(frame - 1).fadeOut("slow");
            d.eq(frame).addClass("current");
            d.eq(0).removeClass("current")
        } else {
            if ((frame != 1) && (frame <= nofferte)) {
                c.eq(frame).fadeIn("slow");
                c.eq(frame - 1).fadeOut("slow")
            } else {
                c.eq(frame).fadeIn("slow");
                c.eq(frame - 1).fadeOut("slow");
                d.eq(frame - nofferte).removeClass("current");
                d.eq(frame + 1 - nofferte).addClass("current")
            }
        }
    }
    frame = (frame + 1) % (c.length);
    timeout_id = setTimeout("manageAnimation()", 5000)
}
function manageClick(a) {
    if (timeout_id) {
        clearTimeout(timeout_id);
        timeout_id = null
    }
    $j("#pictures li").hide();
    $j("#menu2 li").removeClass("current");
    $j("#menu2 li").eq(a).addClass("current");
    if (a == 0) {
        $j("#pictures li").eq(0).show();
        frame = 0
    } else {
        if (a == 1) {
            $j("#pictures li").eq(a).show();
            frame = 1
        } else {
            $j("#pictures li").eq(a + nofferte - 1).show();
            frame = a + nofferte - 1
        }
    }
    timeout_id = setTimeout("manageAnimation()", 5000)
}
function manageHover() {
    if (timeout_id) {
        clearTimeout(timeout_id);
        timeout_id = null
    }
    timeout_id = setTimeout("manageAnimation()", 5000)
}
