//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/retrievingFlickrBtn.gif" alt="Retrieving..." />');

	//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({
        animationSpeed: 'normal', /* fast/slow/normal */
        padding: 40, /* padding for each side of the picture */
        opacity: 0.35, /* Value betwee 0 and 1 */
        showTitle: false, /* true/false */
        allowresize: true, /* true/false */
        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
        theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square */
        hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
        modal: false, /* If set to true, only the close button will close the window */
        changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
        callback: function(){} /* Called when prettyPhoto is closed */
    });

}

//INITIALIZE PRETTY PHOTO ON PAGE LOAD HERE
$(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto({
        animationSpeed: 'normal', /* fast/slow/normal */
        padding: 40, /* padding for each side of the picture */
        opacity: 0.35, /* Value betwee 0 and 1 */
        showTitle: false, /* true/false */
        allowresize: true, /* true/false */
        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
        theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square */
        hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
        modal: false, /* If set to true, only the close button will close the window */
        changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
        callback: function(){} /* Called when prettyPhoto is closed */
    });
});
