$(document).ready(function(){
	if ($("#image_01").length > 0) {
		timeout = window.setTimeout("visible()", 3000);
		timeout = window.setTimeout("swap()", 5000);
	} else if ($("#image_02").length > 0) {
		visible();
		setInterval('rotate()', 2500);
	}
});

function swap()
{
	$("#image_01").fadeOut(2500);
	if($("#image_02")) {
		$("#image_02").fadeIn(2500);
		setInterval('rotate()', 2500);
	}
}

function visible()
{
	$("#image_02").css('visibility', 'visible');
}

function rotate()
{
	var selected = Math.floor((Math.random()*3)+1);
	
	for(i=1;i<=3;i++) {
		$("#image_02 .col_"+selected+".active").fadeOut(1500);
	}
	attributes = $("#image_02 .col_"+selected+".active").attr("class");
	$("#image_02 .col_"+selected+".active").removeClass('active');
	
	attributes = attributes.split(' ');
	attribute = attributes[0].toString();
	next_set = attribute.substring(4);
	
	next_set = parseInt(next_set);
	if (next_set == 3) {
		next_set = 1;
	} else {
		next_set = next_set + 1;
	}
	
	$("#image_02 .set_"+next_set+".col_"+selected).addClass('active');
	$("#image_02 .set_"+next_set+".col_"+selected).fadeIn(1500);
}
