var Poker = {
  "timeout": null,
  "layout_height": 0,
  "side_height": 0,
  "init": function () {
    Poker.Search.init($('query'));
    Poker.resize();
    Poker.scroll();
    Event.observe(window, 'size', Poker.resize);
    Event.observe(window, 'scroll', Poker.scroll);
  },
  "resize": function () {
    Poker.side_height = $('side').getDimensions().height;
    Poker.layout_height = $('layout').getDimensions().height;
  },
  "scroll": function (evt) {
    if (Poker.timeout) window.clearTimeout(Poker.timeout);
    if (Prototype.Browser.IE) {
      Poker.timeout = window.setTimeout("Poker.side()",100);
    } else {
      Poker.side();
    }
  },
  "side": function () {
    if (Poker.timeout) window.clearTimeout(Poker.timeout);
    var top = $('side').viewportOffset().top;
    if (top < 0) {
      if (Math.abs(top) > Poker.layout_height - Poker.side_height) {
        $('side').setStyle({"paddingTop": (Poker.layout_height - Poker.side_height)+"px"});
      } else {
        $('side').setStyle({"paddingTop": (Math.abs(top)+10)+"px"});
      }
    } else {
      $('side').setStyle({"paddingTop": "0px"});
    }
  }
};

Poker.SideBlock = {
  "toggle": function (el) {
    var side = $(el).up('div.side');
    if (side.hasClassName('small')) {
      side.removeClassName('small');
    } else {
      side.addClassName('small');
    }
  }
};

Poker.Tab = {
  "select": function (el, name) {
    $(el).up('.tabblock').removeClassName('tableft');
    $(el).up('.tabblock').removeClassName('tabright');
    $(el).up('.tabblock').addClassName('tab'+name)
  }
};

Poker.AdStart = {
  "timeout": null,
  "show": function () {
    $('body').addClassName('nobg');
    if ($('branding')) $('branding').hide();
    $('content').hide();
    $('adstart').show();
    Poker.AdStart.timeout = window.setTimeout(Poker.AdStart.hide,15000);
  },
  "hide": function () {
    window.clearTimeout(Poker.AdStart.timeout);
    $('body').removeClassName('nobg');
    $('adstart').hide();
    if ($('branding')) $('branding').show();
    $('content').show();
    Poker.resize();
    Poker.scroll();
  }
};

Poker.Auto = {
  "select": function () {
    if (window.location.hash.substr(1).length) {
      if (window.location.hash.substr(1) == 'topic-form' && $('topic-form')) {
        $$('a.topic')[0].onclick();
      } else if (window.location.hash.substr(1) == 'comment-form' && $('comment-form')) {
        $$('a.comment')[0].onclick();
      }
    }
  }
};

Poker.Tags = {
  "get": function () {
    Kwo.exec('/poker/tags', null, {'container':'tags'});
  }
};

Poker.Episodes = {
  "get": function (id,offset) {
    Kwo.exec('/poker/episodes', {'id':id,'offset':offset}, {'container':'episodes'+id});
  },
  "next": function (id,offset) {
    Kwo.exec('/poker/episodes.next', {'id':id,'offset':offset}, {'container':'next.episodes'});
  },
  "prev": function (id,offset) {
    Kwo.exec('/poker/episodes.prev', {'id':id,'offset':offset}, {'container':'prev.episodes'});
  }
};

Poker.Club = {
  "layer": '',
  "btn": '',
  "show": function (code, el) {
    Kwo.exec('/poker/club.'+code, null, {'container':'topics'});
    if (!el) {
      if (Poker.Club.btn != '' && Poker.Club.layer != '') {
        $$('.club-nav .selected').each(function(el){el.removeClassName('selected');});
        $(Poker.Club.btn).addClassName('selected');
        $(Poker.Club.layer).hide();      
      }
    } else {
      $$('.club-nav .selected').each(function(el){$(el).removeClassName('selected');});
      $(el).addClassName('selected');
      if (Poker.Club.btn != '' && Poker.Club.layer != '') {
        $(Poker.Club.layer).hide();
        Poker.Club.layer = '';
        Poker.Club.btn = '';
      }
    }
  },
  "toggle": function (id, el) {
    Poker.Club.layer = id;
    Poker.Club.btn = el;
    if ($(Poker.Club.layer).visible()) {
      $(Poker.Club.layer).hide();
      if ($$('.club-nav .selected').length > 1) {
        $(Poker.Club.btn).removeClassName('selected');
      }
      Poker.Club.layer = '';
      Poker.Club.btn = '';
    } else {
      $(Poker.Club.layer).show();
      $(Poker.Club.layer).setStyle({'top': ($(el).getHeight() + $(el).cumulativeOffset().top) + "px", 'left': $(el).cumulativeOffset().left + "px"});
      $(Poker.Club.btn).addClassName('selected');
    }
  }
};

Poker.Showcase = {
  "timeout":[],
  "pos": [],
  "timer": function (id) {
    window.clearTimeout(Poker.Showcase.timeout[id]);
    Poker.Showcase.timeout[id] = window.setTimeout("Poker.Showcase.next('"+id+"')",4000);
  },
  "first": function (id) {
    Poker.Showcase.timer(id);
    Poker.Showcase.pos[id] = 0;
    $$('div#'+id+' div.pagination img')[Poker.Showcase.pos[id]].src = "/app/poker/pix/puce-on.png";
    $$('div#'+id+' div.news')[Poker.Showcase.pos[id]].show();
  },
  "play": function (id) {
    Poker.Showcase.timer(id);
  },
  "pause": function (id) {
    window.clearTimeout(Poker.Showcase.timeout[id]);
  },
  "prev": function (id) {
    Poker.Showcase.timer(id);
    $$('div#'+id+' div.news')[Poker.Showcase.pos[id]].hide();
    $$('div#'+id+' div.pagination img')[Poker.Showcase.pos[id]].src = "/app/poker/pix/puce-off.png";
    Poker.Showcase.pos[id]--;
    if (Poker.Showcase.pos[id] < 0) {
      Poker.Showcase.pos[id] = $$('div#'+id+' div.news').length-1;
    }
    $$('div#'+id+' div.pagination img')[Poker.Showcase.pos[id]].src = "/app/poker/pix/puce-on.png";
    $$('div#'+id+' div.news')[Poker.Showcase.pos[id]].show();
  },
  "next": function (id) {
    Poker.Showcase.timer(id);
    $$('div#'+id+' div.news')[Poker.Showcase.pos[id]].hide();
    $$('div#'+id+' div.pagination img')[Poker.Showcase.pos[id]].src = "/app/poker/pix/puce-off.png";
    Poker.Showcase.pos[id]++;
    if (Poker.Showcase.pos[id] >= $$('div#'+id+' div.news').length) {
      Poker.Showcase.pos[id] = 0;
    }
    $$('div#'+id+' div.pagination img')[Poker.Showcase.pos[id]].src = "/app/poker/pix/puce-on.png";
    $$('div#'+id+' div.news')[Poker.Showcase.pos[id]].show();
  }
};

Poker.SlideShow = {
  "timeout": [],
  "current": [],
  "root": [],
  "init": function (id) {
    Poker.SlideShow.root[id] = $(id);
    Poker.SlideShow.current[id] = $(id).down('div');
    Poker.SlideShow.current[id].show();
    Poker.SlideShow.timeout[id] = window.setTimeout("Poker.SlideShow.next('"+id+"')",7000)
  },
  "over": function (id, pos) {
    window.clearTimeout(Poker.SlideShow.timeout[id]);
    Poker.SlideShow.current[id].hide();
    if (pos) {
      Poker.SlideShow.current[id] = Poker.SlideShow.root[id].down('div').next('div', pos-1);
    } else {
      Poker.SlideShow.current[id] = Poker.SlideShow.root[id].down('div');
    }
    Poker.SlideShow.current[id].show();
  },
  "out": function (id) {
    Poker.SlideShow.timeout[id] = window.setTimeout("Poker.SlideShow.next('"+id+"')",7000);
  },
  "next": function (id) {
    window.clearTimeout(Poker.SlideShow.timeout[id]);
    Poker.SlideShow.current[id].hide();
    if ($(Poker.SlideShow.current[id]).next('div')) {
      Poker.SlideShow.current[id] = $(Poker.SlideShow.current[id]).next('div');
      Poker.SlideShow.current[id].show();
    } else {
      Poker.SlideShow.current[id] = Poker.SlideShow.root[id].down('div');
      Poker.SlideShow.current[id].show();
    }
    Poker.SlideShow.timeout[id] = window.setTimeout("Poker.SlideShow.next('"+id+"')",7000);
  }
};

Poker.Search = {
  "init": function (el) {
    if ($(el)) {
      if (window.query && typeof window.query != 'object') {
        $('query').focus();
        if (window.query != '*') {
          $('query').value = window.query;
        }
      } else {
        $(el).setStyle({'backgroundImage':"url('/app/poker/pix/smallsearch_text.png')"});
      }
    }
  },
  "focus": function (el) {
    $(el).setStyle({'backgroundImage':"url('/app/sys/pix/empty.gif')"});
  },
  "blur": function (el) {
    if ($(el).value.length<1) {
      $(el).setStyle({'backgroundImage':"url('/app/poker/pix/smallsearch_text.png')"});
    }
  }
};

Poker.Auth = {
  "onLogin": function(args) {
    Kwo.exec("/community/login", args, {"callback": Poker.Auth.onLoginCallback});
    return false;
  },
  "onLoginCallback": function(h) {
    if (Kwo.hasError(h)) {
      Kwo.error(h); 
      return;
    }
    if ("_auth_callback" in window) {
      window["_auth_callback"].call();
    } else {
      if (window.location.href.indexOf("signin") != -1) {
        Kwo.home()
      } else {
        Kwo.reload();
      }
    }
  },
  "onPasswordRequest": function(args) {
    Kwo.exec("/community/password.send", args, {"callback": Poker.Auth.onPasswordRequestCallback});
    return false;
  },
  "onPasswordRequestCallback": function(h) {
    if (Kwo.hasError(h)) {
      Kwo.error(h); 
      return;
    }
    Kwo.warn(h); 
  }
};

Poker.User = {
  "storeProfile": function(args) {
    Kwo.exec("/account/community/profile.store", args, {"callback": Poker.User.storeProfileCallback});
    return false;
  },
  "storeProfileCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la mise à jour de votre profil.");
      return;
    }
    alert("Votre profil a été mis à jour avec succés.");
    Kwo.Account.selectAction($('my_account:profile'));
  },
  "storeNewsletter": function(args) {
    Kwo.exec("/account/community/profile.store", args, {"callback": Poker.User.storeNewsletterCallback});
    return false;
  },
  "storeNewsletterCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la mise à jour de votre profile.");
      return;
    }
    alert("Votre profil a été mis à jour avec succés.");
    Kwo.Account.selectAction($('my_account:newsletter'));
  },
  "storeEmail": function(args) {
    Kwo.exec("/account/community/email.store", args, {"callback": Poker.User.storeEmailCallback});
    return false;
  },
  "storeEmailCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la mise à jour de votre email.");
      return;
    }
    alert("Votre email a été mise à jour avec succés.");
    Kwo.Account.selectAction($('my_account:email'));
  },
  "storePassword": function(args) {
    Kwo.exec("/account/community/password.store", args, {"callback": Poker.User.storePasswordCallback});
    return false;
  },
  "storePasswordCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la mise à jour de votre mot de passe.");
      return;
    }
    alert("Votre mot de passe a été mis à jour avec succés.");
    Kwo.Account.selectAction($('my_account:password'));
  },
  "storeTv": function(args) {
    Kwo.exec("/account/community/profile.store", args, {"callback": Poker.User.storeTvCallback});
    return false;
  },
  "storeTvCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la mise à jour de votre sélection.");
      return;
    }
    alert("Votre sélection a été mise à jour avec succés.");
    Kwo.Account.selectAction($('my_account:mytv'));
  }
};

Poker.Tournament = {
  "edit": function(id) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/poker/tournament.edit", {'id':id}, {"container": "kwo-account-content"});
  },
  "list": function(offset) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/poker/tournament.list", {'offset':offset}, {"container": "kwo-account-content"});
  },
  "store": function(args) {
    Kwo.exec("/account/poker/tournament.store", args, {"callback": Poker.Tournament.storeCallback});
    return false;
  },
  "storeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de la mise à jour du tournoi.");
      return;
    }
    alert("Le tournoi a été mis à jour avec succés.");
    Poker.Tournament.list(0);
  },
  "add": function(args) {
    Kwo.exec("/account/poker/tournament.add", args, {"callback": Poker.Tournament.addCallback});
    return false;
  },
  "addCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de l'ajout du tournoi.");
      return;
    }
    alert("Le tournoi a été ajouté avec succés.");
    Poker.Tournament.list(0);
  },
  "remove": function(id) {
    if (confirm('Etes-vous sure de vouloir supprimer ce tournoi ?')) {
      Kwo.exec("/account/poker/tournament.remove", {'id':id}, {"callback": Poker.Tournament.removeCallback});
    }
  },
  "removeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la suppression du tournoi.");
      return;
    }
    alert("Le tournoi a été supprimé avec succés.");
    Poker.Tournament.list(0);
  }
};


Poker.Article = {
	
  "edit": function(id) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/poker/article.edit", {'id':id}, {"container": "kwo-account-content"});
  },
  "list": function(offset) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/poker/article.list", {'offset':offset}, {"container": "kwo-account-content"});
  },
  "store": function(args) {
    Kwo.exec("/account/poker/article.store", args, {"callback": Poker.Article.storeCallback});
    return false;
  },
  "storeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de la mise à jour du tournoi.");
      return;
    }
    alert("L'article a été mis à jour avec succés.");
    Poker.Article.list(0);
  },
  "add": function(args) {
    Kwo.exec("/account/poker/article.add", args, {"callback": Poker.Article.addCallback});
    return false;
  },
  "addCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de l'ajout du tournoi.");
      return;
    }
    alert("L'article a été ajouté avec succés.");
    Poker.Article.list(0);
  },
  "remove": function(id) {
    if (confirm('Etes-vous sure de vouloir supprimer cet article ?')) {
      Kwo.exec("/account/poker/article.remove", {'id':id}, {"callback": Poker.Article.removeCallback});
    }
  },
  "removeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la suppression de l'article.");
      return;
    }
    alert("L'article a été supprimé avec succés.");
    Poker.Article.list(0);
  }
};




Poker.Sondage = {
	
  "edit": function(id) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/poker/sondage.edit", {'id':id}, {"container": "kwo-account-content"});
  },
  "list": function(offset) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/poker/sondage.list", {'offset':offset}, {"container": "kwo-account-content"});
  },
  "store": function(args) {
    Kwo.exec("/account/poker/sondage.store", args, {"callback": Poker.Sondage.storeCallback});
    return false;
  },
  "storeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de la mise à jour du tournoi.");
      return;
    }
    alert("Le sondage a été mis à jour avec succés.");
    Poker.Sondage.list(0);
  },
    "submit": function(args) {
    Kwo.exec("/account/poker/sondage.submit", args, {"callback": Poker.Sondage.submitCallback});
    return false;
  },
  "submitCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de la mise à jour du tournoi.");
      return;
    }
    alert("votre vote a bien été pris en compte.");
    Kwo.home();
  },
  "add": function(args) {
    Kwo.exec("/account/poker/sondage.add", args, {"callback": Poker.Sondage.addCallback});
    return false;
  },
  "addCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de l'ajout du tournoi.");
      return;
    }
    alert("Le sondage a été ajouté avec succés.");
    Poker.Sondage.list(0);
  },
  "remove": function(id) {
    if (confirm('Etes-vous sure de vouloir supprimer ce sondage ?')) {
      Kwo.exec("/account/poker/sondage.remove", {'id':id}, {"callback": Poker.Sondage.removeCallback});
    }
  },
  "removeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la suppression du sondage.");
      return;
    }
    alert("le sondage a été supprimé avec succés.");
    Poker.Sondage.list(0);
  }
};



Poker.Forum = {
  "closeTopic": function () {
    if ($('topic-form')) {
      $('topic-form').update('');
      $('topic-form').hide();
    }
  },
  "editTopic": function(id, topic_id) {
    Poker.Topic.closeComment();
    $('topic-form').show();
    Kwo.exec("/board/topic.edit", {"forum_id": id,"topic_id": topic_id}, {'container': 'topic-form'});
  },
  "composeTopic": function(id) {
    Poker.Topic.closeComment();
    $('topic-form').show();
    if ($('topic-form').innerHTML.length == 0) {
      Kwo.exec("/board/topic.compose", {"forum_id": id}, {'container': 'topic-form'});
    }
  },
  "onTopicEditSubmit": function(args) {
    if ($(args).hasClassName('disabled')) return;
    $(args).addClassName('disabled');
    Kwo.exec("/board/topic.store", args, {"callback": Poker.Forum.onTopicEditCallback});
  },
  "onTopicComposeSubmit": function(args) {
    if ($(args).hasClassName('disabled')) return;
    $(args).addClassName('disabled');
    Kwo.exec("/board/topic.add", args, {"callback": Poker.Forum.onTopicComposeCallback});
  },
  "onTopicEditCallback": function(h) {
    if (Kwo.hasError(h)) {
      return alert("Une erreur s'est produite lors de l'ajout de votre sujet de discussion.");
    }
    alert("Votre sujet de discussion a été ajouté avec succés.");
    Kwo.go(h);
  },
  "onTopicComposeCallback": function(h) {
    if (Kwo.hasError(h)) {
      return alert("Une erreur s'est produite lors de l'ajout de votre sujet de discussion.");
    }
    alert("Votre sujet de discussion a été ajouté avec succés.");
    Kwo.go(h);
  }
};

Poker.Topic = {
  "closeComment": function () {
    if ($('comment-form')) {
      $('comment-form').update('');
      $('comment-form').hide();
    }
  },
  "editComment": function (id, comment_id) {
    Poker.Forum.closeTopic();
    comment_id = comment_id || 0;
    $('comment-form').show();
    Kwo.exec("/board/comment.edit", {"topic_id": id, "comment_id": comment_id}, {'container': 'comment-form'});
  },
  "composeComment": function (id, comment_id) {
    Poker.Forum.closeTopic();
    comment_id = comment_id || 0;
    $('comment-form').show();
    if ($('comment-form').innerHTML.length == 0) {
      Kwo.exec("/board/comment.compose", {"topic_id": id, "comment_id": comment_id}, {'container': 'comment-form'});
    }
  },
  "onCommentEditSubmit": function(args) {
    Kwo.exec("/sys/comment.store", args, {"callback": Poker.Topic.onCommentEditCallback});
  },
  "onCommentComposeSubmit": function(args) {
    Kwo.exec("/sys/item.comment", args, {"callback": Poker.Topic.onCommentComposeCallback});
  },
  "onCommentEditCallback": function(h) {
    if (Kwo.hasError(h)) {
      return alert("Une erreur s'est produite lors de l'ajout de votre commentaire.");
    }
    alert("Votre commentaire a été modifié avec succés.");
    Kwo.reload();
  },
  "onCommentComposeCallback": function(h) {
    if (Kwo.hasError(h)) {
      return alert("Une erreur s'est produite lors de l'ajout de votre commentaire.");
    }
    alert("Votre commentaire a été ajouté avec succés.");
    Kwo.reload();
  }
};

Poker.Contest = Class.create(Kwo.Dialog, {
  "initialize": function($super, id) {
    opts = {}; 
    opts["width"] = 600;
    opts["height"] = 500;
    $super("/poker/contest.form", {'id':id}, opts);
    Kwo.setDialog(this);
    $("overlay").stopObserving("click", this.close);
  }
});

Poker.Comment = {
  "onSubmit": function (args) {
    if ($F("comment_content").empty()) return ;
    $(args).hide();
    Kwo.exec("/poker/comment.add", args, {"callback": Poker.Comment.onCallback});
  },
  "onCallback": function (h) {
    if (h["error"] >= 1) {
      Kwo.error(h["result"]["msg"]);
    } else {
      Poker.Comment.refresh(h["result"]["callback_url"]);
    }
  },
  "refresh": function (url) {
    if ($F("item_key").empty()) {
      Kwo.go(url);
    } else {
      Kwo.exec("/poker/comments",{"item_key":$F("item_key")},{"container":"commentzone"});
    }
  }
};

Poker.Map = {
  "map": null,
  "maps": new Array(),
  "bound": null,
  "bounds": new Array(),
  "position": 0,
  "registry": new Array(),
  "register": function (map) {
    Poker.Map.registry.push(map);
  },
  "getId": function (map) {
    for (var key in Poker.Map.registry) {
      if (Poker.Map.registry[key] == map) {
        return key;
      }
    }
    return -1;
  },
  "init": function () {
    if (GBrowserIsCompatible()) {
      Event.observe(window,'unload',GUnload);
      Poker.Map.map = new GMap2($('gmap'));
      Poker.Map.bound = new GLatLngBounds();
      var control = new GSmallMapControl();
      Poker.Map.map.addControl(control);
      var point = new GLatLng(0,0);
      Poker.Map.map.setCenter(point,1);
    }
  },
  "initMap": function (map) {
    if (GBrowserIsCompatible()) {
      Event.observe(window,'unload',GUnload);
      Poker.Map.maps[Poker.Map.getId(map)] = new GMap2($(map));
      Poker.Map.bounds[Poker.Map.getId(map)] = new GLatLngBounds();
      var control = new GSmallMapControl();
      Poker.Map.maps[Poker.Map.getId(map)].addControl(control);
      var point = new GLatLng(0,0);
      Poker.Map.maps[Poker.Map.getId(map)].setCenter(point,1);
    }
  },
  "nextMarker": function () {
    if (GBrowserIsCompatible()) {
      GEvent.trigger(markers[positions[Poker.Map.position++]],'click');
      if (Poker.Map.position > positions.length-1) {
        Poker.Map.position = 0;
      }
    }
  },
  "prevMarker": function () {
    if (GBrowserIsCompatible()) {
      GEvent.trigger(markers[positions[Poker.Map.position--]],'click');
      if (Poker.Map.position  < 0) {
        Poker.Map.position = positions.length-1;
      }
    }
  },
  "viewMarker": function (lat,lng,zoom) {
    if (GBrowserIsCompatible()) {
      var point = new GLatLng(lat,lng);
      var icon = new GIcon(G_DEFAULT_ICON);
      var marker = new GMarker(point,{'icon':icon});
      Poker.Map.map.addOverlay(marker);
      Poker.Map.map.setCenter(point,zoom);
      Poker.Map.map.savePosition();
    }
  },
  "viewPos": function (lat,lng,zoom) {
    if (GBrowserIsCompatible()) {
      var point = new GLatLng(lat,lng);
      Poker.Map.map.setCenter(point,zoom);
      Poker.Map.map.savePosition();
    }
  },
  "addMarker": function (name,id,lat,lng,url) {
    if (GBrowserIsCompatible()) {
      var point = new GLatLng(lat,lng);
      var icon = new GIcon(G_DEFAULT_ICON);
      var marker = new GMarker(point,{'icon':icon});
      GEvent.addListener(marker,'click',Poker.Map.viewInfo.curry(lat,lng,name,id,url));
      Poker.Map.map.addOverlay(marker);
      Poker.Map.bound.extend(point);
      return marker;
    }
  },
  "addLauncher": function (name,id,lat,lng,url) {
    if (GBrowserIsCompatible()) {
      var point = new GLatLng(lat,lng);
      var icon = new GIcon(G_DEFAULT_ICON);
      var marker = new GMarker(point,{'icon':icon,'title':name});
      GEvent.addListener(marker,'click',Kwo.go.curry(url));
      Poker.Map.map.addOverlay(marker);
      Poker.Map.bound.extend(point);
    }
  },
  "addLauncherMap": function (map,name,id,lat,lng,url) {
    if (GBrowserIsCompatible()) {
      var point = new GLatLng(lat,lng);
      var icon = new GIcon(G_DEFAULT_ICON);
      var marker = new GMarker(point,{'icon':icon,'title':name});
      GEvent.addListener(marker,'click',Kwo.go.curry(url));
      Poker.Map.maps[Poker.Map.getId(map)].addOverlay(marker);
      Poker.Map.bounds[Poker.Map.getId(map)].extend(point);
    }
  },
  "addMe": function () {
    if (GBrowserIsCompatible() && google.loader.ClientLocation) {
      var point = new GLatLng(google.loader.ClientLocation.latitude,google.loader.ClientLocation.longitude);
      var icon = new GIcon(G_DEFAULT_ICON);
      icon.image = "http://www.google.com/mapfiles/arrow.png";
      icon.shadow = "http://www.google.com/mapfiles/arrowshadow.png";
      icon.iconSize = new GSize(39, 34);
      icon.shadowSize = new GSize(39, 34);
      icon.imageMap = [0,0, 20,0, 20,34, 0,34];
      var marker = new GMarker(point,{'icon':icon,'title':"Votre position"});
      Poker.Map.map.addOverlay(marker);
      Poker.Map.bound.extend(point);
    }
  },
  "openInfo": function (marker) {
    if (GBrowserIsCompatible()) {
      GEvent.trigger(marker,'click');
    }
  },
  "viewInfo": function (lat,lng,name,id,url) {
    if (GBrowserIsCompatible()) {
      var point = new GLatLng(lat,lng);
      var link = "<a href='"+url+"' class='btn next'><div class='left'></div><div class='center'>En savoir plus</div><div class='right'></div></a>";
      var html = "<div class='infowindow'>"+(($(name+"-"+id))?"<div class='title'>"+$(name+"-"+id).innerHTML+"</div>":'')+$(name+"-info-"+id).innerHTML+link+"</div>";
      Poker.Map.map.openInfoWindowHtml(point,html);
    }
  },
  "autoZoom": function (n) {
    if (!n) n = 0;
    if (GBrowserIsCompatible()) {
      var point = Poker.Map.bound.getCenter();
      var zoom = Poker.Map.map.getBoundsZoomLevel(Poker.Map.bound);
      Poker.Map.map.setCenter(point,zoom+n);
      Poker.Map.map.savePosition();
    }
  },
  "autoZoomMap": function (map, n) {
    if (!n) n = 0;
    if (GBrowserIsCompatible()) {
      var point = Poker.Map.bounds[Poker.Map.getId(map)].getCenter();
      var zoom = Poker.Map.maps[Poker.Map.getId(map)].getBoundsZoomLevel(Poker.Map.bounds[Poker.Map.getId(map)]);
      Poker.Map.maps[Poker.Map.getId(map)].setCenter(point,zoom+n);
      Poker.Map.maps[Poker.Map.getId(map)].savePosition();
    }
  }
};

Poker.Video = {
  "hide": function (id) {
    Kwo.exec("/poker/video.hide",{'id':id},{'callback':Poker.Video.onHideCallback});
  },
  "onHideCallback": function (h) {
    if (h["error"] >= 1) {
      Kwo.error(h["result"]["msg"]);
    } else {
      Kwo.reload();
    }
  },
  "post": function (id) {
    if (confirm('Poster cette vidéo sur le forum ?')) {
      Kwo.exec("/poker/video.post",{'id':id},{'callback':Poker.Video.onPostCallback});
    }
  },
  "onPostCallback": function (h) {
    if (h["error"] >= 1) {
      Kwo.error(h["result"]["msg"]);
    } else {
      Kwo.go(h["result"]["url"]+"#comment-form");
    }
  },
  "view": function(url) {
    new Kwo.Dialog("/poker/youtube.frame", {"url":url}, {"width": 500, "height": 405});
  },
  "flv": function (flv,opts) {
    var width = 640;
    if (opts.width) width = opts.width;
    var height = 500;
    if (opts.height) height = opts.height + 20;
    var s1 = new SWFObject('/app/poker/swf/player.ad.swf','player',width,height,'10');
    s1.addParam('allowfullscreen','true');
    s1.addParam('wmode','transparent');
    s1.addParam('flashvars','url=http%3A%2F%2Fwww.poker-actu.fr&video_url='+flv+'&photo_url='+flv+'.jpg');
    s1.write('flvcontainer');
    // var s1 = new SWFObject('/var/docs/player.swf','player',width,height,'10');
    // s1.addParam('allowfullscreen','true');
    // s1.addParam('allowscriptaccess','always');
    // s1.addParam('flashvars','file='+flv+'&image='+flv+'.jpg');
    // s1.write('flvcontainer');
  },
  "big": function (flv) {
    var s1 = new SWFObject('/app/poker/swf/player.ad.swf','player','640','500','10');
    s1.addParam('allowfullscreen','true');
    s1.addParam('wmode','transparent');
    s1.addParam('flashvars','url=http%3A%2F%2Fwww.poker-actu.fr&video_url='+flv+'&photo_url='+flv+'.jpg');
    s1.write('flvcontainer');
    // var s1 = new SWFObject('/var/docs/player.swf','player','640','500','10');
    // s1.addParam('allowfullscreen','true');
    // s1.addParam('allowscriptaccess','always');
    // s1.addParam('flashvars','file='+flv+'&image='+flv+'.jpg');
    // s1.write('flvcontainer');
  },
  "small": function (flv) {
    var s1 = new SWFObject('/app/poker/swf/player.ad.swf','player','400','320','10');
    s1.addParam('allowfullscreen','true');
    s1.addParam('wmode','transparent');
    s1.addParam('flashvars','url=http%3A%2F%2Fwww.poker-actu.fr&video_url='+flv+'&photo_url='+flv+'.jpg');
    s1.write('flvcontainer');
    // var s1 = new SWFObject('/var/docs/player.swf','player','400','320','10');
    // s1.addParam('allowfullscreen','true');
    // s1.addParam('allowscriptaccess','always');
    // s1.addParam('flashvars','file='+flv+'&image='+flv+'.jpg');
    // s1.write('flvcontainer');
  },
  "on": function () {
    var dimensions = document.viewport.getDimensions();
    var offsets = document.viewport.getScrollOffsets();
    if ($("lights")) {
      $("lights").setStyle({"width": dimensions.width+"px",
                            "height": dimensions.height+"px",
                            "left": offsets.left+"px",
                            "top": offsets.top+"px"});
    } else {
      document.body.appendChild(new Element("div", {"id": "lights"}).setStyle({"display": "none",
                                                                               "opacity": "0.5",
                                                                               "width": dimensions.width+"px",
                                                                               "height": dimensions.height+"px",
                                                                               "left": offsets.left+"px",
                                                                               "top": offsets.top+"px"}));
    }
    $("lights").observe("click", Poker.Video.off);
    if (Prototype.Browser.IE && navigator.userAgent.indexOf("MSIE 6") > -1) {
      $$("select").invoke("hide");
    }
    Event.observe(window, "resize", Poker.Video.on);
    Event.observe(window, "scroll", Poker.Video.on);
    $("lights").show();
  },
  "off": function () {
    if ($("lights")) {
      $("lights").remove();
      if (Prototype.Browser.IE && navigator.userAgent.indexOf("MSIE 6") > -1) {
        $$("select").invoke("show");
      }
    }
  }
};



Poker.ChipcountManage = {
    "list": function(offset) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/community/chipcount_manage.list", {'offset':offset}, {"container": "kwo-account-content"});
  },
   "store": function(args) {
    Kwo.exec("/account/community/chipcount_manage.store", args, {"callback": Poker.ChipcountManage.storeCallback});
    return false;
  },
  "storeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
	   Poker.ChipcountManage.list();
      return;
    }
    alert("ChipCount Update");
     Poker.ChipcountManage.list();
  }	,
   "add_player": function(args) {
    Kwo.exec("/account/community/chipcount.add", args, {"callback": Poker.ChipcountManage.addCallback});
    return false;
  },
  "addCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
	   Poker.ChipcountManage.list();
      return;
    }
    alert("joueur ajouté");
     Poker.ChipcountManage.list();
  }	
};



Poker.PayoutManage = {
    "list": function(offset) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/community/payout_manage.list", {'offset':offset}, {"container": "kwo-account-content"});
  },
   "store": function(args) {
    Kwo.exec("/account/community/payout_manage.store", args, {"callback": Poker.PayoutManage.storeCallback});
    return false;
  },
  "storeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
	   Poker.PayoutManage.list();
      return;
    }
    alert("Payout Update");
     Poker.PayoutManage.list();
  }	
};


Poker.Tourstructure = {
    "add": function(args) {
    Kwo.exec("/account/community/structure.add", args, {"callback": Poker.Tourstructure.addCallback});
    return false;
  },
  "addCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de l'ajout du tournoi.");
      return;
    }
    alert("Votre structure a été ajouté");
    Poker.Report.list(0);
  },
};


Poker.Chart = {
    "add": function(args) {
    Kwo.exec("/account/community/chart.add", args, {"callback": Poker.Chart.addCallback});
    return false;
  },
  "addCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de l'ajout du tournoi.");
      return;
    }
    alert("Votre chart a été update");
   Poker.Ligue.list();
  }
};


Poker.Ligue = {
    "add": function(args) {
    Kwo.exec("/account/community/ligue.add", args, {"callback": Poker.Ligue.addCallback});
    return false;
  },
      "addclass": function(args) {
    Kwo.exec("/account/community/ligue.addclass", args, {"callback": Poker.Ligue.addclassCallback});
    return false;
  },
    "list": function(offset) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/community/ligue.list", {'offset':offset}, {"container": "kwo-account-content"});
  },
  "addCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de l'ajout du tournoi.");
      return;
    }
    alert("Le classement a été mis a jour");
    Poker.Ligue.list(0);
  }, "addclassCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de l'ajout du tournoi.");
      return;
    }
    alert("Votre billet a été ajouté");
    Poker.Ligue.list(0);
  },
  "remove": function(id) {
    if (confirm('Etes-vous sure de vouloir supprimer cette league ?')) {
      Kwo.exec("/account/community/ligue.destroy", {'id':id}, {"callback": Poker.Ligue.removeCallback});
    }
  },
  "removeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la suppression de la league.");
      return;
    }
    alert("La league a été supprimé avec succés.");
    Poker.Ligue.list(0);
  }, 
  "edit": function(id) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/community/ligue.edit", {'id':id}, {"container": "kwo-account-content"});
  },
   
  "editclass": function(id) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/community/ligue.editclass", {'id':id}, {"container": "kwo-account-content"});
  },
   "store": function(args) {
    Kwo.exec("/account/community/ligue.store", args, {"callback": Poker.Ligue.storeCallback});
    return false;
  },
  "storeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      return;
    }
    alert("votre league a bien été mis a jour");
    Poker.Ligue.list();
  }
  
		
};


Poker.Report = {
    "add": function(args) {
    Kwo.exec("/account/community/report.add", args, {"callback": Poker.Report.addCallback});
    return false;
  },
    "list": function(offset) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/community/report.list", {'offset':offset}, {"container": "kwo-account-content"});
  },
  "addCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de l'ajout du tournoi.");
      return;
    }
    alert("Votre billet a été ajouté");
    Poker.Report.list(0);
  },
  "remove": function(id) {
    if (confirm('Etes-vous sure de vouloir supprimer ce billet ?')) {
      Kwo.exec("/account/community/report.destroy", {'id':id}, {"callback": Poker.Report.removeCallback});
    }
  },
  "removeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la suppression du billet.");
      return;
    }
    alert("Le billet a été supprimé avec succés.");
    Poker.Report.list(0);
  }, 
  "edit": function(id) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/community/report.edit", {'id':id}, {"container": "kwo-account-content"});
  },
   "store": function(args) {
    Kwo.exec("/account/community/report.store", args, {"callback": Poker.Report.storeCallback});
    return false;
  },
  "storeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      return;
    }
    alert("votre billet a bien été mis a jour");
    Poker.Report.list();
  }
  
		
};


Poker.Post = {
  "add": function(args) {
    Kwo.exec("/account/blog/post.add", args, {"callback": Poker.Post.addCallback});
    return false;
  },
  "list": function(offset) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/blog/post.list", {'offset':offset}, {"container": "kwo-account-content"});
  },
  "addCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors du billet.");
      return;
    }
    alert("Votre billet a été ajouté");
    Poker.Post.list(0);
  },
  "remove": function(id) {
    if (confirm('Etes-vous sure de vouloir supprimer ce billet ?')) {
      Kwo.exec("/account/blog/post.destroy", {'id':id}, {"callback": Poker.Post.removeCallback});
    }
  },
  "removeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert("Une erreur s'est produite lors de la suppression du billet.");
      return;
    }
    alert("Le billet a été supprimé avec succés.");
    Poker.Post.list(0);
  },
  "edit": function(id) {
    $("kwo-account-content").update('<img src="/app/sys/pix/throbber.gif" />');
    Kwo.exec("/account/blog/post.edit", {'id':id}, {"container": "kwo-account-content"});
  },
  "store": function(args) {
    Kwo.exec("/account/blog/post.store", args, {"callback": Poker.Post.storeCallback});
    return false;
  },
  "storeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      return;
    }
    alert("votre billet a bien été mis a jour");
    Poker.Blog.edit();
  }
};

Poker.Blog = {
  "store": function(args) {
    Kwo.exec("/account/blog/blog.store", args, {"callback": Poker.Blog.storeCallback});
    return false;
  },
  "edit": function() {
    Kwo.exec("/account/blog/blog.edit", {"container": "kwo-account-content"});
  },
  "storeCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de MAJ.");
      return;
    }
    alert("votre blog a bien été mis a jour");
    Poker.Blog.edit();
  },
  "add": function(args) {
    Kwo.exec("/account/blog/blog.create", args, {"callback": Poker.Blog.addCallback});
    return false;
  },
  "addCallback": function (h) {
    if (Kwo.hasError(h)) {
      alert(h['result']['msg']);
      // alert("Une erreur s'est produite lors de la creation du blog.");
      return;
    }
    Kwo.reload();
    alert("votre blog a bien été créer");
    Poker.Post.list(0);
  }
};

SlideShow = Class.create({
  "timeout": null,
  "mask": null,
  "nav": null,
  "count": 0,
  "pos": 0,
  "z": 1,
  "initialize": function (id, opts) {
    this.pos = 0;
    this.mask = $(id);
    this.width = this.mask.getWidth();
    this.count = this.mask.childElements().length;
    this.mask.childElements().invoke('setStyle',{left:'0px',top:'0px',zIndex:this.z++});
    $('item'+this.pos).setStyle({zIndex:this.z});
    if (this.count > 1) {
      this.mask.observe("mouseout",this.play.bind(this));
      this.mask.observe("mouseover",this.pause.bind(this));
      if (opts.prev && $(opts.prev)) {
        $(opts.prev).observe('click', this.prev.curry(null).bind(this));
      }
      if (opts.next && $(opts.next)) {
        $(opts.next).observe('click', this.next.curry(null).bind(this));
      }
      if (opts.nav && $(opts.nav)) {
        this.nav = opts.nav;
        $(this.nav).childElements().each(function(s, index) {
          $(s).observe('click', this.view.curry(index).bind(this));
        }, this);
      }
      $(this.nav).down('img').src = "/app/poker/pix/puce-on.png";
      this.play();
    }
  },
  "play": function () {
    this.pause();
    this.timeout = window.setTimeout(this.next.curry(null).bind(this), 7000);
  },
  "pause": function () {
    if (this.timeout) window.clearTimeout(this.timeout);
  },
  "view": function (pos) {
    this.pause();
    if (pos > this.pos) {
      this.next(pos);
    } else if (pos < this.pos) {
      this.prev(pos);
    }
    this.play();
  },
  "next": function (pos) {
    if ($('item'+this.pos) && ($('item'+this.pos).style.left == '0px' || $('item'+this.pos).style.left == this.width+'px' || $('item'+this.pos).style.left == '-'+this.width+'px')) {
      emile($('item'+this.pos).setStyle({left:'0px',zIndex:this.z++}), 'left:-'+this.width+'px', {duration: 400});
      if (Object.isNumber(pos) && pos >= 0) this.pos = pos;
      else this.pos++;
      if (this.pos > this.count - 1) this.pos = 0;
      if (this.pos < 0) this.pos = this.count - 1;
      if ($('item'+this.pos) && ($('item'+this.pos).style.left == '0px' || $('item'+this.pos).style.left == this.width+'px' || $('item'+this.pos).style.left == '-'+this.width+'px')) {
        emile($('item'+this.pos).setStyle({left:this.width+'px',zIndex:this.z++}), 'left:0px', {duration: 400});
      }
      this.page();
      this.play();
    }
  },
  "prev": function (pos) {
    if ($('item'+this.pos) && ($('item'+this.pos).style.left == '0px' || $('item'+this.pos).style.left == this.width+'px' || $('item'+this.pos).style.left == '-'+this.width+'px')) {
      emile($('item'+this.pos).setStyle({left:'0px',zIndex:this.z++}), 'left:'+this.width+'px', {duration: 400});
      if (typeof pos == 'number' && pos >= 0) this.pos = pos;
      else this.pos--;
      if (this.pos > this.count - 1) this.pos = 0;
      if (this.pos < 0) this.pos = this.count - 1;
      if ($('item'+this.pos) && ($('item'+this.pos).style.left == '0px' || $('item'+this.pos).style.left == this.width+'px' || $('item'+this.pos).style.left == '-'+this.width+'px')) {
        emile($('item'+this.pos).setStyle({left:(this.width*(-1))+'px',zIndex:this.z++}), 'left:0px', {duration: 400});
      }
      this.page();
      this.play();
    }
  },
  "page": function () {
    var list = $(this.nav).select('*');
    list.each(function(s) { s.src = "/app/poker/pix/puce-off.png"; });
    list[this.pos].src = "/app/poker/pix/puce-on.png"; 
  }
});

function bounce(pos) {
  if (pos < (1/2.75)) {
    return (7.5625*pos*pos);
  } else if (pos < (2/2.75)) {
    return (7.5625*(pos-=(1.5/2.75))*pos + .75);
  } else if (pos < (2.5/2.75)) {
    return (7.5625*(pos-=(2.25/2.75))*pos + .9375);
  } else {
    return (7.5625*(pos-=(2.625/2.75))*pos + .984375);
  }
}

Event.observe(window, 'load', Poker.init);

