$(document).ready(function() {


    if($("#videoshow")) // afficher une video au chargement de la page si le div ayant pour id lectureVideo
	{
		var id_video = $("img.thumbvideoyoutube:first").attr("id");
                //alert(id_video);
		$('#videoshow').html('<object height="356" width="425" type="application/x-shockwave-flash" id="myytplayer" data="http://www.youtube.com/v/'+id_video+'?enablejsapi=1&playerapiid=ytplayer"><param name="allowScriptAccess" value="always"/></object>');
            //'<object width="360" height="300"><param name="movie" value="'+urlVideo+'?enablejsapi=1&playerapiid=ytplayer&color1=0x2193bd&color2=0x2193bd"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+urlVideo+'&color1=0x2193bd&color2=0x2193bd" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="360" height="300"></embed></object>');
	}
	$("img.thumbvideoyoutube").click( function() { // si on clique sur une miniature on affiche la vidéo dans le bloc ayant pour id "lectureVideo"
                //$("#videoshow").html('<object width="360" height="300"><param name="movie" value="'+$(this).attr("id")+'&color1=0x2193bd&color2=0x2193bd"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+$(this).attr("id")+'&color1=0x2193bd&color2=0x2193bd" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="360" height="300"></embed></object>');
                var id_video = $(this).attr('id');
                $('#videoshow').html('<object height="356" width="425" type="application/x-shockwave-flash" id="myytplayer" data="http://www.youtube.com/v/'+id_video+'?enablejsapi=1&playerapiid=ytplayer"><param name="allowScriptAccess" value="always"/></object>');
	});
	 if($("#vignettes").length){
    /*
     * Produits en promotion index
     */
    var promoRel = '';
    var promoAction = 'true';
    var promoLi = 8;
    var promoHaut = $('.cont-vignette ul').height();

    if(promoAction == "true") {
        promoAction = false;
        $('#vignettes ul li').bind("click", function() {
		  promoAction = "false";
            promoRel = $(this).attr('rel');
            $('#panneau li').fadeOut();
            $('#panneau .'+promoRel).fadeIn();
            $('#vignettes ul li').removeClass('on');
            $('#vignettes ul li').addClass('off');
            $(this).addClass('on');
            promoAction = true;
        });
    }

    var promoMarg = $('#vignettes ul').css('margin-top');
    promoMarg = promoMarg.substr(0,promoMarg.length-2);
    var promoMax = promoHaut-280;
    $('.btn-haut').bind("click", function() {
	    
        if (promoMarg>(-promoMax)) {
            promoMarg = promoMarg - 70;
            $('#vignettes ul').css('margin-top',promoMarg+'px');
            $('.btn-bas').css('visibility','visible');
        }
        if (promoMarg==-promoMax) {
            $('.btn-haut').css('visibility','hidden');
        }
    });

    $('.btn-bas').bind("click", function() {
        if ( promoMarg < 0) {
            promoMarg = promoMarg + 70;
            $('#vignettes ul').css('margin-top',promoMarg+'px');
            $('.btn-haut').css('visibility','visible');
        }
        if (promoMarg==0) {
            $('.btn-bas').css('visibility','hidden');
        }
    });
    }
    /*
     * Gallerie photo
     */
    $(".gphoto").colorbox({slideshow:true,width: 600});

    /*
     * Liste vidéo index
     */
    $(".pvideo").colorbox({iframe:true, innerWidth:305, innerHeight:231});
      $(".lightbox").colorbox({
        'iframe':true,
        'width': 800,
        'height': 500,
        'opacity': 0.7
    });

});
