/* forms */
function show_delete_form(title, id, name, table){
	$('form_delete_id').value = id;
	$('form_delete_table').value = table;
	$('delete_name').innerHTML = name;
	$('form_container').setStyle({borderColor: '#D73233'});
	$('form_title').innerHTML = title;
	
	$('form_back').show();
	$('form_delete').show();
	Effect.Appear($('form_container'), { duration:0.4 });
}

function hide_all_forms(){
	$('form_delete').hide();
	$('form_container').hide();
	$('form_back').hide();
	
	$('form_delete_id').value = '';
	$('delete_name').innerHTML = '';
	$('form_title').innerHTML = '';
	$$('.edit_form').each(function(item) {
		item.hide();
	});
}

function show_form(id, table, form_title){
	$('form_'+table+'_'+id).show();
	
	$('form_container').setStyle({borderColor: '#62BD2D'});
	$('form_title').innerHTML = form_title;
	$('form_id').innerHTML = '';
	if(id != ''){
		$('form_id').innerHTML = 'id: '+id;
	}
	
	$('form_back').show();
	Effect.Appear($('form_container'), { duration:0.4 });
}

function show_form_loader(form_id){
	$(form_id).hide();
	$('form_loader').show();
	
	closeKeepAlive();
	
	$(form_id).submit();
}

/* A pretty little hack to make uploads not hang in Safari. Just call this
 * immediately before the upload is submitted. This does an Ajax call to
 * the server, which returns an empty document with the "Connection: close"
 * header, telling Safari to close the active connection. A hack, but
 * effective. */
function closeKeepAlive() {
  if (/AppleWebKit|MSIE/.test(navigator.userAgent)) {
    new Ajax.Request("/ping/close", { asynchronous:false });
  }
}


/* end forms*/

/* pic switch */
function show_full_pic(id, tn_element){
	hide_all_full_pics();
	reset_all_tn_classes();
	
	Effect.Appear($(id), { 
		duration: 0.2, 
		afterFinish: function(){
			if($(id+'_desc')){
				/*$(id+'_desc').setStyle({opacity: '0.1'});*/
				$(id+'_desc').show();
				/*
				if($(id+'_desc').offsetHeight > '24'){
					var margin_top = -33 - ($(id+'_desc').offsetHeight - 24);
				}
				$(id+'_desc').setStyle({marginTop: margin_top+'px', opacity: '1.0'});
				*/
			}
		}
	});
	

	tn_element.className = 'tn_item active';
}

function hide_all_full_pics(){
	$$('.full_pic').each(function(item) {
		item.hide();
	});
	
	$$('.full_pic_desc').each(function(item) {
		item.hide();
	});
}

function reset_all_tn_classes(){
	$$('.full_pic').each(function(item) {
		item.hide();
	});
	
	$$('.tn_item').each(function(item) {
		item.className = 'tn_item';
	});
}

/* description box */
function set_desc_box(max_h){
	var current_height = $('description').offsetHeight;
	var max_height = max_h;

	if(current_height <= max_height){
		var margin_bottom = max_height - current_height + 15; // gesammte hoehe - textbox hoehe + abstand unten
		margin_bottom = margin_bottom+'px';
		$('description').setStyle({
			marginBottom: margin_bottom, 
			marginTop: '60px'
		});
	}
	if(current_height > max_height){
		var margin_top = 60 - (current_height - max_height);
		$('description').setStyle({
			marginTop: margin_top+'px',
			marginBottom: '15px'
		});
	}
	
	$('content_box_right').setStyle({
		'visibility': 'visible'	
	});
//	alert(current_height);	
}
