
window.addEventListener?window.addEventListener("load",initialise,false):window.attachEvent("onload",initialise);



var pics=new Array();
var currentPic=0;
var lastPic=0;
var rate=5000;

// check for Firefox
function initialise() {
	if(!document.getElementById || !document.createElement){
		return;
	}	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("firefox") != -1){
		 firefoxRun();
	 }else{
		 initialiseGeneral();
	 }
}

//All browsers other than Firefox
function initialiseGeneral() {
	currentPic=1;
	pics = document.getElementById("picArea").getElementsByTagName("img");
	for(i=0;i<pics.length;i++){
		pics[i].Opacity = 0;
	}
	
	changePic();
}

function changePic() {
	fade22(pics[currentPic]);
	currentPic = pics[currentPic+1]?currentPic+1:0;

		setTimeout(changePic,rate);
	}
	

function fade22(picRef){
       $(picRef)
        .css({'height':0, 'left':100})
        .fadeTo('slow',1.0)
        .animate({
            'left':'260',
            'height':'250'
            },{
            duration:1000,queue:false
            });
       $(lastPic)
        .fadeTo('slow',0)
        .animate({
            'left':'600',
            'height':'0'
            },{
            duration:2000,queue:false
            });
       lastPic=picRef;
}


//Firefox browser
function firefoxRun() {
    rate=2000;
	pics = document.getElementById("picArea").getElementsByTagName("img");
	for(i=0;i<pics.length;i++){
		pics[i].height = 250;
		pics[i].style.left="260px";
	}
	for(i=1;i<pics.length;i++){
		pics[i].Opacity = 0;
	}
	pics[0].style.display = "block";
	pics[0].Opacity = .99;
	
	
	setTimeout(changePicFirefox,rate);
}

function changePicFirefox() {
	currentOp = pics[currentPic].Opacity;
	nextIndex = pics[currentPic+1]?currentPic+1:0;
	nextOp = pics[nextIndex].Opacity;
	
	currentOp-=.03; 
	nextOp+=.03;
	
	pics[nextIndex].style.display = "block";
	pics[currentPic].Opacity = currentOp;
	pics[nextIndex].Opacity = nextOp;
	
	setOp(pics[currentPic]); 
	setOp(pics[nextIndex]);
	
	if(currentOp<=0) {
		pics[currentPic].style.display = "none";
		currentPic = nextIndex;
		setTimeout(changePicFirefox,rate);
	} else {
		setTimeout(changePicFirefox,50);
	}
}
	
function setOp(pic) {
		if(pic.Opacity>.99) {
			pic.Opacity = .99;
			return;
		}
		pic.style.opacity = pic.Opacity;
		pic.style.MozOpacity = pic.Opacity;
		pic.style.filter = "alpha(opacity=" + (pic.Opacity*100) + ")";
}
	

