jQuery(document).ready(function(){
    //----------------------Info_bule-----------------------------------
    jQuery('.info_bul').hide();

    if(jQuery('#mycarousel'))
    {
        jQuery('#mycarousel').jcarousel({
            scroll: 1,
            itemLastInCallback:
            {
                onBeforeAnimation: function(carousel , li , index , state) {
                    jQuery("#mycarousel li").each(function() {
                        var carIndex = $(this).attr('jcarouselindex');
                        if(carIndex == index && index !=1)
                        {
                            jQuery("#mycarousel li").removeClass('thisLastItemInCarousel');
                            jQuery(this).addClass('thisLastItemInCarousel');
                        }
                    });
                }
            }
        });
    }

    jQuery("#mycarousel li").each(function() {
        jQuery(this).css('margin-top', 78 - jQuery(this).find('strong').height());
    });
    
    jQuery("#mycarousel li").hover(
        function()
        {
            //jQuery(this).css('margin-top', '18px');
            jQuery(this).css('margin-top', 50 - jQuery(this).find('strong').height());
            if(jQuery(this).hasClass('thisLastItemInCarousel'))
            {
                jQuery(this).find('.info_bul').addClass('info_bul2');
                jQuery(this).find('.info_bul').removeClass('info_bul');
                jQuery(this).find('.info_bul2').show();
                jQuery(this).find('img').width(162);
                jQuery(this).find('img').height(205);
            }
            else
            {
                jQuery(this).find('.info_bul').show();
                jQuery(this).find('img').width(162);
                jQuery(this).find('img').height(205);
            }
        },
        function()
        {
            //jQuery(this).css('margin-top', '46px');
            jQuery(this).css('margin-top', 78 - jQuery(this).find('strong').height());
            if(jQuery(this).hasClass('thisLastItemInCarousel'))
            {
                jQuery(this).find('.info_bul2').addClass('info_bul');
                jQuery(this).find('.info_bul').removeClass('info_bul2');

                jQuery(this).find('.info_bul2').hide();
                jQuery(this).find('.info_bul').hide();;
                jQuery(this).find('img').width(142);
                jQuery(this).find('img').height(177);
            }
            else
            {
                jQuery(this).find('.info_bul').hide();
                jQuery(this).find('img').width(142);
                jQuery(this).find('img').height(177);
            }
        }
    );
	
	
    //---------Survole titre de jcarousel (page Temoignages)--------
    jQuery('.titre_image').css('visibility','hidden');
    jQuery("#lien_temoignages_carousel li").hover(
        function()
        {
            jQuery(this).find('.titre_image').css('visibility','visible');
        },
        function(){
            jQuery(this).find('.titre_image').css('visibility','hidden');
        }
    );	

    //----------agrandir image au Survole dans la page produit------
    jQuery("#main_pop_in a").hover(
        function()
        {
            jQuery(this).find('img').width(190);
            jQuery(this).find('img').height(136);
        },
        function()
        {
            jQuery(this).find('img').width(137);
            jQuery(this).find('img').height(100);
        }
    );
    jQuery("#main_pop_in").mouseenter(function() {
        jQuery("#main_pop_in a.default").removeClass('default');
    });
    jQuery("#main_pop_in").mouseleave(function() {
        jQuery(jQuery("#main_pop_in a")[1]).addClass('default');
    });
    jQuery(jQuery("#main_pop_in a")[1]).addClass('default');

    //----------Lightbox Galerie photos----------------
    jQuery(".loadPictures").each(function() {
        if(jQuery(this).attr('href') != '') {
            jQuery(jQuery(this).attr('href') + ' a').lightBox({
                imageLoading:			'/espaces/Portals/48/Skins/sage_france_mge3/images/v2/lightbox-ico-loading.gif',   // (string) Path and the name of the loading icon
                imageBtnPrev:			LEFT_CAROUSEL_IMAGE,			        // (string) Path and the name of the prev button image
                imageBtnNext:			RIGHT_CAROUSEL_IMAGE,			        // (string) Path and the name of the next button image
                imageBtnClose:			'/espaces/Portals/48/Skins/sage_france_mge3/images/v2/closelabel.gif',		        // (string) Path and the name of the close btn
                imageBlank:				'/espaces/Portals/48/Skins/sage_france_mge3/images/v2/lightbox-blank.gif'			// (string) Path and the name of a blank image (one pixel)
            });
        }
    });
    jQuery(".loadPictures").click(
        function() {
            jQuery(jQuery(jQuery(this).attr('href') + ' a')[0]).click();
			return false;
        }
    );

    //-----------------sexyCombo---------------------
    jQuery(".mixed-combo").sexyCombo(
    {
        triggerSelected: true,
        autoFill: true,
        skin: "custom"
    });

    //-----------------Fix png ie6---------------------		
    if (jQuery.browser.msie && jQuery.browser.version == "6.0")
    {
        jQuery(".icon_liste img").pngfix();
        DD_belatedPNG.fix('#main_pop_in img');
		DD_belatedPNG.fix('#slider_infos li img');
    }

    //-----------------Arondi---------------------	
    if ( jQuery.browser.msie)
    {
        DD_roundies.addRule('.bloc_left', '5px');
    }
	
	//jQuery("a.imagePop").nyroModal();/*{type: 'image', wrap: {image: '<div class="wrapper"><div class="wrapperImg"><div class="wrapperImgIn"></div></div></div>'}}*/
	
	//---------------- Banner video sur page produit || intermediaire --------------
	if($("#main_pop_in_video").length > 0){
		if($("#main_pop_in").length > 0){
			$("#main_pop_in").css('display','none');
		}
		if($("#main_carousel").length > 0){
			$("#main_carousel").css('display','none');
		}
	}
	else{
		if($("#main_pop_in").length > 0){
			$("#main_pop_in").css('display','inline-block');
		}
		if($("#main_carousel").length > 0){
			$("#main_carousel").css('display','inline-block');
		}
	}	
	
	$('#slider_apercu').hide();
	$('#slider_infos').hide();

	$("#btn_apercu").click(function () {
		  $('#slider_apercu').animate({width: 'toggle'}, 120);
		});

	$("#btn_infos").click(function(){
		 $('#slider_infos').animate({width: 'toggle'}, 120);
		});
});

//---------------- Banner video--------------
function displayMainPlayer(xml){
	//player
	var playerWidth = "599";
	var playerHeight = "252";
	var playerBgColor = "#ff0000";
	var conteneurId = "main_player";
	var playerUrl = "/espaces/Portals/48/Skins/sage_france_mge3/player/player.swf";
	
	var flashvars = {};
	flashvars.lcId = "123456";
	flashvars.autoStart = "false";
	flashvars.isDeported = "false";
	flashvars.xmlMedia = xml;
	
	var params = {};
	params.menu = "false";
	params.swliveconnect = "true";
	params.wmode = "transparent";
	params.allowfullscreen = "false";
	params.allowscriptaccess = "always";
	
	swfobject.embedSWF(playerUrl , conteneurId, playerWidth, playerHeight, "8.0.0", false, flashvars, params);
	var player = new Player({
								id : 123456,
								objectId : conteneurId,
								onInitialized :
									function() {
									},
								onEnded:
									function() {
									DisplayMainPopIn();
								} 
							});
									
	players.push(player);
}

function seekMedia(value)
{
	players.getPlayer().seekMedia(value);
}
function DisplayMainPopIn()
{
	$('#main_pop_in_video').hide();
	
	if( $("#main_pop_in").length > 0){
		$('#main_pop_in').show();
	}
	else if( $("#mycarousel").length > 0){
		$('#main_carousel').show();
	}
}
