

jQuery(document).ready(function() {

    if(jQuery.browser.msie) {
        jQuery("body").addClass("ie");   
    }

    // +++++++++++++++++++++++++++
    // make table rows alternate
    // +++++++++++++++++++++++++++
    jQuery('table tbody tr:odd').addClass('odd');
    jQuery('table tbody tr:even').addClass('even');


    // +++++++++++++++++++++++++++
    // replace header fonts with nice ones
    // +++++++++++++++++++++++++++
    Cufon.replace('h1.style1', { fontFamily: 'Frutiger LT 57 Cn Bold' });
    Cufon.replace('h1 .black', { fontFamily: 'Frutiger LT 57 Cn Bold' });
    Cufon.replace('h2.style2', { fontFamily: 'Frutiger LT 57 Cn' });
    
    // hallo spar, klassik, natur cufon
    jQuery("span.hallospar").parent("h1").css({"text-transform":"none"});
    jQuery("span.hallonatur").parent("h1").css({"text-transform":"none"});
    jQuery("span.halloklassik").parent("h1").css({"text-transform":"none"}); 
    Cufon.replace(jQuery("span.hallospar").parent("h1"), jQuery("span.hallonatur").parent("h1"), jQuery("span.halloklassik").parent("h1"), { fontFamily: 'Adobe Caslon Pro' });
    Cufon.replace('span.hallospar, span.hallonatur, span.halloklassik', { fontFamily: 'Adobe Caslon Pro' });
    Cufon.replace('span.hallospar i, span.hallospar em, span.halloklassik i, span.halloklassik em, span.hallonatur i, span.hallonatur em', { fontFamily: 'Adobe Caslon Pro Italic' });
    
    // replace graufett
    Cufon.replace('span.graufett', { fontFamily: 'Frutiger LT 57 Cn Bold' });
    
    
    // +++++++++++++++++++++++++++
    // tooltips    
    // +++++++++++++++++++++++++++
    jQuery(".tooltip").hide();
    
    // tooltips: build container around definitions
    jQuery("div.tooltip-span div").each(function(index) {
        jQuery(this).wrap(function() {
            return '<div class="definition-container"><div class="definition-top"><a href="#" class="close">X</a></div><div class="definition-body"><div class="definition-text">' + $(this).html() + '</div></div><div class="definition-bottom"></div></div>';
        });
    });
    
    jQuery("div.tooltip-span").prev().css({"display":"inline"});
    
    // open tooltip
    jQuery("a.wt_csstooltip").live("click", function(e) {
            
            // if next tooltip is already open, abort
            if(jQuery(this).next('.defcon-active').length > 0) {
                jQuery(".defcon-active").hide();
                jQuery(".defcon-active").removeClass("defcon-active");
                return false;    
            }
            
            // close existing containers
            jQuery(".defcon-active").hide();  
            jQuery(".defcon-active").removeClass("defcon-active"); 
                       
            
            // make the following container active
            jQuery(this).next(".definition-container").addClass("defcon-active");
        
            // position container
            conheight = 0;
            conheight = jQuery(this).next(".definition-container").height();
            
            positionY = e.pageY-conheight;
            positionX = e.pageX;
            //alert(positionX);
            
            
            
            //jQuery(".defcon-active").css("left", +spanwidth -25 +"px");
            
            // positioning of popup
            jQuery(".defcon-active").css("top", positionY+"px");
            jQuery(".defcon-active").css("left", positionX+"px");
        
            if(jQuery(this).parents(".ui-accordion-content").length > 0) {
                
                jQuery(".ui-accordion-content").css("overflow","hidden");
                jQuery(this).parents(".ui-accordion-content").css("overflow","visible");
                positionY = (positionY)+50;
                jQuery(".defcon-active").css("top", "-"+ (conheight-35) +"px");
                
                var position = jQuery(this).position();
                spanwidth = 0;
                spanwidth = jQuery(this).parent().width();
            
                jQuery(".defcon-active").css("left", position.left + spanwidth - 20 +"px");                
            }
        
        
            jQuery(this).next(".definition-container").show(200);
            
            return false;
        }
    );
    
    //close tooltip
    jQuery("a.close").live('click', function() {
        jQuery(this).parent().parent(".definition-container").hide();
        jQuery(this).parent().parent(".definition-container").removeClass("defcon-active");
        
        return false;
    });
    
    
    // +++++++++++++++++++++++++++
    // tellafriend in iframe-lightox
    // +++++++++++++++++++++++++++      
    jQuery(".tipafriend a").colorbox({href:jQuery(this).href, iframe:true, width:"50%", height:"65%"});
    
    
    // +++++++++++++++++++++++++++
    //gruene links
    // +++++++++++++++++++++++++++
    jQuery(".linkgruen").each(function(index) {
        jQuery(this).parent("p").css("white-space","nowrap");
        enew = 0;
        enew = '<a class="linkgruen" href="'+$(this).attr("href")+'"><span class="gruenfront"></span><span class="gruentext">' + $(this).html() + '</span><span class="gruenback"></span></a>';
        jQuery(this).replaceWith(enew);
       
    });
    
    jQuery("input.submit").each(function(index) {
        enew = 0;
        enew = '<button class="grueninputwrap right" type="submit"><span class="gruenfront"></span><span class="gruentext">' + $(this).attr('value') + '</span><span class="gruenback"></span></button>';
        
        jQuery(this).replaceWith(enew);

    });
    
      
    // ++++++++++++++++++++++++++++
    // measure browser width and make sure there is no overflow
    // ++++++++++++++++++++++++++++
    /*
    var navWidth;
    
    if (self.innerWidth != undefined) {      
        navWidth = self.innerWidth - 30;            
    } else {                
        navWidth = document.documentElement.clientWidth-30;      
    }
    
    if (navWidth > 0) {
        jQuery("body").width(navWidth).css("overflow","hidden");
    }
     */
    
    // rewrite menu items
    jQuery("ul.submenu li a:contains('Gut')").each(function(index) {
        b = jQuery(this).html();
        u = b.replace(/Gut/gi, "<strong>GUT</strong>");
        jQuery(this).html(u);
    });
      
});
