// JavaScript Document

/* 
 * email mangling : com example name2 name1 wil be converted to: name1.name2@example.com
 * sarch all a tags where the href contains ' ' (single blanks)
 */

function eMailMangling()
{
	jq("a[href*=' '], a[href*='%20']").click(function() { 
	    var realemail = '';
		var email = jq(this).attr("href");

		if ( ! email || ! email.length ) return 

		if ((email.indexOf("mailto:") == -1) && (email.indexOf("http:") == -1))
		{
			if (email.indexOf(" ") != -1) 
		  	{
		  		var emailArray = email.split(" ");
		  	}
		  	else
		  	{
		  		var emailArray = email.split("%20");
		  	}
			for (var i=emailArray.length; i>=0; i=i-1)
			{
				if (typeof emailArray[i] != 'undefined')
				{
					if (i==2)
					{
					realemail = realemail + emailArray[i] + '@';
					}
					else
					{
					realemail = realemail + emailArray[i] + '.';
					}
				}
			}
			realemail = realemail.substring(0, realemail.length -1);
			realemail = 'mailto:' + realemail;
			jq(this).attr("href", realemail);
		//alert (realemail);
		}
	});
}

/*
 * function init, to be called when document is ready 
 */
function init()
{
		eMailMangling();

		// change event-descr font
		var browsertype = navigator.userAgent;
		if (((browsertype.indexOf("Windows") == -1) || (browsertype.indexOf("Windows NT 6") != - 1)) && jq(".section-cafe-publik").length == 0 )
		{
				//alert ("for no windows and vista");
				jq("p.event-descr, dd.festival-descr").attr("style","font-family: Georgia, Times, 'Times New Roman', serif; font-size: 13px");
		}

		// new place for categoryprices
		if (jq("p.categoryprices").length > 0 ) 
		{
				var catprices = jq("p.categoryprices").html().replace('Karten ','');
				jq("p.tickets span.tickets").append(catprices);
				jq("p.categoryprices").remove();	
		}
		if (jq("body.section-cafe-publik").length > 0 )
		{
			Cufon.set('fontFamily', 'din');
			Cufon.replace('.section-cafe-publik ul span.title');
			Cufon.replace('.section-cafe-publik ul span.special');
  
			Cufon.set('fontFamily', 'conduit');
			Cufon.replace('#subnav li a span', { hover: true }); 
			Cufon.replace('.section-cafe-publik ul span.date');
			Cufon.replace('h1');
			/* Cufon.replace('h2');*/
		}
		
		
		// open external-links in new window 

		jq('a.external-link')
		.attr("target", "_blank");

		// startpage :
		if (jq('body').hasClass('section-startseite') || jq('body').hasClass('section-home')) {
		
			 jq('#slider')
			  .anythingSlider({
			   width        : 705,
			   height       : 547,
			   startStopped : false,
			   animationTime: 600,
			   resumeDelay  : 5000,
			   delay        : 6000
			  })
			  /* this "custom" code is the equivalent of the base caption functions */
			  .anythingSliderFx({
			   inFx: {
			    '.slideInfo'    : { left: 37, opacity: 1, time: 400 }
			   },
			   outFx: {
			    '.slideInfo'    : { left: -9999, opacity: 0, time: 350 }
			   }
			  })
	  
			/* startpage news */
	  
	            jq('#newsBlock dt a').click(function() {
	                var trigger = jq(this).attr('rel');
	                jq('#newsBlock dd').removeClass('active').addClass('inactive');
	                jq('#' +trigger).addClass('active'); 
	            });
	            
	            jq('#newsBlock dd span').click(function() {
	                var trigger = jq(this).attr('class'); 
	                jq('#' +trigger).removeClass('active'); 
	            });
            
          }
                   

			
}

if (window.jQuery)
{
		jq(document).ready(init);
}

