var rotate_imgs;

var ssadjust = "-=" + sswidth;

function fadeControls() {
	jQuery("#slideshow_controls").fadeOut();
}
function rotateImgs() {
	jQuery(".slide").eq(0).css({
		"position": "absolute",
		"z-index": 2
	}).animate({
		'opacity':0
	}, 600, function(){
		jQuery(".slide").eq(0).detach().appendTo(jQuery("#slideshow_content")).css({
			"position":"relative",
			"z-index": 1,
			"opacity": 1
		});
		jQuery(".control_circle").removeClass("active");
		jQuery(".control_circle").eq(jQuery(".slide").eq(0).find("img").attr("order")).addClass("active");
	});
}
function rotateImgsQuick(dot) {
	jQuery(".slide").eq(0).css({
		"position": "absolute",
		"z-index": 2
	}).animate({
		'opacity':0
	}, 100, function(){
		jQuery(".slide").eq(0).detach().appendTo(jQuery("#slideshow_content")).css({
			"position":"relative",
			"z-index": 1,
			"opacity": 1
		});
		jQuery(".control_circle").removeClass("active");
		jQuery(".control_circle").eq(jQuery(".slide").eq(0).find("img").attr("order")).addClass("active");
		if (jQuery(".slide").eq(0).find("img").attr("order") != dot) {
			rotateImgsQuick(dot);
		}
		else {
			clearTimeout(rotate_imgs);
			rotate_imgs = setInterval("rotateImgs()",4000);
			return false;
		}
	});
}

jQuery(document).ready(function(){
	rotate_imgs = setInterval("rotateImgs()",4000);
	jQuery("#slideshow_wrap").click(function(){
		clearTimeout(rotate_imgs);
		jQuery(".slide").eq(0).css({
			"position": "absolute",
			"z-index": 2
		}).animate({
			'opacity':0
		}, 400, function(){
			jQuery(".slide").eq(0).detach().appendTo(jQuery("#slideshow_content")).css({
				"position":"relative",
				"z-index": 1,
				"opacity": 1
			});
			jQuery(".control_circle").removeClass("active");
			jQuery(".control_circle").eq(jQuery(".slide").eq(0).find("img").attr("order")).addClass("active");
		});
		rotate_imgs = setInterval("rotateImgs()",4000);
	});
	jQuery("#slideshow_content .slide").each(function(){
		jQuery("#slideshow_controls").append("<div class='control_circle'></div>");
	});
	var ccs = (jQuery(".control_circle").length * 22) + "px";
	jQuery("#slideshow_controls").css("width",ccs);
	jQuery(".control_circle").eq(0).addClass("active");
	jQuery(".control_circle").click(function(){
		jQuery(".control_circle").removeClass("active");
		var thisdot = jQuery(".control_circle").index(jQuery(this));
		rotateImgsQuick(thisdot);
	});
});

