//version 1.0
//by: eBizzSol
/*
container:'#jContainer'
slide:'.slide'
paginContainer:'#paging'
paginElem:'li'
fadeTime:1.0
waitTime:5.0
next:'#next'
previous:'#prev'
pauseToggle:'#playPause'
isRandom:true
transition:'slide'
*/
function fadeAppear(o){
	var ths = new Object;
	ths.waitTime = (o.waitTime?o.waitTime:5.0)*1000;
	ths.fadeTime = (o.fadeTime?o.fadeTime:1.0)*1000;
	ths.isRandom = o.isRandom?o.isRandom:false;
	ths.transition = o.transition?o.transition:'fade';
	ths.elems = $(o.container + ' > ' + o.slide);
	ths.paging = $(o.paginContainer + ' > ' + o.paginElem);
	ths.pauseToggle = o.pauseToggle?o.pauseToggle:'';
	if( ths.transition == 'slide' )
		ths.eachWidth = $(o.container).width();
	if( ths.isRandom ) ths.hide = Math.round(Math.random() * (ths.elems.length-1));
	else ths.hide = ths.elems.length-1;
	ths.show = ths.hide+1;
	if( ths.show > ths.elems.length-1 ) ths.show = 0;
	if( ths.hide > ths.elems.length-1 ) ths.hide = 0;
	ths.interval = null;
	ths.isPrev = false;
	ths.transitionInterval = null;
	ths.swap = function(){
		ths.tmp = ths.hide;
		ths.hide = ths.show;
		ths.show = ths.tmp;
		}
	ths.fade = function(){
		if( ths.interval )
			clearInterval(ths.interval);
		if( ths.isPrev ){
			if( ths.transition == 'fade' )ths.swap();
			else if( ths.transition == 'slide' ){
				ths.show-=2;
				}
			}
		
		if( ths.show > ths.elems.length-1 ) ths.show = 0;
		else if( ths.show < 0 ) ths.show = ths.elems.length-1;
		if( ths.hide > ths.elems.length-1 ) ths.hide = 0;
		else if( ths.hide < 0 ) ths.hide = ths.elems.length-1;
		if( ths.transition == 'fade' ){
			$(ths.elems[ths.hide]).fadeOut(ths.fadeTime);
			$(ths.elems[ths.show]).fadeIn(ths.fadeTime);
			}
		else{
			if( ths.isPrev ){
				$(ths.elems[ths.show]).css({left:'-'+ths.eachWidth+'px'});
				$(ths.elems[ths.hide]).css({left:'0px'});
				$(ths.elems[ths.hide]).animate({left:'+'+ths.eachWidth+'px'},ths.fadeTime);
				$(ths.elems[ths.show]).animate({left:'0px'},ths.fadeTime);
				}
			else{
				$(ths.elems[ths.show]).css({left:'+'+ths.eachWidth+'px'});
				$(ths.elems[ths.hide]).css({left:'0px'});
				$(ths.elems[ths.hide]).animate({left:'-'+(ths.eachWidth+1)+'px'},ths.fadeTime);
				$(ths.elems[ths.show]).animate({left:'0px'},ths.fadeTime);
				}
			}
		$(ths.paging[ths.hide]).removeClass('active');
		$(ths.paging[ths.show]).addClass('active');
		if( ths.isPrev ){
			if( ths.transition == 'slide' ){
				ths.show++;
				ths.hide = ths.show-1;
				}
			else{
				ths.swap();
				ths.hide--;
				ths.show--;
				}
			ths.isPrev = false;
			}
		else{
			ths.hide++;
			ths.show++;
			}
		ths.interval = setInterval(ths.fade,ths.waitTime);
		}
	ths.pause = function(){
		clearInterval(ths.interval);
		}
	ths.play = function(){
		clearInterval(ths.interval);
		ths.interval = setInterval(ths.fade,ths.waitTime);
		}
	ths.clearTransition = function(){
		clearInterval(ths.transitionInterval);
		ths.transitionInterval = null;
		}
	ths.next = function(){
		if( ths.transitionInterval ) return;
		ths.transitionInterval = setInterval(ths.clearTransition,ths.fadeTime);
		clearInterval(ths.interval);
		ths.fade();
		}
	ths.prev = function(){
		if( ths.transitionInterval ) return;
		ths.transitionInterval = setInterval(ths.clearTransition,ths.fadeTime);
		clearInterval(ths.interval);
		ths.isPrev = true;
		ths.fade();
		}
	ths.directGo = function(){
		//$('#'+this.parent.id + '>').each(function(i,e){});
		//alert(this.type); 
		}
	if( o.next ) $(o.next).click(ths.next);
	if( o.previous ) $(o.previous).click(ths.prev);
	if( ths.pauseToggle ) $(ths.pauseToggle).toggle(function(){
			$(ths.pauseToggle).addClass('pause');
			$(ths.pauseToggle).removeClass('play');
			ths.pause();
			},
		function(){
			$(ths.pauseToggle).addClass('play');
			$(ths.pauseToggle).removeClass('pause');
			ths.play();
			});
	if( ths.elems.length > 1 ){
		for( i = 0; i < ths.elems.length; i++ ){
			e = ths.elems[i];
			$(e).mouseover(ths.pause);
			$(e).mouseout(ths.play);
			$(ths.paging[i]).click(ths.directGo);
			if( ths.transition == 'slide' ) $(e).css({width:ths.eachWidth+'px'});
			if( ths.hide != i ){
				if( ths.transition == 'fade' ) $(e).fadeOut(20);
				else $(e).css({left:'-'+ths.eachWidth+'px'});
				}
			}
		$(ths.paging[ths.hide]).addClass('active');
		ths.interval = setInterval(ths.fade,ths.waitTime);
		}
	else
		$(ths.paging).css({display:'none'});	//dont display paging if only one elements
	}

$("#button").toggle(
		function(){
			$("#jEffects1").animate({opacity:1.0}, 1000);
		},
		function(){
			$("#jEffects1").animate({opacity:0.2}, 1000);
		}
	);