// JavaScript Document
var Designa = {
	
	fadeMenu : {
		oActive : null,	
		controlMenu : function()
		{
			$('#MainNav > li, #Head .rex-navi1 > li').hover(function()
			{
				if (Designa.fadeMenu.oActive)
				{
					Designa.fadeMenu.showHideMenu(0);
					Designa.fadeMenu.oActive = null;
				}
				
				Designa.fadeMenu.showHideMenu(1,this);
			}, function()
			{
				Designa.fadeMenu.oActive = $(this);
				window.setTimeout( function(){ Designa.fadeMenu.checkMenu(); }, 250);
			});
		},
		
		showHideMenu : function(bShow,oObj)
		{			
			if (bShow == 1 && oObj)
			{
				$(oObj).find('ul').fadeIn();
			}
			else
			{
				Designa.fadeMenu.oActive.find('ul').fadeOut('fast');
			}
		},
		
		checkMenu : function()
		{
			if (Designa.fadeMenu.oActive)
			{
				Designa.fadeMenu.showHideMenu(0);
			}
		}
	},
	
	SubNavHoverIE6 : function()
	{
		if ( (document.all && !window.opera) && !window.XMLHttpRequest )
		{
			$('#SubNavLev3 li').hover(function()
			{
				$(this).addClass('hover');
			},function()
			{
				$(this).removeClass('hover');
			});
		}
	}

}


$(document).ready(function(){
	// Laguage Choose
	/*var displayLanguagePosition = $("#DisplayLanguage").position();
	var displayLanguageWidth = $("#DisplayLanguage").outerWidth();
	var headWidth = $("#Head").outerWidth();
	var LanguageChooseWidth = $("#LanguageChoose").outerWidth();
	
	displayLanguagePosition.rightSide = displayLanguagePosition.left + displayLanguageWidth + 20;
	var newLeft = displayLanguagePosition.rightSide - 596;
	var LanguageChooseRightSide = newLeft + LanguageChooseWidth;
	
	if(headWidth < LanguageChooseRightSide ){
		newLeft = newLeft - (LanguageChooseRightSide - headWidth);
		$("#NavActive").css("marginLeft", 495 + (LanguageChooseRightSide - headWidth) );
	}*/
	
	//$('#ServiceNav03').text(headWidth + " : " + LanguageChooseRightSide + " : " + newLeft);
	
	//$("#LanguageChoose").css("left", newLeft);
	// Laguage Choose end
	
	
	
	$("#mycarousel").jcarousel({visible:2, scroll:1});
	
	$('#NewsLetterLink').click(function () {
		$('#NewsLetterForm').slideToggle();
		return false
	});
	
	// CallBack Form Toggle					   
	$('#CallBackLink').click(function () {
		$('#CallBackForm').slideToggle();
		return false
	});
	$("#CallBackForm input.text, #CallBackForm input.text").focus(function(){
	defaultValue = $(this).attr('value');
	//if($(this).attr('value') == 'Ihr Name' || $(this).attr('value') == 'Ihre Telefonnummer'){ 
		$(this).attr('value','');
	//}
	});
	$("#CallBackForm input.text, #CallBackForm input.text").blur(function(){
	if ($(this).attr('value') == '') {
	$(this).attr('value',defaultValue);
	}
	});
	
	//Newsletter Klapper
	$("#NewsLetterForm input.text, #NewsLetterForm input.text").focus(function(){
	defaultValue = $(this).attr('value');
	//if($(this).attr('value') == 'Ihr Name' || $(this).attr('value') == 'Ihre Telefonnummer'){ 
		$(this).attr('value','');
	//}
	});
	$("#NewsLetterForm input.text, #NewsLetterForm input.text").blur(function(){
	if ($(this).attr('value') == '') {
	$(this).attr('value',defaultValue);
	}
	});
	//Newsletter Klapper ende
	
	
	$('#CallBackForm .submit').click(function () {
		cbSubject = $('#CallBackSubject').val().replace('*','');
		cbName = $('#CallBackName').val().replace('*','');
		cbNumber = $('#CallBackNumber').val().replace('*','');
		cbClang = $('#CallBackClang').val().replace('*','');
		cbCountry = $('#CallBackCountry').val().replace('*','');
		type = $('#CallBackForm .type').val();
		recipient = $('#CallBackForm .recipient').val();
		hash = $('#CallBackForm .hash').val();
		

		//alert(cbName + ' - ' + cbNumber);
		$.post("/php/formmail.php",
		       {
				formBetreff: cbSubject,
				formNummer: cbNumber,
				formName: cbName,
				formLand: cbCountry,
				clang: cbClang,
				type: type,
				ajax: 'yes',
				recipient: recipient,
				confirm: hash
			},
			function(data){
				$('#CallBackForm p').html(data);
			}
		);
		return false
	});
	
	
	
	// SheetOrder Form Toggle					   
	$('.sheet-order-link').click(function () {
		$(this).next('.sheet-order-form').slideToggle();
		return false
	});
	$(".sheet-order-form input.text, .sheet-order-form input.text").focus(function(){
	defaultValue = $(this).attr('value');
	//if($(this).attr('value') == 'Ihr Name' || $(this).attr('value') == 'Ihre E-Mail-Adresse'){ 
		$(this).attr('value','');
	//}
	});
	$(".sheet-order-form input.text, .sheet-order-form input.text").blur(function(){
	if ($(this).attr('value') == '') {
	$(this).attr('value',defaultValue);
	}
	});
	
	$('.sheet-order-form .submit').click(function () {
		email = $(this).prevAll('.order-mail').val();
		name = $(this).prevAll('.order-name').val();
		country = $(this).prevAll('.order-country').val();
		clang = $(this).prevAll('.clang').val();
		type = $(this).prevAll('.type').val();
		paper = $(this).prevAll('.thepaper').val();
		hash = $(this).prevAll('.hash').val();
		
		actor = $(this);
		
		//alert(email + ' - ' + name + ' - ' + clang + ' - ' + type);
		$.post("/php/formmail.php",
		       {
				formEmail: email,
				formName: name,
				formCountry: country,
				clang: clang,
				type: type,
				formThepaper : paper,
				confirm: hash,
				ajax: 'yes'
			},
			function(data){
				actor.prevAll('p').html(data);
			}
		);
		return false
	});
	
	
	
	
	$(".box-download-select select").change( function() {
		location.href=$(this).attr('value');
	});
	
	$(".box-download-filter select").change( function() {
		url = $("input.url").attr('value');
		url += $("select[name=branch]").attr('value');
		url += $("select[name=product]").attr('value');
		url += $("select[name=city]").attr('value');
		
		//alert(url);
		location.href=url;
	});
	
	

	$('a[rel=lightbox]').lightBox({
	imageLoading: 'src/img/structure/lightbox/lightbox-ico-loading.gif',
	imageBtnClose: 'src/img/structure/lightbox/lightbox-btn-close.gif',
	imageBtnPrev: 'src/img/structure/lightbox/lightbox-btn-prev.gif',
	imageBtnNext: 'src/img/structure/lightbox/lightbox-btn-next.gif',
	txtImage: 'Bild',
	txtOf: 'von'
        });
	$('#mycarousel li a[rel=casestudy]').lightBox({
	imageLoading: 'src/img/structure/lightbox/lightbox-ico-loading.gif',
	imageBtnClose: 'src/img/structure/lightbox/lightbox-btn-close.gif',
	imageBtnPrev: 'src/img/structure/lightbox/lightbox-btn-prev.gif',
	imageBtnNext: 'src/img/structure/lightbox/lightbox-btn-next.gif',
	txtImage: 'Bild',
	txtOf: 'von'
        });
	

        $('.jttip').hide();

	$('#Map area[title]').qtip({
		position: {
			corner: {
				target: 'topLeft',
				tooltip: 'bottomMiddle'
			}
		},
		style: {
			'padding': 4,
			'padding-left': 177,
			'background': 'url(src/img/structure/layout/map_tip.png) no-repeat right top transparent',
			'height': 17,
			'width': 370,
			'border': 'none',
			'margin-bottom': 5
		}
	});

	Designa.fadeMenu.controlMenu();
	Designa.SubNavHoverIE6();

	$("#DisplayLanguage").click(function () {
		$("#LanguageChoose").slideToggle("fast");
		return false;
	});
	
	$("body").click(function () {
		$("#LanguageChoose").slideUp("fast");
	});
	
	$("#DisplayLanguageActive").click(function () {
		$("#LanguageChoose").slideToggle("fast");
		return false;
	});
	
	$('#ListNEWS').vTicker({
		speed: 1000,
		pause: 3000,
		showItems: 3,
		animation: 'fade'
	});
	
	$('#Map map').click(function(){
		return false;
	});
	
	$(".fixed-height a[href^='#']").click(function(){
		return false;
	});
	
	var myPane = $('.scroll-pane');
	//var firstPane = $(ankerPane[0]);
	//firstPane.jScrollPane({animateTo:true});
	myPane.jScrollPane({scrollbarWidth:7, scrollbarMargin:0});

	
	$('a.scroll, a.go-to-top').click(function()
		{
		//$(this).css('color','red');
		var targetElementSelectorString = $(this).attr('title');
		//alert($(firstPane).html());
		
		myPane[0].scrollTo('#'+targetElementSelectorString);
		return false;
		}
	);
	

	/* Pressebericht Bilderscroller */	
	$("div.imagestripe").smoothDivScroll({
		scrollingSpeed: 12,
		visibleHotSpots: "always"
		//hotSpotsVisibleTime: 9,
		//startAtElementId: "startAtMe"
	});

      


});



var currentFormElem = null;
var showHideValue = function(obj,val)
{
	if (obj != currentFormElem)
	{
		currentFormElem = obj;
		if (obj.value == val)
			obj.value = '';
			
		obj.onblur = function()
		{
			showHideValue(obj,val);
		}
	}
	else
	{
		if (obj.value == '')
			obj.value = val;
		
		obj.onblur = null;
		
		currentFormElem = null;
	}
};

function toggleadress() {
	var ele = document.getElementById("toggleText");
	var text = document.getElementById("displayText");
	if(ele.style.display == "block") {
    		ele.style.display = "none";
  	}
	else {
		ele.style.display = "block";
	}
}