function toggle_slide() {
	if (flag) {
		$clear(running);
		flag = false;
	} else {
		flag = true;
		nextSlide();
	}
	show_button();
}
function show_button() {
	if (flag) {
		if ($('play_stop_button')) $('play_stop_button').src = base_url + "/modules/mod_jv_contentslideshow/assets/images/stop.png";
		if ($('play_stop_button1')) $('play_stop_button1').src = base_url + "/modules/mod_jv_contentslideshow/assets/images/stop.png";
	}	
	else {
		if ($('play_stop_button')) $('play_stop_button').src = base_url + "/modules/mod_jv_contentslideshow/assets/images/play.png";
		if ($('play_stop_button1')) $('play_stop_button1').src = base_url + "/modules/mod_jv_contentslideshow/assets/images/play.png";
	}
}
function show_busy_button() {
	if (flag) {
		if ($('play_stop_button')) $('play_stop_button').src = base_url + "/modules/mod_jv_contentslideshow/assets/images/stop-busy.png";
		if ($('play_stop_button1')) $('play_stop_button1').src = base_url + "/modules/mod_jv_contentslideshow/assets/images/stop-busy.png";
	}	
	else {
		if ($('play_stop_button')) $('play_stop_button').src = base_url + "/modules/mod_jv_contentslideshow/assets/images/play-busy.png";
		if ($('play_stop_button1')) $('play_stop_button1').src = base_url + "/modules/mod_jv_contentslideshow/assets/images/play-busy.png";
	}
}
function disable_control() {
	if ($('jv_xslideitem_control')) {
		$('jv_realcontrol').setStyle('display','none');
		$('jv_nocontrol').setStyle('display','block');
	}
}
function enable_control() {
	if ($('jv_xslideitem_control')) {
		$('jv_realcontrol').setStyle('display','block');
		$('jv_nocontrol').setStyle('display','none');
	}
}
function nextSlide() {
	disable_control();
	clear_all();
	if (running_index==content_items_count-1) {
		running_index = 0;
	} else {
		running_index = running_index + 1;
	}
	showCurrentContent();
}
function prevSlide() {
	disable_control();
	clear_all();
	if (running_index <= 0) {
		running_index = content_items_count-1;
	} else {
		running_index = running_index - 1;
	}
	showCurrentContent();
}
function showCurrentContent() {
	if (running) $clear(running);
	show_busy_button();
	var url = base_url + "modules/mod_jv_contentslideshow/getcontent.php?content_id=" + contentids[running_index];
	var request = new Json.Remote(url, {
		onComplete: change_content
	});
	request.send();
}
clear_all = function() {
	if (t1) clearTimeout(t1);
	if (t2) clearTimeout(t2);
	if (t3) clearTimeout(t3);
	if (t4) clearTimeout(t4);
	if (t5) clearTimeout(t5);
}
hide_content = function() {
	disable_control();
	var _title = $('jv_xslideitem_title');
	var _text = $('jv_xslideitem_text');
	var _image = $('jv_xslideitem_image');
	_image.setStyle('background-position','0 0');
	if (_title) {
		changetext.start({
			'opacity':'0',
			'margin-right':'211px'
		});
	}
	if (_text) {
		t1 = setTimeout(function() {
			changecontent.start({
				'opacity': '0',
				'margin-right':'210px'
			});
		},anitime);
	}
	setTimeout(function() {
		t2 = changeimage.start({
			'opacity': '0',
			'background-position':'-20px 0'
		});
	},anitime * 2);
}
change_content = function(jsonObj) {
	if (jsonObj.src.indexOf('http://')=="-1") {
		jsonObj.src = base_url + jsonObj.src;
	} else if (jsonObj.src.indexOf('https://')=="-1") {
		jsonObj.src = base_url + jsonObj.src;
	}
	var images = new Array();
	images[0] = jsonObj.src;
	var loader = new Asset.images(images, {
		onComplete: function() {
			show_button();
			hide_content();
			t5 = setTimeout(function() {				
				show_me(jsonObj);
			}, anitime* 3);
		}
	});
}
show_me = function(jsonObj) {
	var _title = $('jv_xslideitem_title');
	var _text = $('jv_xslideitem_text');
	var _image = $('jv_xslideitem_image');
	if (_title) _title.innerHTML = "";
	if (_text) _text.innerHTML = "";
	_image.setStyle('background-image','url(' + jsonObj.src +')');
	_image.setStyle('background-repeat','no-repeat');
	_image.setStyle('background-position','-20px 0');
	changeimage.stop();
	changeimage.start({
		'opacity': '1',
		'background-position': '0 0'
	});
	if (_title) _title.innerHTML = jsonObj.title;
	if (_text) _text.innerHTML = jsonObj.content;
	if (_title)
	t3 = setTimeout(function() {
		changetext.start({
			'opacity':'1',
			'margin-right':'191px'
		});
	},anitime);
	if (_text)
	t4 = setTimeout(function() {
		changecontent.start({
			'opacity':'1',
			'margin-right':'190px'
		});
	},anitime * 2);
	if (readmore) {
		jsonObj.content_link = jsonObj.content_link.replace(/&amp;/gi,"&");
		_image.addEvent('click',function() {
			window.location.href = jsonObj.content_link;
		});
		_image.setStyle('cursor','pointer');				
		_image.setStyle('cursor','hand');				
	}
	if (flag) running = nextSlide.periodical(run_time);
	enable_control();
}