Current File : /home/virtualki/22346/oldwp/wp-content/themes/megiw/js/imageslider.js
(function($){
	$(document).ready(function(){
		$('.image-slider').each(function(){		
			
	        var $this = $(this);
	        	        
	        var images = $this.find('.images img');
	        var titles = $this.find('.titles div');
	        var content = $this.find('.content div');
	        
	        images.first().css('opacity',1);
	        titles.first().css('opacity','1');
	        content.first().css('opacity','1');
	        
	        var current = 0;	        
	        var timeout = null;	        
			
	        if(Math.min(images.size(),titles.size()) > 1){       	
	        	
				var nav = $('<div class="nav"></div>');
	            
	            var left = $('<span class="arrow left">&laquo;</span>').prependTo(nav);
	            var right = $('<span class="arrow right">&raquo;</span>').appendTo(nav);
	            
	            left.click(function(){
	            	prev();
	            });
	            
	            right.click(function(){
	            	next();
	            });
	            
	            nav.appendTo($this);
	        }
	        
	        function next(){
	          	var toShow = current + 1;
	          	if(toShow >= images.size()){
	          		toShow = 0; 
	          	}
	          	
	          	show(toShow);
	          	cycle();
	        }
	        
	        function prev(){
	          	var toShow = current - 1;
	          	if(toShow < 0){
	          		toShow = images.size() - 1; 
	          	}
	          	
	          	show(toShow);
	          	cycle();
	        }
	        
	        function show(number){
	        	current = number;
	        	images.css('opacity',0).eq(current).css('opacity',1);
	        	titles.css('opacity','0').eq(current).css('opacity','1');
	        	content.css('opacity','0').eq(current).css('opacity','1');
	        }
	        
	        function cycle() {
				disableCycle()
		
				timeout = setTimeout(function() {
					next();
					cycle();			
				}, 8000);
			}
				
			function disableCycle(){
				if (timeout) {
					clearTimeout(timeout);
					timeout = null;
				}		
			}
			
			// $this.mouseenter(function() {
				// disableCycle()
			// });
		
			// $this.mouseleave(function() {
				// cycle();
			// });			
			
			$(window).load(
				function(){
					cycle();
					$this.addClass('active');
				}
			)    
						        
		})		
	});
})(jQuery)