/*
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;});}});



/**
Vertigo Tip by www.vertigo-project.com
Requires jQuery
*/
jQuery(document).ready(function($){vtip();}) 

this.vtip = function() {    
    this.xOffset = -10; // x distance from mouse
    this.yOffset = 10; // y distance from mouse       
    
    $('.vtip').unbind().hover(    
        function(e) {
            this.t = this.title; 
            this.title = ''; // do not show title tooltip
            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
            
            $('body').append( '<p id="vtip"><img id="vtipArrow" />' + this.t + '</p>' );
                        
            $('p#vtip #vtipArrow').attr('src', './layout/gmo-free-regions/img/vtip_arrow.gif');
            $('p#vtip').css('top', this.top+'px').css('left', this.left+'px').fadeIn();
            
        },
        function() {
            this.title = this.t;
            $('p#vtip').fadeOut().remove();
        }
    ).mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);
                         
            $('p#vtip').css('top', this.top+'px').css('left', this.left+'px');
        }
    );            
    
};

  
 function create_icon(icon)
 {
    var newimg=document.createElement('img');
	newimg.setAttribute('src','layout/img/'+icon+'.gif');
	newimg.setAttribute('class','link-icon');
	return newimg;
 }
 

/*    // vtip    ------------------------------------------ */

$(document).ready(function() {
						   
	$('tr:odd').addClass('odd');
	
	$('table tr').each(function() {
    	$(this).find('th:eq(0)').addClass('th-1');
		
    	$(this).find('td:eq(0)').addClass('td-1');
    	$(this).find('td:eq(1)').addClass('td-2');
    	$(this).find('td:eq(2)').addClass('td-3');
 	});	
	
	$("a[href^='http']").attr('target','_blank');
	
    $("a:has(img)").addClass("img");
	$("a[href^='javascript:linkTo_UnCryptMailto']").addClass("email").append(create_icon('linkmail'));
	// link icons: because of the IE multiline problem do not use css classes
	$("a[href$='.pdf']").not("[class='img']").append(create_icon('pdf_small'));
	$("a[href$='.rtf']").not("[class='img']").append(create_icon('doc_small'));
	$("a[href$='.doc']").not("[class='img']").append(create_icon('doc_small'));
	
	$("a[href$='.rtf']").attr('target','_blank');
	$("a[href$='.doc']").attr('target','_blank');
	$("a[href*='.pdf'], a[href*=':PDF']").attr('target','_blank');
	
	$("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));	
	});	


	// showHide clickable
	$(".show-hide-text").hide(); 
	
	var showHideLinkStart = '<a class="show-hide-link" title="Show text"><img src="layout/img/plus.gif" />';
	var showHideLinkEnd = '</a>';

	$(".show-hide h2, .show-hide h3, .show-hide h4").each(function(){
			$(this).html(showHideLinkStart + $(this).html() + showHideLinkEnd);			  
	});		
	$(".show-hide h2 a, .show-hide h3 a, .show-hide h4 a").click(function(){
		$(this).parents("h3").next("div").toggle();		
		 if ($(this).attr("title") == 'Show text')
		 {
		   $(this).parents("h2, h3, h4").addClass('show');
		   $(this).attr("title","Hide text");
		   $(this).children("img").attr("src","layout/img/minus.gif");
		 } 
	    else
		 {
		   $(this).attr("title","Show text");
		   $(this).children("img").attr("src","layout/img/plus.gif");
		  // $(this).parents("h3").removeAttr('style');
		   $(this).parents("h3").removeAttr('class');
		 }	    
	});	
	
// 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').css({'position': 'relative'});
				 $(this).parent('strong').parent('p,td').prepend( flashContainer );					 
				// alert('TEST: '+ $(this).parent('strong').parent('p,td').html());
				 
			} else {
				 $(this).parent('p,td').css({'position': 'relative'});
				 $(this).parent('p,td').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;
	 });
	
	


						   
});


// typo3  /


function openPic(url,winName,winParams)	{	//
		var theWindow = window.open(url,winName,winParams);
		if (theWindow)	{theWindow.focus();}
	}
	
function openPopUp(url,winName,winParams)	{	//
		var theWindow = window.open(url,winName,winParams);
		if (theWindow)	{theWindow.focus();}
	}
	
function openMap(url,winWidth,winHeight)	{	//   
		if (newWin) {
			newWin.close();
		}
		// simple string without special characters for IE
		var winName = 'PopUp';
        var winParams = 'toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=0,resizable=1,height='+winHeight+',width='+winWidth;
		// do not write var newWin here, but write var newWin outside of the function, then first if(newWin) causes no error
		newWin = window.open(url,winName,winParams);
		if (newWin)	{
			newWin.focus();
		}
	}
