var slideTimeout = false;
var slideTime = 7000;
var aColorTime = 200;
var slidecount;
var isFolio = false;

var folders = new Array("webdesign","reklama-internetowa","plakaty","ulotki","kreacja","ci","druk","oprogramowanie-dedykowane");


var filelist = new Array();
filelist[0] = new Array("8words.jpg","a2.jpg","arcon.jpg","beup.jpg","cambridge.jpg","carad.jpg","czahorowski.jpg","els.jpg","elt.jpg","gd.jpg","gugo.jpg","hg.jpg","innergo.jpg","kasztanowe.jpg","l2.jpg","melosik.jpg","mk.jpg","przedszkole.jpg","rudas.jpg","satisfaction.jpg","spinach.jpg","sulich2.jpg","sumo.jpg","szkola.jpg","wax.jpg","wnetrzarskie.jpg");
filelist[1] = new Array("allianz1.jpg","allianz3.jpg","allianz2.png","allianz4.png","fiat.jpg","gruper1.jpg","gruper2.png","gruper3.png","rwe.png","sphinx1.jpg","sphinx2.png","wolters1.jpg","wolters2.png");
filelist[2] = new Array("ambientpsy.jpg","cambridge.jpg","cambridge-2.jpg","cytrynowe-1.jpg","cytrynowe-2.jpg","cytrynowe-3.jpg","elt.jpg","ep.jpg","ep2.jpg","pascal.jpg","ponioslo.jpg","student.jpg");
filelist[3] = new Array("3bit1.jpg","3bit2.jpg","3bit3.jpg","3bit4.jpg","bk.jpg","desperados2.jpg","desperados3.jpg","lesny-dwor.jpg","lesny-dwor-2.jpg","lexus1.jpg","lexus2.jpg","lexus3.jpg","pilsner1.jpg","pilsner2.jpg","princepolo3.jpg","princepolo4.jpg","princepolo5.jpg","twojstyl.jpg");
filelist[4] = new Array("3bit1.jpg","3bit2.jpg","3bit3.jpg","aqua-slim.jpg","arth.jpg","carad.jpg","chicago.jpg","desperados1.jpg","desperados2.jpg","ekotorba.jpg","else.jpg","ferrari.jpg","gva1.jpg","gva2.jpg","humangrapf.jpg","knorr.jpg","lexus.jpg","pikovit.jpg","pilsner1.jpg","pilsner2.jpg","polo-market.jpg","princepolosmart1.jpg","princepolosmart2.jpg","princepolosmart3.jpg","up1.jpg","up2.jpg","up---orinoko.jpg","up-plyty.jpg","up-wenezuela.jpg");
filelist[5] = new Array("8words.png","adwokaci.png","adwokaci-2.png","chogel.jpg","doroboty.png","doroboty-2.png","druity.png","duoinet.png","duo-inet.png","h-ci.jpg","kolarz.png","mcs-1.png","mcs-2.png","music-watch.png","music-watch-2.png","music-watch-3.png","nugart.png","platin.jpg","pro-sport.png","tersen.jpg");
filelist[6] = new Array("altoria.jpg","armoth.jpg","arval.jpg","denwar.jpg","denwar-2.jpg","heyah.jpg","heyah2.jpg","lipton.jpg","oholender.jpg","promis.jpg","ramatti.jpg","roe.jpg","sejm.jpg","tardyferon.jpg","vilpin.jpg","wedel-1.jpg","wedel-2.jpg");
filelist[7] = new Array("kasyno.jpg","kolor-dnia.jpg","meow.jpg","muzaika.jpg","nork.jpg","powieksz-logo.jpg","puszka-pandory.jpg","romansoradar.jpg");
var currentfile = 1;
var currentfolder = 0;

var websiteTypes = new Array('wizytówka www','dynamiczna witryna bez podstron','witryna do 5 podstron','witryna z rozbudowanym menu');

$(document).ready(function(){
var menuTop = parseInt($('#topmenu').css('top'));
$('#menucontainer2').css('display','none');

$('#bgslider .left').css('width',($('#menucontent').children('li').eq(0).children('a').width()+32)+"px");

if (document.location.hash != '') {
buildpage(document.location.hash.substr(1),1);
}

$(document).bind("scroll", function (e) {
var tmh = parseInt($(window).scrollTop());

if (tmh > 100) {
$('#topmenu').css({'position':'fixed','top':'0px'});
$('#menucontainer2').css({'width':$('#menucontent').width()});
if ($('#menucontainer2').css('display') == "none") {
$('#menucontainer2').stop(true,true).fadeIn(1000);	
}
} else if ($('#topmenu').css('position') == "fixed") {
$('#topmenu').css({'position':'absolute','top':menuTop+'px'});
if ($('#menucontainer2').css('display') != "none") {
$('#menucontainer2').stop(true,true).fadeOut(1000,function(){
$('#menucontainer2').css('display','none');
});	
}

}
});


$('#topmenu a, #logolink, #formlink, .pagelink').click(function(e){
e.preventDefault();
if ($(this).attr('href') != document.location.hash) {
var dest = $(this).attr('href');
dest = dest.substr(1);
buildpage(dest);
}
});

var temphtml = $('#slider .container .images').children('.item').eq(0).html();

slidecount = $('#slider .container .images .item').length;
$('#slider .container .images').append('<div class="item">'+ temphtml +'</div>');

$('#slider .switch a').click(function(e){
e.preventDefault();
var dest = $(this).attr('href');
dest = dest.substr(7);
clearTimeout(slideTimeout);
slideTimeout = setTimeout("slideRotate()",20000);
changeslide(dest-1);
});

if (slideTimeout === false) {
slideTimeout = setTimeout("slideRotate()",slideTime);
}

$(document).keyup(function(e) {
if (isFolio == true) {
	e.preventDefault();
if (e.which == '39') {
changeimage(1);
}
if (e.which == '37') {
changeimage(-1);
}
if (e.which == '40') {
if (currentfolder+1 < folders.length) {
changefolder(currentfolder+1);
} else {
changefolder(0);	
}
}
if (e.which == '38') {
if (currentfolder-1 >= 0) {
changefolder(currentfolder-1);
} else {
changefolder(folders.length-1);	
}
}

}
});

$(window).resize(function() {
$('#shadow').css({'width':'100%','height':'100%'});
$('#shadow').css({'width':(($('html').width() > $('#shadow').width())?$('html').width():$('#shadow').width()),'height':(($('html').height() > $('#shadow').height())?$('html').height():$('#shadow').height())});
});

$('.calcline .slider').draggable({axis: "x",containment:'parent',drag: calcDrag});


});

// end document ready

function calcDrag(e,ui) {
$('.calcline .slider .triangle').css({'left':$('.calcline .slider').width()/2-6});
}

function buildpage(dest,speed) {
if (speed === undefined) {var speed = 500;}
var apos = $('#ml_'+dest).parent().position();
$('#bgslider .left').stop(true,true).animate({'width':($('#ml_'+dest).width()+32)+"px"},speed).parent().animate({'left':(apos.left)+"px"},speed);
$('#main .left .current').stop(true,true).slideUp(speed).removeClass('current');
$('#pg_'+dest).stop(true,true).slideDown(speed).addClass('current');

if ($('#pg_'+dest).hasClass('first')) {
$('#slider, #sliderspace').stop(true,true).slideDown(speed);
changeslide(0,1);
clearTimeout(slideTimeout);
slideTimeout = setTimeout("slideRotate()",slideTime);
} else {
$('#slider, #sliderspace').stop(true,true).slideUp(speed);
clearTimeout(slideTimeout);
}

if ($('#pg_'+dest).hasClass('folio')) {
isFolio = true;
changefolder(0);
$('#main .right').slideUp(Math.round(speed/2),function(){
$('#main .left').animate({'width':'910px'},Math.round(speed/2),function(){
$('#shadow').css({'width':'100%','height':'100%'});
$('#shadow').hide().css({'background':'#1d0000','width':(($('html').width() > $('#shadow').width())?$('html').width():$('#shadow').width()),'height':(($('html').height() > $('#shadow').height())?$('html').height():$('#shadow').height())}).stop(true,false).fadeTo(10000,0.75);
$('#header, #topmenu, #footer, #flags').stop(true,false).fadeTo(10000,0.3);
$('h1, .dzialyfolio').stop(true,false).fadeTo(10000,0.75);
});});
} else {
isFolio = false;
$('#header, #topmenu, #footer, #flags').stop(true,false).fadeTo(500,1);
$('h1, .dzialyfolio').stop(true,false).fadeTo(500,1);
$('#shadow').stop(true,false).fadeTo(500,0,function(){
$(this).css({'background':'none','width':'0','height':'0'});

});

$('#main .left').animate({'width':'600px'},Math.round(speed/2),function(){
$('#main .right').slideDown(Math.round(speed/2));
});

}

var tempnode = $('#'+dest);
$('#'+dest).attr('id','');
document.location.hash = dest;
$(tempnode).attr('id',dest);

}

function changefolder(id) {
currentfolder = id;
currentfile = 0;
changeimage(1);
$('.dzialyfolio .active').removeClass('active');
$('.dzialyfolio a').eq(currentfolder).addClass('active');
}

function changeimage(dir) {
currentfile += dir;
if (currentfile > filelist[currentfolder].length) {
currentfile = 1;
}
if (currentfile <= 0) {
currentfile = filelist[currentfolder].length;
}
$('#loader').stop(true,true).fadeIn(100);

if (filelist[currentfolder][(currentfile)] != undefined) {
$('#nextimage img').attr('src','/portfolio2/'+folders[currentfolder]+'/'+filelist[currentfolder][(currentfile)]);
$('#nextimage2 img').attr('src','/portfolio2/'+folders[currentfolder]+'/'+filelist[currentfolder][(currentfile+1)]);
}
if (filelist[currentfolder][(currentfile-2)] != undefined) {
$('#previmage img').attr('src','/portfolio2/'+folders[currentfolder]+'/'+filelist[currentfolder][(currentfile-2)]);
$('#previmage2 img').attr('src','/portfolio2/'+folders[currentfolder]+'/'+filelist[currentfolder][(currentfile-3)]);
}

$('#folioimage img').stop(true,true).fadeOut(200,function(){
$(this).attr('src','/portfolio2/'+folders[currentfolder]+'/'+filelist[currentfolder][(currentfile-1)]).load(function(){
$('#loader').stop(true,true).fadeOut(100);
var opis = '';
if (opisy[currentfolder] != undefined && opisy[currentfolder][(currentfile-1)] != undefined) {
if (opisy[currentfolder][(currentfile-1)][1] != '' || opisy[currentfolder][(currentfile-1)][0] != '') {
opis += '| ';
}
if (opisy[currentfolder][(currentfile-1)][1] != '') {
opis += '<a href="'+opisy[currentfolder][(currentfile-1)][1]+'" target="_blank">';
}
if (opisy[currentfolder][(currentfile-1)][0] != '') {
opis += opisy[currentfolder][(currentfile-1)][0];
$('#folioimage img').attr('alt',opisy[currentfolder][(currentfile-1)][0]);
}
if (opisy[currentfolder][(currentfile-1)][1] != '') {
opis += ' &raquo;</a>';
}

if (opisy[currentfolder][(currentfile-1)][2] != '') {
opis += ' | '+teksty[0]+': '+opisy[currentfolder][(currentfile-1)][2];
}
if (opisy[currentfolder][(currentfile-1)][3] != '') {
opis += ' | '+teksty[1]+': '+opisy[currentfolder][(currentfile-1)][3];
}
if (opisy[currentfolder][(currentfile-1)][4] != '') {
opis += ' | '+teksty[2]+': '+opisy[currentfolder][(currentfile-1)][4];
}
if (opisy[currentfolder][(currentfile-1)][5] != '') {
opis += ' | '+teksty[3]+': '+opisy[currentfolder][(currentfile-1)][5];
}
if (opisy[currentfolder][(currentfile-1)][6] != '') {
opis += ' | '+teksty[4]+': '+opisy[currentfolder][(currentfile-1)][6];
}
$('.opisfolio').slideUp(200,function(){
$(this).html(opis.substr(2)).slideDown(200);
});
} else {
$('.opisfolio').html('');
}

$(this).show();
});
});
}


function changeslide(dest,speed) {
if(speed === undefined) {var speed = 700;}
$('#slider .container .images').stop(true,true).animate({'top':0-(320*dest)+'px'},speed,function(){
if (dest == slidecount) {
$('#slider .container .images').css('top','0px');
}
});
$('#slider .switch a').removeClass('current').eq(((dest == slidecount)?0:dest)).addClass('current');
}

function slideRotate() {
var curslide = $('#slider .container .images').css('top');
curslide = (curslide.substr(0,curslide.length - 2));
curslide = 0 - Math.round(curslide / 320);
if (curslide > $('#slider .container .images .item').length - 2) {curslide = -1;}
changeslide(curslide + 1);
slideTimeout = setTimeout("slideRotate()",slideTime);
}

function defus(dest,tekst) {
dest = dest.replace(/[^A-Z.@]/g, "").toLowerCase();
document.write("<a href=mailto:" + dest + " class=\"inbl item\"><strong>"+tekst.replace(" ","&nbsp;")+"</strong><span><br>" + dest + "</span></a>");
}

function writelikebox() {
document.write('<fb:like-box href="http://www.facebook.com/sugart.eu" width="410" height="300" show_faces="true" stream="false" header="false"></fb:like-box>');
}

function writelike() {
document.write('<fb:like href="http://facebook.com/sugart.eu" show_faces="false" width="630" font="trebuchet ms" colorscheme="dark"></fb:like>');
}

function kontaktSend(el) {
var temphtml = $('#submitcontainer').html();
$('#submitcontainer').fadeOut(100).html('<img src="/gfx/loader.gif" width="24" height="24" alt="">').fadeIn(100);
$.post("/sendmsg.php", $(el).serialize(),
   function(data){
$(el).parent().slideUp(250,function(){
$('#submitcontainer').html(temphtml);
});

if (data == 'ok') {
$('#msgsent').slideDown(250);
} else {
$('#msgnotsent').slideDown(250);
}
setTimeout("$('#contactformcontainer').slideDown(250);$('#msgnotsent, #msgsent').slideUp(250);",5000);
   });
return false;
}
