﻿totalItemsInBar1 = 8;  // records-1
totalItemsInBar2 = 2;  //records-1





function xMove1(d) { //d - direction    +1 right  -1 left
	 var curr = document.getElementById('bar1');
	 
	 var x;
	 if (curr) {
		 x=parseInt(curr.value);
		 x=parseInt(x)+parseInt(d);
		 curr.value = x;
		 if (x<0) {
			 x=0;
		 }
		 if (x>totalItemsInBar1) {
			 x=totalItemsInBar1;
		 }
		 curr.value=x;
		 UpdateDiv('preview_dest','/getImage.asp?xi='+x);
	 }
}

function xMove2(d) { //d - direction    +1 right  -1 left
	 var curr = document.getElementById('bar2');
	 
	 var x;
	 if (curr) {
		 x=parseInt(curr.value);
		 x=parseInt(x)+parseInt(d);
		 curr.value = x;
		 if (x<0) {
			 x=0;
		 }
		 if (x>totalItemsInBar2) {
			 x=totalItemsInBar2;
		 }
		 curr.value=x;
		 UpdateDiv('preview_dest2','/getImage2.asp?xi='+x);
	 }
}


var stopped=false,reachedLeft,reachedRight;
var slowSpeed=1,width;
var timer="",Stimer="";

function loadGroup(gr) {
     if (parseInt(gr)!=1) enabledAutoScroll=false;
	 if (document.getElementById('content')) document.getElementById('content').style.left=0+'px';
	 if (document.getElementById('content')) document.getElementById('content').style.pixelLeft=0;
	 UpdateDiv('preview_dest','/getImage0.asp?gr='+gr+'&xi=0')  ;
	 UpdateDiv('content','/getImage0.asp?gr='+gr);
}

function  init(){   
		 width = document.getElementById('content').offsetWidth;
		 enabledAutoScroll=false;
		 	 //alert(width);
	     window.clearTimeout(Stimer);
		 stopped=false;
		 slowSpeed=1;
		 window.clearTimeout(timer);
		 document.getElementById('barLeft').className='yes_';
		 document.getElementById('barRight').className='yes_';
}

function stop(){
	 stopped=true;
}

function move(direction) {  // xy  where    x: -+     y: integer      
       	var div;		 
		 
		div = document.getElementById('content');
		 
		if (isIE()) div.style.pixelLeft+=direction;
		if (!isIE()) div.style.left = parseInt(div.offsetLeft)+direction +'px';
		 
		if (stopped) {  //slow speed down
		slowSpeed+=2;
		}
		
		timer=window.setTimeout("move("+direction+")",slowSpeed);
		
		if (isIE()) {  //locate corners on move
		     if (direction>0 && (div.style.pixelLeft>=0 && div.style.pixelLeft<=2)) {
				 stop();
				 document.getElementById('barLeft').className='no_';
				 window.clearTimeout(timer);
				 div.style.pixelLeft=0;
				 reachedLeft=true;
		     }
		     diff=width+div.style.pixelLeft-434;
		     if (direction<0 && (diff<=-8)) {
				 stop();
				 document.getElementById('barRight').className='no_';
				 window.clearTimeout(timer);
				 div.style.pixelLeft=426-width;
				 reachedRight=true;
				 
		     }
		 } else {  
		     if (direction>0 && (div.offsetLeft>=0 && div.offsetLeft<=5)) {
				 stop();
				 document.getElementById('barLeft').className='no_';
				 window.clearTimeout(timer);
				 div.style.left=0+'px';
				 
		     }
		     diff=this.width+div.offsetLeft;
		 }
		if (slowSpeed>25) window.clearTimeout(timer);
	 }

var enabledAutoScroll=true,scrollDelay=60;	 
	 
function scroll(xdirection) {
		 if (enabledAutoScroll&&isIE()){
			 width = document.getElementById('content').offsetWidth;
			 var div1,diff;
			 div1 = document.getElementById('content');
			 div1.style.pixelLeft+=xdirection;		
			 window.clearTimeout(Stimer);
			 Stimer=window.setTimeout("scroll("+xdirection+")",scrollDelay);
		
		     if (xdirection>0 && (div1.style.pixelLeft>=0 && div1.style.pixelLeft<=2)) {
				 window.clearTimeout(Stimer);
				 div1.style.pixelLeft=0;
				 Stimer=window.setTimeout("scroll(-1)",scrollDelay);
		     }
		     
			 diff=width+div1.style.pixelLeft-434;
			 if (xdirection<0 && (diff<=-8)) {
			     window.clearTimeout(Stimer);
				 Stimer=window.setTimeout("scroll(1)",scrollDelay);
				 div1.style.pixelLeft=426-width;
		     }
		 }
	 }	 
	 
	 
function isIE() { 
	 if (navigator.appName=="Microsoft Internet Explorer") {
		 return true ;
	 } else {
		 return false;
	 }
} 

function cpause(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 