window.addEvent('domready', function(){ new SmoothScroll({duration: 700, transition: Fx.Transitions.expoOut}); });

/* FiX DLA LOGA DLA IE */
function fixPNG( myImage )
{
    var arVersion 	= navigator.appVersion.split("MSIE");
    var version 	= parseFloat(arVersion[1]);

    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
        var fiximg = new Element('div').setStyles({
        'filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + myImage.src + "')",
        'cursor':'pointer',
        'width':'461px',
        'height':'201px'
        });
        $(myImage).replaceWith(fiximg);
    }
}


/* WYSWiETLANiE KOMUNiKATOW */
var icons = new Array;
icons[1] = new Image;
icons[2] = new Image;
icons[1].src = 'gfx/ico_warning.png';
icons[2].src = 'gfx/ico_confirm.png';

function showMessage(komunikat,typ)
{
    var box = $('msgbox');
    if (!box) {
        box = new Element('div').setProperty('id', 'msgbox').injectInside(document.body);
        box.setStyles({'opacity': '0','height': window.getScrollHeight()});
        box.addEvent('click', showMessage);
        if ($('ramka')) $('ramka').setStyle('visibility','hidden');
        $$('select').each(function(s) { s.setStyle('visibility','hidden')});
        box.effect('opacity',{ duration:500, onComplete: function() {
            var pwbox = new Element('div').setProperty('id', 'pwbox').injectInside(document.body);
            pwbox.setStyles({'left':((window.getWidth()/2) - 150)+'px','top':((window.getHeight()/2))+'px'});
            if(typ)pwbox.setStyle('border-color','#00a9d3');
            pwbox.setHTML('<img src="gfx/ico_'+(!typ ? 'warning' : 'confirm')+'.png" alt="" /><b>'+komunikat+'</b>');
            if (window.ie) {
                pwbox.setStyle('top', ((window.getHeight()/2)+window.getScrollTop().toInt()) + 'px');
                pwbox.setStyle('position','absolute');
                pwbox.effects({transition:Fx.Transitions.bounceOut}).start({
                'top':[((window.getHeight()/2)+window.getScrollTop().toInt()), (((window.getHeight()/2)+window.getScrollTop().toInt())-60)],
                'height':[0,100]
                });
                window.addEvent('scroll', function(){if($('pwbox'))$('pwbox').setStyle('top',(((window.getHeight()/2)+window.getScrollTop().toInt())-60)+'px')});
            } else {
                pwbox.effects({transition:Fx.Transitions.bounceOut}).start({
                'top':[((window.getHeight()/2)), (((window.getHeight()/2))-60)],
                'height':[0,100]
                });
            }
            pwbox.addEvent('click', showMessage);
        }}).start(0,0.8);

    } else {
        var pwbox = $('pwbox');
        if (pwbox) pwbox.effect('opacity',{duration:300,onComplete:function(){pwbox.remove();}}).start(1,0);
        box.effect('opacity',{duration:500,onComplete:function(){if ($('ramka')) $('ramka').setStyle('visibility','visible');$$('select').each(function(s) { s.setStyle('visibility','visible')});box.remove();}}).start(0.6,0);
    }
}

/* ZGLOSZENiA */
function zglosBlad(id)
{
    new Ajax('ajax.php', {postBody: 'blad='+id}).request();
    showMessage('Zgłoszenie zostało przyjęte',1);
}

/* GLOSOWANiE */
function ocenNa(ile)
{
    $('na1').src = ile >= 1 ? 'gfx/vote3.png' : 'gfx/vote1.png';
    $('na2').src = ile >= 2 ? 'gfx/vote3.png' : 'gfx/vote1.png';
    $('na3').src = ile >= 3 ? 'gfx/vote3.png' : 'gfx/vote1.png';
    $('na4').src = ile >= 4 ? 'gfx/vote3.png' : 'gfx/vote1.png';
    $('na5').src = ile >= 5 ? 'gfx/vote3.png' : 'gfx/vote1.png';
}

function oceny(id)
{
    $('na1').addEvent('mouseover', function() { ocenNa(1) });
    $('na1').addEvent('mouseout',  function() { ocenNa(0) });
    $('na1').addEvent('click',     function() { glosuj(1) });
    $('na2').addEvent('mouseover', function() { ocenNa(2) });
    $('na2').addEvent('mouseout',  function() { ocenNa(0) });
    $('na2').addEvent('click',     function() { glosuj(2) });
    $('na3').addEvent('mouseover', function() { ocenNa(3) });
    $('na3').addEvent('mouseout',  function() { ocenNa(0) });
    $('na3').addEvent('click',     function() { glosuj(3) });
    $('na4').addEvent('mouseover', function() { ocenNa(4) });
    $('na4').addEvent('mouseout',  function() { ocenNa(0) });
    $('na4').addEvent('click',     function() { glosuj(4) });
    $('na5').addEvent('mouseover', function() { ocenNa(5) });
    $('na5').addEvent('mouseout',  function() { ocenNa(0) });
    $('na5').addEvent('click',     function() { glosuj(5) });
}

function glosuj(ocena)
{
    $('ocena').ocena.value = ocena;
    $('ocena').submit();
}

/* KOMENTARZE */
var okw;
function komentuj()
{
    var kw = $('comments').getStyle('height').toInt();
    if (kw > 0) {
        $('comments').effects({ onComplete: function() {
            $('postcomment').effects().start({
            'height':[0,80],
            'opacity':[0.01,1]
            });
        }}).start({
        'height':[kw,0],
        'opacity':[1,0.01]
        });
        okw = kw;
    } else {
        $('postcomment').effects({ onComplete: function() {
            $('comments').effects().start({
            'height':[0,okw],
            'opacity':[0.01,1]
            });
        }}).start({
        'height':[80,0],
        'opacity':[1,0.01]
        });
    }
}

/** ladowanie gry */
var Loading = {
    height: null,

    update: function() {
        if ($('loading_box_progress_bar')) {
            progress = $('loading_box_progress_bar').getStyle('width').toInt();

            if (progress < 100) {
                $('loading_box_progress_bar').setStyle('width', progress+1+'%');
                $('loading_box_progress_percent').setHTML(progress+1+'%');
                setTimeout(Loading.update, 200);
            } else {
                Loading.showGame();
            }
        }
    },
    
    begin: function() {
        Loading.height = $('ramka').getStyle('height').toInt();
        
        document.getElementById('ramka').style.height     = '0px';
        document.getElementById('ramka').style.visibility = 'hidden';
        document.write('<iframe id="loading_box" src="google.html" frameborder="0" scrolling="no"></iframe>');
        document.write('<div id="loading_box_progress"><div id="loading_box_progress_bar"></div><div id="loading_box_progress_percent">0%</div></div>');
        document.write('<a id="skip_loading" href="javascript:void(0)" onclick="Loading.showGame()">Ładowanie gry</a>');

        document.getElementById('ramka').onload = function() { Loading.finished(); }
        
        window.addEvent('domready', Loading.update);
    },

    finished: function() {
        $('skip_loading').setHTML('Gra została załadowana, kliknij tutaj aby rozpocząć grę...');
    },

    showGame: function() {
        $('loading_box').remove();
        $('loading_box_progress').remove();
        $('skip_loading').remove();

        $('ramka').setStyle('height',Loading.height+'px');
        $('ramka').setStyle('visibility','visible');
    }
}