var WW_StandardChanger={
current_pic:0,
container:'',
dummy:'',
pic_1:'',pic_2:'',
sources:'',
timeout:6000,speed:2000,
changer_1:'',changer_2:'',
navi_show:false,navi_prev:'vorheriges Bild',navi_next:'nächstes Bild',navi_pic:'',
init:function(sources,dummy){
this.sources=sources;
for(var x=1;x<sources.length;x++){this._preload(sources[x]);}
this.dummy=dummy;
},
show:function(pic){
clearTimeout(this.changer_1);
clearTimeout(this.changer_2);
this.current_pic=pic;
this.pic_1.attr('src',this.sources[this.current_pic]);
this.pic_2.css({display:'none'});
this._callExternal();
},
showPrev:function(){
this._prev();
this.show(this.current_pic);
},
showNext:function(){
this._next();
this.show(this.current_pic);
},
setSpeed:function(speed){
this.speed=speed;
},
setChangeTime:function(timeout){
this.timeout=timeout;
},
run:function(){
if(this.sources.length>1){
this.container=$('<div id="wwstandardchanger_wrapper"></div>');
if(this.navi_show==true){
var navi=$('<div id="wwstandardchanger_navi"></div>').css({position:'absolute',zIndex:999});
navi.append('<a href="javascript:WW_StandardChanger.showPrev();">'+this.navi_prev+'</a> ');
for(var i=0;i<this.sources.length;i++){
var navi_pic=this.navi_pic;
if (navi_pic==''){navi_pic='Bild '+(i+1);}
navi.append('<a id="wwstandardchanger_navi_pic'+i+'" href="javascript:WW_StandardChanger.show('+i+');">'+navi_pic+'</a> ');
}
navi.append('<a href="javascript:WW_StandardChanger.showNext();">'+this.navi_next+'</a>');
this.container.append(navi);
}
this.pic_1=$('<img src="'+this.sources[0]+'" />').css({position:'absolute',zIndex:5});
this.pic_2=$('<img src="'+this.sources[1]+'" />').css({position:'absolute',display:'inline'});
this.container.append(this.pic_1);
this.container.append(this.pic_2);
this._start();
}
},
_start:function(){
var x=this;
if(this._imgComplete(this.sources[1])){
$('#'+this.dummy).replaceWith(this.container);
setTimeout(function(){x._changeFirst();},x.timeout);}
else{setTimeout(function(){x._start();},x.timeout);}
},
_changeFirst:function(){
var x=this;
this._callExternal();
this.pic_1.fadeOut(this.speed,function(){
x.pic_1.css({display:'inline',zIndex:0});
x.pic_2.css({zIndex:5});
x._next();
x.pic_1.attr('src',x.sources[x.current_pic]);
x.changer_1=setTimeout(function(){x._changeSecond();},x.timeout);
});
},
_changeSecond:function(){
var x=this;
this._callExternal();
this.pic_2.fadeOut(this.speed,function(){
x.pic_2.css({display:'inline',zIndex:0});
x.pic_1.css({zIndex:5});
x._next();
x.pic_2.attr('src',x.sources[x.current_pic]);
x.changer_2=setTimeout(function(){x._changeFirst();},x.timeout);
});
},
_next:function(){
this.current_pic++;
if(this.current_pic==this.sources.length){this.current_pic=0;}
},
_prev:function(){
this.current_pic--;
if(this.current_pic<0){this.current_pic=this.sources.length-1;}
},
_callExternal:function(){
if(typeof this.picChanged=='function'){this.picChanged(this.current_pic);}
},
_preload:function(src){
var d=document;
if(d.images){
if(!d.p){d.p=new Array();}
var key=d.p.length;d.p[key]=new Image;d.p[key].src=src;
}
},	
_imgComplete:function(src){
var img=new Image();
img.src=src;
if(!img.complete){return false;}
if(typeof img.naturalWidth!='undefined'&&img.naturalWidth==0){return false;}
return true;}
};
