var strony = new Array('sugart','oferta','portfolio','klienci','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 xMousePos = 0;
var yMousePos = 0;

$().mousemove(function(e) { xMousePos = e.pageX; yMousePos = e.pageY; });

var foliovisible = false;

function navgotomouse() {
if (sunavi) {
$("#folionav").animate({'left' : (xMousePos - 82)+'px', 'top' : (yMousePos - 82)+'px'});
}
}

function shownav() {
if (foliovisible == false) {
$("#folionav").css({'left' : '0px', 'top' : '136px'});
$("#folionav").fadeIn(500);
foliovisible = true;
	} else {
$("#folionav").fadeOut(500);
foliovisible = false;
	}
}

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);
});
});
}
}

function changelang(lang) {
if (window.location.hash) {
var thehash = "&h="+window.location.hash;
} else {
var thehash = "&h="+strony[0];
}
$("#contents").fadeOut(1000);
$("#header").animate({"top":"-240px"},1000);
$("#footer").animate({"top":"100%"},1000,function() {
document.location.href = "index.php?l="+lang+thehash;
});
}

var rozmiary = new Array();
rozmiary['#'+strony[0]] = new Array(1,265,-20,597,216,17);
rozmiary['#'+strony[1]] = new Array(1,278,0,557,192,128);
rozmiary['#'+strony[2]] = new Array(0,86,-96,850,500,239);
rozmiary['#'+strony[3]] = new Array(0,90,0,557,492,350);
rozmiary['#'+strony[4]] = new Array(1,265,66,428,216,461);

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 == "#portfolio") {
$("#portfolio").load("portfolio.php?ajax=tak",function() {
vgo(0);
if (sunavi) {
shownav();
}
if (sunavi) {
$("#galinfo").stop(true,true).wait(5000).fadeOut(5000);
} else {
$("#galinfo").stop(true,true).hide();
}
});
} else {
if (foliovisible) {
shownav();	
}
}
$(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() {
$("#sugart").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);
}
});
});

}

var status0 = 0;
var status1 = 0;
var sunavi = false;

function sunavicheck(where) {
if (sunavi) {
if(where == "left" || where == "right") {
go(where);
} else {
vgo(where);
}
}
}

function foliojedz(gdzie) {

var ile = $("#dzialyportfolio2").css("top");
ile = ile.substr(0,ile.length - 2);

if (gdzie == "wgore") {
przewijam = setInterval(function() {
if (ile > -200) {
ile--;
ile--;
$("#dzialyportfolio2").css({"top" : ile+"px"});
}
},10);
} else {
przewijam = setInterval(function() {
if (ile < 0) {
ile++;
ile++;
$("#dzialyportfolio2").css({"top" : ile+"px"});
}
},10);
}
}


function przestanjechac() {
clearInterval(przewijam);
}
/*
$("#folio_down").mouseover(function() {
przewijamwdol = setInterval(function() {

},10);
});
$("#folio_up").mouseout(function() {
clearInterval(przewijamwgore);
});
$("#folio_down").mouseout(function() {
clearInterval(przewijamwdol);
});
*/


$(document).ready(function(){

$("a").click(function(){$(this).blur();}).mouseout(function(){$(this).blur();});

$("#sunavionoff").click(function() {

if (thehash == "#portfolio") {
	if (!sunavi) {
	$("#galinfo").stop(true,true).fadeIn(500).wait(5000).fadeOut(5000);
	}
	shownav();
}
if (sunavi) {
$("#sunavionoff").attr({src: "gfx/sunavi_off.png"});
sunavi = false;
} else {
$("#sunavionoff").attr({src: "gfx/sunavi_on.png"});
sunavi = true;
}
});

$(".menulink").mouseover(function() {
if (sunavi) {
if (status == 1) {
if (thehash != $(this).children("a").attr("href")) {
status = 0;
document.location.href = $(this).children("a").attr("href");
goto($(this).children("a").attr("href"));
}
}
}
});

$("#but_goback").mouseover(function() {
if (sunavi) {gobacktocontact();}
});
$("#but_napisz").mouseover(function() {
if (sunavi) {shownapisz();}
});
$("#contactform").children(".sender").mouseover(function() {
if (sunavi) {
$(this).focus();
}
});

$(".ttp").animate({top: "-60px", opacity: 0},0).fadeOut(0);

$("#footer3 > span > a").mouseover(function(){
$(this).parent().children(".ttp").fadeIn(0).animate({top: "-50px", opacity: 0.7},500);
});
$("#footer3 > span > a").mouseout(function(){
$(this).parent().children(".ttp").animate({top: "-60px", opacity: 0.0},500).fadeOut(0);
});

$(".navdiv").mouseover(function() {
status1 = status0;
status0 = $(this).attr("id");
status0 = status0.substr(2);
if (canmoveleft) {
if (status1 == 1 && status0 == 4 ) {
	go("left",250);
}
if (status1 == 2 && status0 == 1 ) {
	go("left",250);
}
if (status1 == 3 && status0 == 2 ) {
	go("left",250);
}
if (status1 == 4 && status0 == 3 ) {
	go("left",250);
}
}

if (canmoveright) {
if (status1 == 1 && status0 == 2 ) {
	go("right",250);
}
if (status1 == 2 && status0 == 3 ) {
	go("right",250);
}
if (status1 == 3 && status0 == 4 ) {
	go("right",250);
}
if (status1 == 4 && status0 == 1 ) {
	go("right",250);
}
}
});

$("#arr_up").mouseover(function() {
vgo(pfolder - 1);
});

$("#arr_down").mouseover(function() {
vgo(pfolder + 1);
});

$(".menulink").children("a").click(function() {
this.blur();
if (status == 1) {
status = 0;
goto($(this).attr("href"));
}
});

});


var currentoffset = 0;
var pfolder = 0;
var canmoveleft = false;
var canmoveright = true;

function vgo(where) {
if (where >= 0 && where <= pfolderow) {
currentoffset = 0;
canmoveleft = false;
canmoveright = true;
$("#arr_l").fadeOut(500);
$("#arr_r").fadeIn(500);
$("#portfolio3").animate({"top":"-"+ (500 * where) +"px"},500);
$("#flo_"+pfolder).animate({"left": "0px"},500);	
pfolder = where;
$("#galtitle").stop(true,true).html($("#vgoer_"+where).html()).fadeIn(1500).fadeOut(500);

}
}

function go(where,speed) {
	if (!speed) {speed = 500;}
if (where == "left" && canmoveleft) {
var offset = 750;
} else if (where == "right" && canmoveright) {
var offset = -750;
} else {
var offset = 0;	
}
var szerokosc = $("#flo_"+pfolder).css("width");
szerokosc = szerokosc.substr(0,szerokosc.length - 2);

$("#flo_"+pfolder).animate({"left": currentoffset + offset+"px"},speed);
currentoffset += offset;

if (currentoffset >= 0) {
canmoveleft = false;
$("#arr_l").hide();	
} else {
canmoveleft = true;
$("#arr_l").show();		
}

if (szerokosc <= (0 - ((currentoffset - 850)))) {
canmoveright = false;
$("#arr_r").hide();		
} else {
canmoveright = true;
$("#arr_r").show();		
}

}

