var Loaded = false;

var decelSpeed = .5;
var scrollDivId = "scrollDiv";
var scrollClipDivId = "scrollClipDiv";
var origSpeed = 10;
var debug = false;

var w3c = (document.getElementById) ? 1:0
var ns4 = (document.layers) ? 1:0
var ie4 = (document.all) ? 1:0
var ver4 = (parseInt(navigator.appVersion) >= 4) ? true: false;
var range = "";
var cap = "";
var mutex = 0;
var xPos = 0;
var yPos = 0;
var xmax = 0;
var ymax = 0;
var xmin = 0;
var ymin = 0;
var scrollDivHeight = 0;
var scrollDivWidth = 750;
var timeID = null;
var decel = 0;
var speed = origSpeed;
var imgIdx = 0;

var contentWidth = 33 * 200;
xmin = (contentWidth - scrollDivWidth) * -1;
xPos = (scrollDivWidth/2) - ((1 - 1) * 30) - 30;
if (xPos < xmin) xPos = xmin;
else if (xPos > xmax) xPos = xmax;
if (contentWidth < scrollDivWidth) xPos = 0;

function opn(cla)

{
catWindow = window.open(cla);
}

function on(name)   
{
	document.images[name].src = name + "_on.jpg";
}

function off(name)   
{
	document.images[name].src = name + "_off.jpg";
}


function client(cla)

{


catWindow = window.open('../'+cla+'/index.html','clients','menubar=no, status=yes, scrollbars=yes,resizable=yes, toolbar=no, location=no');


}

function isIPad() {
    return /iPad;.U/.test( navigator.userAgent );
}

function isIPhone() {
    return /iPhone;.U/.test( navigator.userAgent );
}

function getPic(idx)
{
var preLoad = new Image();
var preIdx = 0;					
						
safari=(navigator.userAgent.indexOf('Safari')!=-1);

if (safari)
   { document.mypic.src="../images/pixel_1.jpg";
     document.mypic.style.width = 'auto';
	 document.mypic.style.height = '580';}
   
document.mypic.src="pic_"+idx+".jpg";
document.mypic.style.height = '580';
imgIdx = idx;

preIdx = idx+1;
preLoad.src = "pic_"+preIdx+".jpg";

}

function getNextPic(maxImg)
{
var preLoad = new Image();
var preIdx = 0;	

safari=(navigator.userAgent.indexOf('Safari')!=-1);

if (safari)
   { document.mypic.src="../images/pixel_1.jpg";
     document.mypic.style.width = 'auto';
	 document.mypic.style.height = '580';}
   
imgIdx = (imgIdx+1)%maxImg;

document.mypic.src="pic_"+imgIdx+".jpg";
document.mypic.style.height = '580';

preIdx = (imgIdx+1)%maxImg;
preLoad.src = "pic_"+preIdx+".jpg";

}


function shiftTo(obj, x, y) {
	if (w3c) {
		obj.style.left = x + "px";
		obj.style.top = y + "px";
	}
	else if (ns4) {
	 obj.moveTo(x,y);
	} 
	else if (ie4) {
		obj.style.pixelLeft = x;
		obj.style.pixelTop = y;
	}
	//showStat();
}

function U_scroll() {
	if (Loaded && mutex == 1 && contentHeight > scrollDivHeight) {
		yPos += speed;
		if (yPos > ymax) {
			yPos = ymax;
			speed = origSpeed;
			decel = 0;
			clearTimeout(timeID);
		}
		shiftTo(theObj,xPos,yPos);
		if (debug) showStat();
		if (decel == 1) speed -= decelSpeed;
		if (speed <= 0) {
			speed = origSpeed;
			decel = 0;
			clearTimeout(timeID);
		} else {
			timeID = setTimeout("U_scroll()",25);
		}
	}
}

function D_scroll() {
	if (Loaded && mutex == 2 && contentHeight > scrollDivHeight) {
		yPos -= speed;
		if (yPos < ymin) {
			yPos = ymin;
			speed = origSpeed;
			decel = 0;
			clearTimeout(timeID);
		}
		shiftTo(theObj,xPos,yPos);
		if (debug) showStat();
		if (decel == 1) speed -= decelSpeed;
		if (speed <= 0) {
			speed = origSpeed;
			decel = 0;
			clearTimeout(timeID);
		} else {
			timeID = setTimeout("D_scroll()",25);
		}
	}
}

function L_scroll() {
	if (Loaded && mutex == 3 && contentWidth > scrollDivWidth) {
		xPos += speed;
		if (xPos > xmax) {
			xPos = xmax;
			speed = origSpeed;
			decel = 0;
			clearTimeout(timeID);
		}
		shiftTo(theObj,xPos,yPos);
		if (debug) showStat();
		if (decel == 1) speed -= decelSpeed;
		if (speed <= 0) {
			speed = origSpeed;
			decel = 0;
			clearTimeout(timeID);
		} else {
			timeID = setTimeout("L_scroll()",25);
		}
	}
}

function R_scroll() {
	if (Loaded && mutex == 4 && contentWidth > scrollDivWidth) {
		xPos -= speed;
		if (xPos < xmin) {
			xPos = xmin;
			speed = origSpeed;
			decel = 0;
			clearTimeout(timeID);
		}
		shiftTo(theObj,xPos,yPos);
		if (debug) showStat();
		if (decel == 1) speed -= decelSpeed;
		if (speed <= 0) {
			speed = origSpeed;
			decel = 0;
			clearTimeout(timeID);
		} else {
			timeID = setTimeout("R_scroll()",25);
		}
	}
}

function showStat() {
	window.status = "xmin:"+xmin+" xPos:"+xPos+" xmax:"+xmax+" speed:"+speed+" decel:"+decel;
}

function stopScroll() {
	decel = 1;
}

function redrawScreen() {
	window.location.reload();
}

function getObject(obj) {
	var theObj = eval("document." + range + obj + cap);
	return theObj;
} 

function scrollIt(msg, dir) {
	window.status = msg;
	speed=10;
	decel=0;
	clearTimeout(timeID);
	mutex = dir;
	if (mutex == 1) U_scroll();
	else if (mutex == 2) D_scroll();
	else if (mutex == 3) L_scroll();
	else if (mutex == 4) R_scroll();
}

function init( ki_max_pics) {
	if (ie4) {
		range = "all.";
  } else if (w3c) {
		range = "getElementById(\"";
		cap = "\")";
	} else if (ns4) {
		window.captureEvents(Event.RESIZE);
		window.onresize = redrawScreen;
		scrollDivId = scrollClipDivId + ".document." + scrollDivId;
	}
	theObj = getObject(scrollDivId);
	Loaded = true;

contentWidth = 33 * ki_max_pics;
xmin = (contentWidth - scrollDivWidth) * -1;
xPos = (scrollDivWidth/2) - ((1 - 1) * 30) - 30;
if (xPos < xmin) xPos = xmin;
else if (xPos > xmax) xPos = xmax;
if (contentWidth < scrollDivWidth) xPos = 0;
}
