/**
 * Harmos Festival
 *
 * @version 1
 * @author  Rolling Mill, http://www.rolling-mill.pt
 * @created 2010-09-10
 * @updated 2010-11-30
 * @link    http://www.harmos.com
 */

	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g,"");
	}

	
	function createMedia(lang, area, image, itemID, type, imageFolder)
	{
		//self.status = 'Ready to save node ' + nodeText + ' which is a sub item of ' + parentId;
		// Use an ajax method here to save this new node. example below:

		fldImage = document.getElementById(image);
	
		var caption_pt = "";
		var caption_en = "";
		
		var img = image;
		
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].setVar('area', area);
		ajaxObjectArray[ajaxIndex].setVar('imagem', img);
		ajaxObjectArray[ajaxIndex].setVar('itemID', itemID);
		ajaxObjectArray[ajaxIndex].setVar('mediaType', type);
		ajaxObjectArray[ajaxIndex].setVar('caption_pt', caption_pt);
		ajaxObjectArray[ajaxIndex].setVar('caption_en', caption_en);
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/photoGallery/createImage.cfm';
		ajaxObjectArray[ajaxIndex].onCompletion = function() { 
			//self.status = 'New node has been saved';
			//alert(ajaxObjectArray[ajaxIndex].response);
			//switchDIV('frmNews')
			getMedia('showcase', lang, area, itemID, imageFolder);
		};	// Specify function that will be executed after file has been found	
		
		ajaxObjectArray[ajaxIndex].runAJAX();		// Execute AJAX function
				
	}
	
	function removeMedia(id, itemID, lang, area, imageFolder)
	{
		//self.status = 'Ready to save node ' + nodeText + ' which is a sub item of ' + parentId;
		// Use an ajax method here to save this new node. example below:
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].setVar('mediaID', id);
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/photoGallery/removeImage.cfm';
		ajaxObjectArray[ajaxIndex].onCompletion = function() { 
			//self.status = 'New node has been saved';
			//alert(ajaxObjectArray[ajaxIndex].response);
			getMedia('showcase', lang, area, itemID, imageFolder);
			callbackRemove = function() {
				
			}
			//getNews('news', edition, lang);
		};	// Specify function that will be executed after file has been found	
		
		ajaxObjectArray[ajaxIndex].runAJAX();		// Execute AJAX function
				
	}
	
	function getMedia(div, lang, area, itemID, imageFolder)
	{
		//self.status = 'Ready to save node ' + nodeText + ' which is a sub item of ' + parentId;
		// Use an ajax method here to save this new node. example below:
		var el = document.getElementById(div);
		//alert(animateID);
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/photoGallery/getMedia.cfm?lang='+lang+'&area='+area+'&itemID='+itemID+'&imageFolder='+imageFolder;
		ajaxObjectArray[ajaxIndex].onCompletion = function() { 
			//self.status = 'New node has been saved';
			//alert(ajaxObjectArray[ajaxIndex].response);
			el.innerHTML = ajaxObjectArray[ajaxIndex].response;
			prepareGallery();
			callback = function(){
				//switchDIV('frmNews')
			}
			
		};	// Specify function that will be executed after file has been found	
		
		ajaxObjectArray[ajaxIndex].runAJAX();		// Execute AJAX function
				
	}
