$(window).load( function() {
	if ($('#home-actions').length) {
		$('#home-actions').cycle('resume');
	}
	
	getSlides();
} );
		
$(document).ready( function() {
	if ($('#home-slides').length) {	
	//$("#home-slides").append("<div id='blank'></div>");

		$('#home-actions').cycle({
			fx: "fade",
			timeout: 8000,
			before: function(c, n, o, f) {  if(f) { $('#home-slides').cycle('next'); } else { $('#home-slides').cycle('prev'); } },
			cleartypeNoBg: true,
			pause: true
		});//.cycle('pause');

		$('#home-slides').cycle({
			fx: "fade",
			cleartypeNoBg: true,
			timeout: 0,
			fit: true,
			width: '100%'
		});
	
		$('#control-next').live("click", function() {
			$('#home-actions').cycle('next');
		});

		$('#control-prev').live("click", function() {
			$('#home-actions').cycle('prev');
		});

		$('#control-play').live("click", function() {
			if ($(this).hasClass('pause')) {
				$(this).removeClass('pause');
				$('#home-actions').cycle('resume');
				return;
			}
			$(this).addClass('pause');
			$('#home-actions').cycle('pause');
		});
	
		$("#home-controls").css("z-index", 50);
	}
} );

function getSlides() {
	var slides;
	var sessid = $("#sessid").val();
	
	$.ajax("/carousel/get/slides", {
		async : true,
		success : function(result) {
			$("#home-slides").append(result);
			
			$.get("/carousel/get/actions", function(actions) {
				$("#home-actions").append(actions);
				
				if ($('#home-slides').length) {	
					$('#home-actions').cycle('pause').cycle({
						fx: "fade",
						timeout: 8000,
						before: function(c, n, o, f) {  if(f) { $('#home-slides').cycle('next'); } else { $('#home-slides').cycle('prev'); } },
						cleartypeNoBg: true,
						pause: true
					});

					$('#home-slides').cycle('pause').cycle({
						fx: "fade",
						cleartypeNoBg: true,
						timeout: 0,
						fit: true,
						width: '100%'
					});
				}
			});
			
		}
		}
	);
}

