//linki zewnętrzne

function targetBlank() {
	if (document.getElementsByTagName) {
		var anchors = document.getElementsByTagName( "a" );
		for (var loop = 0; loop < anchors.length; loop++) {
			var anchor = anchors[loop];
			if (anchor.getAttribute("href") && anchor.getAttribute("rev") == "_blank") {
				anchor.target = "_blank";
			}
		}
	}
}


// Slideshow: next/prev

var slideshow = {
	current : 1,
	path : '',
	numPhotos : 0,
	show : function(nr,path) {
		path = path || slideshow.path;
		document.getElementById('slideShowPhoto').src = path + photos[nr]['src'] + '_small.jpg';
		document.getElementById('slideShowPhoto').parentNode.setAttribute('href',path + photos[nr]['src'] + '.jpg');
		document.getElementById('slideShowOpis').innerHTML = photos[nr]['opis'];
		document.getElementById('slideShowNumeracja').innerHTML = 'фотография '+nr+'/'+slideshow.numPhotos;
		slideshow.current = nr;
	},
	prev : function() {
		(slideshow.current<=1)?slideshow.show(slideshow.numPhotos):slideshow.show(slideshow.current-1);
		return false;
	},
	next : function() {
		(slideshow.current>=slideshow.numPhotos)?slideshow.show(1):slideshow.show(slideshow.current+1);
		return false;
	},
	show1 : function(nr,path) {
		path = path || slideshow.path;
		document.getElementById('slideShowPhoto').src = path + photos[nr]['src_small'];
		document.getElementById('slideShowPhoto').parentNode.setAttribute('href',path + photos[nr]['src_big']);
		document.getElementById('slideShowNumeracja').innerHTML = 'фотография '+nr+'/'+slideshow.numPhotos;
		slideshow.current = nr;
	},
	prev1 : function() {
		(slideshow.current<=1)?slideshow.show1(slideshow.numPhotos):slideshow.show1(slideshow.current-1);
		return false;
	},
	next1 : function() {
		(slideshow.current>=slideshow.numPhotos)?slideshow.show1(1):slideshow.show1(slideshow.current+1);
		return false;
	},
	init : function() {
		if(photos){
			for(var i in photos)++i;
			this.numPhotos=i-1;
		}
	}

}


// befor onLoad

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);
	/*
	if (_timer) {
		clearInterval(_timer);
		_timer = null;
	}
	*/

	// do stuff
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
	document.addEventListener("DOMContentLoaded", targetBlank, false);
}


/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
			targetBlank();
		}
	}, 10);
}


function linkUnderConstruction() {
	if (document.getElementsByTagName) {
		var anchors = document.getElementsByTagName( "a" );
		for (var loop = 0; loop < anchors.length; loop++) {
			var anchor = anchors[loop];
			if (anchor.getAttribute("href") && anchor.getAttribute("rev") == "_alert") {
				anchor.onclick = function() {
					underConstruction();
				}
			}
		}
	}
}


function underConstruction() {
	alert('Przepraszamy.\n\nStrona w przygotowaniu.');
	
	return false;
}

// ON LOAD

window.onload = function() {
	init();
	targetBlank();
	linkUnderConstruction();
}