var d = document;

var id = 0;
var alb = 0;
var lang = 'pl';
var log = 0;

var keep = 1;
var left = 0;
var x = 0;
var obraz = 0;
var fot = 0;

var o = 0;
var timer;

function dopasuj(){
        var h;
        if(window.innerHeight){h = window.innerHeight;}else{h = document.documentElement.clientHeight;}
        if (h>800){$("#kontener").css("margin-top",((h-800)/2)+"px");}
}

function zmienne(i,a,lng,l){
        id = i;
        alb = a;
        lang = lng;
        log = l;
}

function dopasujMiniaturki(i){
        i = i * 100;
        $("#tins").width(i+5+"px");
        Start();
}

function pokazMiniaturki(){
        if (window.XMLHttpRequest){
                xmlhttp2=new XMLHttpRequest();
        }else{
                xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp2.onreadystatechange = function(){
                if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200){
                        $('#thumbs').html(xmlhttp2.responseText);
                        $("a.th").click(function(){
                                var rel = $(this).attr("rel");
                                alb=rel;
                                pokazMiniaturki();
                                if(log==2){pokazForms();}
                        });
                        initLightbox();
                }
        };
        xmlhttp2.open("GET","php/thumbs.php?id="+id+"&alb="+alb+"&lang="+lang+"&log="+log,true);
        xmlhttp2.send();
}

function pokazForms(){
        if (window.XMLHttpRequest){
                xmlhttp1=new XMLHttpRequest();
        }else{
                xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp1.onreadystatechange = function(){
                if (xmlhttp1.readyState == 4 && xmlhttp1.status == 200){
                        $('#tresc').html(xmlhttp1.responseText);
                        $("#tresc").fadeIn(800);
                        if ($.browser.msie){}else{$("\.f").corner("5px");}
                }
        };
        xmlhttp1.open("GET","php/forms.php?id="+id+"&alb="+alb+"&lang="+lang+"&log="+log,true);
        xmlhttp1.send();
}

function wybierzPlik(){if(document.forms.edytor){document.getElementById('nazwapliku').innerHTML='<b>'+document.forms.edytor.plik_upload.value+'</b>';}}
function keepScrolling(){if($("#thumbs").is("#thumbs")){var st=d.getElementById('thumbs').scrollLeft;if(st!==left){d.getElementById('thumbs').scrollLeft+=(left-st)/4;}}if(keep==1){setTimeout("keepScrolling();",40);}}
function armList(){$(".sub").mousemove(function (e){h=$(this).height()-10;t=this.scrollHeight-h;y=e.pageY-($(this).offset().top);st=(y/h)*t;this.scrollTop=(y/h)*t;});}
function pokazMenu(i){$(i).show(0);}
function Start(){var w=$("#thumbs").width()-200;var m=parseInt($("#thumbs").offset().left)+100;var o=0;var t=document.getElementById('thumbs').scrollWidth;o=t-w;$("#thumbs").mousemove(function(e){x=e.pageX;if(((x-m)>0)&&((x-m)<w)){left=((x-m)/w)*(o-200);}});keepScrolling();armList();}
function initLightbox(){
        $('a.lightbox').lightBox({
	       overlayOpacity: 0.5,
	       imageLoading: 'gfx/loading.gif',
	       imageBtnClose: 'gfx/closelabel.gif',
	       imageBtnPrev: 'gfx/prevlabel.gif',
	       imageBtnNext: 'gfx/nextlabel.gif',
	       txtImage: 'Obrazek',
	       txtOf: 'z'
        });
}

function pokazObrazki()
{
        var d=document;
        o++;
        l = d.obrazki.length;
        if(o >= l){o=0;}
        $("#main1").hide();
        $("#main1").attr('src',d.obrazki[o].src);
        $("#main1").fadeIn(800,function()
        {
                $("#main").attr('src',d.obrazki[o].src);
        });
        timer = setTimeout('pokazObrazki();',5000)
}

function wczytajObrazki()
{
        clearTimeout(timer);
        var lista = wczytajObrazki.arguments;
        var d=document;
        var i=0;
        d.obrazki = new Array;
        while(lista[i])
        {
                d.obrazki[i]=new Image();
                d.obrazki[i].src=lista[i];
                i++;
        }
        pokazObrazki();
}

// wstrzymał słońce ruszył ziemię
$(document).ready(function(){
	dopasuj();
        // deklaracja pluginów
        if ($.browser.msie){}else{
	$("\.f").corner("5px");
        $("#kontener").corner("15px");
        $("#obrazki").corner("15px");
        $("#main").corner("15px");
        $("#main1").corner("15px");
	}
        // główne hide i show
        $("#frame").hide();
        $("#main").hide();
        $("#logowanie").hide();if($("\.logout").is("\.logout")){$('#logowanie').show();};
        //uzbrojenie menu
        $("li.menu").hover(
                function(){
                        if ($.browser.msie){
                        	$(this).children("\.submenu").show();
                        	$(this).children("\.submenu").css("left",$(this).position().left);
			}else{
				$(this).children("\.submenu").fadeIn();
                        	$(this).children("\.submenu").css("left",$(this).position().left);
                        }
                },
                function(){
                	if ($.browser.msie){
                        	$("\.submenu").hide();
                	}else{
                		$("\.submenu").fadeOut();
                	}
                }
        );
        $("\.menu").click(
                function(){
                        id = $(this).attr("rel");
                        $("#tresc").fadeOut(100);
                        pokazForms();
                        pokazMiniaturki();
                        alb = 0;
                }
        );
        $("\.sub").click(
                function(){
                        alb = $(this).attr("rel");
                        pokazMiniaturki();
                        if (alb != 0){
				$("#main").show();
				$("#frame").fadeIn(800);
			}
                }
        );
        $("\.logowanie").click(function(){$("#logowanie").fadeIn(500);});
	// uzbrojenie list
	//$("a.list").mouseover(function(){
                //if(alb==0){
                //var rel = $(this).attr("rel");
                //alb=rel;
                //podswietlListe();
                //alb=0;
                //keep = 0;
                //$("#thumbs").scrollTo( $("\.overlay."+rel) , 100,{onAfter:function(){
                        //keep = 1;
                        //left = $("\.overlay."+rel).parent().parent().position().left;
                        //keepScrolling();
                //}});
                //}
        //});
});

