//path to folder with XML - should be filled withe relative (better) or absolute path
var path_to_xml_folder = '/assets/panoramio/';

/**
 * onLoad init
 * @param msg
 */
Event.observe(window, 'load', function() {
	processDivs('panoramio_placeholder left');
	processDivs('panoramio_placeholder right');
	processDivs('panoramio_placeholder');
});




/**
* function gets URL parameter form the query string
* @param divClassName string class name of processed divs
*/
function processDivs(divClassName)
{
	$$('div[class="'+divClassName+'"] div[id]').each(function(processed_element)
	{
		new Ajax.Request(path_to_xml_folder+processed_element.id+'.xml',
		{method:"get", onSuccess:function(transport)
			{
				//alert('t');
				var image_files = transport.responseXML.getElementsByTagName('img');
				if (image_files.length > 0)
				{
					var current_image = image_files[0];
					
					var src = '';
					var caption = '';
					var atts = current_image.attributes;
					for (j=0; j<atts.length; j++) 
					{
						var att = atts.item(j);
						if (att.nodeName.toLowerCase() == 'src') 
						{
							src = att.nodeValue;
						}
						else if (att.nodeName.toLowerCase() == 'caption') 
						{
							caption = att.nodeValue;
						}
					}
					
					if ( (src != '') && (caption !=  '') )
					{
						caption = caption.replace('author :', 'Photo from Panoramio, copyright');
						caption = caption.replace(/<[\/]?u>/g, '');
						caption = caption.replace(/<[\/]?font[^>]*>/g, '');
						
						processed_element.up().innerHTML =  '<div class="panoramio_image">'+
													'<img src="'+src.replace('/medium/', '/small/')+'" alt="'+processed_element.innerHTML+'" title="'+processed_element.innerHTML+'" />'+
'<p class="panoramio_caption">'+processed_element.innerHTML+'</p>'+
'<p class="panoramio_copyright">'+caption+'</p>'+
'</div>';
					}
				} 
			} 
		});
	});
		
	
}