var cur_el = 'div1';
var next_in_line = 1;


window.addEvent('domready', function() {

	if (Browser.Engine.trident4)
	{
		img = document.getElementsByName('image_mask');
		for (var i = 0; i < img.length; i++)
		{
			img[i]['src'] = '_img/root/n/image_mask.gif';
		}
	}

	var myAccordion1 = new Accordion($('mainmenu'), 'h3.mainmenu_tr', 'div.mainmenu_e', {
		opacity: false,
		display: -1,
		onActive: function(toggler, element){
			img = toggler.getElements('img');
			img[0]['src'] = img[0]['src'].replace(".png", "_active.png");

		},
		onBackground: function(toggler, element){
			img = toggler.getElements('img');
			img[0]['src'] = img[0]['src'].replace("_active.png", ".png");
		}
	});
	
	var scr = new ScrollBar('newslist', 'track', 'thumb');
	
	var myAccordion2 = new Accordion($('newslist'), 'h3.newslist_tr', 'div.newslist_e',
	{
		opacity: false,
		onComplete: function(toggler, element)
		{
			scr.update();
		},
		onActive: function(toggler, element)
		{
			toggler.setStyle('color', '#FFFFFF');
			scr.update();
		},
		onBackground: function(toggler, element)
		{
			toggler.setStyle('color', '#7A7A7A');
			scr.update();
		}
	});

	faderInit(cur_el, 0);
});

function faderInit(el, mode)
{
	//2000 5000
	$(el).set('tween', {duration: 2000, onComplete:faderLoadNext.delay(6000)});
	$(el).tween('opacity', mode);
}



function faderLoadNext()
{
	next_in_line++;
	if (next_in_line > 7)
	{
		next_in_line = 1;
	}

	if (cur_el == 'div1')
	{
		cur_el = 'div2';
		$("image1").src = '_img/root/n/bg_' + next_in_line + '.jpg';
		faderInit('div1', 1);
	}
	else
	{
		cur_el = 'div1';
		$("image2").src = '_img/root/n/bg_' + next_in_line + '.jpg';
		faderInit('div1', 0);
	}
}

var ScrollBar = new Class(
{
	Implements: [Events, Options],

	options: {
		maxThumbSize: 10,
		wheel: 8
	},

	initialize: function(content, track, thumb, options){
		this.setOptions(options);

		this.content = $(content);
		this.track = $(track);
		this.thumb = $(thumb);

		this.bound = {
			'start': this.start.bind(this),
			'end': this.end.bind(this),
			'drag': this.drag.bind(this),
			'wheel': this.wheel.bind(this),
			'page': this.page.bind(this)
		};

		this.position = {};
		this.mouse = {};
		this.update();
		this.attach();
	},

	update: function(){

		
		this.contentSize = this.content.offsetHeight;
		this.contentScrollSize = this.content.scrollHeight;
		this.trackSize = this.track.offsetHeight;

		this.contentRatio = this.contentSize / this.contentScrollSize;

		this.thumbSize = (this.trackSize * this.contentRatio).limit(this.options.maxThumbSize, this.trackSize);

		this.scrollRatio = this.contentScrollSize / this.trackSize;

		this.thumb.setStyle('height', this.thumbSize-1);

		this.updateThumbFromContentScroll();
		this.updateContentFromThumbPosition();
		
	},

	updateContentFromThumbPosition: function(){
		this.content.scrollTop = this.position.now * this.scrollRatio;
	},

	updateThumbFromContentScroll: function(){
		this.position.now = (this.content.scrollTop / this.scrollRatio).limit(0, (this.trackSize - this.thumbSize));
		this.thumb.setStyle('top', this.position.now);
	},

	attach: function(){
		this.thumb.addEvent('mousedown', this.bound.start);
		if (this.options.wheel) this.content.addEvent('mousewheel', this.bound.wheel);
		this.track.addEvent('mouseup', this.bound.page);
	},

	wheel: function(event){
		this.content.scrollTop -= event.wheel * this.options.wheel;
		this.updateThumbFromContentScroll();
		event.stop();
	},

	page: function(event){
		if (event.page.y > this.thumb.getPosition().y) this.content.scrollTop += this.content.offsetHeight;
		else this.content.scrollTop -= this.content.offsetHeight;
		this.updateThumbFromContentScroll();
		event.stop();
	},

	start: function(event){
		this.mouse.start = event.page.y;
		this.position.start = this.thumb.getStyle('top').toInt();
		document.addEvent('mousemove', this.bound.drag);
		document.addEvent('mouseup', this.bound.end);
		this.thumb.addEvent('mouseup', this.bound.end);
		event.stop();
	},

	end: function(event){
		document.removeEvent('mousemove', this.bound.drag);
		document.removeEvent('mouseup', this.bound.end);
		this.thumb.removeEvent('mouseup', this.bound.end);
		event.stop();
	},

	drag: function(event){
		
		this.mouse.now = event.page.y;
		this.position.now = (this.position.start + (this.mouse.now - this.mouse.start)).limit(0, (this.trackSize - this.thumbSize));
		this.updateContentFromThumbPosition();
		this.updateThumbFromContentScroll();
		event.stop();
		
	}

});

function SkiTicker(language)
{
	tmp = window.open('ski-ticker/index.html', 'Live', 'width=700,height=500,resizable=no,toolbar=no,status=no,menubar=no,scrollbars=yes');
}