(function(a){
  a.fn.innerfade=function(b){  
    return this.each(function(){ a.innerfade(this,b)})};    
  
  a.innerfade=function(b,c){
    var e={animationtype:"fade",speed:"normal",type:"sequence",timeout:2000,containerheight:"auto",runningclass:"innerfade",children:null};      
    if(c){a.extend(e,c)}
    if(e.children===null){  var g=a(b).children()   }      
    else{ var g=a(b).children(e.children) }      
    
    if(g.length>1){        
      a(b).css("position","relative").css("height",e.containerheight).addClass(e.runningclass);         
      for(var d=0;d<g.length;d++){a(g[d]).css("z-index",String(g.length-d)).css("position","absolute").hide()}         
      if(e.type=="sequence"){
        setTimeout(function(){
          a.innerfade.next(g,e,1,0)
        },e.timeout);
        a(g[0]).show()
      }         
      else{if(e.type=="random"){
        var f=Math.floor(Math.random()*(g.length));         
        setTimeout(function(){do{h=Math.floor(Math.random()*(g.length))}        
        while(f==h);a.innerfade.next(g,e,h,f)},e.timeout);
        a(g[f]).show()
      }         
     else{if(e.type=="random_start"){e.type="sequence";
     var h=Math.floor(Math.random()*(g.length));setTimeout(
     function(){a.innerfade.next(g,e,(h+1)%g.length,h)},e.timeout);a(g[h]).show()}
     else{alert("Innerfade-Type must either be 'sequence', 'random' or 'random_start'")}}}}
    };
 
    a.innerfade.next=function(d,b,e,c){
    	if($('#weather').length == 0){
    		clearTimeout(this);
    		return;
    	}	
    	if(b.animationtype=="slide"){
		  a(d[c]).slideUp(b.speed);
		  a(d[e]).slideDown(b.speed)
    	}else{
		   if(b.animationtype=="fade"){
		   a(d[c]).fadeOut(b.speed);
		   a(d[e]).fadeIn(b.speed,function(){removeFilter(a(this)[0])})
		  }else{
			   alert("Innerfade-animationtype must either be 'slide' or 'fade'")
		  }
    	}
    	if(b.type=="sequence"){
		   if((e+1)<d.length){e=e+1;c=e-1}
		   else{e=0;c=d.length-1}
    	} else{
		   if(b.type=="random"){c=e;while(e==c){e=Math.floor(Math.random()*d.length)}}
		   else{alert("Innerfade-Type must either be 'sequence', 'random' or 'random_start'")}
    	}
    	
    	setTimeout((function(){a.innerfade.next(d,b,e,c)}),b.timeout);
    }
})(jQuery);

function removeFilter(a){
	if(a.style.removeAttribute){a.style.removeAttribute("filter")}
};