var BoxScroller =
{
	box_cont         : null,
	box_scroll_left  : null,
	box_scroll_right : null,
	box_scrollable   : null,
	
	box_cont_width       : 0,
	box_scrollable_width : 0,
	
	box_cont_item_width       : 215,
	box_scrollable_item_width : 32,
	
	box_cont_items       : [],
	box_scrollable_items : [],
	
	scroll_start : false,
	scroll_timer : 400,
	
	_back : null,
	
	_Init : function()
	{
		BoxScroller.box_cont         = document.getElementById('box_cont');
		BoxScroller.box_scroll_left  = document.getElementById('box_scroll_left');
		BoxScroller.box_scroll_right = document.getElementById('box_scroll_right');
		BoxScroller.box_scrollable   = document.getElementById('box_scrollable');
		
		BoxScroller.box_cont_width       = BoxScroller.box_cont.offsetWidth;
		BoxScroller.box_scrollable_width = BoxScroller.box_scrollable.offsetWidth;
		
		BoxScroller._back = document.getElementById('ctl00_ctl00_MainPlaceHolder_GeneralContentDiv'); // TODO: get the Id programmaticaly
		
		var ___y = 0;
		for(x = 0; x < BoxScroller.box_cont.childNodes.length; x++)
		{
			if(BoxScroller.box_cont.childNodes[x].nodeName == '#text')
			{
				continue;
			}
			BoxScroller.box_cont_items[___y] = BoxScroller.box_cont.childNodes[x];
			___y++;
		}
		
		___y = 0;
		for(x = 0; x < BoxScroller.box_scrollable.childNodes.length; x++)
		{
			if(BoxScroller.box_scrollable.childNodes[x].nodeName == '#text')
			{
				continue;
			}
			BoxScroller.box_scrollable_items[___y] = BoxScroller.box_scrollable.childNodes[x];
			
			BoxScroller.box_scrollable_items[___y].onclick = BoxScroller._ShowText;
			BoxScroller.box_scrollable_items[___y].setAttribute('id', ___y);
			___y++;
		}
		
		
		BoxScroller.box_scroll_left.onmousedown  = BoxScroller._ScrollLeft_Start;
		BoxScroller.box_scroll_left.onmouseup    = BoxScroller._ScrollLeft_Stop;
		
		BoxScroller.box_scroll_left.onclick      = BoxScroller._ScrollLeft_Once;
		
		BoxScroller.box_scroll_right.onmousedown = BoxScroller._ScrollRight_Start;
		BoxScroller.box_scroll_right.onmouseup   = BoxScroller._ScrollRight_Stop;
		
		BoxScroller.box_scroll_right.onclick     = BoxScroller._ScrollRight_Once;
	},
	
	_ShowText : function()
	{
		BoxScroller.box_cont.style.left = -(this.id * BoxScroller.box_cont_item_width)+'px';
		BoxScroller._back.style.background = 'url(../images/' + this.getAttribute('rel') + ')';
		BoxScroller._back.style.backgroundRepeat = 'no-repeat';
        
        for(x = 0; x < BoxScroller.box_scrollable_items.length; x++)
		{
			BoxScroller.box_scrollable_items[x].style.background = 'url(../images/pr_top_text_bg.gif) left top no-repeat';
		}
		this.style.background = 'url(../images/pr_top_text_bg_a.gif) left top no-repeat';		
	},
	
	_ScrollRight_Once : function(e)
	{	
		if(BoxScroller.box_scrollable_items.length == 3)
		{
			return;
		}
		var left_current = parseInt(BoxScroller.box_scrollable.style.left);
		if(left_current <= -((BoxScroller.box_scrollable_items.length*32)-96))
		{
			return;
		}
		var left = left_current - BoxScroller.box_scrollable_item_width;
		BoxScroller.box_scrollable.style.left = left+'px';
		
		if(BoxScroller.scroll_start == true)
		{
			BoxScroller._ScrollRight_Start();
		}
	},
	
	_ScrollLeft_Once : function()
	{
		var left = parseInt(BoxScroller.box_scrollable.style.left) + BoxScroller.box_scrollable_item_width;
		if(parseInt(BoxScroller.box_scrollable.style.left) == 0)
		{
			left = 0;
		}
		BoxScroller.box_scrollable.style.left = left+'px';
		if(BoxScroller.scroll_start == true)
		{
			BoxScroller._ScrollLeft_Start();
		}
	},
	
	_ScrollLeft_Start : function()
	{
		BoxScroller.scroll_start = true;
		setTimeout('BoxScroller._ScrollLeft_Once()', BoxScroller.scroll_timer);
	},
	_ScrollLeft_Stop : function()
	{
		BoxScroller.scroll_start = false;
	},
	
	_ScrollRight_Start : function()
	{
		BoxScroller.scroll_start = true;
		setTimeout('BoxScroller._ScrollRight_Once()', BoxScroller.scroll_timer);
	},
	_ScrollRight_Stop : function()
	{
		BoxScroller.scroll_start = false;
	},
	
	_FixEvent : function(e)
	{
		if (typeof e == 'undefined')
		{
			return window.event;
		}
		else
		{
			return e;
		}
	},
	
	_Debug : function(param)
	{
		alert('DEBUG:'+'\n' + param);
	}

// If you remove next line the sky will fall on you head =)
};


