﻿function prepareImageManager() {
	$('#ImageUploadInput').MultiFile({
		STRING: {
			remove: 'x'
		}
	});

    $('#ImageUploadForm').ajaxForm({
    	//beforeSubmit:  showRequest,
        success:       showResponse
    });
    $('#ImageUploadInput').MultiFile('reset');
	reloadImageList();
}

function showRequest(formData, jqForm, options) {
    var queryString = $.param(formData);
    alert('About to submit: \n\n' + queryString);
    return true;
}

function showResponse(responseText, statusText)  {
    //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText);
    eval(responseText);
    if(uploaded) {
		//Reload images list
		reloadImageList();
	} else {
		//Notify user that uploading is failed
	}
}

function reloadImageList() {
	$('#ImageUploadInput').MultiFile('reset');
	$("#imageList").load(link_reload);
}

function makeImageRequest( link ) {
	$.get(link, function(data){
		$('#ImageUploadInput').MultiFile('reset');
		reloadImageList();
	});
}

function showImageDet(id){
	$("#MessageModal").load(link_imageDet + "/imgId=" + id, function(){
		$("#MessageModal").modal();
	});
}

function showHide( code ) {
	var str = $("#" + code).css("display");
	if( str == "none" ) {
		$("#" + code).fadeIn("fast");
	} else {
		$("#" + code).fadeOut("fast");
	}
}

function updateImage( link, array ) {
	var temp = "";
	link = link + "/updated=1";
	for(var p in array) {
		temp = $("#title_"+array[p]).val();
		link = link + "/title_" + array[p] + "=" + temp;
	}
	for(var p in array) {
		temp = $("#descr_"+array[p]).val();
		link = link + "/descr_" + array[p] + "=" + temp;
	}
	$.get(link, function(data){
		$('#MessageModal').fadeOut();
		$.modal.close();
	});
	return false;
}

function imageGallery( div_id ) {
	$(function() {
		$(div_id).lightBox({fixedNavigation:true});
	});
}