// Blurring links:
function blurLink(theObject)	{ //
	if (theObject.blur)	{
		theObject.blur();
	}
}

// typo3 scripts
var browserName=navigator.appName;var browserVer=parseInt(navigator.appVersion);var version="";var msie4=(browserName=="Microsoft Internet Explorer"&&browserVer>=4);if((browserName=="Netscape"&&browserVer>=3)||msie4||browserName=="Konqueror"||browserName=="Opera"){version="n3";}else{version="n2";}
function decryptCharcode(n,start,end,offset){n=n+offset;if(offset>0&&n>end){n=start+(n-end-1);}else if(offset<0&&n<start){n=end-(start-n-1);}
return String.fromCharCode(n);}
function decryptString(enc,offset){var dec="";var len=enc.length;for(var i=0;i<len;i++){var n=enc.charCodeAt(i);if(n>=0x2B&&n<=0x3A){dec+=decryptCharcode(n,0x2B,0x3A,offset);}else if(n>=0x40&&n<=0x5A){dec+=decryptCharcode(n,0x40,0x5A,offset);}else if(n>=0x61&&n<=0x7A){dec+=decryptCharcode(n,0x61,0x7A,offset);}else{dec+=enc.charAt(i);}}
return dec;}
function linkTo_UnCryptMailto(s){location.href=decryptString(s,-1);}

$(document).ready(function() {
	var navAnim = false,tabAnim = false;
	
	$('div.teaserList div.thumbnail')
		.mouseenter(function() {
			var tn = $(this),
				tooltip = $('#tooltip'),
				css = {},
				className = '';
			
			tooltip.children('p').html(tn.children('.tooltip').html());
			
			tooltip.css({ left: '0px', top: '0px', width: 'auto', height: 'auto', visibility: 'hidden', display: 'block' });
			var ttWidth = tooltip.outerWidth(),
				ttHeight = tooltip.outerHeight();
			
			if (tn.offset().left > ($(document).width() / 2)) {
				css = {
					visibility: '',
					left: Math.round(tn.offset().left + tn.outerWidth() - ttWidth) + 'px',
					top: Math.round(tn.offset().top - ttHeight) + 'px'
				};
				className = 'arrowRight';
			} else {
				css = {
					visibility: '',
					left: Math.round(tn.offset().left) + 'px',
					top: Math.round(tn.offset().top - tooltip.height()) + 'px'
				};
				className = 'arrowLeft';
			}
			
			$('#tooltip').removeClass('arrowLeft arrowRight').addClass(className).css(css);
		})
		.mouseleave(function() {
			$('#tooltip').css({ display: 'none' });
		});
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	$('div#languages').mouseover(function() {
		$(this).children('ul').addClass('active');
	}).mouseout(function() {
		$(this).children('ul').removeClass('active');
	});
	
	$('ul#navig > li > ul > li > a').each(function() {
		var link = $(this),li = link.parent(),ul = li.children('ul');
		
		if (!link.is('.active')) {
			ul.hide();
		}
	}).click(function() {
		var link = $(this),li = link.parent(),ul = li.children('ul'),
			oldLink = $('ul#navig > li > ul > li > a.active'),oldLi = oldLink.parent(),oldUl = oldLi.children('ul');
		
		if (navAnim || link.is('.active')) {
			return false;
		}
		
		navAnim = true;
		
		oldLink.removeClass('active');
		// oldUl.hide();
		oldUl.slideUp('fast');
		
		link.addClass('active');
		// ul.show();
		ul.slideDown('fast',function() {
			navAnim = false;
		});
		
		return false;
	});

	$('ul#navig li ul li ul li').mouseover(function() {
		if (!navAnim) {
			$(this).find('div.navThumb').show();
		}
	}).mouseout(function() {
		if (!navAnim) {
			$(this).find('div.navThumb').hide();
		}
	});
	
	
	$('div#tabContents > div').hide().eq(0).show();
	
	$('div#tabContainer ul#tabNavigation li a').click(function() {
		var nav = $('ul#tabNavigation'),
			cnts = $('div#tabContents'),
			
			newLink = $(this),
			newTab = $('#' + newLink.attr('rel')),
			
			curLink = nav.find('li.active a'),
			curTab = $('#' + curLink.attr('rel'));
			
		if (tabAnim || newLink.parent().is('.active')) {
			return false;
		}
		
		tabAnim = true;
		
		curLink.parent().removeClass('active');
		newLink.parent().addClass('active');
		
		cnts.animate({ height: newTab.height() },200);
		curTab.hide();
		newTab.fadeIn(200,function() {
			tabAnim = false;
		});
		
		return false;
	});
});
