$(function(){$('#shoutbox-message').bind('keypress',function(e){if(e.keyCode==13){Shoutbox.shout($(this).val());}});$('#shoutbox-submit').click(function(e){Shoutbox.shout($('#shoutbox-message').val());});});Shoutbox={deleteButton:false,prepend:function(shout){var control='';var icons='';if(this.deleteButton)control+='<a href="javascript:Shoutbox.del('+shout.id+')">Usuń</a>';if(shout.username=='Admin'){icons+='<div class="sprite icon16 admin" title="Administrator"></div>';}
$('#shoutbox').prepend('<div class="post" id="shout-'+shout.id+'">'+'<span class="time">'+shout.time+'</span> '+'<span class="nick">'+icons+shout.username+':</span> '+'<span class="msg">'+shout.message+'</span>'+'<span class="control">'+control+'</span>'+'</div>');},shout:function(msg){Shoutbox.working(true);$.ajax({dataType:'json',type:'POST',url:basePath+'/shoutbox/shout',data:{shout:msg},success:function(data){if(data['status']=='OK'){$('#shoutbox-message').val('');Shoutbox.prepend(data.message);}else{alert(data['error']);}},complete:function(){Shoutbox.working(false);}});},working:function(mode){if(mode)$('#shoutbox-status').fadeIn('slow','linear');else $('#shoutbox-status').fadeOut('slow','linear');},load:function(){$(function(){Shoutbox.working(true);$.ajax({dataType:'json',url:basePath+'/shoutbox/recent',success:function(data){$('#shoutbox').empty();for(i in data){Shoutbox.prepend(data[i]);}
setTimeout(function(){Shoutbox.load();},15000);},complete:function(){Shoutbox.working(false);}});});},del:function(id){$.ajax({dataType:'json',url:basePath+'/shoutbox/delete/id/'+id,success:function(data){if(data['status']=='OK'){$('#shout-'+id).hide('slide',function(){$(this).remove();});}else{alert(data['error']);}}});}};if(top.location!=location){top.location.href=document.location.href;}
function switchLanguage(){var src=$('#original').attr('src');if(src==comicSpanish)$('#original').attr('src',comicEnglish);else if(src==comicEnglish)$('#original').attr('src',comicSpanish);}
function bindEvents(){$(function(){$("#jump-input").click(function(){$(this).select();});$("#jump").click(function(e){ga($("#jump-input").val());});$("#jump-input").bind('keypress',function(e){if(e.keyCode==13){ga($("#jump-input").val());}});$("#smilies>div").click(function(){$("#comment").val($("#comment").attr("value")+' '+$(this).attr("title")+' ').focus();});$("#emot img").mouseout(function(){$(this).css({'cursor':'normal'});});});}
$.datepicker.regional['pl']={closeText:'Zamknij',prevText:'Poprz.',nextText:'Nast.',currentText:'Dziś',monthNames:['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],monthNamesShort:['Sty','Lu','Mar','Kw','Maj','Cze','Lip','Sie','Wrz','Pa','Lis','Gru'],dayNames:['Niedziela','Poniedziałek','Wtorek','Środa','Czwartek','Piątek','Sobota'],dayNamesShort:['Nie','Pn','Wt','Śr','Czw','Pt','So'],dayNamesMin:['N','Pn','Wt','Śr','Cz','Pt','So'],weekHeader:'Tydz',dateFormat:'yy-mm-dd',firstDay:1,isRTL:false,showMonthAfterYear:false,yearSuffix:'',inline:true,yearRange:'1978:'+new Date().getFullYear(),minDate:new Date(1978,5,19),maxDate:new Date(),changeMonth:true,changeYear:true};$.datepicker.setDefaults($.datepicker.regional['pl']);$(function(){bindAJAX();$(document).ajaxStop(function(){bindAJAX();});var hash=window.location.hash.substring(1);if(hash.length==8)ga(hash);$('#login_password_clear').show();$('#login_password').hide();$('#login_password_clear').focus(function(){$('#login_password_clear').hide();$('#login_password').show();$('#login_password').focus();});$('#login_password').blur(function(){if($('#login_password').val()==''){$('#login_password_clear').show();$('#login_password').hide();}});var value='Email lub login';$('#login_email').focus(function(){if($(this).val()==value)$(this).val('');});$('#login_email').blur(function(){if($(this).val()=='')$(this).val(value);});if($.browser.mozilla){$('button.gbtn, input.gbtn').css('paddingTop',1);$('button.gbtn, input.gbtn').css('paddingBottom',3);}
if($.browser.webkit){$('#key-nav').css('display','none');}
$("#key-nav").css({'display':'block'});$('#key-nav').click(function(){$('#key-nav').focus();});$("#key-nav").focus(function(){$(this).html("Sterowanie klawiaturą aktywne");$("#key-nav-info").slideDown();});$("#key-nav").blur(function(){$(this).html("Włącz przeglądanie klawiaturą");$("#key-nav-info").slideUp();});$('#datepicker').datepicker({dateFormat:'ddmmyy',onSelect:function(date){$("#datepicker").datepicker('disable');ga(date);$("#datepicker").datepicker('enable');}});});function bindAJAX(){$(function(){$(".ajax a, a.ajax").unbind('click');$(".ajax a, a.ajax").click(function(e){load($(this).attr("href"));e.preventDefault();});});}
function load(url){$("#log").css({'display':'none'});$("#ajax-loading").css({'display':'block'});$("#log").load(url,function(){$("#ajax-loading").css({'display':'none'});$("#log").css({'display':'block'});});}
function ga(cid){load(basePath+'/ga/'+cid);}
function deleteCommentForever(id){if(!confirm("Jesteś pewien?"))return false;$.getJSON(basePath+'/cp/deleteforever/id/'+id,function(data){switch(data['status']){case'OK':$('#post-'+id).hide('slide',function(){$(this).remove();});alert('OK');break;case'ERROR':alert(data['error']);break;}});}
function restoreComment(id){if(!confirm("Jesteś pewien?"))return false;$.getJSON(basePath+'/cp/restore/id/'+id,function(data){switch(data['status']){case'OK':$('#post-'+id).hide('slide',function(){$(this).remove();});alert('OK');break;case'ERROR':alert(data['error']);break;}});}
function deleteComment(id){if(!confirm("Jesteś pewien?"))return false;$.getJSON(basePath+'/delete/comment/id/'+id,function(data){switch(data['status']){case'OK':$('#post-'+id).hide('slide',function(){$(this).remove();});var count=$("#comments-count").html();$("#comments-count").html(--count);break;case'ERROR':alert(data['error']);break;}});}
function deleteTranslation(filename){if(!confirm("Jesteś pewien?"))return false;$.ajax({dataType:'json',type:'POST',url:basePath+'/delete/translation',data:{id:filename},success:function(data){switch(data['status']){case'OK':alert('OK');ga(cid);break;case'ERROR':alert(data['error']);break;}}});}
function deleteUpload(filename){if(!confirm("Jesteś pewien?"))return false;$.ajax({dataType:'json',type:'POST',url:basePath+'/delete/upload',data:{id:filename},success:function(data){switch(data['status']){case'OK':alert('OK');ga(cid);break;case'ERROR':alert(data['error']);break;}}});}
function acceptUpload(filename){if(!confirm("Jesteś pewien?"))return false;$.ajax({dataType:'json',type:'POST',url:basePath+'/cp/accept',data:{id:filename},success:function(data){switch(data['status']){case'OK':alert('OK');ga(cid);break;case'ERROR':alert(data['error']);break;}}});}
function addComment(){$.ajax({dataType:'json',type:'POST',url:basePath+'/ga/'+cid+'/comment',data:{comment:$('#comment').val()},success:function(data){if(data['status']=='OK')ga(cid);else{alert(data['error']);}}});}
function vote(id){$.getJSON(basePath+'/ga/'+id+'/vote',function(data){var rating=$('#rating > span').html();switch(data['result']){case'OK':$('#rating > span').html(++rating);break;case'DELETED':$('#rating > span').html(--rating);break;}});}
