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


/* JQuery URL Parser
 * Version 1.0
 * Parses URLs and provides easy access to information within them.
 *
 * Author: Mark Perkins
 * Author email: mark@allmarkedup.com
 */
jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}();


// vertical positioning in the viewport -- $('#foo').vCenter();  

(function($){
  $.fn.vCenter = function(options) {
    var pos = {
      sTop : function() {
        return window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop;
      },
      wHeight : function() { 
        return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;
      }
    };
    return this.each(function(index) {
      if (index == 0) {
        var $this = $(this);
        var elHeight = $this.height();
		    var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
        $this.css({
          position: 'absolute',
          marginTop: '0',
          top: elTop
        });
      }
    });
  };

})(jQuery);



/*
 * needs: jQuery 1.2.1 - New Wave Javascript
 *
 */
 
 /*
 Newspaper Columns Plugin
 Oliver Petznick - Webmeisterei GmbH

 @ container:String
 @ column:String
 @ item:String
 @ col:Int
*/

jQuery.fn.npColumns = function(settings) {
    settings = jQuery.extend({
        container: '#npContainer',
        column: '#npColumn',
        item: '.npItem',
        cols: 2
    }, settings);
    
    var count = 1;
    var items = $(settings.container + ' ' + settings.item);
    var sizeOfItems = items.length;	    
    /*
	 items.each(function(i,n) {
      
        $(settings.column + count).append($(this).clone());
        $(this).remove();
        
        if (count == settings.cols) {
            count = 1;
        } else {
            count += 1;
        }
	});
	*/
	var itemsInCol = Math.floor(sizeOfItems/settings.cols);
	
	// check if the last item of the first column is an h3 headline
	//alert('Test: ' + $(items[itemsInCol]).is('h3'));
	if( $(items[itemsInCol]).is('h3')) {
		$(items[itemsInCol]).css({'margin-top': '0'});
		// put the headline in the second column
		itemsInCol = itemsInCol -1;
	}
	
	// alert('items: '+ sizeOfItems + ' - itemsInCol: ' +itemsInCol);
	items.each(function(i,n) {
      
        $(settings.column + count).append($(this).clone());
        $(this).remove();
        
        if(i/itemsInCol == 1){ // || i/itemsInCol == 2
            count += 1;
        }	
	});
	
	// http://jquery.bassistance.de/jquery-getting-started.html
jQuery.fn.check = function(mode) {
	var mode = mode || 'off'; // if mode is undefined, use 'off' as default
	return this.each(function() {
		switch(mode) {
		case 'on':
			this.checked = true;
			break;
		case 'off':
			this.checked = false;
			break;
		case 'toggle':
			this.checked = !this.checked;
			break;
		}
	});
};

$.fn.extend({
	position: function() {
		var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
		
		if (elem) {
			// Get *real* offsetParent
			offsetParent = this.offsetParent();
			
			// Get correct offsets
			offset       = this.offset();
			parentOffset = offsetParent.offset();
			
			// Subtract element margins
			offset.top  -= num(elem, 'marginTop');
			offset.left -= num(elem, 'marginLeft');
			
			// Add offsetParent borders
			parentOffset.top  += num(offsetParent, 'borderTopWidth');
			parentOffset.left += num(offsetParent, 'borderLeftWidth');
			
			// Subtract the two offsets
			results = {
				top:  offset.top  - parentOffset.top,
				left: offset.left - parentOffset.left
			};
		}
		
		return results;
	},
	
	offsetParent: function() {
		var offsetParent = this[0].offsetParent;
		while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static') )
			offsetParent = offsetParent.offsetParent;
		return $(offsetParent);
	}
});
	
function num(el, prop) {
	return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;
};	
    
}


$(document).ready(function() {	


// Flash video pages
	
	$('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;
			// media player from Jeroen Wijering http://www.jeroenwijering.com/
			// var playerURL = 'http://www.planet-diversity.org/fileadmin/player.swf';
			
			var path = jQuery.url.attr("path");	
			// e.g.    /stories-and-videos/interviewswithparticipants.html	
			var relPath = path.replace(/\/[^\/]+/g, '../'); 
			// --> ../../
			relPath =  relPath.slice(0,3);
			// --> remove the first ../
			var playerURL =  relPath+'fileadmin/player.swf';			
			// alert('playerURL: '+playerURL);
			
			// built the video container so that it is displayed on the right site
			var flashContainer = '<div id="flash-container"></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
			$('#flash-container').flash(
			{
				src: playerURL, 
				height: 300,  
				width: 300, 
				bgcolor: '#ffffff', 
				wmode: 'opaque', 
				allowscriptaccess: 'always', 
				version: 9, 
				
				  flashvars: { 
					'file': videoURL, 
					'controlbar': 'over', 
					'dock': 'false', 
					// 'plugins': 'false',
					'plugins' : 'viral-2', 'viral.onpause' : 'false', 'viral.allowmenu' : 'false',
					'viral.functions' : 'link',
					'fullscreen': 'true', 
					'stretching': 'fill', 
					'autostart': 'true' }
				},
				{ version: 9 }
			);	
			// write the remove link
			$('#flash-container').append('<p>Close Flashplayer</p>');
			$('#flash-container p').click(function(){$('#flash-container').remove();});
			return false;
	 });
				   
	
	// $('#splash').vCenter();  
	
	$("#npContainer h3.poiItem:eq(0)").css("margin-top","0px");								
   if ($("#npContainer")){
		jQuery().npColumns({item:'.poiItem'}); 
	 }
	 
	$radiovalueFee     = ($("input[name='Fee']:checked").val());
	$radiovaluePayment = ($("input[name='Payment']:checked").val()); 
	if($radiovalueFee !='60')        $("#j-fee60").hide();
	if($radiovalueFee !='none')      $("#j-feenone").hide();
	if($radiovaluePayment !='none')  $("#j-paymentnone").hide();
	
	$("input[name='Fee']").click(
	function()
	{		
		$radiovalue = ($("input[name='Fee']:checked").val());
		if($radiovalue =='60')
		{			
			$("#j-fee60").show();
		}
		if($radiovalue =='none')
		{			
			$("#j-feenone").show();
		}
	});
	$("input[name='Payment']").click(
	function()
	{		
		$radiovalue = ($("input[name='Payment']:checked").val());
		if($radiovalue =='none')
		{			
			$("#j-paymentnone").show();
		}
	});
	
	
	$("#b1034 #container .csc-firstHeader").append('<p class="top_2"><input type="checkbox" name="international" id="international" checked="checked" class="checkbox" /> <label for="international">show international events</label> &nbsp; <input type="checkbox" name="german" id="german" checked="checked" class="checkbox" /> <label for="german">show German events / Veranstaltungen in Deutschland</label></p>');
	
	$("#b1034 #international").click(function(){
			if(this.checked==false){
				$("#b1034 .en").hide();
			} else {
				$("#b1034 .en").show();
			}
	});
	$("#b1034 #german").click(function(){
			if(this.checked==false){
				$("#b1034 .de").hide();
			} else {
				$("#b1034 .de").show();
			}
	});
	
	
     // Change login input to lower case
  $(".tx-felogin-pi1 #user, .tx-felogin-pi1 #pass").blur(function() {   
	var s = $(this).val().toLowerCase();
	s = s.replace(/ /g,'');
    $(this).val(s);
  });
  
  
	$("a:has(img)").addClass("img");

    $("table a[href$='.swf']").not("[class='img']").prepend(create_icon('flash'));
	$("table a[href$='.flv']").not("[class='img']").prepend(create_icon('flash'));  
	$("table a[href$='.pdf']").not("[class='img']").prepend(create_icon('pdf'));
	$("table a[href$='.rtf']").not("[class='img']").prepend(create_icon('doc'));
	$("table a[href$='.doc']").not("[class='img']").prepend(create_icon('doc'));
	$("table a[href$='.mp3']").not("[class='img']").prepend(create_icon('mp3'));
	// in section TRAEGER and PRESSE do not display link
	 	 
});


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