function showhide(){
	var showhides = $$('a.showhide');
	showhides.each(function(el){
		el.addEvent('click', function(e){
			var tar = el.getProperty('rel');
			if ($(tar)){
				var status = $(tar).hasClass('hide');
				if (status){
					$(tar).removeClass('hide');
				}else{
					 $(tar).addClass('hide');
				}
			};
			var e = new Event(e);
			e.stop();
		});
	});
}
function edits(){
	var editLinks = $$('td.col_edit a');
	editLinks.each(function(el){
		el.getParent().getParent().setStyle('cursor', 'pointer');
		el.getParent().getParent().addEvent('dblclick', function(e){
			window.location = el.href;
		});
	});
}
window.addEvent('domready',function(){
	edits();
	showhide();
	var nav_links = $$('a');
	nav_links.each(function(el){
		el.setProperty('target', '_top');
	});
	var as = $$('a');
	as.each(function(el){
		if (el.getProperty('rel') == 'external'){
			el.setProperty('target', '_blank');
		}
	});
	var tables = $$('table.addlinks');
	tables.each(function(el){
		var url = el.getProperty('rel');
		if (url != ''){
			url = '/admin/' + url + '.php?' + url + '=';
			var links = el.getElements('tr.links');
			for(a=0; a<links.length; a++){
				links[a].addEvent('dblclick', function(e){
					window.location = url + this.getProperty('rel');
				});
				links[a].addEvent('mouseover',function(e){
					this.addClass('mouseover');
				});
				links[a].addEvent('mouseout',function(e){
					this.removeClass('mouseover');
				});
			}
		}
	});
	var dolinks = $$('.dolink');
	dolinks.each(function(el){
		el.addEvent('click', function(e){
			window.location = el.getProperty('rel');
		});
	});
	var remove = $$('.remove, .col_remove a');
	remove.each(function(el){
		el.addEvent('click', function(e){
			el.getParent().getParent().addClass('remove');
			var conf = confirm('Are you sure you wish to permanentely remove this item?\r\n Press \'OK\' to continue and remove...');
			if (!conf){
				var e = new Event(e);
				e.stop();
			}
			el.getParent().getParent().removeClass('remove');
		});
	});
	var submitbutton = $$('.submitbutton');
	submitbutton.each(function(el){
		var fm = el.getParent().getParent().getParent().getParent().getParent();
		fm.addEvent('submit', function(e){
			fm.setProperty('target', '');
			fm.setProperty('action', '');
		});
	});
	var preview = $$('.preview_button');
	preview.each(function(el){
		el.addEvent('click', function(e){
			var rel = el.getProperty('rel');
			if ($(rel)){
				var tar = $(rel);
				alert ('Please note: This will preview your web page in a new window.\r\nThis will NOT upload any additional imagery which you may be uploading at this moment (To upload the photography, please press \'Save\').\r\n\r\nThe address will not be valid for preview except from this link.\r\nIf you require any further information please contact the administrator.');
				tar.setProperty('target', '_blank');
				tar.setProperty('action', '/preview/');
				tar.submit();
			}
		});
	});
	var inputs = $$('input');
	inputs.each(function(el){
		if (el.getProperty('type') == 'file'){
			el.addEvent('focus', function(e){
				if ($('shops_form')){
					if ($('shops_form').getProperty('rel') != 'noted'){
						alert ('Please note:\r\nImagery MUST be jpg/jpeg and RGB (typical camera settings).');
						$('shops_form').setProperty('rel', 'noted');
					}
				}
			});
		}
	});
});
