/* ## preloader settings */
var pImages = new Array("architektura.jpg", "architektura1.jpg", "wnetrza.jpg", "wnetrza1.jpg", "inne.jpg", "inne1.jpg", "wspolpraca.jpg", "wspolpraca1.jpg", "architektura_button01.gif", "architektura_button02.gif", "wnetrza_button01.gif", "wnetrza_button02.gif", "inne_button01.gif", "inne_button02.gif", "wspolpraca_button01.gif", "wspolpraca_button02.gif");
var doneImages = 0;

/* ## rollover library */
function neighbourItem(item) {

	var neighbour = '';

	switch(item) {

		case 'cell1': neighbour = 'cell5'; break;
		case 'cell2': neighbour = 'cell6'; break;
		case 'cell3': neighbour = 'cell7'; break;
		case 'cell4': neighbour = 'cell8'; break;

		case 'cell5': neighbour = 'cell1'; break;
		case 'cell6': neighbour = 'cell2'; break;
		case 'cell7': neighbour = 'cell3'; break;
		case 'cell8': neighbour = 'cell4'; break;
	}

	return neighbour;
}

function rollOver(id) {

	$(id).className = 'hover';
	$(neighbourItem(id)).className = 'hover';

	

}
function rollOut(id) {
	$(id).className = '';
	$(neighbourItem(id)).className = '';
}

/* ## behaviour site scripting */
var siteEvents = {

	'#photos td' : function(td) {

		// rollovers
		td.onmouseover = function() { 
			rollOver(td.id); 
		}

		td.onmouseout = function() {
			rollOut(td.id);
		}
	},

	'#loading' : function(div) {

		// some really stupid preloading initiation, but guess only this will work with Behaviour...
		if(div.style.display == "block") { preloadImages(); }
	},

	'#lyr1' : function(div) {

		// stupid scroller initiation
		if(div.className == "scrollcontent") { initScrollLayer(); }
	}
}

// preloader's helper
function newImage(arg) {
        if (document.images) {
                rslt = new Image();
                rslt.src = arg;

		// "loading" controll events
		if($("loading").style.display == "block") {

			// hide "loading" when ready (Firefox ONLY!)
			if(BrowserDetect.browser == "Firefox") {

				rslt.onload = function() { 

					doneImages++;
					if(doneImages == pImages.length) { $("loading").style.display = "none"; }
				}

			// hide "loading" now and FUCK the case! (fucking stupid MSIE shit)
			} else {

				$("loading").style.display = "none";
			}
		}

                return rslt;
        }
}


// Simple image preloader
function preloadImages() {

	var preloadNow = new Array();
	var loop = 0;

	pImages.each( function(image) {

		imageSource = "img/" + image;
		preloadNow[loop] = newImage(imageSource);

		loop++;
	});
}

// ## RUNTIME
Behaviour.register(siteEvents);
BrowserDetect.init();
