var gallery1Count=0;
var gallery1Layers=0;
gallery1 = {
	render:function(fs) {

     //this.files =gallery1_elems;
		this.files = fs.split("|||");
		

		if (!this.timer) this.timer = 6000;
		if (!this.destDiv) this.destDiv = "gallerydiv";

        $(this.destDiv).innerHTML="<div id='gallery1_frame' style='position:absolute; left:0px; '><div id='gallery1_div1' style='position:absolute; top:0; left:0; '></div><div id='gallery1_div2' style='position:absolute; top:0; left:0;'></div></div>";

        //flag for swapping on off
        if (this.files.length <= 1) {
            this.justone = 1;
        } else {
            this.justone = 0;
        }
        

		//preload
    for (f=0; f<this.files.length; f++) {
			a = new Image();
			a.src=this.files[f];
		}
		if ($(this.destDiv)) {
			gallery1.display();
			gallery1.arrange();
		}

	},
	arrange:function() {
		this.setInt = setInterval("gallery1.nextFile()",gallery1.timer);
		if ($("gallery1_buttonicon")) {
            $("gallery1_buttonicon").src='../_img/gallery/next.gif';
        }
	},
	nextFile:function() {
        if (this.justone == 0) {
            gallery1Count++;
            if (gallery1Count>=this.files.length) {
                gallery1Count=0;
            }
            gallery1.display();
        }
	},
	display:function() {
		var addBtn = "";
		var addcss = "";
		dest_div = (gallery1Layers==0) ? "gallery1_div1" : "gallery1_div2";
		new Effect.Fade(dest_div,{duration:.5, from:1.0, to:0.0});
		gallery1Layers=1-gallery1Layers;
		dest_div = (gallery1Layers==0) ? "gallery1_div1" : "gallery1_div2";
		new Effect.Appear(dest_div,{duration:.5, from:0.0, to:1.0 });
		addcss = "<style>#gallery1_btnpos_a{ display:block; filter:Alpha(opacity=25); opacity:.25;  } #gallery1_btnpos_a:hover  { filter:Alpha(opacity=100);  opacity:1; }</style>";
		
        if (this.justone == 0) {
            addBtn = "<div id='gallery1_btnpos' style='position:absolute; right:32px; bottom:32px; z-index:1000' onmouseover='gallery1.stop()' onmouseout='gallery1.arrange()'><a  id='gallery1_btnpos_a'  href='javascript:gallery1.next()' ><div><img id='gallery1_buttonicon' src='../_img/gallery/next.gif' border=0></div></a></div>";
        }
        
		$(dest_div).innerHTML=addcss+"<div style=''><img src='"+gallery1.files[gallery1Count]+"'>"+addBtn+"</div>";
	},
	next:function() {
        clearInterval(gallery1.setInt);
        gallery1.nextFile();
		//gallery1.arrange();
        
	},
	stop:function() {
		clearInterval(this.setInt);
		
		
	}
}


