$(document).ready(function() {
                var head = $('.head').height();
                var content = $('.firstpage').height();
                var footer = $('.footer').height();
                if($(window).height() > (head + content + footer + 29)){      
                       $('.footer').addClass("footer_full_height");
                }else{
                       $('.footer').removeClass("footer_full_height");
                }
                
                
                
		$('.button').mouseover(function(){
			$(this).find("img").attr("src",'media/gfx/button_hover.png');
		}).mouseout(function(){
			$(this).find("img").attr("src", 'media/gfx/button.png');
		});
		
		$('.button_with_text').mouseover(function(){
			$(this).find("img").attr("src",'media/gfx/button_text_hover.png');
		}).mouseout(function(){
			$(this).find("img").attr("src", 'media/gfx/button_text.png');
		});
		
		$('.button_with_text').click(function(){
                        if($(this).hasClass('button_with_text_nopop')){
                            link = $(this).find("a").attr("href");
                            window.location.href = link;
                            return false;
                        }
                    
			link = $(this).find("a").attr("href");
			$(this).poppy(link);
			linkshare = $('#share').attr('href');
			$('#share').attr('href', linkshare + '&popup='+ link);
			$('.poppyClose').bind('click', function() {
                            $('body').find('div.poppyWrapper').fadeOut('fast').remove();
                            var linkold = $('#share').attr('href');
                            links = linkold.split('&');
                            $('#share').attr('href', links[0]);
							$('.footer').css("padding-top",'');
                            checkWindow();
                        });
			//$('.poppyClose').fadeIn("slow");
			//alert('jetzt sollte sich ein popup \u00d6ffnen');
			return false;
		});
		
		$('.button').click(function(){
			if($(this).hasClass('home') || $(this).hasClass('logo')){
				window.location.href = '1-0-Startseite.html';
			}
			
			if($(this).hasClass('contact')){
				$(this).poppy('29-0-Ansprechpartner.html');
                                var link = $('#share').attr('href');
                                $('#share').attr('href', link + '&popup=29-0-Ansprechpartner.html');
				$('.poppyClose').bind('click', function() {
					$('body').find('div.poppyWrapper').fadeOut('fast').remove();
                                        var linkold = $('#share').attr('href');
                                        links = linkold.split('&');
                                        $('#share').attr('href', links[0]);
                                        $('.footer').css("padding-top",'');
                                        checkWindow();
				});
			}
			
			if($(this).hasClass('orte')){
				$(this).poppy('31-0-Standorte.html');
                                var link = $('#share').attr('href');
                                $('#share').attr('href', link + '&popup=31-0-Standorte.html');
				$('.poppyClose').bind('click', function() {
					$('body').find('div.poppyWrapper').fadeOut('fast').remove();
                                        $('.footer').css("padding-top",'');
                                        var linkold = $('#share').attr('href');
                                        links = linkold.split("&");
                                        $('#share').attr('href', links[0]);
                                        checkWindow();
				});
			}
                        
                        if($(this).hasClass('login')){
				window.location.href = '67-0-Firmenkunden.html';
			}
                        
                        if($(this).hasClass('logout_intranet')){
                            window.location.href = '41-0-Intranet.html?FORM[LOGOUT]=1';
                        }
			//to-do Colorbox
			//alert($(this).find("a").attr("href"));
			//alert('jetzt sollte sich ein popup \u00d6ffnen');
		});
		
		$('.popUpSearch').click(function(){
			link = $(this).attr("href");
			$(this).poppy(link);
			linkshare = $('#share').attr('href');
			$('#share').attr('href', linkshare + '&popup='+ link);
			$('.poppyClose').bind('click', function() {
                            $('body').find('div.poppyWrapper').fadeOut('fast').remove();
                            var linkold = $('#share').attr('href');
                            links = linkold.split('&');
                            $('#share').attr('href', links[0]);
							$('.footer').css("padding-top",'');
                            checkWindow();
                        });
			//$('.poppyClose').fadeIn("slow");
			//alert('jetzt sollte sich ein popup \u00d6ffnen');
			return false;
		});
		
		$('#search').mouseover(function(){
			if($(this).val() == 'Suchbegriff eingeben'){
				$(this).val('');
				$(this).focus();
				//$(this).attr('style', 'border:1px solid gray;');
			}
		}).mouseout(function(){
			if($(this).val() == ''){
				$(this).val('Suchbegriff eingeben');
				$(this).blur();
				//$(this).attr('style', 'border:0;');
			}
		});
		
		$('.landcard_city').hover(function() {
				$(this).addClass('landcard_city_hover');
			} , function() {
				$(this).removeClass('landcard_city_hover');
			}
		);
		
		$('.landcard_city').click(function(){
			$('.landcard_info').find('div.landcardentry_active').removeClass('landcardentry_active').hide();
			$('.landcard').find('span.landcard_city_active').removeClass('landcard_city_active');
			$(this).addClass('landcard_city_active');
			var infobox = '#landcardentry_' + $(this).attr('rel');
			$(infobox).addClass('landcardentry_active');
			$('.landcardentry_active').fadeIn('slow');
                        
		});
                
                $('.accordion_title').click(function(){
                        if($(this).next().is(':hidden')) {
                            $(this).addClass("acc_active");
                        }else{
                            $(this).removeClass("acc_active");
                        }
			
			$(this).next().slideToggle('slow', function(){
                            checkWindow();
                        });
                        
                        return false;
		});
                
                $(window).resize(function() {
                    var head = $('.head').height();
                    var content = $('.firstpage').height();
                    var footer = $('.footer').height();
                   if($(window).height() > (head + content + footer + 40)){
                      
                       $('.footer').addClass("footer_full_height");
                   }else{
                       $('.footer').removeClass("footer_full_height");
                   }
                   
                });
		
                
		
	});
        
        function checkWindow(){
                    
                    var head = $('.head').height();
                    var content = $('.firstpage').height();
                    var footer = $('.footer').height();
                    //alert($(window).height());
                    //alert((head + content + footer + 40));
                    if($(window).height() > (head + content + footer + 29)){      
                           $('.footer').addClass("footer_full_height");
                    }else{
                           $('.footer').removeClass("footer_full_height");
                    }
       }
       
       function checkIResize(){
           var wrapper = $('.poppyWrapper').height();
           //alert($(window).height() + '|' + wrapper);
           if($(window).height() > (wrapper + 10)){
               //alert($(window).height() + '|' + wrapper);
               checkWindow();
           }else{
               var head = $('.head').height();
               var content = $('.firstpage').height();
               var footer = $('.footer').height();
               var padding = wrapper - head - content + footer;
               $('.footer').removeClass("footer_full_height");
               $('.footer').css('padding-top', padding + 'px');
           }
       }
