var numberOfSlides = 0;
var currentPosition = 0;
var intervalSS = 0;
$(document).ready(function () {
    var b = $(".buttonsGallery a");
    numberOfSlides = b.length;
    b.click(function () {
        clearInterval(intervalSS);
        new_position = 20 * this.rel;
        xpoz = new_position + "px";
        $("#buttonsGalleryOn").animate({
            left: xpoz
        }, 500);
        currentPosition = this.rel;
        $(".galleryImage").fadeOut();
        var a = "#ajaxGal_" + this.rel;
        $(a).fadeIn();
        intervalSS = setInterval("playSlideShow()", 5000);
        return false
    });
    intervalSS = setInterval("playSlideShow()", 5000);
    $("#menu a").hover(function () {
        $(this).animate({
            opacity: .5
        }, {queue:false, duration:250})
    }, function () {
        $(this).animate({
            opacity: 1
        }, {queue:false, duration:250})
    });
    $(".bouton").hover(function () {
        $(this).stop().animate({
            opacity: .5
        }, {queue:false, duration:250})
    }, function () {
        $(this).stop().animate({
            opacity: 1
        }, {queue:false, duration:250})
    });
	
	$("body").prepend("<div id='overBK1_content'><div id='overBK1'><div id='overBK1inside'></div><div id='captionsBK1'></div></div><div id='navBK1'><a class='closeBK1' href='#'><img src='css/close.png'></a><a class='nextBK1' href='#'><img src='css/next.png'></a><a class='prevBK1' href='#'><img src='css/prev.png'></a></div></div>");
    $("#overBK1_content").hide();
    $(".closeBK1").css("right", screen.width / 2 - 512);
    $(".prevBK1").css("left", screen.width / 2 - 512);
    $(".nextBK1").css("right", screen.width / 2 - 512);
    var b = 0;
    var c = 0;
    $(".bouton").click(function () {
		$("#footer").fadeOut();
        if ($(this).children("a").attr("rel") == "video") {
            $(".closeBK1").css("top", -30);
            $("#captionsBK1").html("");
            $("#captionsBK1").hide();
            b = 0;
            $("#overBK1inside").css("left", 0);
            c = $(this).children("a");
            var a = "";
            for (i = 0; i < c.length; i++) {
                a += '<object width="1024" height="540"><param name="movie" value="http://www.dailymotion.com/swf/video/' + $(c[i]).attr("href") + '?width=1024&theme=none&foreground=%23F7FFFD&highlight=%23FFC300&background=%23171D1B&start=&animatedTitle=&iframe=0&additionalInfos=0&autoPlay=0&hideInfos=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/' + $(c[i]).attr("href") + '?width=1024&theme=none&foreground=%23F7FFFD&highlight=%23FFC300&background=%23171D1B&start=&animatedTitle=&iframe=0&additionalInfos=0&autoPlay=0&hideInfos=0" width="1024" height="540" allowfullscreen="true" allowscriptaccess="always"></embed></object>'
            }
            $("#overBK1inside").css("width", 1024 * c.length);
            $("#overBK1inside").html(a);
            $("#captionsBK1").html($(c[b]).attr('title'));
            $("#captionsBK1").delay(1000).fadeIn(500);
            $("#overBK1_content").fadeIn();
            $(".nextBK1").hide();
            if (c.length > 1) {
                $(".nextBK1").show()
            }
            $(".prevBK1").hide()
        } else {
            $("#captionsBK1").html("");
            $("#captionsBK1").hide();
            b = 0;
            $("#overBK1inside").css("left", 0);
            c = $(this).children("a");
            var a = "";
            for (i = 0; i < c.length; i++) {
                a += "<img width='1024' height='540' src='" + $(c[i]).attr('href') + "' />"
            }
            $("#overBK1inside").css("width", 1024 * c.length);
            $("#overBK1inside").html(a);
            $("#captionsBK1").html($(c[b]).attr('title'));
            $("#captionsBK1").delay(1000).fadeIn(500);
            $("#overBK1_content").fadeIn();
            $(".nextBK1").hide();
            if (c.length > 1) {
                $(".nextBK1").show()
            }
            $(".prevBK1").hide()
        }
    });
    $(".closeBK1").click(function () {
        $("#overBK1_content").fadeOut()
		$("#footer").fadeIn();
    });
    $(".nextBK1").click(function () {
        $("#overBK1inside").animate({
            left: '-=1024'
        }, 500);
        $(".prevBK1").show();
        b++;
        $("#captionsBK1").html($(c[b]).attr('title'));
        if (b == c.length - 1) {
            $(".nextBK1").hide()
        }
    });
    $(".prevBK1").click(function () {
        $("#overBK1inside").animate({
            left: '+=1024'
        }, 500);
        $(".nextBK1").show();
        b--;
        $("#captionsBK1").html($(c[b]).attr('title'));
        if (b == 0) {
            $(".prevBK1").hide()
        }
    });
    $("#navBK1").css("opacity", 0);
    $("#overBK1_content").hover(function () {
        $("#navBK1").animate({
            opacity: 1
        }, 400)
    }, function () {
        $("#navBK1").animate({
            opacity: 0
        }, 400)
    })
	
});

function playSlideShow() {
    var a = $(".buttonsGallery a");
    numberOfSlides = a.length - 1;
    $("#ajaxGal_" + currentPosition).animate({
        left: -769
    }, 1000);
    if (currentPosition < numberOfSlides) {
        currentPosition++
    } else {
        currentPosition = 0
    }
    new_position = 20 * currentPosition;
    xpoz = new_position + "px";
    $("#buttonsGalleryOn").animate({
        left: xpoz
    }, 500);
    $("#ajaxGal_" + currentPosition).css('left', '769px');
    $("#ajaxGal_" + currentPosition).show();
    $("#ajaxGal_" + currentPosition).animate({
        left: 0
    }, 1000);
	
	
}







