var strony = new Array('logowanie','a','projekty','b','kontakt');
var status;
var przewijam;

$.fn.wait = function(time, type) {
time = time || 1000;
type = type || "fx";
return this.queue(type, function() {
var self = this;
setTimeout(function() {
$(self).dequeue();
}, time);
});
};


var foliovisible = false;


function zaloguj () {
	$("#loginform").submit();
	$("#but_login").children("a").blur();
	}


function gobacktocontact() {
$("#plywak2").animate({"top":"0px"},1000);
}

function shownapisz() {
$("#plywak2").animate({"top":"-240px"},1000);
}

function sendform() {
document.getElementById("contactform").submit();
}

function messageform(ok) {
if (ok == "ok") {
$("#formularz").fadeOut(500,function() {
$("#formularzok").fadeIn(500).wait(2000).fadeOut(3000,function() {
$("#formularz").fadeIn(500);
});
});
} else {
$("#formularz").fadeOut(500,function() {
$("#formularzbad").fadeIn(500).wait(2000).fadeOut(3000,function() {
$("#formularz").fadeIn(500);
});
});
}
}

var rozmiary = new Array();
rozmiary['#'+strony[0]] = new Array(1,330,170,220,100,128);
rozmiary['#'+strony[1]] = new Array(1,278,0,557,192,128);
rozmiary['#'+strony[2]] = new Array(0,86,-143,850,500,239);
rozmiary['#'+strony[3]] = new Array(0,90,0,557,492,350);
rozmiary['#'+strony[4]] = new Array(1,265,66,428,216,350);

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}


function goto(gdzie) {

$("#contents2").fadeTo(500,0.01,function() {
for(var i = 0; i < strony.length; i++) {
$("#"+strony[i]).hide(0);
}

$("#menubar").animate({"left":rozmiary[gdzie][5]},400);

if (rozmiary[gdzie][0] == 0) {


$("#contents").animate({"top": rozmiary[gdzie][1]+"px","left": rozmiary[gdzie][2]+"px"},400);
$("#footer").animate({"top":"600px"},400);
$("#header").animate({"top":"-104px"},400);
$("#menuheader").animate({"top":"-53px"},400);


} else {


$("#contents").animate({"top": rozmiary[gdzie][1]+"px","left": rozmiary[gdzie][2]+"px"},400);

$("#footer").animate({"top":"520px"},400);
$("#header").animate({"top":"0px"},400);
$("#menuheader").animate({"top":"0px"},400);

} //endif
});
$("#contents2").animate({"width": rozmiary[gdzie][3]+"px","height": rozmiary[gdzie][4]+"px"},400,function() {
if (gdzie == "#projekty") {
$("#projekty").html('');
$("#projekty").load("portfolio.php");
}
$(gdzie).show();
$("#contents2").fadeTo(500,1,function() {
status = 1;
thehash = window.location.hash;
if (thehash != gdzie) {
status = 0;
goto(thehash);
}

});
});

}



function makepage() {
$("#loader").fadeOut(500,function() {
$("#logowanie").show(0);
$("#contents").fadeIn(1000);
$("#header").animate({"top":"0px"},1000);
$("#footer").animate({"top":"520px"},1000,function() {
status = 1;
thehash = window.location.hash;
thehash = thehash.substr(1);
if (strony.indexOf(thehash) >= 0) {
status = 0;
goto("#"+thehash);
}
});
});

}


$(document).ready(function(){

$(".menulink").children("a").click(function() {
this.blur();
if (status == 1) {
status = 0;
goto($(this).attr("href"));
}
});

});
