﻿/// <reference path="protoaculous.1.8.1.min.js" />

function aff(id,idi)
{
    if (idi==null) idi='i'+id;

	if ($(id).style.display=="none")
	{
		$(id).style.display="block";
		// src="/images/icons/empty.gif" class="sprite-icon sprite-
		$(idi).className="sprite-icon sprite-application_get"; $(idi).alt="Masquer"; $(idi).title=$(idi).alt;
	}
	else
	{
		$(id).style.display="none";
		$(idi).className="sprite-icon sprite-application_put"; $(idi).alt="Afficher"; $(idi).title=$(idi).alt;
    }
}

function round()
{
    $A($$('.cote .module')).each(function(item) { if (!item.hasClassName('noround')) { item.appendChild(new Element('div', { 'class': 'end' })); } });
    
    var a = new Element('div', { 'class': 'end' });
    var b = new Element('div', { 'class': 'end' });
    
    var last = $($A($$('#centre .module')).last());
    
    if (last!=null) {
        if (!last.hasClassName('noround')) {
            if (Prototype.Browser.IE) {
                var c = new Element('div', { 'class': 'endie' });
                c.style.height=17;
                c.style.borderBottom="solid 1px #D6D6D6";
                c.style.margin="0 18px 0 18px";
                b.appendChild(c);
                last.style.borderBottom="";
                last.style.paddingBottom = 0;
            }
            
            a.appendChild(b);
            last.appendChild(a);
        }
    }

    if ($('centre').style.marginRight == '5px' && $('coldroite')) $('coldroite').style.display = "none";
}

function faff(id)
{
    $(id).style.display="block";
}

function createAlert(idAlert,ipAlert,guid)
{
    var dAlert=$(idAlert);
    var pAlert=$(ipAlert);

    if (Prototype.Browser.IE) {
        pAlert.show();
    } else {
        dAlert.observe('mouseover', function() { pAlert.show(); });
        dAlert.observe('mouseout', function() { pAlert.hide(); });
    }

    pAlert.observe('click', function() {
        new Effect.Fade(dAlert, { afterFinish: function() {
            dAlert.remove();
            deleteAlert(guid);
        } 
        });
    }); 
}

function deleteAlert(guid) {
    new Ajax.Request('/async.ashx?action=delete&what=alert&where=' + guid);
}

function createFriend(idFriend)
{
    var dFriend = $(idFriend);
    var pFriend = $($$('#' + idFriend + ' .delete')[0]);
    var hFriend = $($$('#' + idFriend + ' .friendhandler')[0]);
    
    pFriend.hide();
    hFriend.hide();
    
    dFriend.observe('mouseover', function() { pFriend.show(); hFriend.show(); });
    dFriend.observe('mouseout', function() { pFriend.hide(); hFriend.hide(); });
}

function removeMessage(id)
{
    var m=$(id);
    var ms=null;

    if (m.nextSiblings()[0]!=null) { if (m.nextSiblings()[0].hasClassName('messageseparator')) { ms = m.nextSiblings()[0]; }; }
    else { m.parentNode.update("Vous n'avez pas de message");  }

    new Effect.Fade(m,{afterFinish:function() { if (m!=null) { m.remove(); } if(ms!=null) { ms.remove(); } }});
}

function initEditor()
{
    /*
    tinyMCE_GZ.init({
	    plugins : 'spellchecker,advimage',
	    themes : 'advanced',
	    languages : 'fr',
	    disk_cache : true,
	    debug : false
    });
    */
}

function createEditor(id)
{
    tinyMCE.init({
        mode : "exact",
        elements : id,
        theme : "advanced",
        plugins: "spellchecker,paste,youtube,dailymotion,wollyhood",
        theme_advanced_buttons1: "bold,italic,underline,strikethrough,fontsizeselect,separator,undo,redo,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,link,image,youtube,dailymotion,separator,bullist,numlist,separator,pasteword,separator,icon,wollyhood.userlink,wollyhood.articlelink,wollyhood.movielink,wollyhood.sagalink,wollyhood.directorlink,wollyhood.districtlink,wollyhood.grouplink,separator,wollyhood.help",
        theme_advanced_buttons2: "",
        theme_advanced_buttons3: "",
        theme_advanced_buttons4: "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_resizing : true,
        theme_advanced_resizing_use_cookie : true,
        theme_advanced_resize_horizontal : false,
        theme_advanced_statusbar_location: "bottom",
        gecko_spellcheck : true,
        spellchecker_languages : "Anglais=en,+Français=fr",
        language : "fr"
    });
}

function createCommentEditor(id)
{
    tinyMCE.init({
        mode : "exact",
        elements : id,
        theme : "advanced",
        plugins: "spellchecker,paste,youtube,dailymotion,wollyhood",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_resizing : false,
        theme_advanced_resizing_use_cookie : false,
        theme_advanced_resize_horizontal : false,
        spellchecker_languages : "Anglais=en,+Français=fr",
        language : "fr",
        theme_advanced_buttons1: "bold,italic,underline, strikethrough, separator,undo,redo,separator,image,separator,bullist,numlist,separator,link,youtube,dailymotion,separator,pasteword,separator,icon,wollyhood.userlink,wollyhood.articlelink,wollyhood.movielink,wollyhood.sagalink,wollyhood.directorlink,wollyhood.districtlink,wollyhood.grouplink,separator,wollyhood.help",
        theme_advanced_buttons2: "",
        theme_advanced_buttons3: "",
        theme_advanced_buttons4: "",
        theme_advanced_path: false,
        gecko_spellcheck: true,
        theme_advanced_statusbar_location : "none"
    });
}

function ShowUserItem(element) {
    $(element).style.width = '130px';
}

function HideUserItem(element) {
    $(element).style.width = '0';
}

function clickButton(e, buttonid){
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);
      if (bt){
          if (evt.keyCode == 13){
                bt.click();
                return false;
          }
      }
}

function init()
{
    round();
}

Object.extend(Event, {
  onReady : function(f) {
    if (document.body) f();
    else document.observe('dom:loaded', f);
  }
});

function ToggleColorSelector() {
    var cs = $('colorselector');
    var csc = $('colorselectorcontrol');

    if (cs.hasClassName('colorselectorpenned')) {
        cs.removeClassName('colorselectorpenned');
        cs.addClassName('colorselectorclosed');

        csc.src = '/images/icons/palette.png';
        csc.alt = 'Changer de thème';
    } else {
        cs.removeClassName('colorselectorclosed');
        cs.addClassName('colorselectorpenned');

        csc.src = '/images/icons/cross.png';
        csc.alt = 'Cacher';
    }
    csc.title = csc.alt;
}

function spoiler(span) {
    var div = span.parentNode.nextSiblings()[0];

    if (div.style.display == 'none') {
        div.style.display = 'block';
        span.innerHTML = 'Cacher';
    } else {
        div.style.display = 'none';
        span.innerHTML = 'Afficher';
    }
}

function logout() {
    FB.Connect.ifUserConnected(
        function () {
            FB.Connect.logoutAndRedirect("/logout");
        },'/logout'
    );
}
