function slideSwitch() {
    var $active = $('#slideimg li.active');

    if ( $active.length == 0 ) $active = $('#slideimg li:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideimg li:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

var ImageRotation = {
	init:function(){
		this.images=$('#slideimg li');
		if( this.images.length > 0 ){
			this.prev=-1;
			this.cur=-1;
			this.playing=true;
			this.play();
		}
	},
	play:function(){
		var _this=this;
		if(!this.playing) return false;
		this.step(1);
		this.tm=setTimeout(function(){_this.play()},5000);
	},
	step:function(num){
		this.prev=this.cur;
		this.cur+=num;
		if(this.cur>=this.images.length) this.cur=0;
		if(this.cur<0) this.cur=this.images.length-1;
		if(this.prev>0) $(this.images[this.prev]).fadeOut('slow');
		$(this.images[this.cur]).fadeIn('slow');
		return false;
	},
	pause:function(obj){
		obj.blur();
		if(this.playing){
			obj.parentNode.className="stopped";
			this.playing=false;
			clearTimeout(this.tm);
		}
		else{
			obj.parentNode.className="playing";
			this.playing=true;
			this.play();
		}
		return false;
	}
}

var ImageRotation2 = {
	init:function(){
		this.images=$('#slidenews li');
		if( this.images.length > 0 ){
			this.prev=-1;
			this.cur=-1;
			this.playing=true;
			this.play();
		}
	},
	play:function(){
		var _this=this;
		if(!this.playing) return false;
		this.step(1);
		this.tm=setTimeout(function(){_this.play()},5000);
	},
	step:function(num){
		this.prev=this.cur;
		this.cur+=num;
		if(this.cur>=this.images.length) this.cur=0;
		if(this.cur<0) this.cur=this.images.length-1;
		if(this.prev>0) $(this.images[this.prev]).fadeOut('slow');
		$(this.images[this.cur]).fadeIn('slow');
		return false;
	},
	pause:function(obj){
		obj.blur();
		if(this.playing){
			obj.parentNode.className="stopped";
			this.playing=false;
			clearTimeout(this.tm);
		}
		else{
			obj.parentNode.className="playing";
			this.playing=true;
			this.play();
		}
		return false;
	}
}
// init when document is ready
$(document).ready(function(e){
	//ImageRotation.init();
	//ImageRotation2.init();
	setInterval( "slideSwitch()", 6000 ); 
});

