//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...
	}
}

//FUNCTION TO OUTPUT MORE FLICKR RESULTS
function getMoreFlickrResults(photosetId, pageNumber, setName, userName, numPhotos) {
	
	//PROVIDE FEEDBACK
	$('#flickrViewMore').html('<img src="filebin/images/getting_results.gif" alt="Retrieving..." style="border:0;margin-top:20px;display:block" />');

	//INCREMENT PAGE NUMBER
	pageNumber++;
	
	//GET NEXT SET OF FLICKR FILES
	var callVars = "action=getMoreFlickrResults&photosetId="+photosetId+"&pageNumber="+pageNumber+"&setName="+setName+"&userName="+userName+"&numPhotos="+numPhotos;
	
	//MAKE AJAX CALL
	ajax_json_call('resources/js/ajax_php/flickrAJAX.php', 'POST', callVars, 'initializeFlickrPhotos');
	
}

//FUNCTION TO INITIALIZE PRETTY PHOTO
function initializeFlickrPhotos() {
	$("a[rel^='prettyPhoto']").prettyPhoto({
		opacity: 0.80, /* Value between 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: false, /* true/false */
		default_width: 500,
		default_height: 344,
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		wmode: 'opaque', /* Set the flash wmode attribute */
		autoplay: true, /* Automatically start videos: True/False */
		modal: false, /* If set to true, only the close button will close the window */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		overlay_gallery: false, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
		callback: function(){} /* Called when prettyPhoto is closed */
	});

}

//INITIALIZE PRETTY PHOTO ON PAGE LOAD HERE
$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({
		opacity: 0.80, /* Value between 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		default_width: 500,
		default_height: 344,
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		wmode: 'opaque', /* Set the flash wmode attribute */
		autoplay: true, /* Automatically start videos: True/False */
		modal: false, /* If set to true, only the close button will close the window */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		overlay_gallery: false, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
		callback: function(){} /* Called when prettyPhoto is closed */
	});
});
