xpngFix({root:'content'});	 
xpngFix({elms:[['lr-bg'],['footer-shadow'],['navibar-corner-r'],['navibar-corner-l']]});	 
function openBrWindow(theURL,winName,b,h,features) 
{ 			
	var	x = (screen.width-b)/2,
		y = (screen.height-h)/2,
		s="left="+x+",top="+y+",screenX="+x+",screenY="+y + ",width="+b+",height="+h+","+features;
		window.open(theURL,winName, s);			
}


var timeout;
(function($) 
{
	$.noConflict();
	$(document).ready(function(){
		fixBg();
		
		var leftstarttabs = $('.leftstartbox');
	    for(i=0;i<leftstarttabs.length;i++){
	    	var leftstarttabid = leftstarttabs[i].id;
	    		if($('#'+leftstarttabid).offset().top > 245){
	    			leftstarttabid = leftstarttabid.substring(3,leftstarttabid.length);
	    			$('#box'+leftstarttabid).remove();
	    		}
	    }
		
	 // header hoehe anpassung
	    if($('#header').height() < 219){
		   var headerheight = $('#logo').height() + $('#you-are-here').height()+ 46;
		   $('#header').css("height", headerheight+ "px");
	   }
		//bind menu
		$('#navibar .superfish').superfish({
			onShow: function()
			{
					var subnaviFooterElms,
						subnaviFooterElms = $(this).children('.subnavi-bottom, .subnavi-corner-l, .subnavi-corner-r')
					;

					$(this).children('li:last').children('a').mouseover(function(){
						if ($.browser.msie)
							subnaviFooterElms = $(this).parents('li:first').children('.subnavi-bottom, .subnavi-corner-l, .subnavi-corner-r');

						subnaviFooterElms && subnaviFooterElms.each(function(){
							this.className = addHover(this.className);
						});
					}).
					mouseout(function(){
						subnaviFooterElms && subnaviFooterElms.each(function(){
							this.className = removeHover(this.className);
						});
					});
					
			},
			speed: 1
		});
		
		function addHover(className)
		{
			className.replace(/hover/g,'');
			return className.indexOf('hover')==-1 ? className+'-hover' : className;
		};
		function removeHover(className)
		{
			return className.replace('-hover','');
		};

		function triggerHoverClass (className) 
		{
			if ("subnavi-bottom-hover subnavi-corner-l-hover subnavi-corner-r-hover".indexOf(className)!=-1 )		
				return (className.indexOf('hover')!=-1) ? className.replace('-hover','') : className+'-hover';
		};


		//Product details
		//delete border from the last item in overview
		$('.product-details .overview.blue li:last, .product-details .overview.green li:last').css('border',0);
		//set the boxes on the same size
		var boxBlueH = $('.product-details .overview.blue .content').height(),
			boxGreenH = $('.product-details .overview.green .content').height()
		;
		boxBlueH > boxGreenH ? $('.product-details .overview.blue .content, .product-details .overview.green .content').height(boxBlueH) : $('.product-details .overview.blue .content, .product-details .overview.green .content').height(boxGreenH)
		
		$('#center table').wrap('<div class="table-header"><div class="table-footer"></div></div>');
		$('#center table').find('tr:last td').css('border','none');

		

		//Forms
		$('.iqom form').prepend('<input type="hidden" name="javascript" value="true"/>');
		$('.iqom input').attr('maxLength',200);
		$('.contact-form form').submit(function(){
			submitForm(this);
			return false;
		});
		
		var formsData = {
			login: null,
			customer: null,
			contact: null,
			issue: null
		};
		var submitting = false;
		function submitForm (elm, callback)
		{
			if (!submitting)
			{

					submitting = true;
					$(elm).ajaxSubmit({
						dataType:  'json',
						success: function(responseText, statusText)
						{
							if (responseText.error)
							{
								
								$.popup($('#'+responseText.error).text(),{
									width: 320,
									title: $('#'+responseText.error).attr('title')
								});
							}
							else if (responseText.success && responseText.redirect)
								window.location=responseText.redirect;
							else 
								$(callback);
		
							if (responseText.success && responseText.data)	
							{
			
								formsData[responseText.id] = responseText.data;
								printData(responseText.id, responseText.data);
							};
							submitting = false
						},
						error: function(msg)
						{
							$.popup(msg);
						}			
						 
					}); 
			};
					
		};
		
		//print the data for overview tab on support form
		function printData(id, obj)
		{		
			$('#overview-'+id).empty();
			for ( i in obj)
				for ( data in obj[i] )
				{
					
					var container = $('#overview-'+id);
					$('<div class="left"/>').html(data).
					appendTo(container);
					$('<div class="right"/>').html(obj[i][data]).
					appendTo(container);
					
					
				};
		};
		
		
		//Support form header
		var activeTab='#login';
		$('.support-form #login-tab').click(function(){
			changeTab($(this).attr('href'),activeTab);
			activeTab = '#login';
			return false;
		});
		
		var tabs = "#login#customer#contact#issue#overview";
		function changeTab(nextTab, formElm)
		{
			if ($(nextTab).css('display')=='none')
			{
				
				if (tabs.indexOf(nextTab) > tabs.indexOf(activeTab))
				{
					submitForm(formElm, function(){
						$(activeTab).slideUp(300, function(){
							$(nextTab).slideDown(300, function(){
								fixBg();
								activeTab=nextTab;
								$('.support-form .header a').removeClass('active');
								$(nextTab+'-tab').addClass('active');	
							});
						});
						
						if (nextTab == '#customer')
							$('.support-form #customer-tab').click(function(){
								changeTab($(this).attr('href'),activeTab);
								return false;
							});
						
						if (nextTab == '#contact')
							$('.support-form #contact-tab').click(function(){
								changeTab($(this).attr('href'),activeTab);
								return false;
							});
	
						if (nextTab == '#issue')
							$('.support-form #issue-tab').click(function(){
								changeTab($(this).attr('href'),activeTab);
								return false;
							});
	
						if (nextTab == '#overview')
							$('.support-form #overview-tab').click(function(){
								changeTab($(this).attr('href'),activeTab);
								return false;
							});
	
			
					
					});						
				} 
				//Change Tab without submit
				else
				{
					$(activeTab).slideUp(300, function(){
						$(nextTab).slideDown(300, function(){
							fixBg();
							activeTab=nextTab;
							$('.support-form .header a').removeClass('active');
							$(nextTab+'-tab').addClass('active');
						});
					});	

				};
			};		
		
		};


		
		
		$('#login').submit(function(e){
			changeTab('#customer', this);
			return false;
		});
		$('#customer').submit(function(){
			changeTab('#contact', this);
			$('#contact select[name="contact_title"]').val($('#customer select[name="customer_title"]').val());
			$('#contact select[name="gender"]').val($('#customer .radio-group input[checked]').val());
			$('#contact input[name="contact_firm"]').val($('#customer input[name="firm"]').val());
			$('#contact input[name="contact_last_name"]').val($('#customer input[name="responsible_last_name"]').val());
			$('#contact input[name="contact_first_name"]').val($('#customer input[name="responsible_first_name"]').val());

			return false;
		});
		$('#contact').submit(function(){
			changeTab('#issue', this);
			return false;
		});
		$('#issue').submit(function(){
			changeTab('#overview', this);
			return false;
		});
		$('#overview').submit(function(){
			$.post(
				$('#overview').attr('action'), 
				$('#all_forms *').fieldSerialize(),
				function(data){
					if (data.error)
						$.popup($('#'+data.error).text(),{
							width: 320,
							title: $('#'+data.error).attr('title')
						})
					else if (data.redirect)		
						
						window.location=data.redirect;
				},
				'json'
			);
			return false;
		});	
		


		
		
		//------------------------------------------------------------
		//popup for chat
		if ( !$.cookie('chatpopup') )
		{
			var interval = $('#chat-popup').attr('rel');

			timeout = setTimeout(showChatPopup, interval);
			$(document).one("click",function(e){
				e.stopPropagation();
				if ($.cookie('chatpopup'))
					clearTimeout(timeout);
				else
				{
					clearTimeout(timeout);
					timeout = setTimeout(showChatPopup, interval);
				};
				$(this).unbind('click');
			});
		};

		location.hash == "#chatpopup" && showChatPopup();
		//------------------------------------------------------------
		
	
		
		//Highlighboxes Slideshow
		var settings = $('.highlightbox').attr('rel') ? {interval: $('.highlightbox').attr('rel')} : null;
		settings && $('.highlightbox_rt .highlightbox_rb').contentSlideShow(settings);
		settings && $('.highlightbox_left').contentSlideShow( $.extend(settings, {tabsContainer: '.highlightbox-tabs', tabs: '.tab', random: true, active: '#werbekampagne'}) );
		
		
		//Startpage SlideShow
		var settings = $('#start .start-infoboxes').attr('rel') ? {interval: $('#start .start-infoboxes').attr('rel')} : null;
		settings && $('.infoboxes-left').contentSlideShow(settings);
		
		
		
		

	});	
	
	function fixBg()
	{
		//Fix bakcground
		var 
			h = $('#center').height()+100,
			wH = $(window).height()
		;
		wH>h ? h = wH : false;
		$('#body-bg').height(h);

	};
	$(window).load(function(){
			fixBg();
	});
		
		

	
})(jQuery);

	
function showChatPopup()
{
	(function($) 
	{	
		if ( $('.popup-window').length<1)
		{
			var title = $('#chat-popup h1:first').hide().text();

			$.popup($('#chat-popup').html(),{
				top: 100,
				title: title,
				buttons: {
					back: {
						title: $('#chat-popup').attr('button'),
						onclick: function(wnd){
							wnd.trigger('close');
							setCookie();
						}
					}
					
				},
				width: 560,
				className: 'chat-popup',
				onclose: function(){
					setCookie();
				}
			});

			
			function setCookie(){
				timeout && clearTimeout(timeout);
				//chat popup wird 1 tag nicht angezeigt
				$.cookie('chatpopup',"blocked",  { expires: 1, path: '/'});			
			};
			
			
			$('.chat-popup form.left').submit(function(e){
			
				$(this).ajaxSubmit({
					dataType:  'json',
					success: function(responseText, statusText)
					{
						if (responseText.error)
						{
							$('.chat-popup .errors *').hide();
							$('.chat-popup input').removeClass('input-error');
							//alert('.chat-popoup input.'+responseText.error);
							$('.'+responseText.error).addClass('input-error');
							
							$('#'+responseText.error).show();
							
						}
	
						if (responseText.success)	
						{	
							
							//alert( $('#'+responseText.success).text());
							//$('.chat-popup').trigger('close');
							$('.chat-popup .background').height($('.chat-popup .background').height()).empty().
							append('<h1 class="success">'+$('#'+responseText.success).text()+'</h1>');
						};
					},
					error: function(msg)
					{
						alert(msg);
					}								
				});
			
			
				return false;
			});
			

			$('.chat-popup form.right').submit(function(e){
				showChat();
				
				$('.chat-popup').trigger('close');
			
	
				return false;
				
			});

		};

	
	})(jQuery);
};	

//direct chat popup
function showChat ()
{
	jQuery.browser.msie ? jQuery('#chat_preload').children('a').attr('onclick').apply() : jQuery('#chat_preload a').click();
};			


