var slideMenu=function(){
	var pad=5;
	var sp,st,t,m,sa,l,w,sw,ot;
	return{
		build:function(sm,sw,mt,s,sl,h){
			sp=s; st=sw; t=mt;
			m=document.getElementById(sm);
			sa=m.getElementsByTagName('li');
			l=sa.length; w=m.offsetWidth; sw=w/l;
			ot=Math.floor((w-st)/(l-1)); var i=0;
			for(i;i<l;i++){s=sa[i]; s.style.width=(sw-pad)+'px'; this.timer(s)}
			if(sl!=null){m.timer=setInterval(function(){slideMenu.slide(sa[sl-1])},t)}
		},
		timer:function(s){s.onmouseover=function(){clearInterval(m.timer);m.timer=setInterval(function(){slideMenu.slide(s)},t)}},
		slide:function(s){
			var cw=parseInt(s.style.width,'10')+pad;
			if(cw<st){
				var owt=0; var i=0;
				for(i;i<l;i++){
					if(sa[i]!=s){
						var o,ow; var oi=0; o=sa[i]; ow=parseInt(o.style.width,'10')+pad;
						if(ow>ot){oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi-pad)+'px';}
						owt=owt+(ow-oi)}}
				s.style.width=(w-owt-pad)+'px';
			}else{clearInterval(m.timer)}
		}
	};
}();

var slideShow=function(){
	var speed = 2000;
	var preLoad = new Array();
	var t;
	var j = 2;
	var curPic=1;
	var p;
	var ie;
	return{
		preLoad:function(pic){
			p = pic.length;
				if (p==2)
				{
					var path=pic[0];
					var count=pic[1];
					
					pic=[];
					for (i = 1; i <= count; i++){
						pic[i-1]=path+i+".jpg";
					}
					
					p = count;
				}
				else
					if (p%2==0) alert('no!');
				
			for (i = 0; i < p; i++){
			   	preLoad[i] = new Image();
			   	preLoad[i].src = pic[i];
			}
			
			if (window.XMLHttpRequest) {
			if(document.all){
				ie=true;
			//IE7
			}else{
				ie=false;
			}
			} else {
				ie=true;
			} 

		},
		run:function(){
			if (ie) document.getElementById("pic"+curPic).filters[0].apply();
			document.getElementById("pic"+curPic).style.backgroundImage = "url("+preLoad[j].src+")";
			if (ie) document.getElementById("pic"+curPic).filters[0].play();
			j = j + 1;
			if (j > (p-1)) j=0;
			curPic=(curPic==1?2:1);
			t = setTimeout(function(){slideShow.run()}, speed);
		}
	};
}();
