/*
function initPage()
{
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: true,
		addClassFocus: "focus",
		filterClass: "default"
	});
}
function clearFormFields(o)
{
	if (o.clearInputs == null) o.clearInputs = true;
	if (o.clearTextareas == null) o.clearTextareas = true;
	if (o.passwordFieldText == null) o.passwordFieldText = false;
	if (o.addClassFocus == null) o.addClassFocus = false;
	if (!o.filterClass) o.filterClass = "default";
	if(o.clearInputs) {
		var inputs = document.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++ ) {
			if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass) == -1) {
				inputs[i].valueHtml = inputs[i].value;
				inputs[i].onfocus = function ()	{
					if(this.valueHtml == this.value) this.value = "";
					if(this.fake) {
						inputsSwap(this, this.previousSibling);
						this.previousSibling.focus();
					}
					if(o.addClassFocus && !this.fake) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				inputs[i].onblur = function () {
					if(this.value == "") {
						this.value = this.valueHtml;
						if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
					}
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
				if(o.passwordFieldText && inputs[i].type == "password") {
					var fakeInput = document.createElement("input");
					fakeInput.type = "text";
					fakeInput.value = inputs[i].value;
					fakeInput.className = inputs[i].className;
					fakeInput.fake = true;
					inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
					inputsSwap(inputs[i], null);
				}
			}
		}
	}
	if(o.clearTextareas) {
		var textareas = document.getElementsByTagName("textarea");
		for(var i=0; i<textareas.length; i++) {
			if(textareas[i].className.indexOf(o.filterClass) == -1) {
				textareas[i].valueHtml = textareas[i].value;
				textareas[i].onfocus = function() {
					if(this.value == this.valueHtml) this.value = "";
					if(o.addClassFocus) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				textareas[i].onblur = function() {
					if(this.value == "") this.value = this.valueHtml;
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
			}
		}
	}
	function inputsSwap(el, el2) {
		if(el) el.style.display = "none";
		if(el2) el2.style.display = "inline";
	}
}
if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage);
*/

var overlay;


$(document).ready(function(){
    $('#header .image-slider img').css('display', 'none');
    $('#header .image-slider img:first').addClass('active').css('display', 'block');
    $('#header .image-slider img:last').addClass('last');
    setInterval( "slideSwitch()", 10000 );
    
    $('.searcharea').focus(function(){
		$(this).attr('value', '');
	});
    
    $('a[target="_blank"]').click(function(e){
        e.preventDefault();
		
        var help = $(this).attr('href');
        var url = encodeURI(help);
        if($(this).hasClass('catalog')){
            help = window.open(url);
        } else if(url.substring(7,19) == window.location.host.substring(0,12) || window.location.host.substring(0,12) == url.substring(11,23)){
			window.location = help;
		} else {
            help = window.open("/forwarder.php?url="+url);
        }
    });
    
    $('.pic').click(function(){
        var _url = $(this).attr('href');
        $.nmManual(_url) /*{
			modal: true,
			closeButton: '<a href="#" class="nyroModalClose" id="closeBut">Close</a>',
			bgColor: '#000000',
			cssOpt: {
				bg: {
					'opacity': '0.20'
				},
				content : {
					'overflow-y': 'hidden',
                    'overflow-x': 'hidden'
				}
			},
			url : _url,
			endFillContent : function(elts, settings){
				$(elts.wrapper).after(settings.closeButton);
			},
			endShowContent : function(){
				tooltips();
			},
			zIndexStart:5000
		});*/
		return false;
    });
    /*
    $('.catalog').click(function(){
		var _url = $(this).attr('href');
        $.nmManual(_url, {sizes: {minW: 910, minH: 550}});
        return false;
    });
    */
    
    $('.formular').click(function(){
		var _url = $(this).attr('href');
        _url += '?url=' + $(this).attr('href');
		if ($(this).attr('id')=='contact'){
            _url = _url + '&action=' + $(':checked').attr('id');
        }
        $.nmManual(_url); 
		return false;
	});
    
    $('#formular').click(function(){
		var _url = $(this).attr('href');
        $.nmManual(_url); 
		return false;
	});
    
    $('.login').click(function(){
		var _url = $(this).attr('href');
        $.nmManual(_url); /*{
			modal: true,
			closeButton: '<a href="#" class="nyroModalClose" id="closeBut">Close</a>',
			bgColor: '#000000',
			cssOpt: {
				bg: {
					'opacity': '0.20'
				},
				content : {
					'overflow-y': 'auto'
				}
			},
			url : _url,
			endFillContent : function(elts, settings){
				var form = elts.content.find('form');
				$(form).addClass('nyroModal');
				// cause of modal is false insert the close-button manually
				$(elts.wrapper).after(settings.closeButton);
			},
            endRemove : function(elts, settings){
                window.location.reload();
            },
			ajax :{
				data: 'mode=ajax'
			},
			formIndicator: 'submit_contact_at',
			zIndexStart:5000,
            height: null,
			wrap: {
			  ajax: '<div class="lightbox"></div>',
			  form: '<div class="lightbox"></div>'
			}
		}); */
		return false;
	});
    /*
    $('#contact-form').submit(function(e){
        e.preventDefault();
        $('#contacts').addClass('loading');
        $.get($(this).attr('href'), $(this).serializeArray(), function(data) {
            $('#contacts').html(data);
            $('#contacts').removeClass('loading');
        });
    });*/
	var $_GET = {};

	document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
		function decode(s) {
			return decodeURIComponent(s.split("+").join(" "));
		}
		$_GET[decode(arguments[1])] = decode(arguments[2]);
	});

	$('input[value="'+$_GET['type']+'"]').click();
	$('input[value="'+$_GET['section']+'"]').click();
	$('input[value="'+$_GET['country']+'"]').click();
	$('input[name="zipcode"]').val($_GET['zipcode']);
	$.get($('#contact-form').attr('href'), $('#contact-form').serializeArray(), function(data) {
            $('#contacts').html(data);
            $('#contacts').removeClass('loading');
	});
    
});

function slideSwitch(){
    var help = $('#header .image-slider img.active');
    help.fadeOut('slow');
    if (help.hasClass('last')) {
        $('#header .image-slider img:first').addClass('active').fadeIn('slow');
        help.removeClass('active');
    } else {
        help.next('img').fadeIn('slow').addClass('active');
        help.removeClass('active');
    }
}

function closeOverlay() {
	overlay.close();
}

function tooltips(){
// the tooltip function for the forms
	$("form :input[title!='']").tooltip({
		position: "center right",
		// position is now direct at form field
		relative: false,
		opacity: 1,
		effect: "fade",
		offset: [0,10],
		lazy: false,
		tip: '.tooltip'
	});
}


