jQuery.noConflict();
jQuery(document).ready(function ($){

    // Gestion du flash de la home
    /*
	if ($("#RCHome").length) {
		var flashparams = {
			bgcolor: "#ffffff"
		};
		var flashvars = {
			xmlPath: "flashs/assets/animaux.xml"
		};
		swfobject.embedSWF("flashs/RCHome.swf", "RCHome", "445", "430", "9.0.124", "flashs/expressInstall.swf", flashvars, flashparams);
	}
	*/

    $("#videotheque .slider a").click(function(){

        var flashvars = {
            flv: this.href,
            autoplay: '1',
            autoload: '1',
            margin: '0',
            bgcolor: '000000',
            showstop: '1',
            showvolume: '1',
            showtime: '1',
            showloading: 'always',
            showfullscreen: '1'
        };
       
        var params = {
            allowFullScreen: 'true',
            wmode: 'transparent'
        };
        
        var player = $("#flvplayer");
        var width = player.attr("width");
        var height = player.attr("height");

        var tsp = new Date().getTime();
        
        swfobject.embedSWF("/extension/royalcanin/design/groupe/flashs/player_flv_maxi.swf?id="+tsp, "flvplayer", width, height, "9.0.0", false, flashvars, params);

        $("#titreVideo").text($(this).attr("title"));
       
        var idvideo = $(this).attr("id").substr(6);
        var language_pos = unescape( $(this).attr("href") ).indexOf("/(language)/", 0);
        var language_code = unescape( $(this).attr("href") ).substr( language_pos+12, 6 );
        // requete ajax pour recup la description longue de la video
        $.get("/layout/set/video_desc?object_id="+idvideo+"&language_code="+language_code, function(data){
            $("#descVideoAjax").html(data);            
        });        
        
        this.blur();
        return false;        
    });

    

    $("#phototheque .slider a").click(function(){

        $("#photoContent").attr("src",this.href);

        $("#titrePhoto").text($(this).attr("title"));
       
        var idphoto = $(this).attr("id").substr(6);
        var language_pos = unescape( $(this).attr("href") ).indexOf("/(language)/", 0);
        var language_code = unescape( $(this).attr("href") ).substr( language_pos+12, 6 );
        // requete ajax pour recup la description longue de la video
        $.get("/layout/set/photo_desc?object_id="+idphoto+"&language_code="+language_code, function(data){
            $("#descPhotoAjax").html(data);
        });       
        
        this.blur();
        return false;        
    });
    
    if ($("#RCAideChoixChien").length) {

        var flashvars = {
          serviceName: "dogCatalogue",
          linkPath: "",
          assetsFolder: "/extension/royalcanin/design/filiale/flashs/assets/"
          //   ATTENTION POUR "assetsfolder", il faut absolument METTRE LE CHEMIN � partir DE LA RACINE DU SITE expl : "/royalcanin.fr/flashs/assets/". Pour permettre l'affichage des images et des produits des dossier "img" et "product"
        };
        var params = {
            menu: "false",
            allowScriptAccess: "always",
            scale: "noscale",
	    wmode: "transparent"
        };
        var attributes = {};
    
        swfobject.embedSWF("/extension/royalcanin/design/filiale/flashs/RCAideChoixChien.swf", "RCAideChoixChien", "695", "100%", "9.0.124", "/extension/royalcanin/design/groupe/flashs/expressInstall.swf", flashvars, params, attributes);
    }
    
    if ($("#RCAideChoixChat").length) {
        var flashvars = {
            serviceName: "catCatalogue",
            linkPath: "",
            assetsFolder: "/extension/royalcanin/design/filiale/flashs/assets/"
            //   ATTENTION POUR "assetsfolder", il faut absolument METTRE LE CHEMIN � partir DE LA RACINE DU SITE expl : "/royalcanin.fr/flashs/assets/". Pour permettre l'affichage des images et des produits des dossier "img" et "product"
        };
        var params = {
            menu: "false",
            allowScriptAccess: "always",
            scale: "noscale",
	    wmode: "transparent"
        };
        var attributes = {};
    
        swfobject.embedSWF("/extension/royalcanin/design/filiale/flashs/RCAideChoixChat.swf", "RCAideChoixChat", "695", "100%", "9.0.124", "/extension/royalcanin/design/groupe/flashs/expressInstall.swf", flashvars, params, attributes);
    }
    
    if ($("#annuaire").length) {
        var flashparams = {
            wmode: 'transparent'
        };
        var flashvars = {
            url: "http://www.google.fr/",
            dep13: "1",
            dep69: "1",
            dep04: "0"
        };
        swfobject.embedSWF("/extension/royalcanin/design/filiale/flashs/Annuaire.swf", "annuaire", "275", "230", "9.0.124", "/extension/royalcanin/design/groupe/flashs/expressInstall.swf", flashvars, flashparams);
    }
    
    if ($("#-promoLightSwf").length) {
        var flashparams = {
            wmode: "transparent"
        };
        var flashvars = {
        };
        swfobject.embedSWF("/extension/royalcanin/design/filiale/flashs/RCLightboxPrintemps.swf", "promoLightSwf", "700", "550", "9.0.0", "/extension/royalcanin/design/groupe/flashs/expressInstall.swf", flashvars, flashparams);
    }
    
});

function resizeSwf(y) {
    var cssObj = {'height' : y + 'px'}
    jQuery('#RCAideChoixChien,#RCAideChoixChat').css(cssObj);
    
}

function chargeFlashVideo(href){

   // Chargement de la video par d�faut � l'ouverture de la lightbox video
   var flashvars = {
        flv: href,
        autoplay: '1',
        autoload: '1',
        margin: '0',
        bgcolor: '000000',
        showstop: '1',
        showvolume: '1',
        showtime: '1',
        showloading: 'always',
        showfullscreen: '1'
    };
   
    var params = {
        allowFullScreen: 'true',
        wmode: 'transparent'
    };

    var tsp = new Date().getTime();

    swfobject.embedSWF("/extension/royalcanin/design/groupe/flashs/player_flv_maxi.swf?id="+tsp, "flvplayer", 320, 240, "9.0.0", false, flashvars, params);
};

/**
 * Force Scroll
 * @param goBottom:Boolean
 * @return void
 */
function resizeSwfComplete(goBottom)
{
    if (goBottom)
    {
        window.location="#flashContentBottom";
	}
    else {
	    window.location="#flashContent";
    }
}

function closeLightBox()
{
	jQuery("#promoLightbox").hide();
	jQuery("#overlayLightbox").hide();
}

function lightBoxProduct() {
	jQuery("#overlayLightbox").show();
	jQuery('#productLightbox').show();
}

//Nom de la catégorie d'évènement pour l'event tracking google de l'aide au choix
var aideAuChoixEventCategory = 'Aide au choix';

// Petit div de debug à réactiver au besoin
/*
jQuery(document).ready(function($) {
  	jQuery('#flashContent').before('<div id="flashDebug"></div>');
});
*/

function lightBoxProductInner(inner) {
	jQuery("#overlayLightbox").show();
	jQuery('#productLightboxIframe').attr('src', inner);
	jQuery('#productLightbox').show();

	//jQuery('#flashDebug').html('<b>Action:</b>: Visite produit<br/><b>Valeur: </b>' + inner);
	_gaq.push(['_trackEvent', aideAuChoixEventCategory, 'Visite produit', inner]);
}

/**
 * Récupère les évènements flash envoyés par l'aide au choix et fait les appels
 * à google _track_event le cas échéant.
 * 
 * @param flashEvent Evènement flash envoyé.
 */
function aideChoixTrackEvent(flashEvent) {
	var eventAction = null;
	var eventValue = null;

	if (flashEvent.nameFilter != null && flashEvent.valueFilter != null) {
		switch (flashEvent.nameFilter) {
		case 'breed':
			eventAction = 'Selection race';
			eventValue = flashEvent.valueFilter.value;
			break;
		case 'size':
			eventAction = 'Selection taille';
			eventValue = flashEvent.valueFilter.value;
			break;
		case 'age':
			eventAction = 'Selection age';
			eventValue = flashEvent.valueFilter.value;
			break;
		case 'sterile':
			eventAction = 'Selection stérilisé';
			eventValue = flashEvent.valueFilter.value;
			break;
		case 'dealer':
			eventAction = 'Selection vendeur';
			if (flashEvent.valueFilter.id == 1) {
				eventValue = 'Magasin';
			} else {
				eventValue = 'Veto';
			}
			break;
		case 'treatment':
			eventAction = 'Selection traitement';
			eventValue = flashEvent.valueFilter.value;
			break;
		case 'need':
			eventAction = 'Selection besoin spécifique';
			eventValue = flashEvent.valueFilter.value;
			break;
		}
	}
	else {
		if(flashEvent == 'Recherche produit')
		{
			eventAction = 'Recherche produit';
		}
	}

	if (eventAction != null) {
		//jQuery('#flashDebug').html('<b>Action:</b>: ' + eventAction + '<br/><b>Valeur: </b>'+ eventValue);
		_gaq.push(['_trackEvent', aideAuChoixEventCategory, eventAction, eventValue]);
	}
}
