function getElementsByClassName(clss, prnt, tg) 
{
    var elements = new Array();
    tg = tg || '*';
    prnt = prnt || document;
    var list = prnt.getElementsByTagName(tg);
    for (var i = 0; i < list.length; ++i) 
    {
        if (list[i].className == clss) 
        {
            elements.push(list[i]);
        }
    }
	return elements;
}

var ScrollReg = new scrollers();
var scrollStat = new Array ('pasif','aktif','ustunde');
var scrollRight = new Array();
var scrollLeft = new Array();
for(i=0;i<scrollStat.length;i++)
{
	scrollRight[i] = new Image();
	scrollLeft[i]  = new Image();
	scrollRight[i].src = 'sag_buton_'+ scrollStat[i] +'.gif'
	scrollLeft[i].src  = 'sol_buton_'+ scrollStat[i] +'.gif'
}

function scrollers ()
{
	var sarr = new Array()
	this.add = add
	this.get = get

	function add(scr) 
	{
		sarr.push(scr)
	}
	function get(id) {
		for(i=0;i<sarr.length;i++) 
		{
			if(sarr[i].id == id) 
			{
				return sarr[i]
			}
		}
	}
}

function nso () 
{
	var me = this
	this.id = ''
	this.dir = 0
	this.pos = 0

	this.offset = 0
	this.max = 8
	this.view = 1
	this.cpos = 0
	this.moving = false
	this.interval = ''
	// 
	//this.movearray = new Array ( 1, 2, 3, 5, 8, 12, 17, 10, 31, 23, 17, 12, 8, 5, 3, 2, 1 );
	this.movearray = new Array ( 1, 2, 3, 5, 8, 15, 20, 26, 40, 26, 20, 15, 8, 5, 3, 2, 1 );
	//this.movearray = new Array ( 1, 1, 1, 1, 1, 1, 1, 1, 94, 94, 1, 1, 1, 1, 1, 1, 1 );

//this.movearray = new Array ( 1, 2, 3, 5, 8, 12, 15, 18, 21, 18, 15, 12, 8, 5, 3, 2, 1 );
//this.movearray = new Array ( 1, 2, 3, 5, 8, 12, 17, 23, 31, 23, 17, 12, 8, 5, 3, 2, 1 );

	this.getStatus = getStatus
	this.updateIcons = updateIcons
	function getStatus(side)
	{
		if(side==0)
		{
			if(me.cpos==0)
			return 0
			return 1
		}

		if(side==1)
		{
			if( (me.cpos+me.view) < me.max)
				return 1	
			return 0
		}

	}
	function updateIcons(hover,side)
	{
		if(hover)
		{
			if(side&1 && getStatus(0))
				document.getElementById('scrollleft_'+me.id).src = scrollLeft[2].src
			if(side&2 && getStatus(1))
				document.getElementById('scrollright_'+me.id).src = scrollRight[2].src
		} else {
			if(side&1)
				document.getElementById('scrollleft_'+me.id).src = scrollLeft[getStatus(0)].src
			if(side&2)
				document.getElementById('scrollright_'+me.id).src = scrollRight[getStatus(1)].src
		}
	}
}

function initScrollers()
{
	var scrollers = getElementsByClassName('scrollamatic', document.getElementById('scroll-wrap'), 'div')
	for(i=0;i<scrollers.length;i++)
	{
		var scr = scrollers[i]
		var scid = scr.id
		var sc = document.getElementById( 'scrollcontent_'  + scid )
		var sob = new nso();
		sob.id = scid
		if(sc.style.left != '')
		{
			sob.offset = parseInt(sc.style.left);
		}
		// count children
		sob.max = getElementsByClassName('scrollPromoBox',document.getElementById('scrollshell_'+scid),'div').length
		sob.updateIcons(false,3)
		ScrollReg.add(sob)
	}
}

function singleScroll(unit,scid)
{
	var sob = ScrollReg.get(scid)
	sob.dir = unit	
	if(  !sob.moving && ( (sob.dir>0 && (sob.cpos+sob.view)<sob.max )  ||  (sob.dir<0 && sob.cpos>0) ) )
	{
		sob.moving = true
		sob.cpos += sob.dir
		if(sob.dir > 0)
		{
			sob.updateIcons(false,1)
		} 
		else {sob.updateIcons(false,2)}
		if(sob.getStatus(0) == 0)
			sob.updateIcons(false,1)
		if(sob.getStatus(1) == 0)
			sob.updateIcons(false,2)
		sob.interval = setInterval(function () { unitScroller(sob) },15)
	}
}
function unitScroller(sob)
{
	var sc = document.getElementById( 'scrollcontent_'  + sob.id )
	if(sob.pos == sob.movearray.length)
	{
		sob.pos = 0
		clearInterval(sob.interval)
		sob.moving = false
		return
	}
	sob.offset += ((-1 * sob.dir) * sob.movearray[sob.pos])
	sc.style.left = sob.offset + 'px'
	//alert(sob.offset);
	sob.pos++
}
/* =onload functions
-------------------= */
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);
		_timer = null;
	}
	if(typeof(Ninbar) != "undefined") 
	{
	    ninbar = new Ninbar();
		if(ninbar.headlineTicker != null) {
		    setTimeout("ninbar.headlineTicker.nextHeadline(1, 0)", 300 );
		}
	}
	if(typeof(initScrollers) != "undefined") {
	    initScrollers();
	}	
	if(typeof(cycloMaticInit) != "undefined") {
	    if (typeof TOTAL_IMAGES != "undefined") {
	        if(TOTAL_IMAGES > 0) {
	            cycloMaticInit();
	        }
	    }
	}	
	if(typeof(extInit) != "undefined") {
	    extInit();
	}
	if(typeof(addBookmarkLink) != "undefined") {
        addBookmarkLink();
    }	
};
	
/* for Mozilla */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, null);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)></script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			init(); // call the onload handler
		}
	};
/*@end @*/
	
/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = function() {
init();
/*@cc_on @*/
/*@if (@_win32)
    
	if(typeof(initScrollers) != "undefined") {
	    initScrollers();
	}
	
	if(typeof(addBookmarkLink) != "undefined") {
        addBookmarkLink();
    }
	

	/*@end @*/
}