
/**
 * [#UPLOAD_SAFARI_TRICK] 
 * make uploads not hang in safari. this is called when submitting upload 
 * /uploads/edit.php (click handler). this performes an ajax call to
 * share/ping/close.php which returns "connection: close" header, telling 
 * safari to close the active connection.
 */
function closeKeepAlive(url) {
	if (/AppleWebKit|MSIE/.test(navigator.userAgent)) {
		new Ajax.Request(url, { asynchronous:false });
	}
} // end closeKeepAlive()


// [#FORM_HANDLING] 
if ( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', form_ff_adapt, false );

/**
 * [#FORM_HANDLING] does insert span tags in labels in order to prevent width in mozilla (Firefox) browsers
 * using the Mozilla-specific document.addEventListener() method to launch the script. 
 * This really is ideal, as it only runs for Mozilla (which is all we need) and 
 * it launches as soon as the DOM has been loaded.
 */
function form_ff_adapt() {
	
	if (navigator.userAgent.match(/\bMozilla\b/)) {
	
		// Hide forms
		// $$('form').hide(); // latest prototype version and safari 2 does not recognize elements which are set display to hidden (as if they didn't exists)
		// with new $ version 1.2.1 and noconflict(), it can be used again
		
		/**
		* with latest version of $ 1.2.1 li/label does not function properly, only label used here
		* $( 'form#editform' ).find( 'li/label' ).each( function( i ){
		*/
		var f = $$('form label'); // get all label elements within form
		
		for(var i=0; i<f.length; i++){
			
			var labelContent = f[i].innerHTML;
			var labelWidth = f[i].getStyle('width');
			var labelSpan = document.createElement( 'span' );
				labelSpan.style.display = 'block';
				labelSpan.style.width = labelWidth;
				labelSpan.innerHTML = labelContent;
			f[i].style.display = '-moz-inline-box';
			f[i].innerHTML = ""; // statt this.innerHTML = null; fuer opera 9.0
			f[i].appendChild( labelSpan );
			
		}
	  
		// Show forms
		// $$('form').show();
	
	} // end if
} // end form_ff_adapt


/**
 * SliderBanner
 * slide show for banner on home
 * with transition fade in and out
 */
var SliderBanner = Class.create();
SliderBanner.prototype = {
		initialize: function(target) {
		this.myTarget = $(target);
		this.myCurrent = $('first_slide');	
	},
	loadImage: function(imagePath) {
		var bannerImage = document.createElement('img');
		bannerImage.setAttribute('src', imagePath);	
		$(bannerImage).setStyle( { position: 'absolute', left: '0px', top: '0px', opacity: '0'  } );
		this.myTarget.appendChild(bannerImage);
		if (!bannerImage.complete) {
			Event.observe(bannerImage, 'load', this._onLoad.bindAsEventListener(null, this, bannerImage)); // load image
		} else {
			this._transImage(bannerImage);
		} // if
	},
	_onLoad: function(Event, Ref, bannerImage) {
		Ref._transImage(bannerImage);
	},
	_transImage : function(bannerImage) {
		new Effect.Appear(bannerImage, { duration: 2, from: 0.0, to: 1.0 } );
		if (this.myCurrent!=null) {
			new Effect.Appear(this.myCurrent, { duration: 2, from: 1.0, to: 0.0, afterFinish: this._removeImage });
		} // if
		this.myCurrent = bannerImage;
	},
	_removeImage: function(Ref) {
		Ref.element.remove();
	}
} // SliderBanner

/** array slides and slideIndex are defined in content/index.php */
function slider_banner() {
	slide_obj.loadImage(slides[slideIndex]); 
	
	slideIndex++; 
	if (slideIndex>=slides.length) slideIndex=0; 
	
} // slider_banner()
