function printConfirmation() {
    var prtContent = document.getElementById('mail_confirmation');
    var WinPrint = window.open('', '', 'letf=0,top=0,width=700,height=800,toolbar=0,scrollbars=0,status=0');
    WinPrint.document.write(prtContent.innerHTML);
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close();
}

function slideSwitch() {
    var current = jQuery('ul.slides li.show');
    var nth = jQuery("ul.slides li").index(jQuery("li[class='show']")) + 1;
    var new_nth;
    if (current.length == 0) {
        current = jQuery('#ul.slides li:last-child');
        new_nth = 4;
    }

    var next;
    if (current.next().length) {
        next = current.next();
        new_nth = nth + 1;
    }
    else {
        next = jQuery('ul.slides li:first-child');
        new_nth = 1;
    }

    jQuery("ul.pages li:nth-child(" + nth + ")").removeClass('active');
    jQuery("ul.pages li:nth-child(" + new_nth + ")").addClass('active');

    next.addClass('show')
    current.removeClass('show');
}



//Font Size Cookie
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function checkChildren(id) {
    jQuery("ul.category_list li." + id).each(function (index) {
        if (jQuery(this).hasClass("show")) {

            var bg = jQuery("ul.category_list li span." + id).css("background-image");
            if (bg.lastIndexOf("minus.gif") > 0) {
                jQuery("ul.category_list li span." + id).css("background", 'url("../../../images/plus.gif") no-repeat transparent');
                jQuery("ul.category_list li span." + id).css("background-position", "0 -3px");
            }
            jQuery(this).removeClass("show");
            jQuery(this).addClass("hidden");
        }
    });
    return null;
}

//Homepage Pop-Up

function close() {
    jQuery('.popupLayerShow').removeClass('popupLayerShow').addClass('popupLayer');
    jQuery('.showpopup').removeClass('showpopup').addClass('hidepopup');

}

function showPopup() {
    jQuery('#popupList .hidepopup').removeClass('hidepopup').addClass('showpopup');
    jQuery('.popupLayer').removeClass('popupLayer').addClass('popupLayerShow');
}

//function showPopup() {
//    var randomNumber = getRandomNumber();
//    jQuery('#popupList .hidepopup:nth-child(' + randomNumber + ')').removeClass('hidepopup').addClass('showpopup');
//    jQuery('.popupLayer').removeClass('popupLayer').addClass('popupLayerShow');

//}




//function getRandomNumber() {
//    var numberOfChildren = jQuery('#popupList').children().length;
//    var zahl = Math.round(Math.random() * numberOfChildren);
//    if (zahl == 0) {
//        return 1;
//    }
//    return zahl;
//}



jQuery(document).ready(function () {


    //Reset Font Size 
    var cookie = readCookie("txtsize");
    var standard = cookie ? cookie : 10;
    var p = document.getElementsByTagName('html');
    for (i = 0; i < p.length; i++) {
        p[i].style.fontSize = standard + "px";
    }

    //Reset Styles
    jQuery(".rightpane ul.thumbnaillist li:nth-child(2)").css("margin", "0 5px");
    jQuery(".rightpane ul.thumbnaillist li:nth-child(5)").css("margin", "0 5px");
    jQuery(".rightpane ul.thumbnaillist li:nth-child(8)").css("margin", "0 5px");
    jQuery(".rightpane ul.quicklinks li:nth-child(even)").css("margin-left", "10px");
    jQuery(".rightpane ul.quicklinks li:last-child").css("padding-bottom", "10px");


    //category
    jQuery("ul.category_list li.level2").addClass('hidden');
    jQuery("ul.category_list li.level3").addClass('hidden');
    jQuery("ul.category_list li.level4").addClass('hidden');


    jQuery('ul.category_list li span.parent').toggle(function () {
        var bg = jQuery(this).css("background-image");
        if (bg.lastIndexOf("plus.gif") > 0)
            jQuery(this).css("background", 'url("../../../images/minus.gif") no-repeat transparent');
        else
            jQuery(this).css("background", 'url("../../../images/plus.gif") no-repeat transparent');

        jQuery(this).css("background-position", "0 -3px");

    }, function () {
        var bg = jQuery(this).css("background-image");
        if (bg.lastIndexOf("minus.gif") > 0)
            jQuery(this).css("background", 'url("../../../images/plus.gif") no-repeat transparent');
        else
            jQuery(this).css("background", 'url("../../../images/minus.gif") no-repeat transparent');
        jQuery(this).css("background-position", "0 -3px");
    });


    
    jQuery('ul.category_list li span.parent').click(function () {
        var id = jQuery(this).attr("class").split(' ');
        jQuery('ul.category_list li').each(function () {
            //Class Name: parent [ID] oder nochild
            if (jQuery(this).hasClass(id[1])) {
                if (jQuery(this).hasClass("show")) {
                    jQuery(this).removeClass("show");
                    jQuery(this).addClass("hidden");

                    var className = jQuery(this).children("span").attr('class').split(' ');
                    for (i = 0; i < className.length; i++) {
                        if (className[i].match(/\d{6}/)) {
                            checkChildren(className[i]);
                            break;
                        }
                    }
                } else {
                    jQuery(this).removeClass("hidden");
                    jQuery(this).addClass("show");
                }
            }
        });
        return false;
    });

    //category named click newfix
    jQuery('ul.category_list li span.parent').next().click(function () {
        var id = jQuery(this).prev().attr("class").split(' ');
        jQuery('ul.category_list li').each(function () {
            //Class Name: parent [ID] oder nochild
            if (jQuery(this).hasClass(id[1])) {
                if (jQuery(this).hasClass("show")) {
                    jQuery(this).removeClass("show");
                    jQuery(this).addClass("hidden");

                    var className = jQuery(this).children("span").attr('class').split(' ');
                    for (i = 0; i < className.length; i++) {
                        if (className[i].match(/\d{6}/)) {
                            checkChildren(className[i]);
                            break;
                        }
                    }
                } else {
                    jQuery(this).removeClass("hidden");
                    jQuery(this).addClass("show");
                }
            }
        });
        return false;
    });
    jQuery('ul.category_list li span.parent').next().toggle(function () {
        var bg = jQuery(this).prev().css("background-image");
        if (bg.lastIndexOf("plus.gif") > 0)
            jQuery(this).prev().css("background", 'url("../../../images/minus.gif") no-repeat transparent');
        else
            jQuery(this).prev().css("background", 'url("../../../images/plus.gif") no-repeat transparent');

        jQuery(this).prev().css("background-position", "0 -3px");

    }, function () {
        var bg = jQuery(this).prev().css("background-image");
        if (bg.lastIndexOf("minus.gif") > 0)
            jQuery(this).prev().css("background", 'url("../../../images/plus.gif") no-repeat transparent');
        else
            jQuery(this).prev().css("background", 'url("../../../images/minus.gif") no-repeat transparent');
        jQuery(this).prev().css("background-position", "0 -3px");
    });
    //category named click newfix end

    jQuery("ul.slides li:first-child").addClass('show');

    jQuery(".change_font a").click(function () {
        var size = this.className.match(/size(\d+)/)[1];
        // alert(size);
        var currentFontSize = 10; //jQuery('html').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSize;


        if (size == 1) {
            newFontSize = currentFontSizeNum * 1.1;
        }
        else if (size == 2) {
            newFontSize = currentFontSizeNum * 1.4;
        }
        else if (size == 3) {
            newFontSize = currentFontSizeNum * 1.6;
        }
        //alert(newFontSize);
        jQuery('html').css('font-size', newFontSize);
        createCookie('txtsize', newFontSize);

        return false;
    });

    // Increase Font Size
    jQuery(".increase_font a").click(function () {
        var currentFontSize = jQuery('html').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum + 1;
        if (newFontSize < 17) {
            jQuery('html').css('font-size', newFontSize);
            createCookie('txtsize', newFontSize);
        }
        return false;
    });

    // Decrease Font Size
    jQuery(".decrease_font a").click(function () {
        var currentFontSize = jQuery('html').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum - 1;
        if (newFontSize > 9) {
            jQuery('html').css('font-size', newFontSize);
            createCookie('txtsize', newFontSize);
        }
        return false;
    });

    // Image Teaser
    teaser_interval = setInterval("slideSwitch()", 8000);
    jQuery('ul.pages li').hover(function () {
        clearInterval(teaser_interval);
        jQuery('ul.pages li').removeClass('active');
        jQuery('ul.slides li').removeClass('show');
        var index = jQuery(this).prevAll().length + 1;
        jQuery("ul.pages li:nth-child(" + index + ")").addClass('active');
        jQuery("ul.slides li:nth-child(" + index + ")").addClass('show');
    }, function () {
        teaser_interval = setInterval("slideSwitch()", 8000);
    });
    jQuery('ul.slides li').hover(function () {
        clearInterval(teaser_interval);
        jQuery('ul.pages li').removeClass('active');
        jQuery('ul.slides li').removeClass('show');
        var index = jQuery(this).prevAll().length + 1;
        jQuery("ul.pages li:nth-child(" + index + ")").addClass('active');
        jQuery("ul.slides li:nth-child(" + index + ")").addClass('show');
    }, function () {
        teaser_interval = setInterval("slideSwitch()", 8000);
    });

    // Pretty Photo
    jQuery("a[rel^='prettyPhoto']").prettyPhoto({
        animationSpeed: 'normal',
        padding: 40,
        opacity: 0.35,
        showTitle: true,
        allowresize: true,
        counter_separator_label: '/',
        theme: 'light_square',
        hideflash: false,
        modal: false,
        changepicturecallback: function () { },
        callback: function () { }
    });

    //Homepage Popup
    //if (jQuery.cookie('homepageOverlayIsSet') != 'true') {
    showPopup();
    //  jQuery.cookie('homepageOverlayIsSet', 'true', { expires: 30 });
    jQuery('.popupClose').click(function () {
        close();
    });

    //}



});

