/************************************************************************************************************
Ajax dynamic content
Copyright (C) November, 2005  DTHMLGoodies.com, Alf Magne Kalleland

************************************************************************************************************/	
var noFading = false;
var timeBetweenSlides = 2000;	// Amount of time between each image(1000 = 1 second)
var fadingSpeed = 10;	// Speed of fading	(Lower value = faster)


var stats = new Array();

var linki = new Array('http://www.guardian.co.uk/','http://www.independent.co.uk/','http://www.telegraph.co.uk/','http://www.usatoday.com/','http://www.timesonline.co.uk/');
var slideIndex = new Array();	// Index of current image shown
var slideIndexNext = new Array();	// Index of next image shown
var imageDivs = new Array();	// Array of image divs(Created dynamically)
var currentOpacity = new Array();	// Initial opacity
var imagesInGallery = new Array();	// Number of images in gallery
var Opera = navigator.userAgent.indexOf('Opera')>=0?true:false;
function createParentDivs(imageIndex,divId)
{
	if(imageIndex==imagesInGallery[divId]){	
		showGallery(divId);
	}else{
		var imgObj = document.getElementById(divId + '_' + imageIndex);	
		if(Opera)imgObj.style.position = 'static';
		if(!imageDivs[divId])imageDivs[divId] = new Array();
		imageDivs[divId][imageDivs[divId].length] =  imgObj;

		imgObj.style.visibility = 'hidden';	
		imageIndex++;
		createParentDivs(imageIndex,divId);	
	}		
}

function showGallery(divId)
{
	if(slideIndex[divId]==-1)slideIndex[divId]=0; else slideIndex[divId]++;	// Index of next image to show
	if(slideIndex[divId]==imageDivs[divId].length)slideIndex[divId]=0;
	slideIndexNext[divId] = slideIndex[divId]+1;	// Index of the next next image
	if(slideIndexNext[divId]==imageDivs[divId].length)slideIndexNext[divId] = 0;

	
	currentOpacity[divId]=100;	// Reset current opacity

	// Displaying image divs
	imageDivs[divId][slideIndex[divId]].style.visibility = 'visible';
	document.getElementById('news_link').href = linki[slideIndex[divId]];
	if(Opera)imageDivs[divId][slideIndex[divId]].style.display = 'inline';
	if(navigator.userAgent.indexOf('Opera')<0){
		imageDivs[divId][slideIndexNext[divId]].style.visibility = 'visible';
	}
	
	if(document.all){	// IE rules
		imageDivs[divId][slideIndex[divId]].style.filter = 'alpha(opacity=100)';
		imageDivs[divId][slideIndexNext[divId]].style.filter = 'alpha(opacity=1)';
	}else{
		imageDivs[divId][slideIndex[divId]].style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
		imageDivs[divId][slideIndexNext[divId]].style.opacity = 0.01;
	}		
	

	setTimeout('revealImage("' + divId + '")',timeBetweenSlides);		
}

function revealImage(divId)
{

	if(noFading){
		imageDivs[divId][slideIndex[divId]].style.visibility = 'hidden';
		if(Opera)imageDivs[divId][slideIndex[divId]].style.display = 'none';
		showGallery(divId);
		return;
	}
	currentOpacity[divId]--;
	if(document.all){
		imageDivs[divId][slideIndex[divId]].style.filter = 'alpha(opacity='+currentOpacity[divId]+')';
		imageDivs[divId][slideIndexNext[divId]].style.filter = 'alpha(opacity='+(100-currentOpacity[divId])+')';
	}else{
		imageDivs[divId][slideIndex[divId]].style.opacity = Math.max(0.01,currentOpacity[divId]/100);	// Can't use 1 and 0 because of screen flickering in FF
		imageDivs[divId][slideIndexNext[divId]].style.opacity = Math.min(0.99,(1 - (currentOpacity[divId]/100)));
	}
	if(currentOpacity[divId]>0){
		setTimeout('revealImage("' + divId + '")',fadingSpeed);
	}else{
		imageDivs[divId][slideIndex[divId]].style.visibility = 'hidden';	
		if(Opera)imageDivs[divId][slideIndex[divId]].style.display = 'none';		
		showGallery(divId);
	}
}

function initImageGallery(divId)
{
	var galleryContainer = document.getElementById(divId);
	
	
	slideIndex[divId] = -1;
	slideIndexNext[divId] = false;
	
	var galleryImgArray = galleryContainer.getElementsByTagName('IMG');
	for(var no=0;no<galleryImgArray.length;no++){
		galleryImgArray[no].id = divId + '_' + no;
	}
	
	imagesInGallery[divId] = galleryImgArray.length;
	createParentDivs(0,divId);		
	
}

function PopupImage(img,szer,wys) {
  tytul="Bydgoskie Zasoby Internetowe";
  var szer1 = parseInt(szer) + 28;
  var wys1 = parseInt(wys) + 28;
  szer1 = (szer1 < screen.availWidth) ? szer1 : screen.availWidth;
  wys1 = (wys1 < screen.availHeight) ? wys1 : screen.availHeight;
  var winl = (screen.availWidth - szer1) / 2;
  var wint = (screen.availHeight - wys1) / 2; 
  w=window.open("","","width="+szer1+",height="+wys1+",top="+wint+",left="+winl+",toolbar=no,scrollbars=yes,resizable=no,status=no,location=no,menubar=no,");	
  w.document.write("<HTML><HEAD><TITLE>"+tytul+"</TITLE></HEAD>");
  w.document.write("<BODY leftMargin=0 topMargin=0 marginwidth=0 marginheight=0 style=\"background-color: #000000; overflow: auto;\"><table cellpadding=0 cellspacing=0 style=\"height: 100%; width: 100%\" border=0><tr><td style=\"height: 100%; text-align: center; vertical-align: middle\" valign=\"middle\"><a href=\"javascript: self.close()\" title=\"zamknij okno\"><IMG src=\""+img+"\" galleryimg='no' style=\"border: 2px solid #505050; margin: auto\" height=\""+wys+"\" width=\""+szer+"\"></a></td></tr></table>");
  w.document.write("</BODY></HTML>");
  w.document.close();
		}

function checklogin()	{
var str1 = document.forms[0].login.value;
var str2 = document.forms[0].pass.value;
var re = new RegExp(/^[\wĄąĘęÓóĆćŁłŃńŚśŹźŻż()+-:,.? /]+$/);
if (str1 == ''){
        alert("Nie wypełniłeś pola LOGIN!");
        document.forms[0].login.focus();
        return false;
    }
else if (str2 == ''){
        alert("Nie wypełniłeś pola HASŁO!");
        document.forms[0].pass.focus();
        return false;
    }
else if (!re.test(str1)) {
        alert("W polu LOGIN akceptujemy polskie litery alfabetu, cyfry i nastepujace znaki: \n ( ) _ + - : , . ? /");
		  document.forms[0].login.focus();
		  return false;
    }
else if (!re.test(str2)) {
        alert("W polu HASŁO akceptujemy polskie litery alfabetu, cyfry i nastepujace znaki: \n ( ) _ + - : , . ? /");
		  document.forms[0].pass.focus();
		  return false;
    }
else return true;
}
