var popupStatus = 0;

function resizeOverlay() {
    if(jQuery.browser.msie){
        jQuery(".overlay").width( jQuery(window).width() );
        jQuery(".overlay").height( jQuery(window).height() );
    }
    else{
        jQuery(".overlay").width( jQuery(document).width() );
        jQuery(".overlay").height( jQuery(document).height() );
    }
}

           
function loadPopup(loadType){  
    //loads popup only if it is disabled  
    if(popupStatus==0){ 
        resizeOverlay();
        if(loadType == 1) 
            jQuery(".popup iframe").attr("src",jQuery(".login-popup-trigger").attr("href"));
        else
            jQuery(".popup iframe").attr("src","leistungen-iframe.html");
        jQuery(".overlay").css("opacity","0.9"); 
        jQuery(".overlay").show(); 
        jQuery(".popup").show();  
        jQuery("select").hide();
        popupStatus = 1;  
    }  
}  

function disablePopup(){  
    //disables popup only if it is enabled  
    if(popupStatus==1){  
        jQuery(".overlay").hide();    
        jQuery(".popup").hide();
        jQuery("select").show();  
        popupStatus = 0;  
    }  
}  

   
function centerPopup(animate){   
    
    
    var windowWidth = document.documentElement.clientWidth;  
    var windowHeight = document.documentElement.clientHeight;
    
    var popupHeight = jQuery(".popup").height();  
    var popupWidth = jQuery(".popup").width();  
    
    var scrollTop = jQuery(document).scrollTop();
    var top =  scrollTop + (windowHeight/2-popupHeight/2);
    
    
    if (animate ==1)
    {
        jQuery(".popup").animate({    
            "top": (windowHeight/2-popupHeight/2),  
            "left": windowWidth/2-popupWidth/2  
        },600);    
    }
    else {
        jQuery(".popup").css({    
            "top": (windowHeight/2-popupHeight/2),  
            "left": windowWidth/2-popupWidth/2  
        });    
    }
    if(jQuery.browser.msie && jQuery.browser.version.substr(0,1) < "7")
    {
        jQuery(".overlay").css({"height": document.body.clientHeight});
        var scrollTop = jQuery(document).scrollTop();
        var windowHeight = document.documentElement.clientHeight;
        var top =  scrollTop + (windowHeight/2-popupHeight/2);
        jQuery(".popup").css({    
            "top": top    
        }); 
    }
    
    

}

function scrollPopup(){  
    var windowHeight = document.documentElement.clientHeight;  
    var popupHeight = jQuery(".popup").height();  
    
    jQuery(".overlay").css({"height": document.body.clientHeight});
    var scrollTop = jQuery(document).scrollTop();
    var top =  scrollTop + (windowHeight/2-popupHeight/2);
    jQuery(".popup").css({    
        "top": top    
    }); 
}

var loginShow = 0;
jQuery(document).ready(function() {
	
    jQuery(".box-l-production,.box-r-production,.box-l-pixapart,.box-r-interactive,.box-r-kontakt,.box-l,.box-r,.box-l-twitter,.box-r-angebote").click(function(){
        var link = jQuery("p a", this).attr("href");
        document.location.href = link;
    });
    
    jQuery('.box-l-production,.box-r-production,.box-l-pixapart,.box-r-interactive,.box-r-kontakt,.box-l,.box-r,.box-l-twitter,.box-r-angebote').hover(function(){
        jQuery(this).bgFade('fadeIn',
        {
            fadeToOpacity: 1,
            fadeSpeed: 300 
        }); 
        }, function() {
            jQuery(this).bgFade('fadeOut',
            {
                fadeToOpacity: 0,
                fadeSpeed: 300 
        }); 
    }); 
    
    if(jQuery("#slideshow").length > 0) {            
        
        jQuery('#slideshow').cycle({
            fx: 'scrollHorz',
            timeout: 9000,
            speed: 700,
            pager: '.pager ul',
            activePagerClass: 'activeSlide',
            prev: '.prev a',
            next: '.next a'
        });
        
        jQuery("#slideshow").touchwipe({
            wipeLeft: function() {
                jQuery("#slideshow").cycle("next");
            },
            wipeRight: function() {
                jQuery("#slideshow").cycle("prev");
            },
            preventDefaultEvents: true
        });

    }
    
    jQuery(".control-nav").mouseover(function() {
        jQuery(".next").css("display","block");
        jQuery(".prev").css("display","block");
        jQuery('#slideshow').cycle('pause');
    });
    
    jQuery(".control-nav").mouseout(function() {
        jQuery(".next").css("display","none");
        jQuery(".prev").css("display","none");
        jQuery('#slideshow').cycle('resume');
    });
    
    jQuery("#contentBottom .box-l").click(function(){
        jQuery('#hiddenContent_1').slideToggle();
    });
    
    jQuery("#contentBottom .box-r,#contentBottom #referenzen-bottom .box-l").click(function(){
        jQuery('#hiddenContent_2').slideToggle();
    });       
    
    
    jQuery(".login-form-trigger").click(function(){
        if (loginShow == 0)
        {
            jQuery(this).blur();
            jQuery(".hp-top .login-form-area").animate({top: "0px"}, 600 );
            loginShow = 1;
        }
        else
        {
            jQuery(this).blur();
            jQuery(".hp-top .login-form-area").animate({top: "-160px"}, 600 );
            loginShow = 0;
        }
        
    }); 
    
    jQuery('#impressum-slide-1 .ce_text').jScrollPane(
		{
			showArrows: true
		}
	);
	jQuery('#impressum-slide-2 .ce_text').jScrollPane(
		{
			showArrows: true
		}
	);
	jQuery('#ftp,#leistungen-iframe').jScrollPane(
		{
			showArrows: true
		}
	);
    
    
    /* POPUP */   
    
    jQuery(".login-popup-trigger").click(function(){  
        centerPopup(0);    
        loadPopup(1);
        return false;   
    });
    
    jQuery(".webhosting-cols").click(function(){  
        centerPopup(0);    
        loadPopup(2);
        return false;   
    });
    
        
    jQuery(".popup a.close").click(function(){  
        disablePopup();  
    });  
      
    jQuery(".overlay").click(function(){  
        disablePopup();  
    });  
      
    jQuery(document).keypress(function(e){  
        if(e.keyCode==27 && popupStatus==1){  
            disablePopup();  
        }  
    });  
    
    
    jQuery(window).resize( function() {
        if(popupStatus ==1 && jQuery.browser.msie ==0) 
        {
            resizeOverlay();
            centerPopup(1,".popup");
        }
        
    });
    
    if(jQuery.browser.msie && jQuery.browser.version.substr(0,1) < "7")
        jQuery(window).bind("scroll", function() {
            if(popupStatus ==1) 
            {
                scrollPopup();
            }
            
        DD_belatedPNG.fix('.popup,.noPrint a img,.webhosting-detail img');
            
    });
    
    /* POPUP END */ 
    
});
