/* (c) Kalamun.org - GNU/GPL 3 */

var kBrowser={
	IE:!!(window.attachEvent&&!window.opera),
	IE4:navigator.userAgent.indexOf('MSIE 4')>-1,
	IE5:navigator.userAgent.indexOf('MSIE 5')>-1,
	IE6:navigator.userAgent.indexOf('MSIE 6')>-1,
	IE7:navigator.userAgent.indexOf('MSIE 7')>-1,
	OP:!!window.opera,
	SF:navigator.userAgent.indexOf('Safari')>-1,
	FF:navigator.userAgent.indexOf('Gecko')>-1&&navigator.userAgent.indexOf('Safari')==-1
	};

kAddEvent=function(obj,event,func,where) {
	if(!where) var where="after";
	if(typeof obj[event]!='function') obj[event]=func;
	else {
		var oldfunc=obj[event];
		if(where=="before") obj[event]=function() { func(); if(oldfunc) oldfunc(); };
		else obj[event]=function() { if(oldfunc) oldfunc(); func(); };
		}
	}
kGetPosition=function(obj) {
	var pos=Array();
	pos['left']=0;
	pos['top']=0;
	if(obj) {
		while(obj.offsetParent) {
			pos['left']+=obj.offsetLeft;
			pos['top']+=obj.offsetTop;
			obj=obj.offsetParent;
			}
		pos['left']+=obj.offsetLeft;
		pos['top']+=obj.offsetTop;
		}
	return {x:pos['left'],y:pos['top']};
	}

kWindow=new function() {
	this.filterResults=function(win,docel,body) {
		var result=win?win:0;
		if(docel&&(!result||(result>docel))) result=docel;
		return body&&(!result||(result>body))?body:result;
		}

	// size
	this.clientWidth=function() {
		return this.filterResults(window.innerWidth?window.innerWidth:0,document.documentElement?document.documentElement.clientWidth:0,document.body?document.body.clientWidth:0);
		}
	this.clientHeight=function() {
		return this.filterResults(window.innerHeight?window.innerHeight:0,document.documentElement?document.documentElement.clientHeight:0,document.body?document.body.clientHeight:0);
		}

	// scroll
	this.scrollLeft=function() {
		return this.filterResults(window.pageXOffset?window.pageXOffset:0,document.documentElement?document.documentElement.scrollLeft:0,document.body?document.body.scrollLeft:0);
		}
	this.scrollTop=function() {
		return this.filterResults(window.pageYOffset?window.pageYOffset:0,document.documentElement?document.documentElement.scrollTop:0,document.body ? document.body.scrollTop:0);
		}

	// mouse
	this.mousePos={x:0,y:0};
	this.elementOver=null;
	}

kMouseMove=function(e) {
	var e=e||window.event;
	var mPos={x:0,y:0};
	if(e.pageX||e.pageY) mPos={x:e.pageX,y:e.pageY};
	else mPos={x:e.clientX+document.body.scrollLeft-document.body.clientLeft,y:e.clientY+document.body.scrollTop-document.body.clientTop};
	kWindow.mousePos=mPos;
	kWindow.elementOver=(e.target)?e.target:e.srcElement;
	return false;
	}
kAddEvent(document,"onmousemove",kMouseMove);

var bodyNews=null;
var scrollTimer=null;
function scrollNews() {
	bodyNews=document.getElementById('bodyNews');
	bodyNews.style.top="150px";
	for(var i=0;bodyNews.childNodes[i];i++) {
		bodyNews.childNodes[i].onmouseover=stopScroll;
		bodyNews.childNodes[i].onmouseout=startScroll;
		}
	startScroll();
	}
function startScroll() {
	scrollTimer=setInterval(scrollaNews,100);
	}
function stopScroll() {
	clearInterval(scrollTimer);
	}
function scrollaNews() {
	bodyNews.style.top=parseInt(bodyNews.style.top)-2+'px';
	if(parseInt(bodyNews.style.top)+bodyNews.offsetHeight<0) bodyNews.style.top='150px';
	}

var arrowUp=null;
var arrowDw=null;
var mainText=null;
var scrollText=null;
var scrollTimer=null;
function arrowsOn() {
	mainText=document.getElementById('maintext');
	scrollText=document.createElement('DIV');
	scrollText.style.cssText="position:absolute;top:0;left:0;padding-right:40px;";
	scrollText.innerHTML=mainText.innerHTML;
	mainText.innerHTML="";
	mainText.appendChild(scrollText);
	if(mainText.offsetHeight<scrollText.offsetHeight) {
		arrowUp=document.createElement('IMG');
		arrowUp.src=BASEDIR+'/img/arrow_up.gif';
		arrowUp.className='arrowUp';
		arrowUp.onmousedown=mainTextScrollDw_start;
		arrowUp.onmouseup=mainTextScrollDw_stop;
		mainText.appendChild(arrowUp);
		arrowDw=document.createElement('IMG');
		arrowDw.src=BASEDIR+'/img/arrow_dw.gif';
		arrowDw.className='arrowDw';
		arrowDw.onmousedown=mainTextScrollUp_start;
		arrowDw.onmouseup=mainTextScrollUp_stop;
		mainText.appendChild(arrowDw);
		}
	}
function mainTextScrollUp_start() {
	if(scrollTimer) clearInterval(scrollTimer);
	scrollTimer=setInterval(mainTextScrollUp,10);
	}
function mainTextScrollUp_stop() {
	clearInterval(scrollTimer);
	}
function mainTextScrollUp() {
	if(parseInt(scrollText.style.top)>mainText.offsetHeight-scrollText.offsetHeight) scrollText.style.top=(parseInt(scrollText.style.top)-1)+'px';
	}
function mainTextScrollDw_start() {
	if(scrollTimer) clearInterval(scrollTimer);
	scrollTimer=setInterval(mainTextScrollDw,10);
	}
function mainTextScrollDw_stop() {
	clearInterval(scrollTimer);
	}
function mainTextScrollDw() {
	if(parseInt(scrollText.style.top)<=0) scrollText.style.top=(parseInt(scrollText.style.top)+1)+'px';
	}

var photogalleryTimer=null;
var photogalleryTable=null;
var photogalleryOffset=60;
var photogalleryImgNum=0;
var photogalleryImgWidth=110;
var photogalleryCount=0;
function photogalleryInit() {
	photogalleryTable=document.getElementById('photogallery').getElementsByTagName('TABLE')[0];
	photogalleryImgNum=photogalleryTable.getElementsByTagName('TD').length-1;
	photogalleryTable.style.left="200px";
	photogalleryTimer=setInterval(photogalleryStartPos,10);
	}
function photogalleryStartPos() {
	var x=parseInt(photogalleryTable.style.left);
	if(x>photogalleryOffset) photogalleryTable.style.left=(x-5)+'px';
	else clearInterval(photogalleryTimer);
	}
function photogalleryLeft() {
	if(photogalleryCount>0) {
		photogalleryCount--;
		photogalleryTimer=setInterval(photogalleryMove,10);
		}
	}
function photogalleryRight() {
	if(photogalleryCount<photogalleryImgNum) {
		photogalleryCount++;
		photogalleryTimer=setInterval(photogalleryMove,10);
		}
	}
function photogalleryMove() {
	var x=parseInt(photogalleryTable.style.left);
	if(x>-(photogalleryCount*photogalleryImgWidth)+photogalleryOffset) photogalleryTable.style.left=(x-5)+'px';
	else if(x<-(photogalleryCount*photogalleryImgWidth)+photogalleryOffset) photogalleryTable.style.left=(x+5)+'px';
	else clearInterval(photogalleryTimer);
	}