/* JQuery URL Parser
 * Version 1.0
 * Author: Mark Perkins
 * For full documentation and more go to http://projects.allmarkedup.com/jquery_url_parser/
 */
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}}();
	
	
	
	jQuery.noConflict();		
	jQuery(document).ready(function(){
									
			
	// typo3 helper: if the anchor is on the same page do not reload
	jQuery('#maincontent a[href*=#]').click(function(){	
		// global var url_path of the current page				
		var url_path = jQuery.url.attr('path');									 
		var link_href = jQuery(this).attr('href');
		var link_path = jQuery.url.setUrl(link_href).attr('path');
		// reset jQuery.url
		jQuery.url.setUrl(window.location);
		// console.log('url_path: %s, link_path: %s',url_path, link_path );
		if(url_path == link_path) {
		  // go to the anchor
		 location.href = link_href;
		 return false;
		}				
	});	
									
									
	var path = 'http://www.bioland.de/kunden/einkauf/baecker/plz/';								
	var html = '<p class="float-right"><span>Weitere Postleitzahlenbereiche:</span> ' +       
	'<select name="redirect" onChange="location.href=this.options[this.selectedIndex].value;">' +
		'<option selected>PLZ-Bereich&nbsp;</option>' +
		'<option value="'+path+'00-29.html">PLZ-Bereich 00 - 29999</option>' +
		'<option value="'+path+'30-49.html">PLZ-Bereich 30 - 49999</option>' +
		'<option value="'+path+'50-69.html">PLZ-Bereich 50 - 69999</option>' +
		'<option value="'+path+'70-74.html">PLZ-Bereich 70 - 74999</option>' +
		'<option value="'+path+'75-79.html">PLZ-Bereich 75 - 79999</option>' +
		'<option value="'+path+'80-99.html">PLZ-Bereich 80 - 99999</option>' +
      '</select></p>';								
									
	jQuery('body#b1983 .tx-sunexcelread-pi1').prepend(html);
	
	
	var path = 'http://www.bioland.de/kunden/einkauf/metzger/plz/';								
	var html = '<p class="float-right"><span>Weitere Postleitzahlenbereiche:</span> ' +       
	'<select name="redirect" onChange="location.href=this.options[this.selectedIndex].value;">' +
		'<option selected>PLZ-Bereich&nbsp;</option>' +
		'<option value="'+path+'00-29.html">PLZ-Bereich 00 - 29999</option>' +
		'<option value="'+path+'30-49.html">PLZ-Bereich 30 - 49999</option>' +
		'<option value="'+path+'50-69.html">PLZ-Bereich 50 - 69999</option>' +
		'<option value="'+path+'70-74.html">PLZ-Bereich 70 - 74999</option>' +
		'<option value="'+path+'75-79.html">PLZ-Bereich 75 - 79999</option>' +
		'<option value="'+path+'80-99.html">PLZ-Bereich 80 - 99999</option>' +
      '</select></p>';								
									
	jQuery('body#b1984 .tx-sunexcelread-pi1').prepend(html);
	
									
	if(jQuery('body#b62').length > 0) // on page 62 http://www.bioland.de/kunden/einkauf.html
	{
		jQuery('select').css('border','solid 1px #ccc');
		jQuery('.select').hide();		
		// jQuery("a[href*='kunden/adressen/index.html']").css("color", "red");		
		jQuery("a[href*='kunden/adressen/index.html']").click(function(){											  
			jQuery(this).parents("p").next("div").toggle();
			return false;
		});	
		
	}				
									
									
	jQuery('.news-single-item p img').each(function(){
		if(	jQuery(this).attr('title'))
		{			
			if(	jQuery(this).attr('class')) {
								  
				var imgclass = jQuery(this).attr('class');
				jQuery(this).wrap('<p></p>');
				jQuery(this).parent('p').addClass(imgclass);
				jQuery(this).removeClass();			
			}
			
			var caption = '<br \><span class="caption">'+jQuery(this).attr("title")+'</span>';
			jQuery(this).after(caption);			
			
			var imgwidth = jQuery(this).width();
			jQuery(this).parent('p').css('width',imgwidth);	
		}												  
	});


	jQuery(".showhidecontent").hide(); 
	
	if(jQuery("#b20").length > 0) {
		var showhideLinkTitle = 'Links anzeigen';
	} else {
		var showhideLinkTitle = 'Text anzeigen';		
	}
	
	var showhideLinkStart = '<a href="#" class="showhide" title="'+showhideLinkTitle+'">';
	var showhideLinkEnd = '</a>';

	jQuery(".showhidecontentwrap h2").each(function(){
			jQuery(this).html(showhideLinkStart + jQuery(this).html() + showhideLinkEnd);			  
	});		
	jQuery(".showhidecontentwrap h2 a").click(function(){
		jQuery(this).parents("h2").next("div").toggle();		
		 if (jQuery(this).attr("title") == 'Text anzeigen')
		 {
		   jQuery(this).parents("h2").addClass('show');
		   jQuery(this).attr("title","Text ausblenden");
		   jQuery(this).children("img").attr("src","layout/img/minus.gif");
		 } 
	    else
		 {
		   jQuery(this).attr("title","Text anzeigen");
		   jQuery(this).children("img").attr("src","layout/img/plus.gif");
		   jQuery(this).parents("h2").removeAttr('class');
		 }
		 return false;
	});
									

    // Startseite - Mitte erstes Element ohne Linie oben
	jQuery("#b20 .csc-textpic").eq(0).css({"margin-top": "0", "border":"none"});	


	// Oster Gewinnspiel
	jQuery("#gewinnspielanmeldung").hide(); 	
	jQuery("#anmeldung-link").append(" <a href=\"#gewinnspielanmeldung\" title=\"Anmelde-Formular anzeigen\" >» Anmelde-Formular anzeigen</a>");	
	jQuery("#anmeldung-link a").click(function(){													  
		jQuery("#gewinnspielanmeldung").css({ "margin-left":"222px" });
		jQuery("#gewinnspielanmeldung").show(); 
		jQuery("#gewinnspiellogin").hide();
		return false;
	});	
	
	
	// Bildarchiv typo3 page 360
	// only if normal login - then hide loogin-form
	if(jQuery("#b360 #login-header").length > 0) 
	{
		jQuery("#b360 #login-form").hide(); 
		jQuery("#b360 #forgot-password").hide(); 
		jQuery("#b360 .tx-srfeuserregister-pi1").hide();	
	
		jQuery("#b360 #login-header").append("<a href=\"#\" title=\"Login-Formular anzeigen\" >» Login-Formular anzeigen</a>");	
		jQuery("#b360 #login-header a").click(function(){													  
			jQuery("#b360 #login-form").show(); 
			jQuery("#b360 #forgot-password").show(); 
			jQuery("#b360 #login-header a").hide();		
			return false;
		});	
	}
	
	// FOREN
    if(jQuery("#b390 #login-header").length > 0) 
	{		
		// tx-srfeuserregister-pi1 important for email-confirmation and following redirect
		jQuery("#b390 .tx-srfeuserregister-pi1").hide();
	}
									
});