var popupStatus = 0;

function resizeOverlay() {
    jQuery("#overlay").width( jQuery(document).width() );
    jQuery("#overlay").height( jQuery(document).height() );
}

           
function loadPopup(){  
    //loads popup only if it is disabled  
    if(popupStatus==0){  
        jQuery("#overlay").css({"opacity": "0.70"});  
        jQuery("#overlay").show();  
        jQuery("#popup").fadeIn("slow");  
        popupStatus = 1;  
    }  
}  

function disablePopup(){  
    //disables popup only if it is enabled  
    if(popupStatus==1){  
        jQuery("#overlay").fadeOut("slow");  
        jQuery("#popup").fadeOut("slow");  
        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("#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    
    }); 
}


this.tooltip = function(){	
			
	jQuery("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		jQuery("body").append('<div id="tooltip"><div class="all"><p>'+ this.t +'</p></div></div>');
		var pos = jQuery(this).position();
		if(jQuery.browser.msie)
		{
            var left = pos.left - 72;
            var top = pos.top - 65; 
        }
        else
		{
            var left = pos.left - 72;
            var top = pos.top - 65;
        }
        if (jQuery(this).hasClass("tooltip-first-left")) left = -5;
		jQuery("#tooltip")
			.css("top",top + "px")
			.css("left",left + "px")
			.fadeIn("fast");		 
		/*newTop = top + 5;
		newTopString = newTop+"px";
		jQuery("#tooltip").animate({top: newTopString },400);*/
    },
	function(){
		this.title = this.t;		
		jQuery("#tooltip").fadeOut("fast");
		jQuery("#tooltip").remove();
    });	
	/*jQuery("a.tooltip").mousemove(function(e){
		jQuery("#tooltip")
			.css("top",(e.pageY - 20) + "px")
			.css("left",(e.pageX + 20) + "px");
	});*/			
};



// starting the script on page load
jQuery(document).ready(function(){
	tooltip();
});


jQuery(document).ready(function() { 
      
    if(jQuery.browser.msie && jQuery.browser.version < "7.0")
    {
        jQuery("#nav > li").mouseover(function(){
            jQuery(this).addClass("mnhover");
        });
        jQuery("#nav > li").mouseout(function(){
            jQuery(this).removeClass("mnhover");
        });
        jQuery(".utility-bar > ul > li").mouseover(function(){
            jQuery(this).addClass("mnhover");
        });
        jQuery(".utility-bar > ul > li").mouseout(function(){
            jQuery(this).removeClass("mnhover");
        });
        jQuery(".detail-info-anbieter-tooltip").mouseover(function(){
            jQuery(this).addClass("detail-info-anbieter-tooltip-hover");   
        });
        jQuery(".detail-info-anbieter-tooltip").mouseout(function(){
            jQuery(this).removeClass("detail-info-anbieter-tooltip-hover");   
        });  
        
        jQuery(window).bind("scroll", function() {
            if(popupStatus ==1) 
            {
                scrollPopup();
            }
        });
    }
    
    jQuery(".toggle-div a").click(function(){
        jQuery(this).toggleClass("toggle-off");
        var ind = jQuery(".toggle-div a").index(this);
        jQuery(".filter-box-content:eq("+ind+")").slideToggle();
        jQuery(this).blur();
    });
    
    jQuery("img.button-hover").mouseover(function(){
        var fileName = jQuery(this).attr('src');
        jQuery("<img>").attr("src", fileName.replace('.png', '_hover.png'));
        jQuery(this).attr('src', fileName.replace('.png', '_hover.png'));    
    });
    
    jQuery("img.button-hover").mouseout(function(){
        var fileName = jQuery(this).attr('src');
        jQuery(this).attr('src', fileName.replace('_hover.png', '.png'));
    });
    
    jQuery("input.button-hover").mouseover(function(){
        var fileName = jQuery(this).attr('src');
        jQuery(this).attr('src', fileName.replace('.jpg', '_hover.jpg'));    
    });
    
    jQuery("input.button-hover").mouseout(function(){
        var fileName = jQuery(this).attr('src');
        jQuery(this).attr('src', fileName.replace('_hover.jpg', '.jpg'));
    });
    
    
    jQuery(".open-popup").click(function(){  
        centerPopup();    
        loadPopup();  
    });          
    
    
    
    if(jQuery.browser.msie)
    {
        jQuery("#popup").css({"position": "absolute"}); 
    }
    
    
    jQuery(".popup-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);
        }
        
    });
    
    jQuery(".sort-bar-katalog a.activ").click(function(){
        jQuery(".katalog-list input").attr('checked', true);
        jQuery(this).blur();
    });
    
    jQuery(".sort-bar-katalog a.passiv").click(function(){
        jQuery(".katalog-list input").attr('checked', false);
        jQuery(this).blur();
    });
      
});