var activeTabID = "home";
var navAniTime = 350;
var slideAniTime = 750;
var timeoutTime = 250;
var _timeoutID = 0;

$(function() {
  $('div.moreorless a').toggle(
		function() {
			atag = $(this);
			$(this).parent().parent().parent().next().show();
			$(this).parent().parent().parent().animate({
				height: '100px'
			}, 1000, function(){
				// Animation complete.
				atag.removeClass("closed").addClass("open");
			});
			
			
		},
		function() {
			atag = $(this);
			$(this).parent().parent().parent().animate({
				height: '20px'
			}, 1000, function(){
				$(this).next().hide();
				atag.removeClass("open").addClass("closed");
			});
		}
	);	
});

function setActive(tabID) {
	if (tabID != activeTabID) {
		$("#slide_home_de").fadeOut(slideAniTime);$("#slide_home_en").fadeOut(slideAniTime);$("#slide_home_es").fadeOut(slideAniTime);$("#slide_home_fr").fadeOut(slideAniTime);
		
		$("#slide_"+tabID).fadeIn(slideAniTime);
		$("#slide_"+activeTabID).fadeOut(slideAniTime);
		
		$("#pn_"+tabID.replace(/_de|_en|_fr|_es/,"")+"_Active").fadeIn(navAniTime);
 		$("#pn_"+activeTabID.replace(/_de|_en|_fr|_es/,"")+"_Active").fadeOut(navAniTime);		
		/*
		if (tabID != "home") $("#pn_"+tabID+"Active").fadeIn(navAniTime);
		if (activeTabID != "home") $("#pn_"+activeTabID+"Active").fadeOut(navAniTime);
		*/
		activeTabID = tabID;
	}
}

function clickActive(tabID) {
	cancelSetActive();
	setActive(tabID);
}

function delaySetActive(tabID) {
	_timeoutID = window.setTimeout(function(){_timeoutID = 0; setActive(tabID);},timeoutTime);		
}

function cancelSetActive() {
	if (_timeoutID != 0) { 
		window.clearTimeout(_timeoutID); 
		_timeoutID = 0;
	}
}

/* Script für die News */
var newsCount = 3;
var newsCounter = 0;

function newsNext() {
	if (newsCounter < newsCount -1) {
		++newsCounter;
		document.getElementById("arrowsLeft").className = "redArrowsLeft";
		document.getElementById("newsPrev").className = "backward active";
		if (newsCounter >= newsCount -1) {
			document.getElementById("arrowsRight").className = "greyArrowsRight";
			document.getElementById("newsNext").className = "forward inactive";
		}
	}
}

function newsPrev() {
	if (newsCounter > 0) {
		--newsCounter;
		document.getElementById("arrowsRight").className = "redArrowsRight";
		document.getElementById("newsNext").className = "forward active";
		if (newsCounter <= 0) {
			document.getElementById("arrowsLeft").className = "greyArrowsLeft";
			document.getElementById("newsPrev").className = "backward inactive";
		}
	}
}

$(function() {
		
	$("div.newsTabs").tabs(".newsEntry", {

		// enable "cross-fading" effect
		effect: 'fade',
		fadeOutSpeed: "slow",

		// start from the beginning after the last tab
		rotate: false

	// use the slideshow plugin. It accepts its own configuration
	}).slideshow({clickable: false});
});

function clearNavHover(){
	//reset the hovergraphic of the first nav
	$("#firstNav > ul > li > a").css({ 'background': ''	})
}


	
$(function(){		 
	$('#firstNav > ul > li > a')
		//set the hover graphic of the current 1st nav element (all languages are fixed)
		.mouseover(function(){
			var x = $(this).css('background-position-x');
			if (x == "") {
				x = $(this).css('backgroundPosition').split(" ")[0];
			}		

			var offset = x + ' -23px';
	
			//temporary reset of all hover graphics
			clearNavHover()
			$(this).css({ 'background-image': $(this).css('background-image'), 'backgroundPosition': offset	})
		})
		
	$('#firstNav > ul > li')
		.mouseleave(function(){
			clearNavHover()
		})
});

$(function(){
	$('#topNav > ul > li > a.search')
		.mouseover(function(){
			$("#search-de").css({ 'display': 'block' })
			$("#search-en").css({ 'display': 'block' })
			$("#search-fr").css({ 'display': 'block' })
			$("#search-es").css({ 'display': 'block' })
		})
		
	$('#search-de')
		.mouseover(function(){ $("#search-de").css({ 'display': 'block' }) })
	$('#search-de')
		.mouseleave(function(){	$("#search-de").css({ 'display': 'none' }) })
	$('#search-en')
		.mouseover(function(){ $("#search-en").css({ 'display': 'block' }) })
	$('#search-en')
		.mouseleave(function(){	$("#search-en").css({ 'display': 'none' }) })
	$('#search-fr')
		.mouseover(function(){ $("#search-fr").css({ 'display': 'block' }) })
	$('#search-fr')
		.mouseleave(function(){	$("#search-fr").css({ 'display': 'none' }) })
	$('#search-es')
		.mouseover(function(){ $("#search-es").css({ 'display': 'block' }) })
	$('#search-es')
		.mouseleave(function(){	$("#search-es").css({ 'display': 'none' }) })
		
	$('#topNav > ul > li')
		.mouseleave(function(){
			$("#search-de").css({ 'display': 'none' })
			$("#search-en").css({ 'display': 'none' })
			$("#search-fr").css({ 'display': 'none' })
			$("#search-es").css({ 'display': 'none' })
	})
});

// Funktion zur Prüfung der Pflichtfelder der Formulare
(function($) {
	
	$.fn.formValidator = function(options) {
		$(this).click(function() { 
		
			var result = $.formValidator(options);
		
			if (result && jQuery.isFunction(options.onSuccess)) {
				options.onSuccess();
				return false;
			} else {
				return result; 
			}
		});
	};
	
	$.formValidator = function (options) {
		
		// merge options with defaults
		var merged_options = $.extend({}, $.formValidator.defaults, options);
		
		// result boolean
		var boolValid = true;
		
		// result error message
		var errorMsg = '';
		
		// clean errors
		$(merged_options.scope + ' .error-both, ' + merged_options.scope + ' .error-same, ' + merged_options.scope + ' .error-input').removeClass('error-both').removeClass('error-same').removeClass('error-input');
		
		// gather inputs & check is valid
		$(merged_options.scope+' .req-email, '+merged_options.scope+' .req-string, '+merged_options.scope+' .req-same, '+merged_options.scope+' .req-both, '+merged_options.scope+' .req-numeric, '+merged_options.scope+' .req-date, '+merged_options.scope+' .req-min').each(function() {
			thisValid = $.formValidator.validate($(this),merged_options);
			boolValid = boolValid && thisValid.error;
			if (!thisValid.error) errorMsg  = thisValid.message;
		});
		
		// submit form if there is and valid
		if ((merged_options.scope != '') && boolValid) {
			$(merged_options.errorDiv).fadeOut();
		}
		
		// if there is errorMsg print it if it is not valid
		if (!boolValid && errorMsg != '') {
			
			var tempErr = (merged_options.customErrMsg != '') ? merged_options.customErrMsg : errorMsg;
			$(merged_options.errorDiv).hide().html(tempErr).fadeIn();
		}
		
		return boolValid;
	};
	
	$.formValidator.validate = function(obj,opts) {

		var valAttr = obj.val();
		var css = opts.errorClass;
		var mail_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var numeric_filter = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)|(^-?\d*$)/;
		var tmpresult = true;
		var result = true;
		var errorTxt = '';
		
		// REQUIRED FIELD VALIDATION
		if (obj.hasClass('req-string')) {
			tmpresult = (valAttr != '');
			if (!tmpresult) errorTxt = opts.errorMsg.reqString;
			result = result && tmpresult;
		}
		// SAME FIELD VALIDATION
		if (obj.hasClass('req-same')) {
			
			tmpresult = true;
			
			group = obj.attr('rel');
			tmpresult = true;
			$(opts.scope+' .req-same[rel="'+group+'"]').each(function() { 
				if($(this).val() != valAttr || valAttr == '') {
					tmpresult = false;
				}
			});
			if (!tmpresult) {
				$(opts.scope+' .req-same[rel="'+group+'"]').parent().parent().addClass('error-same');
				errorTxt = opts.errorMsg.reqSame;
			} else {
				$(opts.scope+' .req-same[rel="'+group+'"]').parent().parent().removeClass('error-same');
			}
			
			result = result && tmpresult;
		}
		// BOTH INPUT CHECKING
		// if one field entered, the others should too.
		if (obj.hasClass('req-both')) {
			
			tmpresult = true;
			
			if (valAttr != '') {
				
				group = obj.attr('rel');

				$(opts.scope+' .req-both[rel="'+group+'"]').each(function() { 
					if($(this).val() == '') {
						tmpresult = false;
					}
				});
				
				if (!tmpresult) {
					$(opts.scope+' .req-both[rel="'+group+'"]').parent().parent().addClass('error-both');
					errorTxt = opts.errorMsg.reqBoth;
				} else {
					$(opts.scope+' .req-both[rel="'+group+'"]').parent().parent().removeClass('error-both');
				}
			}
			
			result = result && tmpresult;
		}
		// E-MAIL VALIDATION
		if (obj.hasClass('req-email')) {
			tmpresult = mail_filter.test(valAttr);
			if (!tmpresult) errorTxt = (valAttr == '') ? opts.errorMsg.reqMailEmpty : opts.errorMsg.reqMailNotValid;
			result = result && tmpresult;
		}
		// DATE VALIDATION
		if (obj.hasClass('req-date')) {
			
			tmpresult = true;
			
			var arr = valAttr.split(opts.dateSeperator);
			var curDate = new Date();
			
			if (valAttr == '') {
				
				tmpresult = true;
			} else {
				
				if (arr.length < 3) {
					tmpresult = false;
				} else {
					tmpresult = (arr[0] <= 12) && (arr[1] <= 31) && (arr[2] <= curDate.getFullYear());
				}
			}
			
			if (!tmpresult) errorTxt = opts.errorMsg.reqDate;
			result = result && tmpresult;
		}
		// MINIMUM REQUIRED FIELD VALIDATION
		if (obj.hasClass('req-min')) {
			tmpresult = (valAttr.length >= obj.attr('minlength'));
			if (!tmpresult) errorTxt = opts.errorMsg.reqMin.replace('%1',obj.attr('minlength'));
			result = result && tmpresult;
		}
		// NUMERIC FIELD VALIDATION
		if (obj.hasClass('req-numeric')) {
			tmpresult = numeric_filter.test(valAttr);
			if (!tmpresult) errorTxt = opts.errorMsg.reqNum;
			result = result && tmpresult;
		}
				
		if (result) {
			obj.removeClass(css);
		} else {
			obj.addClass(css);
		}
		
		return {
			error: result,
			message: errorTxt
		};
	};
	
	// CUSTOMIZE HERE or overwrite by sending option parameter
	$.formValidator.defaults = {
		onSuccess		: null,
		scope		:	'',
		errorClass		:	'error-input',
		errorDiv		:	'',
		errorMsg		: 	{
								reqString		:	'Fill the required fields',
								reqDate			:	'Date is <b>not</b> valid',
								reqNum			:	'Only numbers allowed',
								reqMailNotValid	:	'E-Mail is <b>not</b> valid',
								reqMailEmpty	:	'Please fill e-mail',
								reqSame			:	'Repeating inputs are not same',
								reqBoth			:	'Related field(s) required',
								reqMin			:	'Minimum %1 characters required'
							},
		customErrMsg	:	'',
		dateSeperator	:	'.'
	};
})(jQuery);
	// EXECUTE PLUGIN ON DOM READY - START
		$(function () {
			
			$('#submitBtn1').formValidator({
				scope		: '#form-1',
				errorDiv	: '#errorDiv1'
			});
		});
		// EXECUTE PLUGIN ON DOM READY - END
// FORM VALIDATOR JQUERY PLUGIN - END
// Ende Formularprüfung

/*
	--------------------------------------------------------------------------
	$Id: spamspan.js 5 2007-09-29 15:56:26Z moltar $
	--------------------------------------------------------------------------
	Version: 1.03
	Release date: 13/05/2006
	Last update: 07/01/2007

	(c) 2006 SpamSpan (www.spamspan.com)

	This program is distributed under the terms of the GNU General Public
	Licence version 2, available at http://www.gnu.org/licenses/gpl.txt
	--------------------------------------------------------------------------
*/

var spamSpanMainClass		= 'spamspan';
var spamSpanUserClass		= 'u';
var spamSpanDomainClass		= 'd';
var spamSpanAnchorTextClass = 't';
var spamSpanParams			= new Array('subject', 'body');

/*
	--------------------------------------------------------------------------
	Do not edit past this point unless you know what you are doing.
	--------------------------------------------------------------------------
*/

// load SpamSpan
addEvent(window, 'load', spamSpan);

function spamSpan() {
	var allSpamSpans = getElementsByClass(spamSpanMainClass, document, 'span');
	for (var i = 0; i < allSpamSpans.length; i++) {
		// get data
		var user = getSpanValue(spamSpanUserClass, allSpamSpans[i]);
		var domain = getSpanValue(spamSpanDomainClass, allSpamSpans[i]);
		var anchorText = getSpanValue(spamSpanAnchorTextClass, allSpamSpans[i]);
		// prepare parameter data
		var paramValues = new Array();
		for (var j = 0; j < spamSpanParams.length; j++) {
			var paramSpanValue = getSpanValue(spamSpanParams[j], allSpamSpans[i]);
			if (paramSpanValue) {
				paramValues.push(spamSpanParams[j] + '=' +
					encodeURIComponent(paramSpanValue));
			}
		}
		// create new anchor tag
		var at = String.fromCharCode(32*2);
		var email = cleanSpan(user) + at + cleanSpan(domain);
		var anchorTagText = document.createTextNode(anchorText ? anchorText : email);
		var mto = String.fromCharCode(109,97,105,108,116,111,58);
		var hrefAttr = mto + email;
			hrefAttr += paramValues.length ? '?' + paramValues.join('&') : '';
		var anchorTag = document.createElement('a');
			anchorTag.className = spamSpanMainClass;
			anchorTag.setAttribute('href', hrefAttr);
			anchorTag.appendChild(anchorTagText);
		// replace the span with anchor
		allSpamSpans[i].parentNode.replaceChild(anchorTag, allSpamSpans[i]);
	}
}

function getElementsByClass(searchClass, scope, tag) {
	var classElements = new Array();
	if (scope == null) node = document;
	if (tag == null) tag = '*';
	var els = scope.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	for (var i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getSpanValue(searchClass, scope) {
	var span = getElementsByClass(searchClass, scope, 'span');
	if (span[0]) {
		return span[0].firstChild.nodeValue;
	} else {
		return false;
	}
}

function cleanSpan(string) {
	// string = string.replace(//g, '');
	// replace variations of [dot] with .
	string = string.replace(/[\[\(\{]?[dD][oO0][tT][\}\)\]]?/g, '.');
	// replace spaces with nothing
	string = string.replace(/\s+/g, '');
	return string;
}

// http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent)
	{
		obj['e' + type + fn] = fn;
		obj[type + fn] = function() { obj['e' + type + fn](window.event); }
		obj.attachEvent('on' + type, obj[type + fn]);
	}
}

//Funktion, die die Tooltops über den Flaggen aktiviert
$(function() {
	$("#flags a[title]").tooltip({ 
    // use single tooltip element for all tips 
    tip: '#flagtip',								         
    // tweak the position
    position: 'bottom left', 
    offset: [-3, 33],
    predelay: 333							         
    // add dynamic plugin  
  });
});

//Funktion zum Togglen der Releasenotes
function toggle(id) {
	if (document.getElementById(id).style.display == 'none')
		document.getElementById(id).style.display = 'block';
	else
		document.getElementById(id).style.display = 'none';	
}

function openAllBugs() {
	var descriptions = document.getElementsByTagName("dd");
	for(i=0;i<descriptions.length; i++) {
		document.getElementsByTagName("dd")[i].style.display = '';
	}
}

function closeAllBugs() {
	var descriptions = document.getElementsByTagName("dd");
	for(i=0;i<descriptions.length; i++) {
		document.getElementsByTagName("dd")[i].style.display = 'none';
	}
}
