jQuery.noConflict();
(function($) {
	$(document).ready(function () {

		if (typeof(slideArray) != 'undefined' && slideArray.length > 0) {
			if ( slideArray.length > 1 ) {
				InitSplide();
			}
		}				
					
	});
})(jQuery);

var isSliding = false;
var slideTimer = null;
function InitSplide() {
	clearTimeout(slideTimer);
	slideTimer = setTimeout( 'showNextSlide()', slideArray[slideNow] );
}

function showNextSlide() {
	if ( !isSliding ) {
		
		clearTimeout(slideTimer);
		isSliding	= true;
		
		var nextEl = slideNow+1;
		if ( nextEl >= slideArray.length )
			nextEl = 0;
		
		for (var i = 0; i < slideArray.length; i++ ) {
			if (i==nextEl || i==slideNow)
			 ;
			else
				jQuery('#slider_'+i).css('display','none');
		
			if (i==nextEl)
			 jQuery('#slider_dot_'+i).attr('src','/g/new_slider_dot_sel.png');
			else
				jQuery('#slider_dot_'+i).attr('src','/g/new_slider_dot.png');
		}
		
		jQuery('#slider_'+slideNow).css('zIndex',4).css('opacity',1);			
		
		jQuery('#slider_'+nextEl).stop();
		jQuery('#slider_'+nextEl).css('zIndex',5).css('opacity',0).css('left',0).css('display','block').animate({
		    opacity: 1   
		  }, {
		    duration: 1500,
		    complete: function() {
		    	isSliding	= false;
		    	slideNow = nextEl;
		    	
		    			      
		      slideTimer = setTimeout( 'showNextSlide()', slideArray[slideNow] );
		    }
		  });
	}
}

function showPrevSlide() {
	if ( !isSliding ) {
		clearTimeout(slideTimer);
		isSliding	= true;
		
		var nextEl = slideNow-1;
		if ( nextEl < 0 )
			nextEl = slideArray.length-1;
			
		for (var i = 0; i < slideArray.length; i++ ) {
			if (i==nextEl || i==slideNow)
			 ;
			else
				jQuery('#slider_'+i).css('display','none');
		
			if (i==nextEl)
			 jQuery('#slider_dot_'+i).attr('src','/g/new_slider_dot_sel.png');
			else
				jQuery('#slider_dot_'+i).attr('src','/g/new_slider_dot.png');
		}
		
		jQuery('#slider_'+slideNow).css('zIndex',4).css('opacity',1);		
		
		
		jQuery('#slider_'+nextEl).stop().css('zIndex',5).css('opacity',0).css('left',0).css('display','block').animate({
		    opacity: 1
		  }, {
		    duration: 1500,
		    complete: function() {
		    	isSliding	= false;
		    	slideNow = nextEl;
		    			    	
		    			      
		      slideTimer = setTimeout( 'showNextSlide()', slideArray[slideNow] );
		    }
		  });
		
	}
}

function slideTo(i) {
	
	if ( !isSliding && slideNow != i  ) {
		clearTimeout(slideTimer);
		isSliding	= true;
		
		var nextEl = i;
			
		for (var i = 0; i < slideArray.length; i++ ) {
			if (i==nextEl || i==slideNow)
			 ;
			else
				jQuery('#slider_'+i).css('display','none');
		
			if (i==nextEl)
			 jQuery('#slider_dot_'+i).attr('src','/g/new_slider_dot_sel.png');
			else
				jQuery('#slider_dot_'+i).attr('src','/g/new_slider_dot.png');
		}
		
		jQuery('#slider_'+slideNow).css('zIndex',4).css('opacity',1);		
		
		
		jQuery('#slider_'+nextEl).stop().css('zIndex',5).css('opacity',0).css('left',0).css('display','block').animate({
		    opacity: 1
		  }, {
		    duration: 800,
		    complete: function() {
		    	isSliding	= false;
		    	slideNow = nextEl;
		    	
		    	
		    			      
		      slideTimer = setTimeout( 'showNextSlide()', slideArray[slideNow] );
		    }
		  });
		
	}
	
}
