/***************************************************************
 *  @author Leonhardt GmbH <serviceteam@leonhardt.de>
 *  @version 0.0.5
 *
 *  Prüfung für mobile Geräte und Neugestaltung des Seiteninhalts
 *
 *  Copyright notice
 *  (c) 2010 Leonhardt GmbH <serviceteam@leonhardt.de>
 *  All rights reserved
 *
 ***************************************************************/
var startpage = false;

function writeCookie(name, value, expDay){
	var now = new Date();
	var exp = new Date(now.getTime() + (1000 * 60 * 60 * 24 * expDay));
	
	document.cookie = name + "=" + escape(value) + ";" + "expires=" + exp.toGMTString() + ";" + "path=/";
}

function getCookie(name){
	var cn = name + "=";
	var dc = document.cookie;
	if (dc.length > 0) {
		var st = dc.indexOf(cn);
		if (st != -1) {
			st += cn.length;
			var sp = dc.indexOf(";", st);
			if (sp == -1) {
				sp = dc.length;
			}
			return unescape(dc.substring(st, sp));
		}
	}
	return null;
}

function delCookie(name){
	var now = new Date();
	var exp = new Date(now.getTime() - 1);
	
	document.cookie = name + "=;" + "expires=" + exp.toGMTString() + ";" + "path=/";
}

function writeHandheldCss(){
	$('link[media="handheld"]').each(function(){
		$(this).attr('media', 'screen');
	});
	if (document.URL.search(/index\.asp/) != -1) {
		var startpageScript = '<link rel="stylesheet" type="text/css" href="/content/language1/css/handheld_startpage.css" media="screen" />' +
		'<script type="text/javascript" src="/content/language1/scripts/handheld_startpage_de.js"></script>';
		document.write(startpageScript.toString());
		startpage = true;		
	}
	var c = getCookie('rbs-fontsize');
	if (c != null) {
		//$('body').css('font-size', '20px');
		var fontSizeCSS = '<style type="text/css">' +
		'	body{' +
		'		font-size:' + c + ';' +
		'	}' +
		'</style>';
		document.write(fontSizeCSS.toString());
	}
	
	var staticCSS = '<style type="text/css">' +
	'	#navi{' +
	'		display:none;' +
	'	}' +
	'</style>';
	document.write(staticCSS.toString());
}

function writeFallbackCssAndJs(){
	$('link[media="handheld"]').each(function(){
		$(this).attr('media', 'all');
	});
	var fakeJs = '<script type="text/javascript" src="/content/language1/scripts/fakeJs.js"></script>';
	document.write(fakeJs.toString());
	
	$().ready(function(){
		$('body').append("<script type='text/javascript'>" +
		"	$('.subPageContent').each(function(){" +
		"		$(this).css('display','block');" +
		"	});" +
		"	$('.stageBoxItem').each(function(){" +
		"		$(this).css('display','block');" +
		"	});" +
		"	$('.stageBoxMenu').css('display','none');" +
		"</script>");
	});
}

function in_array(item, arr){
	for (p = 0; p < arr.length; p++) 
		if (item == arr[p]) 			
			return true;
	return false;
}


jQuery.fn.outerHTML = function(){
	return $('<div>').append(this.eq(0).clone()).html();
};


function getDocUrl(){
	var docUrl = document.URL;
	var set;
	set = docUrl.replace(/\?version=pc/i, '');
	set = docUrl.replace(/\?version=mobile/i, '');
	set = docUrl.replace(/(&amp;|&)version=pc/i, '');
	set = docUrl.replace(/(&amp;|&)version=mobile/i, '');
	return set;
}

function recodeHead(){	
	var fontSizeLabel = 'A-';
	var c = getCookie('rbs-fontsize');
	if (c != null) {
		if(c == '20px'){
			fontSizeLabel = 'A-';
		}else{
			fontSizeLabel = 'A+';
		}
	}
	var mobileTopMenu = '<div id="mobileNavi">' +
	'	<div class="mobileHeadMenu">' +
	'		<div class="mhDivider"><!-- divider --></div>' +
	'		<div class="mhMenu arrowRight mhmMenu" id="mhmMenu">' +
	'			<a href="" onclick="showMenu();return false;">Menü</a>' +
	'			<div class="clear"></div>' +
	'		</div>' +
	'		<div class="mhDivider"><!-- divider --></div>' +
	'		<div class="mhMenu arrowRight mhmSearch" id="mhmSearch">' +
	'			<a href="javascript:showSearch();" onclick="">Suche</a>' +
	'		</div>' +
	'		<div class="mhDivider"><!-- divider --></div>' +
	'		<div class="mhMenu arrowLeft mhLang">' +
				$('.lang.langButton .link').html() +
	'			<div class="clear"></div>' +
	'		</div>' +
	'		<div class="mhDivider" id="mhDividerFontsize"><!-- divider --></div>' +
	'		<div class="mhMenu arrowLeft mhFontSize" id="mhFontsize">' +
	'			<a href="" onclick="changeFontSize(); return false;">' + fontSizeLabel + '</a>' +
	'			<div class="clear"></div>' + 
	'		</div>' +
	'		<div class="clear"></div>' +
	'	</div>' +
	'	<div id="mhSearch" style="z-index: 1;display:none;">' +
	'		<div class="activeMenuTabBottom"></div>' +
	'		<form action="4388.asp" id="mhSearchForm" name="mhSearchForm" onsubmit="fsearchstart(); return false;">' +
	'			<div class="searchInputWrap">' +
	'				<div class="searchInputOutline">' +
	'					<input id="searchtext" name="searchtext" value="" />' +
	'				</div>' +
	'			</div>' +
	'			<a class="searchLink" href="javascript:fsearchstart()">Suche starten</a>' +
	'			<div class="clear"></div>' +
	'		</form>' +
	'		<div class="searchBorderBottom"></div>' +
	'	</div>' +
	'</div>';
	
	$('.content').prepend(mobileTopMenu);
	
	$('#navi').before('<div class="activeMenuTabBottomWrap"><div class="activeMenuTabBottom"></div></div>');
	$('#navi').after('<div id="bcMobile">' + $('.navibackbox').outerHTML() + '</div>');
	
	// recodeIDs for cklick-Function in  Menu
	$('#navi #menuDiv .menuFold').each(function(){
		$(this).attr('id', $(this).attr('id') + 'YYY');
		var newLink = $(this).find('a').outerHTML().replace(/\'\)/, 'YYY\')');
		$(this).find('a').remove();
		$(this).prepend(newLink);
	});
	$('#navi #menuDiv .menuFoldhl').each(function(){
		$(this).attr('id', $(this).attr('id') + 'YYY');
		var newLink = $(this).find('a').outerHTML().replace(/\'\)/, 'YYY\')');
		$(this).find('a').remove();
		$(this).prepend(newLink);
	});
	$('#navi #menuDiv .sectionListHide').each(function(){
		$(this).attr('id', $(this).attr('id') + 'YYY');
	});
	$('#navi #menuDiv .sectionListShow').each(function(){
		$(this).attr('id', $(this).attr('id') + 'YYY');
	});
}

function recodeFooter(){	
	var footerMenu = '<div id="footerMenu">' +
	'	<div class="footerWrap">' + 
	'		<div class="searchBorderBottom"></div>' +
	'		<div class="fmLabel">' +
	'			Menü' +
	'		</div>' +
			$('#navi').html() + 
	'		<div class="searchBorderBottom"></div>' +
	'	</div>' +
	'</div>';
	
//	$('.footbox').prepend(footerMenu);
	$('#footerFirst').after(footerMenu);
	
	// recodeIDs for cklick-Function in Footer Menu
	$('#footerMenu #menuDiv .menuFold').each(function(){
		$(this).attr('id', $(this).attr('id') + 'XXX');
		var newLink = $(this).find('a').outerHTML().replace(/\'\)/, 'XXX\')');
		$(this).find('a').remove();
		$(this).prepend(newLink);
	});
	$('#footerMenu #menuDiv .menuFoldhl').each(function(){
		$(this).attr('id', $(this).attr('id') + 'XXX');
		var newLink = $(this).find('a').outerHTML().replace(/\'\)/, 'XXX\')');
		$(this).find('a').remove();
		$(this).prepend(newLink);
	});
	$('#footerMenu #menuDiv .sectionListHide').each(function(){
		$(this).attr('id', $(this).attr('id') + 'XXX');
	});
	$('#footerMenu #menuDiv .sectionListShow').each(function(){
		$(this).attr('id', $(this).attr('id') + 'XXX');
	});

}


function CreateDelegate(contextObject, delegateMethod){
	return function(){
		return delegateMethod.apply(contextObject, arguments);
	}
}


function imgTesting_onload(){
	var str = this.src.split('/');
	
	var imgCssObj = {
		'max-width': this.width,
		'max-height': this.height
	}
	$("img[src$='" + str[str.length - 1] + "']").css(imgCssObj);
}


function recodeContent(){
	// set keyv bg as img
	keyvisualArr = new Array();
	$('.keyvisual_img').each(function(index){
		keyvisualArr[index] = $(this).css('background-image').replace(/url\((.*)\)/i, "$1");
		if (keyvisualArr[index] != '' && keyvisualArr[index] != 'none' && keyvisualArr[index].match(/(.*)\.(jpg|jpeg|gif|png)/) != null) {
			$(this).removeAttr('style');
			keyvisualArr[index] = keyvisualArr[index].replace(/(\'|\"|%22)/g, "");
			$(this).prepend("<img src='" + keyvisualArr[index] + "' />");
			$(this).parent().css('display', 'block');
		}
		else {
			$(this).parent().css('display', 'none');
		}
	});
	$('.keyvisual_text').each(function(index){
		$(this).removeAttr('style');
	});
	$('#tagCloud').css('width', '100%');
	$('#tagCloud').parent().find('div').css('width', '100%');
	$('.tagCloudLink a').css('white-space', 'normal');
	$('.tagCloudLink').css('padding-right', '15px');
	
	// set pageheadline
	if ($('.contentheadline').length) {
		var contentheadline = '<div class="box">' + $('.contentheadline').outerHTML() + '</div>';
		$('.contentbox').prepend(contentheadline);
		$('.box .contentheadline:last').remove();
	}
	
	if ($('#navi .navibackbox .naviback').length) {
		$('#navi .navibackbox').css('display', 'block');
	}
	else {
		$('#navi .navibackbox').css('display', 'none');
	}
	
	// set img size
//	imgArr = new Array();
//	$('.content img').each(function(index){
//		var img = new Image();
//		img.onload = CreateDelegate(img, imgTesting_onload);
//		img.src = $(this).attr('src');
//	});
	
	// del line.gif
	$("img").filter(function(){
		if ($(this).attr('src').match(/line/) != null) {
			$(this).parent().css('display', 'none');
		}
	});
	
	$("img").filter(function(){
		if ($(this).attr('src').match(/weiss.jpg/) != null) {
			$(this).parent().css('display', 'none');
		}
	});
	
	$("img").filter(function(){
		if ($(this).attr('src').match(/spacher.gif/) != null) {
			$(this).parent().css('display', 'none');
		}
	});
}


function recodeSubPageMenu(){

	// markiere alle zu entfernenden subPageMenus
	$('.subPageMenu').each(function(){
		$(this).attr('class', 'del');
	});
	
	// erstelle neue subPageMenus und binde sie direkt vor dem dazugeh�rigen Content ein
	$('.subPageButton').each(function(){
		var newSubPageMenu = '<div id="subPageMenu" class="subPageMenu"><div class="subPageButtons"><div class="subPageButtonRow">';
		newSubPageMenu += $(this).outerHTML();
		newSubPageMenu += '</div></div></div>';
		var newID = $(this).attr('id').replace('PageButton', '');
		$('#' + newID + '').before(newSubPageMenu);
	});
	
	$('.subPageMenu .subPageButtons .subPageButtonRow .subPageInnerButton a').each(function(){
		var tmp = $(this).text();
		$(this).after('<div class="headline">' + tmp + '</div>');
		$(this).remove();
	});
//	//$('.subPageMenu').parent().append('<div class="subPageMenuBorderBottom"></div>')
	
	$('.subPageInnerButton a').each(function(){
		$(this).removeAttr("onclick");
	});
	
	// entferne alle markierten subPageMenus und subPageBrowse - Buttons
	$('.del').remove();
	$('.subPageBrowse').remove();
	
	// der Erste ist der aktive und alle anderen inaktive
	$('.subPageMenu:first .subPageInnerButton a').attr('class', 'activeSub');
	
	
	// setze die click-funktion neu
	/*$('.subPageInnerButton a').click(function(){
		var newID = $(this).attr('id').replace('a', '');
		if ($(this).attr('class') == 'activeSub') {
			$('#' + newID + '').css('display', 'none');
			$(this).attr('class', 'noActiveSub');
		}
		else {
			$('#' + newID + '').css('display', 'block');
			$(this).attr('class', 'activeSub');
			$('.subPageInnerButton a').not(this).attr('class', 'noActiveSub');
		}
		// entferne die subPageBrowse - Buttons
		$('.subPageBrowse').remove();
		if ($('.subPageContent:last').css('display') == 'block') {
			$('.subPageMenu:last').css('border-bottom', '1px solid #E1DCD1');
		}
		else {
			$('.subPageMenu:last').css('border-bottom', '10px solid #E1DCD1');
		}
	});*/
	$('.subPageMenu:last').css('border-bottom', '10px solid #E1DCD1');
	
}


function showMenu(){
	if ($('#navi').css('display') != 'block') {
		$('#navi').css('display', 'block');
		$('.activeMenuTabBottomWrap').css('display', 'block');
		$('#bcMobile .navibackbox:last').css('display', 'none');
		$('#bcMobile .navibackboxMenu').css('display', 'block');
		$('#mhmMenu').addClass('activeMenuTabTop');
	}
	else {
		$('#navi').css('display', 'none');
		if ($('#bcMobile .navibackbox:last .naviback').length) {
			$('#bcMobile .navibackbox:last').css('display', 'block');
		}
		else {
			$('#bcMobile .navibackbox:last').css('display', 'none');
		}
		$('#navi .navibackboxMenu').css('display', 'none');
		$('.activeMenuTabBottomWrap').css('display', 'none');
		$('#mhmMenu').removeClass('activeMenuTabTop');
	}
	if ($('#navi').css('display') == 'block' && $('#mhSearch').css('display') == 'block') {
		$('#mhSearch').css('display', 'none');
		$('#mhmSearch').removeClass('activeMenuTabTop');
	}
}


function showSearch(){
	if ($('#mhSearch').css('display') != 'block') {
		$('#mhSearch').css('display', 'block');
		$('#mhmSearch').addClass('activeMenuTabTop');
	}
	else {
		$('#mhSearch').css('display', 'none');
		$('#mhmSearch').removeClass('activeMenuTabTop');
	}
	
	if (($('#navi').css('display') == 'block') && ($('#mhSearch').css('display') == 'block')) {
		$('#navi').css('display', 'none');
		$('#mhmMenu').removeClass('activeMenuTabTop');
	}
	
}


function changeFontSize(){
	var c = getCookie('rbs-fontsize');
	var bodyFontsize = $('body').css('font-size');
	if (bodyFontsize == '16px') {
		$('body').css('font-size', '20px');
		$('#mhFontsize a').html('A-');
		$('#navi #mhSearch a img').css('margin-top', '3px');
		if (c != null) {
			delCookie('rbs-fontsize');
			writeCookie('rbs-fontsize', '20px', 1);		
		}else{
			writeCookie('rbs-fontsize', '20px', 1);
		}
	}
	else {
		$('body').css('font-size', '16px');
		$('##mhFontsize a').html('A+');
		$('#navi #mhSearch a img').css('margin-top', '0');
		if (c != null) {
			delCookie('rbs-fontsize');
			writeCookie('rbs-fontsize', '16px', 1);
		}else{
			writeCookie('rbs-fontsize', '16px', 1);
		}
	}
	$('#navi .mobileHeadMenu a').css('font-size', '12px');
	$('#navi .mobileHeadMenu a').css('line-height', '15px');
	
}


function recodeMediathek(){

	// headline an andere Seiten anpassen
	if ($('#mediathek').length) {
		$('#mediathek h1').wrap('<div class="headlineContainer" />');
		$('#mediathek h1').wrap('<div class="contentheadline" />');
	}
	
	
	if ($('#flashMediathekWrap')) {
		var screenWidth = screen.width;
		screenWidth = (screenWidth >= 680) ? 670 : screenWidth - 10;
		
		var screenHeight = (screenWidth >= 670) ? 466 : (screenWidth * 473) / 680;//(screenWidth * 0.695); 
		var mwPercent = (screenWidth * 100) / 680;
		var mhPercent = (screenHeight * 100) / 473;
		
		var mw = (mwPercent / 100) * 680;
		var mh = (mhPercent / 100) * 473;
		
		var flashWrapCssObj = {
			'width': mw,
			'min-width': mw,
			'max-width': mw,
			'height': mh,
			'min-height': mh,
			'max-height': mh
		}
		$('#flashMediathekWrap').css(flashWrapCssObj);
		$('#flashMediathekWrap').css('border-bottom', '10px solid #E1DCD1');
		$('#flashMT').css(flashWrapCssObj);
		$('#flashMT param').css(flashWrapCssObj);
		$('#flashMT embed').css(flashWrapCssObj);
		
		var screenMediaPlayerWidth = screen.width;
		screenMediaPlayerWidth = (screenMediaPlayerWidth >= 680) ? 670 : screenMediaPlayerWidth - 10;
		
		var screenMediaPlayerHeight = (screenMediaPlayerWidth >= 670) ? 466 : (screenMediaPlayerWidth * 473) / 680;//(screenWidth * 0.695); 
		var mpwPercent = (screenMediaPlayerWidth * 100) / 643;
		var mphPercent = (screenMediaPlayerHeight * 100) / 480;
		
		var mpw = (mwPercent / 100) * 643;
		var mph = (mhPercent / 100) * 480;
		
		var mediaplayerWrapCssObj = {
			'width': mpw,
			'min-width': mpw,
			'max-width': mpw,
			'height': mph,
			'min-height': mph,
			'max-height': mph
		}
		
		$('#flashMediaplayerWrap').css(mediaplayerWrapCssObj);
		$('#rbs_mediaplayer').css(flashWrapCssObj);
		$('#rbs_mediaplayer param').css(flashWrapCssObj);
		$('#rbs_mediaplayer embed').css(flashWrapCssObj);
		$('#dialog').css(flashWrapCssObj);
		
		$('.container').css('width', mw);
	}
}


function resizePlayer(){
	if (!$('#flashMediathekWrap')) {
		$('.flashbox').each(function(){
			var screenMediaPlayerWidth = screen.width;
			screenMediaPlayerWidth = (screenMediaPlayerWidth >= 680) ? 670 : screenMediaPlayerWidth - 10;
			
			var screenMediaPlayerHeight = (screenMediaPlayerWidth >= 670) ? 466 : (screenMediaPlayerWidth * 473) / 680;//(screenWidth * 0.695); 
			var mpwPercent = (screenMediaPlayerWidth * 100) / 643;
			var mphPercent = (screenMediaPlayerHeight * 100) / 480;
			
			var mpw = (mwPercent / 100) * 643;
			var mph = (mhPercent / 100) * 480;
			
			var mediaplayerWrapCssObj = {
				'width': mpw,
				'min-width': mpw,
				'max-width': mpw,
				'height': mph,
				'min-height': mph,
				'max-height': mph
			}
			
			$(this).css(mediaplayerWrapCssObj);
			$(this + ' div').css(mediaplayerWrapCssObj);
			$(this + ' param').css(mediaplayerWrapCssObj);
			$(this + ' embed').css(mediaplayerWrapCssObj);
		});
	}
}


function delSearchResultFixedWidth(){
	if (document.URL.search(/4388\.asp/) != -1) {
		var searchTextBoxWidth = screen.width;
		searchTextBoxWidth = (searchTextBoxWidth >= 680) ? 660 : searchTextBoxWidth - 20;
		
		$('.box .textbox').removeAttr('style');
		var searchTextBoxCssObj = {
			'min-width': '230px',
			'max-width': '670px',
			'padding': '0 0 10px 0',
			'float': 'left !important',
			'width': '100%'			
		}
		//$('.box .textbox').css('width', 'auto');
	}
}


function delSearchInputDefaultValue(){
	$('#mhSearch #searchtext').focus(function(){
		if ($(this).val() == '...') {
			$(this).val('');
		};
			});
}


function recodePcVersionHeaderAndFooterLinks(){
	var headNaviLinks = $('.head_navi_btns').html();
	
	var footerNaviLinks = writeMobileVersionLink();
	footerNaviLinks += $('.foot_navi .link .rssIcon').parent().outerHTML();
	footerNaviLinks += $('.foot_navi .link.addThisDiv').outerHTML();
	
	$('.foot_navi .link a.rssIcon').parent().css('display', 'none');
	$('.foot_navi .link.addThisDiv').css('display', 'none');
	$('.foot_navi').prepend(headNaviLinks);
	$('.foot_navi span').css('display', 'block');
	$('.foot_navi span').css('float', 'left');
	$('.head_navi_btns span.link').css('display', 'none');
	$('.head_navi_btns').prepend(footerNaviLinks);
	$('.head_navi_btns div').css('display', 'inline');
	//$('.head_navi_btns .link.addThisDiv a').removeClass('addthis_button_compact addthis at300m');
	
	var bookmarkCssObj = {
		'background-image': 'url("/content/language1/shared/mobile_RBS_Mobil_Footer_Bookmark.gif")',
		'background-position': '0 0',
		'padding-left': '25px',
		'padding-bottom': '5px',
		'margin-left': '5px'
	}
	$('.head_navi_btns .link.addThisDiv a').append('<span style="background:none;" class="at300bs at15t_compact"></span><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js?pub=xa-4ac2220d52fc2665"></script>');
	
	$('.head_navi_btns .link.addThisDiv a').css(bookmarkCssObj);
	$('.head_navi_btns .link.addThisDiv a').hover(function(){
		$(this).css('background-image', 'url("/content/language1/shared/mobile_Bookmark_hover.gif")');
	}, function(){
		$(this).css('background-image', 'url("/content/language1/shared/mobile_RBS_Mobil_Footer_Bookmark.gif")');
	});
	
	
	var rssCssObj = {
		'background-image': 'url("/content/language1/shared/mobile_RBS_Mobil_Footer_RSS.gif")',
		'background-position': '0 0',
		'padding-left': '25px',
		'padding-bottom': '5px',
		'margin-left': '5px'
	}
	$('.head_navi_btns .link .rssIcon').css(rssCssObj);
	$('.head_navi_btns .link .rssIcon').hover(function(){
		$(this).css('background-image', 'url("/content/language1/shared/mobile_RSS_hover.gif")');
	}, function(){
		$(this).css('background-image', 'url("/content/language1/shared/mobile_RBS_Mobil_Footer_RSS.gif")');
	});
	
	var mobileVersionCssObj = {
		'background-image': 'url("/content/language1/shared/mobile_Mobil.gif")',
		'background-position': '0 0',
		'background-repeat': 'no-repeat',
		'padding-left': '25px',
		'padding-bottom': '5px',
		'margin-left': '5px'
	}
	$('.head_navi_btns .link.mobileVersion a').css(mobileVersionCssObj);
	$('.head_navi_btns .link.mobileVersion a').hover(function(){
		$(this).css('background-image', 'url("/content/language1/shared/mobile_Mobil_hover.gif")');
	}, function(){
		$(this).css('background-image', 'url("/content/language1/shared/mobile_Mobil.gif")');
	});
	
	$('#formoff a').hover(function(){
		$(this).css('background-image', 'url("/content/language1/shared/arrowhl.gif")');
	}, function(){
		$(this).css('background-image', 'url("/content/language1/shared/arrow.gif")');
	});
	
	$('.lang.langButton a').hover(function(){
		$(this).css('background-image', 'url("/content/language1/shared/arrowhl.gif")');
	}, function(){
		$(this).css('background-image', 'url("/content/language1/shared/arrow.gif")');
	});
	
	$('.foot_navi .link a').hover(function(){
		$(this).css('background-image', 'url("/content/language1/shared/arrowhl.gif")');
	}, function(){
		$(this).css('background-image', 'url("/content/language1/shared/arrow.gif")');
	});
	
	
	$('.container').prepend('<a style="width:0;height:0;" name="topofpage"></a>');
	$('.foot_navi').prepend('<div class="link"><a class="topOfPage" href="#topofpage">zum Seitenanfang</a></div>');
	$('.foot_navi .topOfPage').css('padding-right', '140px');
	$('.foot_navi .topOfPage').css('padding-left', '10px');
	$('.foot_navi .topOfPage').css('background-image', 'url("/content/language1/shared/mobile_arrow_grey_top_6x9.gif")');
	$('.foot_navi .topOfPage').hover(function(){
		$(this).css('background-image', 'url("/content/language1/shared/mobile_arrow_red_top_9x4.png")');
	}, function(){
		$(this).css('background-image', 'url("/content/language1/shared/mobile_arrow_grey_top_6x9.gif")');
	});
	$('.head_navi').css('padding-right', '5px');
}

function testVideoTagAndCodec(){
	var videoElement = document.createElement('video');
	return !!(videoElement.canPlayType && videoElement.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''))
}
function testVideoTag(){
	var videoElement = document.createElement('video');
	return !!(videoElement.canPlayType)
}



function mobileDetection(){
	var c = getCookie('rbs');
	if (c != null) {
		if (document.URL.search(/version=pc/) != -1) {
			if (c != 'pc') {
				delCookie('rbs');
				writeCookie('rbs', 'pc', 1);
				return 'pc';
			}else{
				return c;
			}
		}else if (document.URL.search(/version=mobile/) != -1) {
			writeCookie('rbs', 'high', 1);
			return 'high';
		}else{
			return c;
		}
	}
	
	var screenWidth = screen.width;
	if(screenWidth < 640){
		if(testVideoTag()){
			writeCookie('rbs', 'high', 1);
			return 'high';
		}else{
			writeCookie('rbs', 'low', 1);
			return 'low';
		}
	}else{
		var userAgent = navigator.userAgent;
		var userAgentToLower = userAgent.toLowerCase();
		if (userAgentToLower.match(/(Android|iPhone|iPod)/i)) {
			writeCookie('rbs', 'high', 1);
			return 'high';
		}
		writeCookie('rbs', 'pc', 1);
		return 'pc';
	}
}

var md = mobileDetection();


switch (md) {
	case 'high':
		var screenWidth = screen.width;
		writeHandheldCss();
		
		$().ready(function(){
			recodeHead();
			if (startpage) {
				recodeStartpage();
			}
			recodeContent();
			recodeSubPageMenu();
			recodeMediathek();
			resizePlayer();
			delSearchResultFixedWidth();
			delSearchInputDefaultValue();
			recodeFooter();
			
			
			//			$('.contentbox').css('display', 'block');
//			$('.contentbox').toggle();
//			$('.footer').css('display', 'block');
			
			$('a.playOverlayVideoPlayer').live('click', function(e){
				var playerWidth = (navigator.appName.indexOf('Netscape') != -1) ? self.innerHeight : document.body.clientHeight;
				playerWidth = (playerWidth >= 680) ? 680 : playerWidth;
				playerWidth = playerWidth - 10;
				
				var path = $(this).attr("rel");
				$(this).attr('href', path);
				$(this).attr('target', '_blank');
				var html = "";
				var type = path.search(/\.mp3/);
				if (type != -1) {
					html += '<audio src="' + path + '" controls="controls" width="auto" height="auto" style="margin-bottom:10px;max-width:' + playerWidth + 'px;">' +
					'</audio>';
					$(this).parents('.mediaStageBoxContent').find('.image.imgblock').html(html);
					return false;
				}
				else {
					var format = path.search(/\.mp4/);
					if (format != -1) {
						html += '<video controls="controls" width="auto" height="auto" preload="auto" poster="" style="margin-bottom:10px;max-width:' + playerWidth + 'px;">' +
						'	<source src="' +
						path +
						' " type="video/mp4" />' +
						'</video>';
						//alert($(this).parents('.mediaStageBoxContent .image.imgblock').html());
						$(this).parents('.mediaStageBoxContent').find('.image.imgblock').html(html);
						return false;
					}
					else {
						var tmp = $(this).parents('.mediaStageBoxContent').find('.image.imgblock').html();
						html += tmp;
						$(this).attr('href', path);
						$(this).attr('target', '_blank');
					//						$(this).parents('.mediaStageBoxContent').html(html);
					}
				}
			});
			
			var spacer = 5;
			$(".switchBoxItem .text").each(function(i){
				theHeight = $(this).height();
				heightArray[i] = (i > 0) ? parseInt(theHeight + spacer) : theHeight;
			});
			
			$('.switchBox').each(function(){
				$(this).find(".text").show();
				$(this).find(".headline").removeClass("headline").addClass("headlineXXX");
				$(this).find(".headlineXXX").addClass("colorRed");
				$(this).find(".headlineXXX").css("cursor","auto");
				$(this).find(".switchIcon").empty();
				$(this).find(".switchIcon").append("<img src='http://www.bosch-stiftung.de/content/language1/shared/iconRed.gif' width='10' height='10' border='0' alt=''/>");
			});
			
			$('.listenbox_sp2_text').each(function(){
				$(this).find('div.link:first').css('margin-top', '10px');
			});
			
		});
		break;
	case 'low':
		writeFallbackCssAndJs();
		break;
	default:
		$().ready(function(){
			//writeMobileVersionLink();
			//recodePcVersionHeaderAndFooterLinks();
		});
}

