jQuery(function(){
		setInterval(imageSlider,5000);
		
		jQuery('.lightbox_close, #fade').click(function(e){
			e.preventDefault();
			jQuery('.light').css('display','none');
			jQuery('#fade').css('display','none');
		});
		
		jQuery('a[rel="lightbox"]').click(function(e){
			e.preventDefault();
			jQuery('.'+this.id).fadeIn(500);
			jQuery('#fade').css('display','block');
		});
		
		jQuery('.dot_links').click(function(){
				imageSwitch(jQuery(this).attr('id'),jQuery('.current_dot').attr('id'));
				return false;
		});
});

function imageSlider(){
	if(jQuery('.current_dot').next().attr('id')){
		next_image=jQuery('.current_dot').next().attr('id');
	}else{
		next_image=jQuery('.current_dot').parent().children().filter(':first').attr('id');
	}
	imageSwitch(next_image,jQuery('.current_dot').attr('id'));
	return false;
}

function imageSwitch(image_id,prev_id){
	jQuery('#feature_box').fadeOut('fast',function(){
			jQuery(this).addClass('feature_'+image_id).fadeIn('fast');
			jQuery(this).removeClass('feature_'+prev_id);
			jQuery('.current_dot').removeClass('current_dot');
			jQuery('#'+image_id).addClass('current_dot');
			
			return false;
	});
	return false;
}

function imageSwap(url,id){
	swapImg('.'+id+' .main_image',url,id);
}

function swapImg( img2, src,id) {
	var actions = 2;
	var img = jQuery('<img src="' + src + '" />').load( next );
	
	
	jQuery(img2).fadeTo( 1, 0.0, next );
	jQuery('.'+id+' .image_wrapper').append('<div class="ajax_loader"></div>');
	
	function next() {
		if( --actions ) return;
		jQuery('.'+id+' .ajax_loader').remove();
		jQuery(img2).attr({ src: src}).fadeTo( 500, 1.0 );
	}
}


