	
	
	function ajaxFlashLoadItem(exhibition, itemUrl)
	{
		if(itemUrl==null) {
			_doExhibitionAjax(exhibition);
		} else {
			_doItemAjax(itemUrl, exhibition);
		}
	}
	
	function _doItemAjax(itemUrl, exhibition)
	{
		$.ajax({
			type: "POST",
			url: '/assets/ajax/item-page.php',
			data: "action=itemload&itemid="+itemUrl+"&exhibition="+exhibition,
			dataType: 'html',
			error: function(results){
				// errror
				//$('#load-content').fadeIn();
			},
			success: function(results){
				_toggleAjaxLoading(false);
				$('#load-content').html(results);
				$('#load-content').fadeIn( function(){
					initItemPageLoad();
				});
				$('#pods-wrapper').fadeIn();
			}
		});
	}
	
	function _doExhibitionAjax(exhibition)
	{
		$.ajax({
			type: "POST",
			url: '/assets/ajax/item-page.php',
			data: "action=exhibitionload&exhibition="+exhibition,
			dataType: 'html',
			error: function(results){
				// errror
				//$('#load-content').fadeIn();
			},
			success: function(results){
				$('#load-content, #pods-wrapper').fadeOut( function(){
					_toggleAjaxLoading(false)
					$('#load-content').html(results);
					$('#load-content').fadeIn( function(){
						initItemPageLoad();
					});
				});
			}
		});
	}
	
	function _toggleAjaxLoading(show)
	{
		if(show) {
		$('#load-content-wrapper').css('backgroundImage','url(/assets/images/item/loading-ajax.gif)'); 
		$('#load-content-wrapper').css('backgroundRepeat','no-repeat'); 
		$('#load-content-wrapper').css('backgroundPosition','center 30px');
		} else {
			$('#load-content-wrapper').css('backgroundImage','none'); 
		}
	}
	
	function initItemPageLoad()
	{
		_initLoginOverlay();
		_initRegisterOverlay();
		$('#add-comment').focus( function() {
			_commentTextFocus($(this));
		})
		.blur( function() {
			_commentTextBlur($(this));
		});
		$('#submit-comment').submit( function(){
			if($("#add-comment").val() != '' && $("#add-comment").val() != 'Tell us what you think...') {
				_ajaxAddComment();
			}
			return false;
		});
		$('#myexhibition-remove').click( function(){
			if($("#itemid").val() != '') {
				_ajaxAddRemoveMyExhibition('myexhibitionRemove');
			}
			return false;
		});
	}
	
	function initAddExhibition()
	{
		// Only initialised if logged in
		$('#myexhibition-add').click( function(){
			if($("#itemid").val() != '') {
				_ajaxAddRemoveMyExhibition('myexhibitionAdd');
			}
			return false;
		});
	}
	
	function hideItemDetail()
	{
		$('#load-content').fadeOut('fast', function() {
			_toggleAjaxLoading(true);
		});
	}
	
	
	function _ajaxAddComment()
	{
		$.ajax({
			type: "POST",
			url: '/assets/ajax/item-page.php',
			data: "action=addcomment&itemid="+$("#itemid").val()+"&add-comment="+$("#add-comment").val(),
			dataType: 'html',
			error: function(results){
				// errror
			},
			success: function(results){
				// reload comments + flash first one
				if(results) {
					$('#comments-list').html(results);
					$("#add-comment").val('Tell us what you think...');
					_flashNewitem('#comments-list ol li:first');
				} else {
					_flashField($("#add-comment"));
				}
			}
		});
	}
	
	function _ajaxAddRemoveMyExhibition(action)
	{
		$.ajax({
			type: "POST",
			url: '/assets/ajax/item-page.php',
			data: "action="+action+"&itemid="+$("#itemid").val(),
			dataType: 'html',
			error: function(results){
				// errror
			},
			success: function(results){
				if(results) {
					if(action=='myexhibitionAdd') {
						$('#my-add').fadeOut( function(){
							$('#my-remove').fadeIn();
						});
					} else {
						$('#my-remove').fadeOut( function(){
							$('#my-add').fadeIn();
						});
					}
				}
			}
		});
	}
	
	function _commentTextFocus(field)
	{
		if(field.val() == 'Tell us what you think...') {
			field.val('');
		}
	}
	function _commentTextBlur(field)
	{
		if(field.val() == '') {
			field.val('Tell us what you think...');
		}
	}
	
	function _flashNewitem(css)
	{
		$(css)
			.animate({ backgroundColor: "#C9F6BE", color: "#197304" }, 400)
			.animate({ backgroundColor: "#ffffff", color: "#333333" }, 400)
			.animate({ backgroundColor: "#C9F6BE", color: "#197304" }, 400)
			.animate({ backgroundColor: "#ffffff", color: "#333333" }, 400)
		;
	}
