/*----------------------------------------------------------------------------//
// Javascript pour le site client  -------------------------------------------//
//----------------------------------------------------------------------------//
// Client : -
// Note   : -
// Date   : -
//----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
// Inclusion dynamique des fichiers externes javascripts
/*----------------------------------------------------------------------------*/
function importJavascript(src)
{
	document.write("<script type=\"text/javascript\" src=\"" + src + "\"></scr" + "ipt>");
}
function importCss(href, media)
{
	document.write('<link rel="stylesheet" type="text/css" media="' + media + '" href="' + href + '" />');
}

/*----------------------------------------------------------------------------*/
// Importations de fichiers
/*----------------------------------------------------------------------------*/
importJavascript("/includes/js/swfobject.js");

importJavascript("/includes/js/plugins/jquery.ifixpng.js");
importJavascript("/includes/js/plugins/jquery.thicker.js");

importJavascript("/includes/js/plugins/thickbox.js");
importCss("/includes/js/plugins/thickbox.css", "screen");

/*----------------------------------------------------------------------------*/
// Declarations jQuery
/*----------------------------------------------------------------------------*/
jQuery.noConflict();

function InitEnteteDropDown() {
    jQuery("#Entete div.Liste p a").click(function() {
        var parentDD = jQuery(this).parents("div.Liste");
        jQuery("#Entete div.Liste ul").hide();
        jQuery("ul", parentDD).slideDown(150);
        jQuery("ul a", parentDD).click(function() {
            jQuery("ul", parentDD).hide();
            jQuery(this).unbind("click");
        });
        jQuery(document).unbind("click").bind("click", function() {
            jQuery("ul", parentDD).hide();
            jQuery(this).unbind("click");
        });
        return false;
    });
}

jQuery(document).ready(function() {

    // PNGs
    /*jQuery.ifixpng("/images/spacer.gif");
    jQuery("#Entete .Logo img").each(function(){
        jQuery(this).ifixpng();
    });
    jQuery("div.Perso .Descrip img").each(function(){
        jQuery(this).ifixpng();
    });
    jQuery("p.PhotoSoiree img").each(function(){
        jQuery(this).ifixpng();
    });*/

    // DropDowns
    window.setTimeout("InitEnteteDropDown()", 1);
        
//    jQuery("#Entete div.Liste p a").click(function() {
//        var parentDD = jQuery(this).parents("div.Liste");
//        jQuery("#Entete div.Liste ul").hide();
//        jQuery("ul", parentDD).slideDown(150);
//        jQuery("ul a", parentDD).click(function() {
//            jQuery("ul", parentDD).hide();
//            jQuery(this).unbind("click");
//        });
//        jQuery(document).unbind("click").bind("click", function() {
//            jQuery("ul", parentDD).hide();
//            jQuery(this).unbind("click");
//        });
//        return false;
//    });

    // FIX Playlist
    jQuery("#ColD .Playlist ul li a").click(function() {
        jQuery("#ColD .Playlist ul li").removeClass("On");
        jQuery(this).parent().addClass("On");
        return false;
    });

    // Details du vote
    jQuery("body.Vote ul.Questions a").click(function() {
        jQuery("body.Vote div.Resultat").hide();
        jQuery("body.Vote div." + jQuery(this).attr("href").substring(1)).show();
        jQuery("body.Vote ul.Questions a").removeClass("On");
        jQuery(this).addClass("On");
        return false;
    });

});
function StatsForVideo(sURI){
    var regex = new RegExp("[0-9]{12}");
    var result = sURI.match(regex);
    var dt = '';
    
    if (result != null && result.length > 0)
        dt = result[0];

    statsToProfils(
    'DCS.dcsuri', sURI,
    'profil', 'global;sc;sc_audiovideo;sc_audiovideo_differe;sc_audiovideo_video;GUI_srcEmbed;lang_fr;av_nomEmission_Remyx',
    'titrepage', '',
    'descriptiondansurl',
        'media=video' +
        '&diffusion=differe' +
        '&GUI=srcEmbed' +
        '&chaine=ExclusifWeb' +
        '&emi=Remyx' +
        '&dt=' + dt +
        '&decoupe='
    );
    
    
    // 
    // dt = 200909082000

//où _sURI prend la valeur du path+nom du video de l'épisode et dt correspond à la date+heure de diffusion de l'épisode (dans l'exemple c'est pour le 8 sept 2009 à 20h00). Si vous n'avez pas d'heure mettez simplement 0000 pour les heures.
}
function initPersoEpisode() {
	jQuery("div.Section.Perso li a").mouseover(function(){
		var descrip = jQuery(this).parents("div.Section.Perso").find(".Descrip");
		var perso = jQuery("img", this).attr("alt");
		jQuery("div.Section.Perso li a").removeClass("On");
		jQuery(this).addClass("On");
		jQuery(".Sign img", descrip)
			.attr("src", "/Documents/images/Personnages/" + perso + "_Sign.png")
			.attr("alt", perso)
			.ifixpng();
		jQuery(".Photo img", descrip).attr("src", "/Documents/images/Personnages/" + perso + "_Photo.png").ifixpng();
		jQuery(".Texte", descrip).html(jQuery(this).attr("rel"));
	});
	jQuery("div.Section.Perso li a:first").mouseover();
}


/* Fontions qui affichent les pages sous thickbox */
function showFirstTimeConfirmationDialog() {
    jQuery(window).load(function() {
        setTimeout(function() { tb_show(null, '/confirmation-du-profil.html?TB_iframe=true&modal=true&width=471&height=571', false); }, 1500);
    });
}

function showFanBoxDialog() {
    tb_show(null, '/page-des-fans.html?TB_iframe=true&width=500&height=700', false); // 298&height=542
}

function showProfilePage(userId) {
    tb_show(null, '/profil-de-la-communaute.html?id=' + userId + '&TB_iframe=true&width=471&height=570', false);
}

function showLoginNotification() {
    //jQuery(window).load(function() {
    tb_show(null, '/notification-de-login.html?TB_iframe=true&width=471&height=337', false);
//});
}

function showLoginNotificationWithoutAnonymousUsers() {
    //jQuery(window).load(function() {
    tb_show(null, '/notification-de-login.html?anonymous=0&TB_iframe=true&width=471&height=235', false);
    //});
}

function showNewsletter() {
    tb_show(null, '/windows/Newsletter.aspx?keepThis=true&amp;TB_iframe=true&amp;height=238&amp;width=480', false);
}

function showCommunityInTB() {
    tb_show(null, '/windows/community.aspx?keepThis=true&amp;TB_iframe=true&amp;height=570&amp;width=480', false);
}

function showVoteDetails(episode) {
    tb_show(null, '/windows/VoteDetails.aspx?episode=' + episode + '&amp;keepThis=true&amp;TB_iframe=true&amp;height=544&amp;width=480', false);
}

function showCommunity() {
    self.location = "/windows/community.aspx";
    
    //tb_show(null, '/windows/community.aspx?keepThis=true&TB_iframe=true&height=600&width=480', false);
}

function showIncidentReportForm() {
    tb_show(null, '/Windows/IncidentReport.aspx?keepThis=true&amp;TB_iframe=true&amp;height=614&amp;width=480', false);
}

function showListMembers(){
    showCommunity();
}
function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else {
        return document.getElementById(movieName);
    }
}

/* Publicités */

reloadAds = function() {
    jQuery('div.smartAd iframe').each(function() { this.src = this.src; });
}

function VerifyAndAskForFacebookPublishRights(callbackFunction) {
    // Vérifier les permissions
    FB.Facebook.apiClient.users_hasAppPermission('publish_stream', function(result) {
        if (result != "1") {
            // Demander les permissions
            FB.Connect.showPermissionDialog('publish_stream', callbackFunction);
        }
    });
}