/**
 * globale variable die alle flashanimationen und ihre daten enthält
 */
var flashAnis = new Array();

/**
 * Funktion die Flashelemente zur seite hinzufügt
 *
 * @param string containerid	//id des elements das die animation enhält
 * @param string filename			//dateiname/pfad der animation
 * @param string flashid			//id des embed-elements das erzeugt wird
 * @param string width				//breite ohne px angabe bsp: "230"
 * @param string height				//hoehe ohne px angabe bsp: "230"
 * @param string bgcolor			//bgcolor von containerid (falls die animation kleiner ist als width und heigth)
 */				
 

 
function addFlash(containerid, filename, flashid, width, height, bgcolor){
	number = flashAnis.length;
	flashAnis[number] = new Object();
	flashAnis[number]['containerid'] = containerid;
	flashAnis[number]['filename'] = filename;
	flashAnis[number]['flashid'] = flashid;
	flashAnis[number]['height'] = height;
	flashAnis[number]['width'] = width;
	flashAnis[number]['bgcolor'] = bgcolor;
	var flashmovie = new SWFObject(filename, flashid, width, height, "8", bgcolor);
	flashmovie.write(containerid);
}

/**
 * Funktion die alle flashanimationen von der seite entfernt
 * ACHTUNG: Funktioniert nur wenn sie mit addflash angelegt wurden
 */
function hideFlashAnis(){
	for(i=0; i<flashAnis.length;i++){
		$('#'+flashAnis[i]['containerid']).empty();	
	}
}

/**
 * Funktion die alle flashanimationen wieder auf der Seite einbaut
 * ACHTUNG: Funktioniert nur wenn sie mit addflash angelegt wurden
 */				
function showFlashAnis(){
	for(i=0; i<flashAnis.length;i++){
		var flashmovie = new SWFObject(flashAnis[i]['filename'], flashAnis[i]['flashid'], flashAnis[i]['width'], flashAnis[i]['height'], "8", flashAnis[i]['bgcolor']);
		flashmovie.write(flashAnis[i]['containerid']);
	}
}							

/**
 * wird beim schliessen des modalfensters aufgerufen
 * entfernt die flashanimation im modal und blendet alle anderen animationen wieder ein
 */				
function modalClose (dialog) {
	$('#flashmovie').empty();	
	/*
	dialog.data.fadeOut('slow', function () {
		dialog.container.hide('slow', function () {
			dialog.overlay.slideUp('slow', function () {
				$.modal.close();
			});
		});
	});
	*/
	$.modal.close();
	showFlashAnis();
}				

/**
 * wird beim öffnen des modalfensters aufgerufen
 * erzeugt neue flashanimation im modalfenster
 * @param object dialog				//objektzeiger auf das ausführende objekt
 * @param string containerid	//id des elements das die animation enhält
 * @param string flashfile		//dateiname/pfad der animation
 * @param string flashid			//id des embed-elements das erzeugt wird
 * @param string width				//breite ohne px angabe bsp: "230"
 * @param string height				//hoehe ohne px angabe bsp: "230"
 * @param string bgcolor			//bgcolor von containerid (falls die animation kleiner ist als width und heigth) 
 */
function modalOpen (dialog, writeto, flashfile, flashid, flashwidth, flashheight, flashcolor) {
	//iehack - flash kommt nur oben...
	if ($.browser.msie) {
		$('#toupper').click();
	}
	var so = new SWFObject(flashfile, flashid, flashwidth, flashheight, "8", flashcolor);
	so.write(writeto);
	dialog.overlay.fadeIn('fast', function () {
		dialog.container.fadeIn('fast', function () {
			dialog.data.hide().slideDown('fast');	 
		});
	});
}	

/**
 * ruft das modalfenster auf, blendet alle anderen flashelemente aus und zeigt eine flashanimation im modalen fenster
 * 
 * @param string toclickid							//das element mit dieser id löst das modalfenster beim click aus
 * @param string modalcontainerid				//dies ist die id des modalcontainers - in diesen alles reinpacken was modal angezeigt wird
 * @param string modalflashcontainerid	//hier wird das flashfile hineingepackt
 * @param string flashfile							//dateiname/pfad der modalenanimation
 * @param string flashid								//id des modalen-embed-elements das erzeugt wird
 * @param string width									//breite ohne px angabe bsp: "230"
 * @param string height									//hoehe ohne px angabe bsp: "230"
 * @param string bgcolor								//bgcolor von modalflashcontainerid (falls die animation kleiner ist als width und heigth) 
 */
function modalFlash(toclickid, modalcontainerid, modalflashcontainerid, flashfile, flashid, flashwidth, flashheight, flashcolor){
	$('#'+toclickid).click(function (e) {
		e.preventDefault(); 
		hideFlashAnis();
		$('#'+modalcontainerid).modal ({
				onClose: function (e) {
					modalClose(e);
				},
				onOpen: function (e){
					//bindet das im modalfenster anzuzeigende flash ein
					modalOpen(e, modalflashcontainerid, flashfile, flashid, flashwidth, flashheight, flashcolor);
				},
				overlay: 80 //setzt opacity auf 80% oder 0.8
		});
	});	
}

/**
 * IE Workaround for resizing
 */
function resizeBackground(){
	if ($.browser.msie) {
		$('#modalOverlay').css('height','100%');
		$('#modalOverlay').css('width','100%');
	}
}

