Event.observe(window, 'load', pageload, false);

function pageload() {
	initLightbox();
}

function remove_gallery_item(target) {
	var target_ul = document.getElementById('galleryDrag');
	var target_li = document.getElementById(target);
	target_li.parentNode.removeChild(target_li);
	Sortable.create('galleryDrag', {tag:'li', handle:'handle_image', overlap:'horizontal',constraint: false, onUpdate:function(){new Ajax.Updater('gallery_status', 'user_gallery_update.php', {parameters:Sortable.serialize('galleryDrag'), asynchronous:true})}})
	new Ajax.Updater('gallery_status', 'user_gallery_remove.php', {postBody:'target='+target, asynchronous:true});
}

function removefromlist(target_element, f_name) {
	var target_ul = document.getElementById(f_name+'_target');
	var target_li = document.getElementById(target_element);
	var form_element = document.getElementById(f_name+'_form_element');
	target_li.parentNode.removeChild(target_li);

	var form_submission = ';';
	
	if (document.getElementById && document.createTextNode) {
		var ul_target=document.getElementById (f_name+'_target');
		var lis=ul_target.getElementsByTagName('li');
		for(var j=0;j<lis.length;j++) {
			var val = lis[j].id.replace("li_"+f_name+"_","");
			form_submission += val+';';
		}
	}
	
	if (form_submission!=';undefined;' && form_submission!=';;'  && form_submission!=';') { form_element.value = form_submission; } else { form_element.value = ''; };
	new Ajax.Updater(f_name+'_status', '/message_amend_list.php', {postBody:'newlist='+form_element.value+'&f_name='+f_name, asynchronous:true});
}

function initMetaShow() {	

		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');
		
		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			var relAttribute = String(anchor.getAttribute('rel'));
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
	
				anchor.onmouseover = function () { 
												var gInfo_id = this.id.replace("gAnc_","gInfo_");
												gInfo = document.getElementById(gInfo_id);
												new Effect.Opacity(gInfo_id, {duration:0.0, from:0.0, to:0.0});
												gInfo.style.display = "block";
												new Effect.Opacity(gInfo_id, {duration:0.5, from:0.0, to:1});
											};		
	
				anchor.onmouseout = function () { 
												var gInfo_id = this.id.replace("gAnc_","gInfo_");
												gInfo = document.getElementById(gInfo_id);
												gInfo.style.display = "none";
											};		
	
			}
		}
}

function play_track(track_child_id) { new Ajax.Updater('audio_player', '/audio_player.php', {postBody:'id='+track_child_id, asynchronous:true}); }

function add_smilie (target, value) {
	tgt = document.getElementById(target);
	tgt.value += value;
	tgt.focus;
}