var doFix = false;
function adjustBackground() {
	var width = 3336;
	var height = 2336; 

	var width = $('#background').width();
	var height = $('#background').height(); 
	
	
	var ratio = height / width;	
	// Get browser window size
	var browserwidth = $(window).width();
	var browserheight = $(window).height();
	// Scale the image
	if ((browserheight/browserwidth) > ratio){
		$('#background').height(browserheight);
		$('#background').width(browserheight / ratio);
	} else {
		$('#background').width(browserwidth);
		$('#background').height(browserwidth * ratio);
	}
	// Center the image
	$('#background').css('left', (browserwidth - $('#background').width())/2);
	$('#background').css('top', (browserheight - $('#background').height())/2);
	if ($.browser.msie) {
		$('#background').show();
	}
	else {
		$('#background').fadeIn(600);
	}
}

$(window).resize(function(){  
	adjustBackground();
});
$(window).load(function() {
	$(document).pngFix();
	adjustBackground();

	$('a').each(function() {
		if ($(this).attr('rel') == 'external') {
			$(this).click(function() {
				window.open($(this).attr('href'));
				return false;
			});
		}
	});	
	
	$(".thickbox").fancybox({
		'speedIn'		: 600, 
		'speedOut'		: 600, 
		'transitionIn'  : 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'showNavArrows' : true,
		'overlayOpacity': 0.5
	});
	
	$(".popup").fancybox({
		'speedIn'		: 200, 
		'speedOut'		: 200, 
		'overlayOpacity': 0.5,
		'autoScale'		: false,
		'autoDimensions': false,
		'type'			: 'iframe',
		'width': 320,
		'height': 320 
	});	
	
	$('.textfield').corner("round 5px");

	$('#dwgform').submit(function() {
		pageTracker._trackPageview($('#dwgfile').val());
		window.open($('#dwgfile').val());
		return false;
	});
	
});

function focusField(element, value) {
	element.className = 'textfield active';
	if (element.value == value) {
		element.value = '';
	}
}

function blurField(element, value) {
	if (element.value == '') {
		element.value = value;
		element.className = 'textfield inactive';
	}
}

function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
		for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}

$.clientCoords = function() {
	var dimensions = {width: 0, height: 0};
	if (document.documentElement) {
		dimensions.width = document.documentElement.offsetWidth;
		dimensions.height = document.documentElement.offsetHeight;
	} 
	else{
		if (window.innerWidth && window.innerHeight) {
			dimensions.width = window.innerWidth;
			dimensions.height = window.innerHeight;
		}
	}
	return dimensions;
}

var activeTab = 1
function switchTab(id) {
	if (id != activeTab) {
		$('#tab_' + activeTab).removeClass('active');
		$('#tab_' + id).addClass('active');
		$('#tab_' + activeTab + ' .img1').attr('src', '/img/tab_inactive_links.png');
		$('#tab_' + activeTab + ' .img2').attr('src', '/img/tab_inactive_rechts.png');
		$('#tab_' + id + ' .img1').attr('src', '/img/tab_active_links.png');
		$('#tab_' + id + ' .img2').attr('src', '/img/tab_active_rechts.png');		
		$('#tab_page_' + activeTab).hide();
		$('#tab_page_' + id).fadeIn();
		activeTab = id;
	}
}
