//FUNCTION TO OUTPUT MORE FLICKR RESULTS
function outputSelectedSlide(selectedId, slideIndex) {
	
	//PROVIDE FEEDBACK
	$('#slideDataWrapper').html('<img src="/filebin/images/loading.gif" alt="" /> Retrieving...');
	
	//GET NEXT SET OF FLICKR FILES
	var callVars = "action=outputSelectedSlide&selectedId="+selectedId+"&slideIndex="+slideIndex;
	
	//MAKE AJAX CALL
	ajax_json_call('/resources/js/ajax_php/carouselAJAX.php', 'POST', callVars, 'outputSelectedSlideOnComplete('+slideIndex+')');
}

//FUNCTION TO OUTPUT MORE FLICKR RESULTS ON COMPLETE
function outputSelectedSlideOnComplete(slideIndex) {
//	$('.jcarousel-item a').removeClass('selected').addClass('normal');
//	$('.jcarousel-item-'+slideIndex+' a').removeClass('normal').addClass('selected');
}


//STANDARD AJAX HANDLERS
function ajax_json_call(callUrl, callType, callVars, onCompleteFunc) {
	try {
		$.ajax({
			type: callType,
			url: callUrl,
			data: callVars,
			dataType: "json",
			success: function(data) {
				if (data) {
					process_success_ajax_json_call(data);
				} else {
					//error
				}
		 	},
			complete: function() {
				if (eval("typeof " + onCompleteFunc + " == 'function'")) {
					eval(onCompleteFunc+'()');
				}
			}
		});
	} catch (e) {
		//nothing for now
	}
}

function process_success_ajax_json_call(data) {
	if (data) {
		var alert_content="";
		$.each(data, function(id, dataHolder) {
			if ($("#"+id) && id!="alert_msg") {
				if (dataHolder.jAction.indexOf('insert')>-1) {
					$(dataHolder.jContentReturn)[dataHolder.jAction]('#'+dataHolder.jHelpId);
				} else {
					$("#"+id)[dataHolder.jAction](dataHolder.jContentReturn);
				}
			}
			if (id=="alert_msg") alert_content += content+"\n";
		});
		if (alert_content != "") alert(alert_content);
	}
	else {
		//process error here...
	}
}
