// JavaScript Document

var scroll_image = new Array();
var scroll_link = new Array();
var scroll_text = new Array();

var scroll_current = 0;
var scroll_max = 0;

var scroll_height = 300;

var scroll_conteneur;
var scroll_title;
var scroll_img;
var scroll_list;

var scroll_timer = 0;
var scroll_auto = 0;
var scroll_step = 20;

function scroller2_init(chaine){
	
	tl = new Array();
	tl = chaine.split(',');
	
	rcount = 0;
	
	scroll_conteneur = document.getElementById('scroller2_cont');
	scroll_title = document.getElementById('scroller2_title');
	scroll_img = document.getElementById('scroller2_img');
	scroll_list = document.getElementById('scroller2_list');
	
	for(i=0;i<tl.length;i++){
		if(tl[i].length > 0){
			tz = new Array();
			tz = tl[i].split('|');
			
			scroll_image[i] = tz[0];
			scroll_text[i] = tz[2];
			scroll_link[i] = tz[1];
			
			scroll_img.innerHTML += '<div onclick="javascript:location=\''+tz[1]+'\';" id="scroller2_i'+rcount+'" style="background-image:url('+tz[0]+'); height:300px; width:100%; cursor:pointer"></div>';
			
			rcount++;
		}
	}
	
	scroll_img.scrollTop = 0;
	scroll_current = 0;
	scroll_max = rcount-1;

	scroller2_update();
	scroll_auto = setInterval('auto_scroll()',4000);
	
}
function isIE(){
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		 
		 if (ieversion>=8){
			return 8;
		 }
		 else if (ieversion>=7){
		  return 7;
		 }
		 else if (ieversion>=6){
		  return 6;
		}
		else{
			return ieversion;	
		}
	}
	
	return false;

}
function scroller2_jump(idd){
	
	if(scroll_auto != 0){
		clearInterval(scroll_auto);	
	}
	
	document.getElementById('scroller2_item_'+scroll_current).className = 'scroller2_item';
	
	var jumpto = document.getElementById('scroller2_i'+idd).offsetTop;
	
	scroll_step = 20;
	
	if(scroll_timer != 0){
		clearInterval(scroll_timer);	
	}
	
	if(idd > scroll_current){
		scroll_timer = setInterval('scroller2_timer(\''+jumpto+'\',\'1\',\''+idd+'\')',20);
	}
	else{
		scroll_timer = setInterval('scroller2_timer(\''+jumpto+'\',\'0\',\''+idd+'\')',20);
	}
	
}
function scroller2_open(){
	location = scroll_link[scroll_current];	
}
function scroller2_update(){
	
	document.getElementById('scroller2_item_'+scroll_current).className = 'scroller2_item_s';
	scroll_title.innerHTML = '<a href="'+scroll_link[scroll_current]+'">'+scroll_text[scroll_current]+'</a>';
}
function scroller2_timer(rd,sens,jp){
	
	var current_pos = scroll_img.scrollTop;
	rd = parseInt(rd);

	if(sens == '1'){
		
		var dif = scroll_step*(parseInt(rd)-scroll_img.scrollTop)/3000;

		scroll_img.scrollTop += 1+scroll_step*dif;
		
		if(parseInt(rd)-scroll_img.scrollTop <= 0){
			
			clearInterval(scroll_timer);
			
			
			scroll_timer = 0;
			scroll_current = jp;
			scroll_img.scrollTop = rd;
			
			scroller2_update();
		}
		
	}
	else{
		
		var dif = scroll_step*(scroll_img.scrollTop-parseInt(rd))/3000;
		
		scroll_img.scrollTop -= 1+scroll_step*dif;
		
		if(scroll_img.scrollTop-parseInt(rd) <= 0){

			clearInterval(scroll_timer);	
			
			scroll_timer = 0;
			scroll_current = jp;
			scroll_img.scrollTop = rd;
			
			scroller2_update();
			
		}
	}
	
}
function auto_scroll(){
	
	document.getElementById('scroller2_item_'+scroll_current).className = 'scroller2_item';
	
	if(scroll_current < scroll_max){
		var goto = parseInt(scroll_current)+1;
		
	}
	else{
		var goto = 0;
	}
	
	var jumpto = document.getElementById('scroller2_i'+goto).offsetTop;
	
	
	scroll_step = 20;
	
	if(scroll_timer != 0){
		clearInterval(scroll_timer);	
	}
	
	if(goto > scroll_current){
		scroll_timer = setInterval('scroller2_timer(\''+jumpto+'\',\'1\',\''+goto+'\')',20);
	}
	else{
		scroll_timer = setInterval('scroller2_timer(\''+jumpto+'\',\'0\',\''+goto+'\')',20);
	}
	
}
