function decode_utf8(utftext) {
	var plaintext = ""; var i=0; var c=c1=c2=0;
	// while-Schleife, weil einige Zeichen uebersprungen werden
	while(i<utftext.length) {
		c = utftext.charCodeAt(i);
		if (c<128) {
			plaintext += String.fromCharCode(c);
			i++;
		} else if((c>191) && (c<224)) {
			c2 = utftext.charCodeAt(i+1);
			plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
			i+=2;
		} else {
			c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
			plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
			i+=3;
		}
	}
	return plaintext;
}

function strip_tags($text){
	return $text.replace(/<\/?[^>]+>/gi, '');
}

function phpserialize (a) {
	// This converts a javascript array to a string in PHP serialized format.
	// This is useful for passing arrays to PHP. On the PHP side you can
	// unserialize this string from a cookie or request variable. For example,
	// assuming you used javascript to set a cookie called "php_array"
	// to the value of a javascript array then you can restore the cookie
	// from PHP like this:
	//	&lt;?php
	//	session_start();
	//	$my_array = unserialize(urldecode(stripslashes($_COOKIE['php_array'])));
	//	print_r ($my_array);
	//	?&gt;
	// This automatically converts both keys and values to strings.
	// The return string is not URL escaped, so you must call the
	// Javascript "escape()" function before you pass this string to PHP.

	var a_php = "";
	var total = 0;
	for (var key in a)
	{
		++ total;
		a_php = a_php + "s:" +
				String(key).length + ":\"" + String(key) + "\";s:" +
				String(a[key]).length + ":\"" + String(a[key]) + "\";";
	}
	a_php = "a:" + total + ":{" + a_php + "}";
	return a_php;
	// return a;
}

function initNews( i_L, s_LANG ) {
	ua_iphone = (navigator.userAgent.toLowerCase().indexOf('iphone')!=-1);
	ua_ipad = (navigator.userAgent.toLowerCase().indexOf('ipad')!=-1);

	if ($('#intro').length>0) {
		var so = new SWFObject("fileadmin/davedolle/swf/news_080326.swf", "ddintro", "629", "314", "8", "#ffffff", "BEST");
		so.addParam( "wmode",		   "transparent" );
		so.addVariable( "s_xmlURL",	 escape("fileadmin/davedolle/inc/news_xml.php?L="+ i_L +"&"));
		// so.addVariable( "s_newsURL",	escape(""+ s_LANG +"/news/"));
		so.addVariable( "s_newsURL",	'');
		so.addVariable( "s_imagePath",  escape("fileadmin/Eigene_Dateien/News/"));
		so.write( "intro" );
	}

	if(ua_iphone || ua_ipad)
		$('#intro').addClass('introLoaded');
}

function initMenu( i_uid, i_L, i_trainer_id ) {
	var so = new SWFObject("fileadmin/davedolle/swf/menu.swf", "ddmenu", "129", "500", "8", "#ffffff", "BEST");
	so.addVariable( "s_uniqueID",   i_uid );
	// so.addVariable( "s_xmlPath",	escape("index.php?id=###UID###&L=###L###&type=100") );
	so.addVariable( "s_xmlPath",	escape("index.php?id="+ i_uid +"&L="+ i_L +"&type=100&trainer_id="+ i_trainer_id) );
	so.addParam( "wmode", "transparent" );
	so.write( "nav" );
}


function initFacebook() {
	$("a.Facebook").tooltip({
		tip: '#Facebook',
		position: 'bottom right',
		effect: 'slide',
		slideFade: true,
		bounce: true,
		direction: 'right',
		offset: [0, -30]
	}); 
}


function initWidgets(lang) {
	$('#ddWidgetLoader').load('/'+lang+'/widgets #ddWidgets', function(){
		Cufon.refresh();
		$('#ddWidgetLoader').animate({"top":0, "opacity":1});
	});
}


function initDaveDolle( uid, l, lang, trainer_id) {
	initNews( l, lang );
	initMenu( uid, l, trainer_id );
	initLightbox();
	initFacebook();
	initWidgets( lang );
}
