var hexBoxTopn = "#868D97";
var hexBoxLeftn = "#868D97";
var hexBoxRightn = "#868D97";
var hexBoxBottomn = "#868D97";
var hexBoxCentern = "#FFFFFF";

var hexBoxTops = "#B1B1B1";
var hexBoxLefts = "#B1B1B1";
var hexBoxRights = "#000000";
var hexBoxBottoms = "#000000";
var hexBoxCenters = "#E11E1E";

var sImages = "";	
for(var i = 0; i < oImageList.length; i++){
		sImages += "'"+oImageList[i]+".jpg',";
	}

preloadImages(sImages);

var detect = navigator.userAgent.toLowerCase();

var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

var oSelected = new Array(oImageList.length)

for(var i = 0; i < oSelected.length; i++){
	if(i == 0)
		oSelected[i]="selected";
	else
		oSelected[i]="";
}

function preloadImages() { 
 var d=document; if(d.images){ if(!d.p) d.p=new Array();
   var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function fadingObject(id){
	this.id = id;

	this.getOpacity = function(){
		if (document.all){
            return document.all[this.id].filters['alpha'].opacity;
        }
		else if (document.getElementById){
            return document.getElementById(this.id).style.MozOpacity*100;
         }
	}
		
	this.setOpacity = function(percent){
    	if (document.all){
            document.all[this.id].filters['alpha'].opacity = percent;
          }
          else if (document.getElementById){
            document.getElementById(this.id).style.MozOpacity = percent/100;
          }
	}

	this.fadeTo = function(newOpacity, deltaPercent, i){
		window.clearTimeout(this.timeout);
        currentOpacity = this.getOpacity();
        if (newOpacity > currentOpacity){
            if (currentOpacity < newOpacity - deltaPercent){
              this.setOpacity(currentOpacity + deltaPercent);
              this.timeout = window.setTimeout('obj_'+this.id+'.fadeTo('+newOpacity+', '+deltaPercent+','+i+')', 50);
        	}else{
              this.setOpacity(newOpacity);
        	}
        }else if (newOpacity < currentOpacity) {
            if (currentOpacity > newOpacity + deltaPercent){
              this.setOpacity(currentOpacity - deltaPercent);
              this.timeout = window.setTimeout('obj_'+this.id+'.fadeTo('+newOpacity+', '+deltaPercent+','+i+')', 50);
			}else{
				this.setOpacity(newOpacity);
			  	if(i != "undefined"){
			  		swapImage('oImage','',oImageList[i]+'.jpg',1);
			  	}
					obj_oImage.fadeTo(99,5,"undefined");
            	}
          	}
        }
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() {
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function Next(){
	var ival = oSelected.shift();
	oSelected.push(ival);

	for(var i = 0; i < oSelected.length; i++){
		if(oSelected[i] == "selected"){
			HighlightImage(i);
		}
	} 
	var ivalue = oImageList.shift();
	oImageList.push(ivalue);
	ChangeImage();
}

function Previous(){
	var ival = oSelected.pop();
	oSelected.unshift(ival);

	for(var i = 0; i < oSelected.length; i++){
		if(oSelected[i] == "selected"){
			HighlightImage(i);
		}
	} 

	var ivalue = oImageList.pop();
	oImageList.unshift(ivalue);
	ChangeImage(); 
}

function ChangeImage(){
	var x = 1;
	for(var i = 0; i < 5; i++){
		swapImage('oThumb'+x,'',oImageList[i]+'-tmb.jpg',1);
		x++;
	}
}


function ChangeColor(object,hex) {
	if(document.all)
		document.all[object].style.background = hex;
	if(document.layers)
		document[object].background = hex;
	if(!document.all && document.getElementById)
		document.getElementById(object).style.background = hex;
}

function HighlightImage(iSelected){
	
	for(var i = 0; i < oSelected.length; i++){
		oSelected[i]="";
	}
	
	oSelected[iSelected]="selected";
	
	for(var i = 0; i < 5; i++){
		
		ChangeColor('oBox-top-'+i,hexBoxTopn);
		ChangeColor('oBox-left-'+i,hexBoxLeftn);
		ChangeColor('oBox-right-'+i,hexBoxRightn);
		ChangeColor('oBox-bottom-'+i,hexBoxBottomn);
		ChangeColor('oBox-center-'+i,hexBoxCentern);
	}
	
	if(iSelected <= 4){
		ChangeColor('oBox-top-'+iSelected,hexBoxTops);
		ChangeColor('oBox-left-'+iSelected,hexBoxLefts);
		ChangeColor('oBox-right-'+iSelected,hexBoxRights);
		ChangeColor('oBox-bottom-'+iSelected,hexBoxBottoms);
		ChangeColor('oBox-center-'+iSelected,hexBoxCenters);
	}
}

var iImage = oImageList[0];

function ShowImage(i){
	HighlightImage(i);
	if(iImage != oImageList[i]){
			iImage = oImageList[i];
		if(browser == "Safari" || (OS == "Mac" && browser == "Internet Explorer"))
			swapImage('oImage','',oImageList[i]+'.jpg',1);
		else
			obj_oImage.fadeTo(0,15,i);
	}
}

obj_oImage = new fadingObject("oImage");

function Initiate(){
	ChangeImage();
	swapImage('oImage','',oImageList[0]+'.jpg',1);
	HighlightImage(0);
}