var Functions= {};

$(window).bind('resize', function() {	
	Functions.moveFooter();
});

$(window).bind('load', function() {	
	Functions.init();
});

Functions= {
	footerIsOpen: false,
	
	init: function() {
		Functions.initFooter();
		Functions.initClientSlider();
	},
	getWindowHeight: function() {
		if(typeof( window.innerWidth) == 'number') {
			return window.innerHeight;
		} else {
			return document.documentElement.clientHeight;
		}
	},
	
	getTotalHeight: function() {
		return window.outerHeight;
	},
	getTotalWidth: function() {
		return window.outerWidth;
	},
	getBrowserWidth: function() {
		return (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);
	},
	getBrowserHeight: function() {
		return (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth);
	},
	initFooter: function() {
		Functions.moveFooter();
		$("#openf").click(function() {
			Functions.openFooter();
	    });
		$("#footerpfeilclick").click(function() {
			Functions.openFooter();
	    });
	},
	unbindFooter: function() {
		$("#openf").unbind("click");
		$("#footerpfeilclick").unbind("click");
	},
	moveFooter: function() {
		if(!Functions.footerIsOpen) {
			$("#footer").css("top", Functions.getWindowHeight() - 35);
		} else {
			$("#footer").css("top", (Functions.getWindowHeight() - 257));
		}
	},
	openFooter: function() {
		Functions.turnPfeil();
		if(!Functions.footerIsOpen) {	
			Functions.unbindFooter();			
			$("#footer").animate({ 
				top: Functions.getWindowHeight()-257+"px"
			}, 600, null, Functions.footerAniReady );
		} else {			
			$("#footer").animate({ 
				top: Functions.getWindowHeight()- 35+"px"
			}, 600, null, Functions.footerAniReady );
		}
	},
	footerAniReady: function() {
		Functions.footerIsOpen = !Functions.footerIsOpen;
		Functions.initFooter();
	},
	turnPfeil: function() {
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window["footerpfeil"].javaTurnPfeil();
        } else {
            return document["footerpfeil"].javaTurnPfeil();
        }
	},
	initClientSlider: function() {
		//set sliderpositions
		var left= 0;
		$("#logos ul li").each(function() {
			$(this).css("left", left);
			left+= parseInt($(this).css("width"))+50;
		});
		var sliderWidth= left-900-50;
		
		//set sliderhandle
		$("#slider").slider({ 
			handle: '.ui-slider-handle',
			slide: function (event, ui) {
				left= (sliderWidth*ui.value)/100;
				$("#logos ul").css('left', '-' + left + 'px');
			}, 
			stop: function (event, ui) {
				left= (sliderWidth*ui.value)/100;
				$("#logos ul").animate({ 'left' : '-' + left + 'px' }, 500, 'linear');
			}
		});
	},
	checkEmail: function(){
			var email=$("#check_email");
			var result=true;
			
			if(email.get(0).value.match(/\S@\S.\S{2,}/)==null) {
				result= false;
				alert("Bitte geben Sie eine korrekte E-Mail-Adresse an.");
			}			
			
			return result;
	}
	
}

