jQuery(function( $ ){	
	
	var loc = window.location.href;
	if(loc.indexOf('/en/')!="-1"||loc.indexOf('L=1')!="-1"){
		
		$(".browsebox-list-1").each(function(){
			var bbox = $(this).html();
			if(bbox.indexOf('bis')){
				var bbox = bbox.replace(/bis/i,'to').replace('von insgesamt','of').replace('Datensätzen','records');
				$(".browsebox-list-1").html(bbox);
			}
			if($(this).next().html()=='Klicken Sie auf einen Buchstaben oder senden Sie eine Suchabfrage.'){
				$(this).next().html('Please click on a tab or send a search word.');
			}
		});
		
		var alle = $(".tab-Alle a span").html();
		if(alle=='Alle') $(".tab-Alle a span").html('All');
		$(".tab-XYZ a span").each(function(){
			if($(this).html()=='Andere') $(this).html('Others');
		});

		if($(".cell-0 a:first").html()=='ProjektNr') $(".cell-0 a:first").html('ProjectNo');
		if($(".cell-0 a:first").html()=='Artikel') $(".cell-0 a:first").html('Article');

		if($(".cell-1 a:first").html()=='Fördergremium') $(".cell-1 a:first").html('Committee');
		if($(".cell-1 a:first").html()=='Publikationstyp') $(".cell-1 a:first").html('Type');
		
		if($(".cell-2 a:first").html()=='Kurztitel') $(".cell-2 a:first").html('Shorttitle');
		if($(".cell-2 a:first").html()=='Erscheinungsjahr') $(".cell-2 a:first").html('Year');

		if($(".cell-3 a:first").html()=='Ansprechpartner') $(".cell-3 a:first").html('Contact');
		
	}
	
	// collect all links with rel=gmmo on coords in the alt-tag and bind mouseover/-out to them
	if ( $("a[rel='gmmo']:first").length ) {
		var coord = $("a[rel='gmmo']:first").attr("alt");
		var coord = coord.split("#");
		$("#wtdirectory_list_map_pointer").css('margin-top',coord[0]+'px');
		$("#wtdirectory_list_map_pointer").css('margin-left',coord[1]+'px');

	    $("a[rel='gmmo']").each(function(){
			var coord = $(this).attr("alt");
			$(this).attr("alt",$(this).html());
			if(coord!=''){
				var coord = coord.split("#");
				$( this ).bind (
					"mouseover",
					function(){
						$("#wtdirectory_list_map_pointer").css('margin-top',coord[0]+'px');
						$("#wtdirectory_list_map_pointer").css('margin-left',coord[1]+'px');
					}
				);
				$( this ).bind (
					"mouseout",
					function(){
						//$("#wtdirectory_list_map_pointer").css('margin-top','30px');
						//$("#wtdirectory_list_map_pointer").css('margin-left','30px');
					}
				);
			}
		});
	}	
	
	if( $("title").html() == "Downloads" ){
		//$(".whiteboxfg").css("height","725px");
	}
	
	if( $("title").html() == "Mediaclipping" || $("title").html() == "Medienbeobachtung" || $("title").html() == "Media monitoring" ){
		
		var articles = $("div.mw_article"),
		      categories = {},
		      navi = $("<div></div>").attr("id", "mw_navi").insertBefore(articles.eq(0));
		  articles.each(function(){
		    var typename = $(this).find('.mw_typename').text() || 'News DIL';
		    if(!(typename in categories)) {
		      categories[typename] = $("<div></div>").addClass("mw_container");
		      $("<h2>" + typename + "</h2>").appendTo(categories[typename]);
		      $("<a></a>").addClass("mw_navi_link")
		        .attr('href', '#')
		        .html(typename).appendTo(navi)
		        .click(function(){
		          $(".mw_container").hide();
		          categories[typename].show();
		          return false;
		        });
		    }
		    $(this).appendTo(categories[typename]);
		  });
		  for (var category in categories){
		    if (Object.prototype.hasOwnProperty.call( categories, category ))
		      categories[category].insertAfter('div#mw_navi').hide();
		  };
		  $('#mw_navi a:eq(0)').click();
		
		
		// collect all rss-feed items and manipulate html and content
		if ( $(".mw_article:first").length ) {
			$(".mw_article").each(function(){
				var container = $(this);
				var title = $(this).find(".mw_title").html();
				var date = $(this).find(".mw_date").html();
				var mw_match = $(this).find(".mw_match").html();
				var mw_typename = $(this).find(".mw_typename").html();
				var cat = date.split(", ")[1];
				var time = date.split(", ")[0].split(" ")[1];
				var date = date.split(", ")[0].split(" ")[0].split("/");
				var year = "2010";
				if(date[1]=="12") var year = "2009";
				var date = date[0]+'.'+date[1]+'.'+year+" "+time;
				var bodytext = $(this).find(".mw_ingress").html();
				var mehrref = $(this).find(".mw_bug a").attr("href");

				var matches = $(this).find(".mw_match").html().split(":")[1].split(",");
				var trimatches = new Array();		
				matches.each(function(e){
					var trimmed = jQuery.trim(e);
					var point = trimmed.substr(-1);
					if(point == "."){
						var trimmed = trimmed.substr(0,(trimmed.length-1));
					}
					trimatches.push(trimmed);
				});
				var newhtml = '<h3><span class="news-list-date" style="padding-left:4px;padding-top:1px;text-align:left;">'+date+'</span><span class="news-list-cat">'+cat+'</span>'+title+'</h3><p class="bodytext">'+bodytext+'</p><div class="news-list-cat">'+mw_typename+'</div><div class="news-list-tags">'+mw_match+'</div><div class="news-list-morelink"><a href="'+mehrref+'" target="_blank">mehr lesen</a></div>';
				$(this).html(newhtml);
				$(this).removeClass("mw_article");
				$(this).addClass("news-list-item");

				trimatches.each(function(e){
					(bodytext.replace(e,"<strong>"+e+"apdisfo</strong>"));	
//					container.find('p').highlight(e);
				});
			});
		}	
	}
	
	if ( $(".browsebox").next("p").length ) {
		$(".browsebox").next("p").css("padding","0");
	}
});
