/*	When document is full loaded (ready)
 *  init dom element's behaviours and animations
 */
function getInternetExplorerVersion()// Returns the version of Windows Internet Explorer or a -1
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null) 
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

$.fn.serializeForm = function()
{
    data = {};
    url = this.attr("action");
    items = this.serializeArray();
    $.each(items,function(i,item)
    {
        data[item['name']]=item['value'];
    }
    );
    return data;
}


function submitHook(form, callback)
{
    $(form).submit(function(e){
        items = {};
        items = $(form).serializeForm();
        url = $(form).attr("action");
        if(""==url)
        {
            alert("AJAX error");
            return false;
        }
        callback = callback?callback:function(){};
        $.post(url,items,callback);
        return false;
    });
}

temp = "Adres został zapisany. Aby otrzymywać newsletter musisz aktywować swój adres poprzez kliknięcie w link aktywacyjny, który wysłaliśmy Ci e-mailem. Prosimy nie odpowiadać na tą wiadomość.";
function nl_add(data) {
        if(data == 'OK') {
            $('#nl_status').html(temp).show('fast');
        } else {
            $('#nl_status').html(data).show('fast');
        }
 //   });
}
cap = false;
function showCaptcha() {
    if(!cap) {
        $('#named').hide();
        $('#texted').hide();
        $('#captcha').show('fast');
        $('#capcont').removeClass('text');
        cap = true;
    } else {
        $('#comment_form').submit();
    }
}

function comment_add(data) {
    if(data =='OK') {
        $('#errors').hide();
        $('#comform').hide('fast', function(){
            $('#success').show('fast');
        });
        cap = false;
    } else {
        errors = eval('('+data+')');
        error_html = '';
        $.each(errors, function(i,error) {
            error_html += '<li>'+error+'</li>';
        });
        $('#errors').html(error_html).show('flash');
    }
}

var rotn = 1;
var rotd = 6000;

function headerRot() {

    i = rotn;
    j = rotn+1;
    if(j > 4) j = 1;

    $('.image'+i).fadeOut('slow');
    $('.image'+j).fadeIn('slow');

    rotn = j;

    setTimeout(headerRot, rotd);
}

function initHeaderRot() {
    for(i=2;i<5;i++)
        $('.image'+i).hide();

    setTimeout(headerRot, rotd);
}


$(document).ready(function(){

    var browserName = navigator.appName;
    var browserVer = getInternetExplorerVersion();
    
    if (browserName == 'Microsoft Internet Explorer' & browserVer == '6') {
    
        /* IE6 PNG FIX */
        $(' div.oneImg a, div.imgCoverCont a, div.singleBox h3, div.bottom1box a, a.singleElement span.cover').ifixpng();

    }

    submitHook('#newsletter_add',nl_add);
    submitHook('#comment_form',comment_add);
    
    $('ul#menu').superfish({
		   hoverClass:    'sfHover',
		   pathClass: 'current',
		   delay:       1000,                            // one second delay on mouseout
                   pathLevels:    1,
                   animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation
                   speed:       'fast',                          // faster animation speed
                   autoArrows:  false,                           // disable generation of arrow mark-up
                   dropShadows: false
		 });

                 makeGals();

    initHeaderRot();

}); //end ready function




