/**
* JavaScript für »Thüringen für Kinder«
* Flash-Animation auf der Startseite soll beim Verlassen (Link-Klick oder Form-Submit)
* getauscht werden;
* geschieht über Interaktion mit dem Actionscript
*
* © 2008 <i-D> internet & Design GmbH & Co. KG
* Erfurter Str. 35
* 99423 Weimar
* Deutschland
* Fon:     03643 7785 0
* Fax:     03643 7785 29
* E-Mail:  office@i-d.de
* Web:     http://www.i.d.de/
*
* @author Niels Bobogk <n.bobogk@i-d.de>
*/

// --------------------------------------------------------------------------------

// Abk. f. document
if (!d) var d    = document;

// ID des swf-Containers für die Animation
var SWF_ID       = "flashLoewe";

// ID Ladeanimation
var LADEANI_ID   = "ajaxLoader";

// Transparenz geht nicht in linux, daher nur statisches Bild lassen
var COMPATIBLE   = !( navigator.userAgent.toLowerCase().indexOf('linux') != -1 );

// --------------------------------------------------------------------------------

// wenn kompatibel, dann das Start-swf mit swfObject laden
// geaendert erster Parameter von: "/kinderinternet/swf/kinderinternet.swf"
//if (COMPATIBLE) {
//	swfobject.embedSWF(
//		"/kinderinternet/swf/ludwig_start_1.swf", 
//		SWF_ID, 
//		"200", 
//		"300", 
//		"9.0.28.0", 
//		false, 
//		{
//			url1:               "/kinderinternet/swf/ludwig_start_1.swf", // erste Animation (winkender Löwe; Standard)
//			url2:               "/kinderinternet/swf/ludwig_start_2.swf", // zweite Animation beim Verlassen (Löwe geht)
//			debugmode:          "false", // Anzeige von Debuginformationen
//			waitSecondAni:      "false"  // ob auf zweite Animation gewartet werden soll oder bei nicht fertig geladenem Zustand der URL sofort gewechselt wird
//		}, 
//		{
//			wmode:              "transparent", 
//			allowScriptAccess:  "sameDomain"
//		}, 
//		{
//			id:                 SWF_ID
//		}
//	);
//}

// --------------------------------------------------------------------------------

/**
* URL wechseln (bei Link) bzw. Form absenden
* Quelle aus der globalen Variable
*/
function changeURL() {
	// Ladeanimation ausblenden
	if ($(LADEANI_ID)) {
		$(LADEANI_ID).hide();
	}
	if ($('skipIntro' + SWF_ID)) {
		$('skipIntro' + SWF_ID).hide();	
	}

	try {
		// Formular
		if (d.globalAniEventTarget.tagName.toLowerCase() == 'form') {
			d.globalAniEventTarget.submit()
		} else if (d.globalAniEventTarget.tagName.toLowerCase() == 'a' && !d.globalAniEventTarget.rel.empty()) {
			location.href = d.globalAniEventTarget.rel;
		}
	} catch(err) {
		// alert(err);	
	}
}

// --------------------------------------------------------------------------------

/**
* Dispatcher-Funktion 
* wird aus dem swf-Actionscript aufgerufen
*/
function callbackFromActionScript() {
	// timeout entfernen, wird sonst nach Backbutton ausgeführt
	window.clearTimeout(d.animationTimeout);
	// URL wechseln
	changeURL(d.animationTimeout);
}

// --------------------------------------------------------------------------------

/** 
* Animation wechsel
* ruft swf-Actionscriptfunktion auf
*
* @param Event click/submit-Event
*/
function toggleAni(event) {
	// Aufrufer direkt merken
	if (Event.element(event).tagName.toLowerCase() == 'form'
		|| Event.element(event).tagName.toLowerCase() == 'a') {
		d.globalAniEventTarget = Event.element(event);
	} 
	// oder Quelle suchen
	else {
		try
		{
			d.globalAniEventTarget = $(Event.element(event)).up('a'); 
		} catch (err) { 
			// alert(err);
		}
	}
	
	// Ladeanimation einblenden
	if ($(LADEANI_ID)) {
		$(LADEANI_ID).show();
	}
	d.skipIntro.show();
	
	// Actionscript aufrufen
	$(SWF_ID).StartSecondAnimation();
}

// --------------------------------------------------------------------------------

/**
* Initialisierung beim window.onload
* registriert alle Links und Formulare für den Animationswechsel
*/
Event.observe (window, 'load', function() { 
	// Ladeanimation ausblenden
	if ($(LADEANI_ID)) {
		$(LADEANI_ID).absolutize();
		$(LADEANI_ID).hide();
	}
	
	// Animation refreshen
	if ($(LADEANI_ID)) {
		$(LADEANI_ID).src = $(LADEANI_ID).src;	
	}
	
	// Aenderung 2009-06-05: Wechsel entfaellt
	return;
	
	if (COMPATIBLE && $(SWF_ID).tagName.toLowerCase() == 'object') {
		try
		{
			// alle Links reg.
			for (var i = 0; i < d.links.length; i++) {
				d.links[i].rel = d.links[i].href;
				d.links[i].href = 'javas' + 'cript:;'
				Event.observe(document.links[i], 'click', toggleAni);
			}
			
			// alle Formulare reg.
			for (var j = 0; j < d.forms.length; j++) {
				Event.observe($(d.forms[j]), 'submit', function (event) {
					Event.stop(event);	
					toggleAni(event);	
				});
			}
			
			// Skip Intro
			d.skipIntro = new Element('a', {id: 'skipIntro' + SWF_ID}).setStyle({opacity: 0.5, display: 'block', textAlign: 'right', width: '410px', position: 'absolute', left: '0px', top: '16px', cursor: 'pointer'});
			d.skipIntro.update('Animation &uuml;berspringen!');
			Event.observe(d.skipIntro, 'click', changeURL);
			d.skipIntro.hide();
			$(SWF_ID).ancestors()[0].insert(d.skipIntro);
		} catch (err) {
			// alert(err);
		}
	}
});


