var BUCKETTIMERSTEP = 5000; //ms
var BUCKETTIMERSTARTDELAY = 5000; //ms

var langue_menu_opened=false;

$(function() {
	//alert('init');

	$("#loading-message-bg").height($('body').height());

	/* FOR JS OFF */
	$('body').removeClass('js_off');
	$('body').addClass('js_on');
	$('.nonjs, .nonjs-message').hide();

	/*  header langue-menu */
	if($('#langue-menu-active').length) $('#langue-menu-active').click(showLangMenu);

	$('.optionsContainer').css('opacity', '0.9');

	// breadcrumbs
	if($('#breadcrumbs-2').length) breadCrumbsInit();

	// <select> replacement
	initElSelect();

	// Gallery
	if($('.gallery-single-pop').length){
		var my_gallery = new Gallery();
		my_gallery.Galinit();
	}

	// Contact form events & validation
	ContactForm();

	$("#sendbutton").click(function(e){
//			if(!$('#mphone').val() && !($('#mname').val() &&  $('#memail').val())) {
			if( !( ( $('#mname').val() || $('#msubject').val() ) && ($('#mphone').val() ||  $('#memail').val() ) ) ) {
					alert($('#menu-content-form-validmsg').text());
					e.stopPropagation();
					return false;
			}
			return true;
	});

	$('#menu-contact-form input').blur(function () {
		var contact_droparea = $('div.tx-thmailformplus-pi1').parent().parent().parent().parent().parent();
		contact_droparea.attr('style', 'display:block');
		//!TODO trigger mouseover / mouseenter  on the menue point (a-Tag)
		timeoutid = setTimeout(close_contactdroparea,6000);
	});

	// Pop-Up init
	initPopUp();

	/* Block collapse */
	$('dl.block .block-dt-button').click(function(){
		$(this).parent().parent().toggleClass('closed');
	});

	/* fce_4-collapse-alt collapse */
	$('.fce_4-collapse-alt .fce_4-collapse-button').click(function(){
		$(this).parent().parent().toggleClass('closed');
		if ($(this).parent().parent().hasClass('closed')) {
			$(this).text('Expand');
		} else {
			$(this).text('Collapse');
		}
		return false;
		// alert('ddd');
		// myElement.set('text', text);
	});

	// init tt_news archive menu, remove all active, set first active
	if ($('.news-amenu-container').length) {
		$('.news-amenu-container:first').addClass('active');
	}

	// Tabs Containers init
	initTabsContainer();

	// Full Tag Cloud
	initTagCloud();

	// folder functions for tt_news archive menu
	if($('.news-amenu-container').length) {
		$('.news-amenu-container li span.year').click(function(){
			$(this).parent().parent().find('li').removeClass('active');
			$(this).parent().addClass('active');
		});
	}

	// reference bucket gallery
	initRefBucket();

	// init PNG transparency (not required yet, so commentin it out) [M]
	//$(".pngfix").pngFix();

	// init #footer-banners popups
	if($("#footer-banners .pop")) footerBannersPopups();

	// init #fce_bucket
	if($("#fce_bucket").length) fce_bucket("#fce_bucket");
	if($("#pagehistory").length) fce_bucket("#pagehistory");

	// fce 2 - 3 col
	$(".fce-cols td").hover(fceover,fceout);

 	if ($('#searchbox-position-container').length > 0 && $("#sub-header").length > 0)
 			$('#searchbox-position-container').insertAfter($("#sub-header"));

	// init() moving here
	init();


	// bookmark link
	$("#share-menu .menu li:first a").mouseover(function(){
		$(this).removeAttr("target").attr({"href":"javascript:add_to_fav();"});
		if(window.opera) $(this).attr({"href":document.location.href,"title":document.title,"rel":"sidebar"});
	});

	// kontakt/projektanfrage.html file upload mod
	if($("input.multi-pt").length) setTimeout("file_upload_mod()",1000);

	// read more block clickable
	if($(".read-more-block").length) readMoreClickable();

	// loading message hide
	$("#loading-message, #loading-message-bg").hide();

	$('#langue-menu-drop li .langue-item img').css('display', 'inline');
});



function readMoreClickable(){
	$(".read-more-block").each(function(i,e){
		var href = $(e).find("a:first").attr("href");
		if(href.indexOf('http') == -1) href = '/' + href;
		$(e).click(function(){ document.location.href = href; });
	        $(e).find("a").each(function(i,e){ $(e).replaceWith("<span class='htl'>"+$(e).text()+"</span>"); });
	});
}

function file_upload_mod(){
	input = $("input.multi-pt");
	$("body").addClass("js_on");
	fake = $("<div>").addClass("fake_upload").addClass("fake_upload_"+aoe_contact['submit_lang']);
	fake.append($("<span>"));
	fake.insertBefore($("input.multi-pt"));
}

function add_to_fav(){
	var documentTitle = document.title;
	var docUrl = document.location.href;
	if (window.sidebar){
		window.sidebar.addPanel(documentTitle, docUrl,"");
	} else if( window.external ){
		window.external.AddFavorite(docUrl, documentTitle); 
	} else if(window.opera){
		return false;
	} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)  
		alert('Unfortunately, this browser does not support the requested action,'  
		+ ' please bookmark this page manually.');  
	}
}

function fceover(){
	$(this).addClass("box-over");
}
function fceout(){
	$(this).removeClass("box-over");
}


function footerBannersPopups(){
	$("#footer-banners .pop").hide();
	$("#footer-banners a").hover(function(){
		// mouse over
		var pop = $(this).find(".pop");
		if(!pop) return false;
		var border = $(pop).find(".border");
		var a = $(pop).parent();

		$(a).addClass('hover');

		$(a).css('overflow', 'visible');
		//$(a).find("img:first").css('visibility', 'hidden');
		$(a).find("img:first").hide();

		$(border).css('opacity', '0.2');
		$(border).hide();
		$(pop).css('visibility', 'hidden'); // hiding and displaying, so the width can be obtained
		$(pop).css('display', 'block');

		border.width(pop[0].offsetWidth);
		border.height(pop[0].offsetHeight);

		if(a[0].offsetLeft + a[0].offsetWidth < 500)
			$(pop).css('left', a[0].offsetWidth-40);
		else
			$(pop).css('right', 0);

		$(pop).css('visibility', 'visible');
		$(pop).css('display', 'none');
		$(pop).fadeIn("fast");
		$(border).fadeIn("normal");
	},function(){
		// mouse out
		var pop = $(this).find(".pop");
		var a = $(pop).parent();

		$(a).removeClass('hover');

		$(a).css('overflow', 'hidden');
		$(a).find("img:first").show();

		pop.hide();
	});
}

/* [fce bucket] */

var bucket;
var bucket_time = 5000;

function fce_bucket(obj){
	$(obj + " .items").css({'height':$("#fce_bucket .fce_nav_history_list").height()});
	$(obj + " .fce_nav_history_list p:first").hide();
	setTimeout("bucket_shift('"+obj+"')",bucket_time);

	$(obj + " #aoepagetracker-clearHistory").click(function(){
		$(obj + " .fce_nav_history_list p").fadeOut("normal",function(){$(obj + " .fce_nav_history_list p").remove()})
		$.get( $(this).parents("a:first").attr("href") );
		return false;
	});
}
	function bucket_shift(obj){
		bucket = $(obj + " .fce_nav_history_list");
		first = bucket.find("p:first");
		first.slideDown("normal");
	}

/* [/fce bucket] */

function initElSelect() {

	if($('#div_companysize, #div_businesstype, #div_launchdate, #site #content .forms select.i-text')) $('#div_companysize select, #div_businesstype select, #div_launchdate select, #site #content .forms select.i-text').styledSelect({
		selectClass: 'i-select',
		openSelectClass: 'active',
		optionClass: 'i-select-item',
		selectedOptionClass: 'selected',
		closedOptionClass: 'inactive',
		firstOptionClass: 'start',
		lastOptionClass: 'end'
	});

	/*
	if($('#div_companysize').length) var mySelect = new elSelect( {container : 'div_companysize'} );
	mySelect.initialize({container : 'div_companysize'});
	if($('#div_businesstype').length) var mySelect = new elSelect( {container : 'div_businesstype'} );
	if($('#div_launchdate').length) var mySelect = new elSelect( {container : 'div_launchdate'} );
	*/
}

function breadCrumbsInit(){
	var zIndex=100;

	$('#breadcrumbs-2 div.b-item ul').each(function(){
		var currHeight=0; var finalHeight=0; var widthStr=''; var tmpWidth=''; var currWidth=0; var maxWidth=0;
		breadcrumbs_ul = $(this);

		breadcrumbs_ul.children('li').each(function(){
			breadcrumbs_ul_li = $(this);
			if(breadcrumbs_ul_li.hasClass('current-item')) {
				//breadcrumbs_ul.getParent().css('width', breadcrumbs_ul_li.getElement('a').offsetWidth + 11 + 'px');
				breadcrumbs_ul_li.css('width', breadcrumbs_ul_li.find('a').outerWidth() + 'px');
				breadcrumbs_ul_li.find('a').css('display', 'block');

				if(breadcrumbs_ul_li.prev()) breadcrumbs_ul_li.prev().css('border-bottom','none');
			}
		});

		var debugStr='';

		breadcrumbs_ul.children('li').each(function(){
			breadcrumbs_ul_li = $(this);
			if(breadcrumbs_ul_li.hasClass('current-item')) {
				currWidth = breadcrumbs_ul_li.outerWidth();
			} else {
				tmpWidth = breadcrumbs_ul_li.find('a').outerWidth();
				breadcrumbs_ul_li.find('a').css('display', 'block');
				if (tmpWidth > maxWidth)
				 //debugStr = breadcrumbs_ul_li.getElement('a').get('text');
				 maxWidth = (tmpWidth > maxWidth) ? tmpWidth : maxWidth;
			}
		});

		var blockWidth = (maxWidth > currWidth) ? maxWidth : currWidth-6;
		//alert('[' + debugStr + ']\n maxWidth: ' + maxWidth + '\n CurrWidth: ' + currWidth + '\n BlockWidth: ' + blockWidth);
		breadcrumbs_ul.css('width',blockWidth + 'px');
		breadcrumbs_ul.parent().css('width', currWidth + 'px');
		breadcrumbs_ul.parent().css('z-index',zIndex--);
		breadcrumbs_ul.children('li').each(function(){

			breadcrumbs_ul_li = $(this);
			//if(breadcrumbs_ul_li.getProperty('class') != 'current-item') {
				breadcrumbs_ul_li.css('width',blockWidth + 'px');
			//}
		});


		breadcrumbs_ul.children('li').each(function(){
			breadcrumbs_ul_li = $(this);
			if(breadcrumbs_ul_li.hasClass('current-item')) {
				finalHeight = currHeight;
			}else{
				currHeight=currHeight + breadcrumbs_ul_li.outerHeight();
			}
		});

		breadcrumbs_ul.css('margin-top', '-' + (finalHeight) - 2 + 'px');
		breadcrumbs_ul.css('top', '0px');

		/*if(ie6) {*/
			/*breadcrumbs_ul.getParent().*/
			if(breadcrumbs_ul.parent().find('iframe')) {
				breadcrumbs_ul.parent().find('iframe').css({
					'margin-top' : '-' + (finalHeight) - 2 + 'px',
					'height' : breadcrumbs_ul.outerHeight() + 'px',
					'width' : breadcrumbs_ul.outerHeight() + 'px'});
			}
		/*}*/

	});

}

/* [bucket] */



/* [/bucket] */

function initRefBucket () {
	if($('#fce_lat-ref-container').length) {
		var effectInProgress = false;
		//var myScroll = new Fx.Morph('fce_lat-ref-container', {link: 'cancel', duration: 1000, transition: Fx.Transitions.Elastic.easeOut});

		//var myScroll = new Fx.Tween('fce_lat-ref-container', {link: 'cancel', duration: 500});
		//$('#fce_lat-ref-container').animate();

		var fce_lat_ref_container_width = $('#fce_lat-ref-container').children('p').length * 228;
		$('#fce_lat-ref-container').css('width', fce_lat_ref_container_width + 'px');

		$('#fce_lat-ref-prev').click(function(){
			bucketLeft(BUCKETTIMERSTARTDELAY);
		});

		$('#fce_lat-ref-next').click(function(){
			bucketRight(BUCKETTIMERSTARTDELAY);
		});

		startBucketTicker(BUCKETTIMERSTARTDELAY);

		//alert('go!');
	}

	var bucketTimerCount;
	function startBucketTicker(n){
		bucketTimerCount = setTimeout(function(){
			bucketTimer(BUCKETTIMERSTEP);
		}, n);
	}

	function bucketTimer(){
		if(Math.abs(parseInt($('#fce_lat-ref-container').css('left'))) < ($('#fce_lat-ref-container').children('p').length-1)*228) {
			bucketRight(BUCKETTIMERSTEP);
		}else{
			executeBucketEffect(0,'fce_lat-ref-container');
			clearTimeout(bucketTimerCount);
			startBucketTicker(BUCKETTIMERSTEP);
		}
	}

	function bucketRight(nextAction){
		if(!effectInProgress){
			if(Math.abs(parseInt($('#fce_lat-ref-container').css('left'))) < ($('#fce_lat-ref-container').children('p').length-1)*228) {
				executeBucketEffect((parseInt($('#fce_lat-ref-container').css('left'))-228));
			}else{
				executeBucketEffect(0,'fce_lat-ref-container');
			}
			clearTimeout(bucketTimerCount);
			startBucketTicker(nextAction);
			effectInProgress = true;
			return false;
		}
	}

	function bucketLeft(nextAction){
		if(!effectInProgress){
			if(Math.abs(parseInt($('#fce_lat-ref-container').css('left'))) != 4 && Math.abs(parseInt($('#fce_lat-ref-container').css('left'))) != 0) {
				executeBucketEffect((parseInt($('#fce_lat-ref-container').css('left'))+228));
			}else{
				executeBucketEffect((parseInt($('#fce_lat-ref-container').css('width'))-228)*-1, 'fce_lat-ref-container');
			}
			clearTimeout(bucketTimerCount);
			startBucketTicker(nextAction);
			effectInProgress = true;
			return false;
		}
	}

	function executeBucketEffect(moveTo,obj2hide){
		if(obj2hide) $(obj2hide).hide('slow');

		//$('#fce_lat-ref-container').animate({'left': moveTo+'px'});
		$('#fce_lat-ref-container').animate({'left': moveTo+'px'}, 'slow', 'swing', function(){
			if(obj2hide) $(obj2hide).hide('slow');
			setTimeout(function(){
				effectInProgress = false;
			}, 500);
		});
	}
}

function initTagCloud () {

	if($('#full-tag-cloud-view-link').length) {
		$('#full-tag-cloud-view-link').click(function(){
			full_tag_link = $('#full-tag-cloud-view-link').offset();
			corrector = 26;
			if($.Browser == 'msie') corrector = 390;
			$('#full-tag-cloud').css('top', full_tag_link.top + corrector + 'px');

			$('#full-tag-cloud').toggle();
		});

		$('#full-tag-cloud-close').click(function(){
			$('#full-tag-cloud').css('display', 'none');
		});
	}
}

function initTabsContainer () {
	$('.tabs-container-tabs li').click(function(){
		sIFR.useDomLoaded = !sIFR.ua.ie;
		var tabContainer = $(this).parents('.tabs-container');
		var items = tabContainer.find('ul.tabs-container-tabs li');
		items.each(function () {
			$(this).removeClass('active');
		});
		$(this).addClass('active');

		var bodyItems = tabContainer.find('div.tabs-container-body>div');
		bodyItems.each(function () {
			$(this).css('display', 'none');
		});
		$('#tab-' + this.id).css('display', 'block');
		if(navigator.cookieEnabled) {
			var dinrg = { src: 'fileadmin/templates/flash/dinrg.swf' };
			sIFR.activate(dinrg);
			sIFR.replace(dinrg, { selector: '#tab-' + this.id + ' h3',  css: '.sIFR-root { color: #637b89; background-color: transparent;}', wmode: "transparent"});
		}
	});
}

function initPopUp () {
	var bodyp = $('body .notice');
	var pop_it = $('.pop-it');


	pop_it.each(function(){

		$(this).click(function(){
			var pd = new String($(this).attr('id'));
		    pid = $('#pop-up-'+pd.substr(10));

			//console.log(pd);

			pid.parent().toggleClass('pop-up-off');
			var notice_h = pid.parent().css('height');
			var notice_w = pid.parent().css('width');
			// alert();
			pid.parent().find('.notice_bg').css('height', parseInt(notice_h) + 24 + ' px');
			pid.parent().find('.notice_bg').css('width', parseInt(notice_w) + 20 + ' px');
			//alert(notice_h);
			// pid.getParent();
			return false;
		});
	});

	 $('.close_popup').click(function(){
		$(this).parent().parent().parent().addClass('pop-up-off');
		return false;
	});
	/* pop-up positioning */
	var intWindowHeight = window.outerHeight;
	var intWindowWidth = window.outerWidth;

	if ($.browser == "msie" && $.browser.version == '6.0') {
		// ie6 fixed emulation
		function move_box() {
		    var offset = 300; // set offset (likely equal to your css top)
		    var elements = $('.filetree-popup');
			elements.each(function(){
				$(this).css('top', document.documentElement.scrollTop + offset + 'px');
			});

		}
		window.setInterval(move_box, 100);
	}
}

function ContactForm () {
	if($('.forms').length) {

		if($('#forma').length) {
			$('#forma').attr('autocomplete', 'off');
		}

		$('#forma').validate();
		$('#forma input').keypress(function (e) {
		 	$('#forma').validate().element($(this));
		});

		/* Forms radio buttons */
		var r_inputs = $('.forms .radios input');
		var radios = $('.forms .radios');
		var r_labels = $('.forms .radios label');
		var textarea = $('.forms #text');
		var radios_cont = $('.forms #radios_container .radio_cont');

		r_labels.each(function(){
			if(!$(this).prev().is('[checked]')) $(this).addClass('link');
		});

		r_inputs.each(function() {
			$(this).click(function(){
				//alert($(this));
				var item = $(this);
				var input_id = new String(item.attr('id'));
				radio_cont = $('#' + input_id + '-cont');
				label = radios.find('label[for='+input_id+']');
				r_labels.addClass('link');
				//radios_cont.addClass('off');
				radios_cont.hide('slow');

				// console.log(item.attr('checked'));

				if (item.attr('checked') == true) {
					label.removeClass('link');
					if (radio_cont.hasClass('off')) {
						//radio_cont.removeClass('off');
					}
				}
			});
		});

		textarea.focus(function(){
			//alert(radios.find('input[checked]').attr('id'));
                        $('#' + radios.find('input[checked]').attr('id') + '-cont').find('.collapse').text(aoe_contact['collapse']);
                        $('#' + radios.find('input[checked]').attr('id') + '-cont').find('.collapse').click(function() {
                                $('#' + radios.find('input[checked]').attr('id') + '-cont').hide('slow');
                                return false;
                        });

			$('#' + radios.find('input[checked]').attr('id') + '-cont').show('slow');
		});



		/* Forms edit mode */
		var input_has_options = $('.forms .f-row .has-options');
		var frow_has_options = input_has_options.parent();
		var edit_link = $('.forms .f-row .options .edit_link a');
			// alert(edit_link);

		input_has_options.each(function(){
			$(this).focus(function(){
				collapse_ll_row_expand_current($(this).parent());
			});
			edit_link.click(function(){
				frow_has_options.removeClass('edit_on');
				frow_has_options.addClass('edit_off');
				// edit on for selected
				SaveInputValues();
				$(this).parent().parent().parent().parent().removeClass('edit_off');
				$(this).parent().parent().parent().parent().addClass('edit_on');
				return false;
			});
		});

		function collapse_ll_row_expand_current(item_to_expand) {
			// edit off for all
			//item_to_expand.parent().siblings().not(item_to_expand).removeClass('edit_on').addClass('edit_off').find('.collapse').click();

			// close all other
			item_to_expand.siblings().filter(function() {
				return($(this).find('.options').length && !$(this).is('.closed'))
			}).not(item_to_expand).not("#radios_container").removeClass('edit_on').addClass('edit_off').find('.collapse').click();

			SaveInputValues();
			item_to_expand.removeClass('edit_off').addClass('edit_on');

			if (item_to_expand.hasClass('closed')) {
				item_to_expand.removeClass('closed');
				var coll = item_to_expand.find('.collapse');
				if ($.browser == "msie" && $.browser.version == '6.0') {
					coll.css('top', '40px');
				}
				item_to_expand.find('.options').slideDown('slow', function(){
					if ($.browser == "msie" && $.browser.version == '6.0') {
						coll.css('top', '40px');
					}
				});

				coll.text(aoe_contact['collapse']);
			}
		}

		function SaveInputValues () {
			var input_fields = $('.forms .f-row .options input.i-text');

			input_fields.change(function(){

					var input_id = new String($(this).attr('id'));
					var input_val = $(this).val();

					// console.log(input_val);

					$('#'+input_id+'-span').text(input_val);
			});
		}

		/* Forms optional */
		var input_optional = $('.forms input.optional');

		input_optional.val('optional');
		input_optional.css('color', '#cfcfcf');

		input_optional.focus(function(){
			if ($(this).val() == 'optional') {
				$(this).val('');
				$(this).css('color', '#637b89');
			}
		});

		input_optional.blur(function(){
			if ($(this).val() == '') {
				$(this).val('optional');
				$(this).css('color', '#cfcfcf')
			}
		});

		var forms = $('.forms .f-row');

		forms.each(function(){
			var options = $(this).find('.options');
			options.hide();

			forms_frow = $(this);

			forms_frow.find('.collapse').click(function(){
				$(this).parent().toggleClass('closed');
				//console.log(optionsEf.element.id);
				if ($.browser == "msie" && $.browser.version == '6.0') {
					$(this).css('top', '40px');
				}

				options.slideToggle('slow');

				if ($(this).parent().hasClass('closed')) {
					$(this).text(aoe_contact['options']);
				} else {
					$(this).text(aoe_contact['collapse']);
				}
				return false;
			});

			forms_frow.find('input').focus(function(){
				collapse_ll_row_expand_current($(this).parent());

				return false;
			});
		});

	}
}

function showLangMenu(){
	$('#langue-menu-active').css('display', 'none');
	$('#langue-menu-drop').css('display', 'block');

	langue_menu_opened = true;

	$('body').click(hideLangMenu);
}

function hideLangMenu(e){
	if(langue_menu_opened){
		var srcObj=e.srcElement ? e.srcElement : eval(e.target);
		if(srcObj){
			if(srcObj.id != 'langue-menu-active' && srcObj.id != 'langue-menu-active-flag' && srcObj.id != 'langue-menu-active-name'){
				$('#langue-menu-drop').css('display', 'none');
				$('#langue-menu-active').css('display', 'block');
				langue_menu_opened = false;
			}
		}
	}
}

/* FCE ABC Testing */
function random(low, high) {
    var num;
    num = Math.floor ((Math.random() * (high)) + low);
    return num;
  }

/* Rotation FCEs */

function rotate(cssid){
  var count = $('div.'+cssid).length;
  var selected = random(1,count);
  if (selected != 1) {
    $('div.js_'+cssid+'_'+selected).attr({"style":"display:block;"});
    $('div.js_'+cssid+'_1').attr({"style":"display:none;"});
  }
}



function init() {
	if(navigator.cookieEnabled) {
		document.cookie =  'sifrFetch=true';

		/* javascript configuration for sifr3 */
		var dinrg = { src: 'fileadmin/templates/flash/dinrg.swf' };
		sIFR.useDomLoaded = !sIFR.ua.ie;
		sIFR.activate(dinrg);
		sIFR.replace(dinrg, { selector: '.template-inner #content h1, .template-inner #content h2, #content>h1, #content>h2, #content h3, #col-center h2, #col-right h2', css: '.sIFR-root { color: #637b89; } .sIFR-root a { color: #637b89!important; text-decoration: none; } .sIFR-root a:hover { color: #637b89!important; text-decoration: none; }', wmode: "transparent"});
		sIFR.replace(dinrg, { selector: '#sub-header-right-area h2', css: '.sIFR-root { color: #ffffff; } .sIFR-root a { color: #ffffff!important; text-decoration: none; } .sIFR-root a:hover { color: #ffffff!important; text-decoration: none; }', wmode: "transparent"});

		var dinrb = { src: 'fileadmin/templates/flash/dinrb.swf' };
		sIFR.useDomLoaded = !sIFR.ua.ie;
		sIFR.activate(dinrb);
		sIFR.replace(dinrb, { selector: '#fce_welcome-flag dt .sifr', css: '.sIFR-root { color: #ffffff; }', tuneWidth: 15, offsetTop: 3,wmode: "transparent"});
		sIFR.replace(dinrb, { selector: '#header-3-cols h2, #sub-header-right-area h1', css: '.sIFR-root { color: #637b89; }', wmode: "transparent"});
    }
}


	function cancel(e) {
		if (e && e.preventDefault)
		e.preventDefault(); // DOM style
		return false; // IE style
	}

// GALLERY
var Gallery = Class.create({
 	Galinit: function(){
		var Gallery = this;
		if($('.gallery-single-pop').length) {
			$('.gallery-single-pop').each(function(){
				//
				var el = $(this);
				$(this).insertAfter("#site");
				var newGal = $(".gallery-single-pop:last");
				el = newGal;

				var galleryFrameContainer = el.find('.gallery-single-pop-frame-container');
				var gallerySinglePopRowLeft = el.find('.gallery-single-pop-row-left');
				var gallerySinglePopRowRight = el.find('.gallery-single-pop-row-right');
				var galleryFrameContainerWidth = el.find('.gallery-single-pop-frame').length * 390;

				galleryFrameContainer.css({ 'width' : galleryFrameContainerWidth });

				gallerySinglePopRowLeft.bind('click', function(event){
					Gallery.singleGalleryShift(1, galleryFrameContainer, el);
				});
				gallerySinglePopRowRight.bind('click', function(event){
					Gallery.singleGalleryShift(-1, galleryFrameContainer, el);
				});

				el.find('.gallery-single-pop-close').bind('click', function(event){
					el.fadeOut();
					el.find('.gallery-single-pop-frames').fadeOut();
				});

				//el.fade('hide');
				el.fadeOut();
				el.css({"visibility":"visible"});
				el.hide();
				Gallery.singleGalButChange(el,'left','block');
				Gallery.singleGalButChange(el,'right','block');
			});
			$('.galleryLauncher').each(function(){
				$(this).bind('click', function(event){
					//
					var a = "#"+$(this).attr('rel');
					$(a).fadeIn();
					$(a).find('.gallery-single-pop-frames').fadeIn();
					return false;
				});
			});
		}
 	},

	singleGalleryShift: function(shift, galleryFrameContainer, el) {
		var Gallery = this;
		var inrWidth = el.find('.gallery-single-pop-frame-image').width();
		var galleryFrameContainer = el.find('.gallery-single-pop-frame-container');
		if(shift < 0){
			if(Math.abs(galleryFrameContainer.position().left) < (galleryFrameContainer.find('.gallery-single-pop-frame').length-1)*inrWidth) {
				Gallery.scrollContainer(el, null, parseInt(galleryFrameContainer.position().left) + shift * inrWidth, galleryFrameContainer);
			} else {
				Gallery.scrollContainer(el, '.gallery-single-pop-frames', 0, galleryFrameContainer)
			}
			Gallery.singleGalButChange(el,'right','none');
		}
		if(shift > 0){
			if(Math.abs(galleryFrameContainer.position().left) > 0) {
				Gallery.scrollContainer(el, null, parseInt(galleryFrameContainer.position().left) + shift * inrWidth, galleryFrameContainer);
			} else {
				Gallery.scrollContainer(el, '.gallery-single-pop-frames', (galleryFrameContainer.find('.gallery-single-pop-frame').length-1)*inrWidth*-1, galleryFrameContainer)
			}
			Gallery.singleGalButChange(el,'left','none');
		}
	},


	singleGalButChange: function(el,obj,param) {
		el.find('.gallery-single-pop-row-'+obj).css({'display':param});
	},

	scrollContainer: function(el,el2hide,moveX,galleryFrameContainer){
		var Gallery = this;
		var galleryFrameContainer = el.find('.gallery-single-pop-frame-container');
		//if(el2hide) el.find(el2hide).fadeOut("fast");

		galleryFrameContainer.animate({"left":moveX}, 500, "linear",function(){
			//if(el2hide) el.find(el2hide).fadeIn();
			Gallery.singleGalButChange(el,'left','block');
			Gallery.singleGalButChange(el,'right','block');
		});
	}

});

// MOOTOOLS...

// Tell-a- Friend
function tell_friend_submit() {
	var action = $('#tipform').attr('action');
	var name = $('#name').val();
	var email = $('#email').val();
	var recipient = $('#recipient').val();
	var message = $('#message').val();
	var code = $('#code').val();
	//var url = $('#url').html();

	action += '&TIPFORM[name]=' + name + '&TIPFORM[email]=' + email + '&TIPFORM[recipient]=' + recipient + '&TIPFORM[message]=' + message + '&TIPFORM[captchaResponse]=' + code + '&sendTip=1';

    $.get(action,"type=86",function(data,status){
		//
		if(status=="success"){
			//
			$('#fog').fadeOut("fast");
			$('#tellafriend_form').fadeOut("fast",function(){
				$("#tipafriend_container").remove();
				var newLightBoxForTipAFriend = $(document.createElement("div"));
				newLightBoxForTipAFriend.attr({"id":"tipafriend_container"}).html(data).insertAfter("#header");
				$("#tipform").submit(tell_friend_submit);

				$('#tellafriend_area img').live('click', function(){
					$('#fog').fadeOut("fast");
					$('#tellafriend_form').fadeOut("fast",function(){ $("#tipafriend_container").remove(); });
				});
				$('#backlink a').live('click', function(){
					$('#fog').fadeOut("fast");
					$('#tellafriend_form').fadeOut("fast",function(){ $("#tipafriend_container").remove(); });
					return false;
				});
			});
		}
	});
	return false;

}
/* */


function tell_friend(){

	var tipUrl = $('.icon-tell-a-friend').attr('href');
    $.get(tipUrl,"type=86",function(data,status){
		//
		if(status=="success"){
			var newLightBoxForTipAFriend = $(document.createElement("div"));
			newLightBoxForTipAFriend.attr({"id":"tipafriend_container"}).html(data).insertAfter("#header");
			$("#tipform").submit(tell_friend_submit);

			//var newLightBoxForTipAFriend = new Element('div', { 'id': 'tipafriend_container'}).set('html', response).injectAfter('header');
			$('#tellafriend_area img').live('click', function(){
				//
				$('#fog').fadeOut("fast");
				$('#tellafriend_form').fadeOut("fast",function(){ $("#tipafriend_container").remove(); });
			});
			var action = $('#tipform').attr('action');
			$('#tipform').attr({'action':action.replace('?&type=86', '')});
		}
	});
	return false;
}

var bigPic;
var bigPicWrpr
var closePic;
var vertPad=40;
var horPad=40;
var myBigPicWrpr=$("<div>");
var myBigPic=$("<img>");
var myCloseBut=$("<div>");
var flash = false;

function openPic1(obj,w,h,isflash){

	flash = typeof(isflash) != 'undefined' ? true : false;

	if(!flash){
		var tmpImg = new Image();
		tmpImg.src = obj.href;
		tmpImg.onload = bigPicLoaded;
	}

	if($('.myBigPicWrpr').length == 0){

		myBigPicWrpr = $("<div>").addClass("myBigPicWrpr").css({"margin-left":-1*(w+horPad*2)/2, "margin-top":-1*(h+vertPad*2)/2,"width":(w+horPad*2),"height":(h+vertPad*2),"visibility":"visible","opacity":"0"}).hide();

		if(!flash){
			myBigPic = $("<img>").addClass("myBigPic").css({"width":w,"height":h,"margin-left":-1*w/2,"margin-top":-1*h/2,"background":"url("+obj.href+") 50% 50% no-repeat"}).attr('src','/fileadmin/templates/images/blank.gif').click(function(){ closePic1(bigPic, myCloseBut, bigPicWrpr, closePic); }).hide();
		} else {
			myBigPic = $("<div>").addClass("myBigPic").append(obj).css({"width":w,"height":h,"margin-left":-1*w/2,"margin-top":-1*h/2});
		}

		myCloseBut = $("<div>").addClass("myCloseBut").attr({"title":"Click to hide"}).css({"margin-left":(w+horPad*2)/2-25,"margin-top":(-1*(h+vertPad*2)/2+15)}).click(function(){  closePic1(bigPic, myCloseBut, bigPicWrpr, closePic); });


		if($.browser.msie && $.browser.version < 7){ // check if ie6
			//myBigPicWrpr.css({'top': ($("body").scrollTop() + ($("body").height() / 2))});
			//myBigPic.css({'position':'absolute', 'top': ($("body").scrollTop() + ($("body").height() / 2))});
			//myCloseBut.css({'top': ($("body").scrollTop() + ($("body").height() / 2))});
		}

		bigPicWrpr = myBigPicWrpr.insertAfter($('#site').parent());
		bigPic = myBigPic.insertAfter($('#site').parent());
		closePic = myCloseBut.insertAfter(myBigPicWrpr);
		bigPicWrpr.fadeIn();
		bigPicWrpr.fadeTo("fast",0.25);
		setTimeout("bigPic.fadeIn()", 1000);
	}
}

function closePic1(bigPic, myCloseBut, bigPicWrpr, closePic){
	bigPic.fadeOut();
	myCloseBut.fadeOut();
    bigPicWrpr.fadeOut('normal', closePics());
	//setTimeout("closePics()",1000);
}
function closePics(){
	bigPic.remove(),bigPicWrpr.remove(),closePic.remove();
}
function bigPicLoaded(){
	w = this.width+200;
	h = this.height+200;
	myBigPicWrpr.animate({"marginLeft":-w/2, "marginTop":-h/2,"width":(w),"height":(h)},500);
	if($.browser.msie && $.browser.version < 7){ // check if ie6
		myBigPic.animate({"width":w,"height":h,"marginLeft":-w/2+100,"marginTop":-h/2+100},500);
	}else{
		myBigPic.animate({"width":w,"height":h,"marginLeft":-w/2,"marginTop":-h/2},500);
	}
	myCloseBut.animate({"marginLeft":w/2-25,"marginTop":-1*h/2+15},500);
}

/* hide delay timer for the droparea of the callbackform */
var timeoutid = null;
function close_contactdroparea() {
	var contact_droparea = $('div.tx-thmailformplus-pi1').parent().parent().parent().parent().parent();
	contact_droparea.attr('style', '');
	clearTimeout(timeoutid);
}


/*  Welcome Flag */
function welcome_flag() {
    
	var flagUrl = window.location.protocol+'//'+window.location.host+'/';
      
	$.ajax({
   	beforeSend: function(xhrObj){
			xhrObj.setRequestHeader("Referer",document.referrer);
       },
       type: "GET",
       url: flagUrl,
       data: "type=77&referer="+ urlencode(document.referrer),
       dataType: "html",
       success: function(data){
          	        var newWelcomeFlag = $(document.createElement("div"));
		newWelcomeFlag.attr({"id":"welcomeflag_container"}).html(data).insertAfter("#header");

		if($("#fce_welcome-flag").find('dd.content').html().length > 5) {
			setTimeout('Show_fce_welcome_flag()',3000);
		}
       }
});
  
	return false;
}

function urlencode(str) {
  return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}