//-------------------------------------------------------------------------

function keyDown()
{
}


function getElement(sId)
{
	return document.getElementById(sId);
}


function setIcon(sId, sIcon)
{
	var oObj;
	oObj = getElement(sId)
	oObj.src = 'img/icons/'+ sIcon;
}


function liteOn(oObj)
{
	oObj.src = 'img/icons/'+ oObj.id + '_a.gif';
}

function liteOff(oObj)
{
	oObj.src = 'img/icons/'+ oObj.id + '.gif';
}

function toogleInfo()
{
	var oInfo;

	oInfo = getElement('imageinfo');
	if (oInfo)
	{
		oInfo.style.visibility = (oInfo.style.visibility == 'visible') ? 'hidden' : 'visible';
	}
}


function init()
{
	ShowScrolls('txt', 'gora', 'dol');
	
	AttachMouseWheelEvent();

	if (checkAvailHeight(672))
	{
		window.moveTo(0,0);
		window.resizeTo(screen.availWidth,screen.availHeight);

		if (checkAvailHeight(672))
		{
			if (confirm('fotografia.websky.pl nie mieści się w Twoim oknie :-('+ "\n\n" + 'czy chcesz otworzyć stronę w większym pop-up\'ie ?'+ "\n"))
				goPopUp();	
		}
	}
}

function checkAvailHeight(minHeght)
{	
	if (window.document.body.clientHeight)
	{
		if (window.document.body.clientHeight < minHeght)
			return true;
		return false;
	}
	if (screen.availHeight)
	{
		if (screen.availHeight - 32 < minHeght)
			return true;
		return false;
	}
	return true;
}

function goPopUp()
{	
	var win, basePath, opts;

	w = screen.availWidth;
	h = screen.availHeight;
	
	basePath	= window.location;
	opts		= 'status=0, toolbar=0, scrollbars=1, top=0, left=0, width='+w+', height='+h+',resizable=1';
	
	win = window.open(basePath, 'PopUp', opts);
	if (win)
	{
		win.moveTo(0,0);
		win.resizeTo(w,h);
		win.focus();
	}
}

//-------------------------------------------------------------------------


var oScrl = null;
var iIntervalID = 0;
var iScrlTime	= 0;
var iScrlTop	= 0;
var iScrlLenght = 0;


function StartUp(sScrl)
{
	StopScroll();
	oScrl = getElement(sScrl);
	iIntervalID = window.setInterval("ScrollUp()", 5);
	//alert(oScrl.scrollTop);
}


function StartDown(sScrl)
{
	StopScroll();
	oScrl = getElement(sScrl);
	iIntervalID = window.setInterval("ScrollDown()", 5);
}



function StopScroll()
{
	if (oScrl != null)
	{
		window.clearInterval(iIntervalID);
		iIntervalID	= 0;
		iScrlTime	= 0;
		oScrl		= null;
		iScrlTop	= 0;
		iScrlLenght = 0;
	}
}

function ScrollUp()
{
	if (oScrl == null)
		return;
	iScrlTime += 1;
	if (iScrlTime < 20)
	{
		if (iScrlTime % 3 == 1)
			oScrl.scrollTop -= 1;
	}
	else
	if (iScrlTime < 80)
		oScrl.scrollTop -= Math.floor(parseFloat(iScrlTime) / 20);	
	else
		oScrl.scrollTop -= 4;

	if (oScrl.scrollTop <= 0)
	{
		StopScroll();
		//alert('stop jo');
	}
}

function ScrollDown()
{
	if (oScrl == null)
		return;
	iScrlTime += 1;
	if (iScrlTime < 20)
	{
		if (iScrlTime % 3 == 1)
			oScrl.scrollTop += 1;
	}
	else
	if (iScrlTime < 80)
		oScrl.scrollTop += Math.floor(parseFloat(iScrlTime) / 20);	
	else
		oScrl.scrollTop += 4;
		
	if (oScrl.scrollTop >= oScrl.scrollHeight - oScrl.clientHeight)
	{
		StopScroll();
		// alert('stop jo');
	}
}


function ShowScrolls(sScrl, sArr1, sArr2)
{
	var s, a1, a2;
	s = getElement(sScrl);
	a1 = getElement(sArr1);
	a2 = getElement(sArr2);

	if (a1 && a2 && s)
	{
	
		//alert(s.scrollHeight + ' - ' +s.clientHeight ); 
		if (s.scrollHeight > s.clientHeight)
		{
			a1.style.visibility = 'visible';
			a2.style.visibility = 'visible';
		}
	}
}

function AttachMouseWheelEvent()
{
	var i;

	var aDivs = document.body.getElementsByTagName("DIV");

	for( i = 0; i < aDivs.length; i++ )
	{
		if (aDivs[i].getAttribute('mouse-scroll') != null)
			if(aDivs[i].attachEvent){
				aDivs[i].attachEvent("onmousewheel", WheelScroll );
			}else{
				aDivs[i].addEventListener("DOMMouseScroll", WheelScroll, false);
			}
	}
}

//--------------------------------------------------------

function WheelScroll(e)
{
	var iScrlLen, oObj, mf;
	
	if (!e) 
		var e = window.event
	
	/*
	if (e.target) 
		oObj = e.target
	else 
		if (e.srcElement) 
			oObj = e.srcElement
	
	if (oObj.nodeType == 3) // defeat Safari bug
		oObj = targ.parentNode;
	
	while (((iScrlLen = oObj.getAttribute('mouse-scroll')) == null ) && oObj.parentNode)
	{
		alert("You rolled on a " + oObj.tagName + " element. łiil: "+ e.wheelDelta + " detail " + e.detail );
		oObj = oObj.parentNode;
	}

	//alert("XXX a " + oObj.tagName + " element. łiil: "+ e.wheelDelta + " detail " + e.detail );

	if (iScrlLen == null)
		return;
	

	if (e.wheelDelta <= 0 || e.detail > 0)
		ScrollUpBy(oObj.id, parseInt(iScrlLen));
	else
		ScrollDownBy(oObj.id, parseInt(iScrlLen));
	*/

	oObj		= getElement('txt');
	iScrlLen	= oObj.getAttribute('mouse-scroll');
	mf			= 0;

	if (e.wheelDelta != undefined)
	{
		mf = parseInt(e.wheelDelta / -120);
	}
	else
	if (e.detail != undefined)
	{
		mf = parseInt(e.detail / 3);
	}
	else
		return;
	
	if (mf)
		ScrollDownBy(oObj.id, parseInt(iScrlLen) * mf );
	else
		ScrollUpBy(oObj.id, parseInt(iScrlLen) * -mf);
}


function ScrollUpBy(sScrl, iScrlLen)
{
	if (oScrl != null)
		return;

	oScrl		= getElement(sScrl);
	iScrlLenght = iScrlLen;
	iScrlTop	= oScrl.scrollTop;
	iScrlTime	= 0;

	//oScrl.scrollTop = iScrlTop - iScrlLenght;
	//StopScroll();
	
	iIntervalID = window.setInterval("DoScrollUpBy()", 5);
}


function ScrollDownBy(sScrl, iScrlLen)
{
	if (oScrl != null)
		return;

	oScrl		= getElement(sScrl);
	iScrlLenght = iScrlLen;
	iScrlTop	= oScrl.scrollTop;
	iScrlTime	= 0;

	iIntervalID = window.setInterval("DoScrollDownBy()", 5);
}

function DoScrollUpBy()
{
	if (oScrl == null)
		return;
	
	iScrlTime += 1;

	if (iScrlTime >= 40)
	{
		oScrl.scrollTop = iScrlTop - iScrlLenght;
		StopScroll();
		return;
	}
	
	oScrl.scrollTop = iScrlTop - Math.floor( Math.sin( parseFloat(iScrlTime)/79.0 * Math.PI ) *  parseFloat(iScrlLenght) );
	//oScrl.scrollTop = iScrlTop - Math.floor( parseFloat(iScrlTime)/40.0 *  parseFloat(iScrlLenght) );

	if (oScrl.scrollTop <= 0)
		StopScroll();
}

function DoScrollDownBy()
{
	if (oScrl == null)
		return;
	
	iScrlTime += 1;

	if (iScrlTime >= 40)
	{
		oScrl.scrollTop = iScrlTop + iScrlLenght;
		StopScroll();
		return;
	}
	
	oScrl.scrollTop = iScrlTop + Math.floor( Math.sin( parseFloat(iScrlTime)/79.0 * Math.PI ) *  parseFloat(iScrlLenght) );
	//oScrl.scrollTop = iScrlTop + Math.floor( parseFloat(iScrlTime)/40.0 *  parseFloat(iScrlLenght) );

	if (oScrl.scrollTop >= oScrl.scrollHeight - oScrl.clientHeight)
		StopScroll();

}




