$(document).ready(function(){
    init();
}); //Ende $(document).ready();
/*******************************************************************************
 * log() : sort of var_dump() for JS
 ******************************************************************************/
var log = function(){
    if (window && window.console && window.console.log) {
        for (var i = 0, len = arguments.length; i < len; i++) {
            console.log(arguments[i]);
        }
    }
    else {
        for (var i = 0, len = arguments.length; i < len; i++) {
            $("body").prepend(arguments[i]);
        }
    }
}//Ende log
/*******************************************************************************
 * all the things that have to be done on document load
 * requires JQuery
 *
 * @return void
 ******************************************************************************/
var init = function(){
    $(".hidden").hide();
    $("a[href^=#]").each(function(){
        $(this).click(function(){
            var $href = $(this).attr("href");
            $href = $href.split("#");
            $href = "#" + $href[1];
            window.location.hash = $href;
            return false;
        });
    });
    //Empty Search-Field on focus, refill on blur 
    var $val;
    $("#such_input, .empty-on-focus").focus(function(){
        $val = $(this).val();
        $(this).val("");
    }).blur(function(){
        if ($(this).val().length <= 0) {
            $(this).val($val);
        }
    });
    address = $("#adresse").html();
    if (address) {
        if (address.length > 0) 
            loadGoogleMap(address);
    }
    
    $("#print").click(function(){
        $("#content, #content2, #content3, #content4").print();
    });
    //IE6 PNG-Fix
    if ($.browser.msie && parseInt($.browser.version) == 6) {
        //$("body").prepend($.browser.version);
        DD_belatedPNG.fix('body, img');
    }
}

/****************************************
 * GOOGLE MAP laden
 ****************************************/
function loadGoogleMap(address){
    geocoder = new GClientGeocoder();
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        if (geocoder) {
            geocoder.getLatLng(address, function(point){
                if (!point) {
                    alert(address + " not found");
                }
                else {
                    map.setCenter(point, 13);
                    map.addControl(new GLargeMapControl());
                    var marker = new GMarker(point);
                    map.addOverlay(marker);
                    var description = $("#map #beschreibung").html();
                    marker.openInfoWindowHtml((description ? description : address));
                }
            });
        }
    }
}

/*************************************
 * JQuery Print by OT
 *************************************/
jQuery.fn.print = function(){
    var styles = '';
    $("head link").each(function(){
        styles += '<link rel="stylesheet" type="text/css" href="' + $(this).attr("href") + '" />' + "\n";
    })
    var frameName = ("printer-" + (new Date()).getTime());
    var frameTitle = document.title;
    $("<iframe name='" + frameName + "'>").css({
        "width": "1px",
        "height": "1px",
        "position": "absolute",
        "left": "-10px"
    }).appendTo($("body"));
    var frameDoc = window.frames[frameName].document;
    frameDoc.open();
    frameDoc.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
    frameDoc.write("<html>");
    frameDoc.write("<head>");
    frameDoc.write("<style type=\"text/css\">#content_bottom{display:none;}</style>");
    frameDoc.write("<title>");
    frameDoc.write(frameTitle);
    frameDoc.write("</title>");
    frameDoc.write("</head>");
    frameDoc.write("<body>");
    frameDoc.write(styles);
    frameDoc.write(this.html());
    frameDoc.write("</body>");
    frameDoc.write("</html>");
    frameDoc.close();
    window.frames[frameName].focus();
    window.frames[frameName].print();
}

