function Fader(div,w,h,t){
		this.fadeimages = [];
        this.slideshow_width = w+'px'; 				//SET IMAGE WIDTH
		this.slideshow_height = h+'px'; 				//SET IMAGE HEIGHT
		this.pause = t;                          //SET PAUSE BETWEEN SLIDE (3000=3 seconds)
		this.count = 0;

        this.curpos = 0
		this.fader = 1
		this.degree = 0
		this.curcanvas = div+"canvas0"
		this.nextcanvas = div+"canvas1"
		this.curimageindex = 0
		this.nextimageindex = 1

		this.time;



		this.getImages = function(){
			var small = document.getElementById(div).getElementsByTagName("img");
			for (var i=0; i<small.length; i++){
		   		this.fadeimages[i]=[small[i].src, small[i].parentNode.href, small[i].parentNode.target, small[i].alt]
			}
			var show = document.getElementById(div).parentNode;

			this.canvas0 = document.createElement("div")
			this.canvas0.id = div+"canvas0";

			this.canvas1 = document.createElement("div")
			this.canvas1.id = div+"canvas1";

			this.canvas0.style.width = this.slideshow_width;
			this.canvas0.style.height = this.slideshow_height;
			this.canvas0.style.opacity = 1;
			this.canvas1.style.width = this.slideshow_width;
			this.canvas1.style.height = this.slideshow_height;
			this.canvas1.style.opacity = 1;

            show.appendChild(this.canvas0);
			show.appendChild(this.canvas1);
		}

		this.fadepic = function(xx){
			if (this.curpos<100){
          //      document.getElementById(this.curcanvas).style.visibility="visible";
				this.curpos+=this.fader;
		   		if (this.tempobj.filters) {
					this.tempobj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+this.curpos+")"
		   		} else if (this.tempobj.style.opacity) {
		   			this.tempobj.style.opacity=this.curpos/101;
				}
				if (this.curpos>=99){
       //           document.getElementById(this.curcanvas).style.visibility="hidden";
					document.getElementById(div+"canvas0").style.backgroundColor = "#000";
 					document.getElementById(div+"canvas1").style.backgroundColor = "#000";
				}
		   	} else {
				this.dropslide = clearInterval(this.dropslide);
				if(typeof(xx) == "undefined") {
				 	this.dropslide = eval(setTimeout(div+"fade.rotateimage()",this.pause));
//					document.getElementById(this.nextcanvas).style.visibility="hidden";
				}
			}
		}

		this.insertimage = function(i){
			if(document.getElementById("alt4gallery")!=null){
	    		document.getElementById("alt4gallery").innerHTML = this.fadeimages[i][3];
			}
			var tempcontainer;
				if(this.fadeimages[i][1]!="" && this.fadeimages[i][1].indexOf("#")<0)
				tempcontainer = '<a href="'+this.fadeimages[i][1]+'" target="'+this.fadeimages[i][2]+'">';
				else
				tempcontainer = '';


				tempcontainer+='<img src="'+this.fadeimages[i][0]+'" border="0" width="'+this.slideshow_width+'" height="'+this.slideshow_height+'"/>'
				tempcontainer=this.fadeimages[i][1]!=""? tempcontainer+'</a>' : tempcontainer
			   return tempcontainer
		}

		this.rotateimage = function(xx){
		  	this.count++;
            if(typeof(xx) != "undefined"){
              if(div!="gallery"){
              	document.getElementById(div+"canvas0").style.backgroundColor = "#fff";
				document.getElementById(div+"canvas1").style.backgroundColor = "#fff";
				}
              	this.time = clearInterval(this.time)
     			this.dropslide = clearInterval(this.dropslide);
				this.fader = 20;
				if(div == "gallery"){this.fader = 8;}
     		    temp = 'setInterval("'+div+'fade.fadepic()",5000)';
                this.time = eval(temp)
			} else {
 //              document.getElementById(div+"canvas0").style.backgroundColor = "#000";
//			   document.getElementById(div+"canvas1").style.backgroundColor = "#000";
               this.fader = 1;
			}

			this.resetit(this.curcanvas)
			var crossobj=this.tempobj=document.getElementById(this.curcanvas)
			crossobj.style.zIndex++
			crossobj.style.opacity = 0;
			if(div == "lg" && this.count == 2){
                 lgfade = 0;
			   //	 document.getElementById("lgcanvas0").innerHTML = "";
			   //	 document.getElementById("lgcanvas0").style.backgroundColor = "#fff";
				 return
			}

			if(typeof(xx) == "undefined"){
             	x = 1;
			} else {
				x = xx;
			}
            this.nextimageindex = this.curimageindex + x;
			this.nextimageindex=(this.nextimageindex<0) ? this.fadeimages.length - 1 : this.nextimageindex;
			this.nextimageindex=(this.nextimageindex>this.fadeimages.length - 1) ? 0 : this.nextimageindex;
            document.getElementById(this.curcanvas).innerHTML=this.insertimage(this.nextimageindex);

			this.tempobj.style.visibility="visible";
			var temp='setInterval("'+div+'fade.fadepic()",50)';
			if(typeof(xx) != "undefined"){
		   		temp = 'setInterval("'+div+'fade.fadepic('+xx+')",50)';
			}
			this.dropslide=eval(temp);
			this.curcanvas=(this.curcanvas==div+"canvas0")? div+"canvas1" : div+"canvas0";
			this.nextcanvas=(this.curcanvas==div+"canvas0")? div+"canvas1" : div+"canvas0";

            this.curimageindex = this.nextimageindex;
		}

		this.resetit = function(what){
			this.curpos=0;
			var crossobj = document.getElementById(what);
			if (crossobj.filters)
		   	//	crossobj.filters.alpha.opacity=this.curpos;
				crossobj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+this.curpos+")"
			else if (crossobj.style.MozOpacity)
		   		crossobj.style.MozOpacity=this.curpos/101;
		}

		this.startit = function(){
            this.getImages();
			document.getElementById(this.curcanvas).innerHTML=this.insertimage(this.curimageindex);
			document.getElementById(this.nextcanvas).innerHTML=this.insertimage(this.curimageindex);
            if(div!="lg")
			this.curimageindex = -1;
			if(div=="gallery" || div =="main1" || div =="main2"){
			this.curimageindex = 0;
			}
			if(div!="gallery") {
				this.rotateimage()
			}
			else{
			  	if (document.getElementById("gallerycanvas0").filters)
                document.getElementById("gallerycanvas0").style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100)"
			}
		}
		if(div!="small2")
		this.startit();
		else
		document.getElementById("small2").style.display = "block"
}
