/* this javascript needs jquery */

/*
jquery.flash v1.3.1 -  02/01/10
(c)2009 Stephen Belanger - MIT/GPL.
http://docs.jquery.com/License
*/
Array.prototype.indexOf=function(o,i){for(var j=this.length,i=i<0?i+j<0?0:i+j:i||0;i<j&&this[i]!==o;i++);return j<=i?-1:i;};$.fn.extend({flash:function(opt){var has,cv,ie;function attr(a,b){return' '+a+'="'+b+'"';}function param(a,b){return'<param name="'+a+'" value="'+b+'" />';}var p=navigator.plugins;if(p&&p.length){var f=p['Shockwave Flash'];if(f){has=true;if(f.description)cv=f.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split(".");}if(p['Shockwave Flash 2.0']){has=true;cv='2.0.0.11';}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");cv=[6,0,21];has=true;}catch(e){};try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){};}if(axo!=null){cv=axo.GetVariable("$version").split(" ")[1].split(",");has=true;ie=true;}}$(this).each(function(){if(has){var e=$(this),s=$.extend({'id':e.attr('id'),'class':e.attr('class'),'width':e.width(),'height':e.height(),'src':e.attr('href'),'classid':'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000','pluginspace':'http://get.adobe.com/flashplayer','availattrs':['id','class','width','height','src'],'availparams':['src','bgcolor','quality','allowscriptaccess','allowfullscreen','flashvars','wmode'],'version':'9.0.24'},opt),a=s.availattrs,b=s.availparams,rv=s.version.split('.'),o='<object';if(!s.codebase){s.codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+rv.join(',');}if(s.express){for(var i in cv){if(parseInt(cv[i])>parseInt(rv[i])){break;}if(parseInt(cv[i])<parseInt(rv[i])){s.src=s.express;}}}if(s.flashvars){s.flashvars=unescape($.param(s.flashvars));}a=ie?a.concat(['classid','codebase']):a.concat(['pluginspage']);for(k in a){var n=(k==a.indexOf('src'))?'data':a[k];o+=s[a[k]]?attr(n,s[a[k]]):'';};o+='>';for(k in b){var n=(k==b.indexOf('src'))?'movie':b[k];o+=s[b[k]]?param(n,s[b[k]]):'';};o+='</object>';e.replaceWith(o);}return this;});}});

  
 function create_icon(icon)
 {
    return '<img src="layout/ensser/img/'+icon+'.gif" class="link-icon" />';
 }
 

 $(document).ready(function(){
							
    /* Helper for mm_forum templates */
	$('.tx-mmforum-pi1-markread').next('<br />').remove();
	
    $("a:has(img)").addClass("img");
	
	$("a[href^='javascript:linkTo_UnCryptMailto']").addClass("email");
	// link icons: because of the IE multiline problem do not use css classes
	$("a[href$='.pdf']").not("[class='img']").append(create_icon('pdf'));
	$("a[href$='.rtf']").not("[class='img']").append(create_icon('doc'));
	$("a[href$='.doc']").not("[class='img']").append(create_icon('doc'));
	$("a[href$='.flv']").not("[class='img']").append(create_icon('video'));
	// in section TRAEGER and PRESSE do not display link icons 
	
		// if ther follows a , or a . or a ) the link, img will get class link-icon2
    // IE has it's own html() 
	$("p a img.link-icon").parents('p').each(function(){
		// alert($(this).html());
        var expr = /link-icon([^>]*)><\/a>([,\.\)]{1})/gi;
		var repl = 'link-icon2$1></a>$2';
		$(this).html($(this).html().replace(expr,repl));	
	});	
	
	/* No img for external links
	if($("#b1172").length == 0 && $("#b1179").length == 0) 
	{
		$("a[href^='http']").not("[class='img']").append(create_icon('link_extern'));
	}
	*/
	
	// open external links with target _blank	
	$("a[href^='http']").attr('target','_blank');
	$(".search_result a[href^=http]").attr('target','_self');
	
	if(!$('.tx-mmforum-pi1').length){
		$("#container a:not([href^=http])").not("[href^=#]").not("[href^='javascript:linkTo_UnCryptMailto']").not("[href$='.pdf']").not("[href$='.doc']").not("[id^='c']").not("[class='img']").prepend("»&nbsp;");
	}
	
	
	$("p:contains('(at)')").each(function(){
		// alert($(this).html());
		var filter = /<span> \(at\) <\/span>/i;
		var at = "@";
		$(this).html($(this).html().replace(filter,at));	
	});	

	
		//zebra table
	//$("tr:nth-child(odd)").addClass("odd");
	$("tr:odd").addClass("odd");
	
	
		
	
	// Flash video pages
	
	$('a[href$=".mp4"], a[href$=".flv"]').click( function(){ 		
														 
			// close flasplayer
			if($('#flash-container').length != 0 ) {
				$('#flash-container').remove();
			}
			// video url is linked, so get the location									 
			var videoURL = this.href;
			// get the pathname of the current file
			var playerURL = 'fileadmin/player.swf';			
			// console.info(playerURL, 'playerURL');
			
			// built the video container so that it is displayed on the right site
			var flashContainer = '<div id="flash-container"><div id="flashplayer"></div></div>';
			if ($(this).parents('.csc-textpic-imagewrap').length > 0)
			{
				// alert ('Ok: csc-textpic-imagewrap');
				$(this).parents('.csc-textpic-imagewrap').before( flashContainer );
			 
			} else if ($(this).parent('strong').length > 0) {				
 				 $(this).parent('strong').parent('p,td,li,ol').css({'position': 'relative'});
				 $(this).parent('strong').parent('p,td,li,ol').prepend( flashContainer );					 
				// alert('TEST: '+ $(this).parent('strong').parent('p,td').html());
				 
			} else {
				 $(this).parent('p,td,li,ol').css({'position': 'relative'});
				 $(this).parent('p,td,li,ol').prepend( flashContainer );	
			}		
			
			if ($('td:has(#flash-container)').length != 0 && $('td p:has(#flash-container)').length == 0) {
				var top = $('td:has(#flash-container)').position().top;
		    	$('td #flash-container').css({'top': top+'px'});
				// alert('TOP: '+top+'px');
			}
				
			// fill in the video flash width jquery-flash.js
			// videoURL = 'http://content.longtailvideo.com/videos/flvplayer.flv';
			$('#flashplayer').flash(
			{
				'src': playerURL, 
				'height': '240',  
				'width': '320', 
				'bgcolor': '#ffffff', 
				'wmode': 'opaque', 
				'allowscriptaccess': 'always', 
				'version': '9.0.115', 
				  flashvars: { 
					'file': videoURL,
					'provider': 'video',
					// 'bufferlength': '10',
					'controlbar': 'over', 
					'dock': 'false', 
					// 'plugins': 'false',
					'plugins' : 'viral-2', 'viral.onpause' : 'false', 'viral.allowmenu' : 'false',
					'viral.functions' : 'link',
					'fullscreen': 'false', 
					'stretching': 'uniform', //strech
					'smoothing': 'false',
					'autostart': 'true' 
				}
			});
			// write the remove link
			$('#flash-container').append('<p class="flashplayer-close-link">Close Flashplayer</p>');
			$('#flash-container p').click(function(){$('#flash-container').remove();});
	
			return false;
	 });
	
});
