var stopped = 0;

$(document).ready(function() {
	

	/*** HOME BANNER ***/
	$('#cbox div').click(function() {
	
		if($(this).hasClass('activebox')) {
			return false;
		}
		
		$('#cbox div').removeClass('activebox').removeClass('box');
		$('#cbox div').addClass('box');
		$(this).removeClass('box').addClass('activebox');
		
		var ci = 0;
		var sel = 0;
		
		$('#cbox div').each(function() {
			if($(this).attr('class') == 'activebox') {
				sel = ci;
			}
			ci++;
		});
		
		ci = 0;
		
		$('#home_banner div.ban').each(function() {
			$(this).fadeOut();
			if(sel == ci) {
				$(this).fadeIn();
			}
			ci++;
		});
		
		stopped = 1;
	});

});

setTimeout ( "bannerMove()", 10000 );

function bannerMove ( )
{
	
	if(stopped) {
		stopped = 0;
		setTimeout ( "bannerMove()", 10000 );
		return false;
	}
	
	var ci = 0;
	var sel = 0;
	
	$('#cbox div').each(function() {
		if($(this).attr('class') == 'activebox') {
			$(this).removeClass('activebox').addClass('box');
			sel = ci;
		}
		ci++;
	});
	
	sel++;
	
	if(sel == ci) {
		sel = 0;
	}
	
	ci = 0;
	
	$('#cbox div').each(function() {
		if(ci == sel) {
			$(this).removeClass('box').addClass('activebox');
		}
		ci++;
	});
	
	ci = 0;
	
	$('#home_banner div.ban').each(function() {
		$(this).fadeOut();
		if(sel == ci) {
			$(this).fadeIn();
		}
		ci++;
	});
	
	if(!stopped) {
		setTimeout ( "bannerMove()", 7000 );
	}
}
