﻿function setHeightSlider(sObject, sObject_small, iMinus, page_id) {
 var aElement = $(sObject);
 sNewHeight = 0;
 for (i=0; i<aElement.length; i++) {
  if(sNewHeight < $(sObject+":eq("+i+")").height())
    sNewHeight = $(sObject+":eq("+i+")").height();
  }
  $("div#fading-container_"+page_id).css("height",sNewHeight+"px");
  if(sObject_small != "") {
    $(sObject_small).css("height", sNewHeight - iMinus+"px");
  }
  return sNewHeight;
} 
function slideDown(item) {
    if($("div#"+item).css("display") == "none") {
        $("div#"+item).css("display","block");
    } else {
        $("div#"+item).css("display","none");
    }
  setHeight(".setheight");
}
function setHeight(sObject, sObject_small, iMinus) {
    var aElement = $(sObject);
    sNewHeight = 0;
    for (i=0; i<aElement.length; i++) {
        aElement.css("height", "auto");
        if(sNewHeight < aElement[i].offsetHeight)
            sNewHeight = aElement[i].offsetHeight;
        }
        $(sObject).css("height",sNewHeight+"px");
        if(sObject_small != "") {
            $(sObject_small).css("height", sNewHeight - iMinus+"px");
        }
    
}
function smallSlideShow(pageId, slideIntervall) {
    $('#small-slide_'+pageId).innerfade({ speed: 'slow', timeout: slideIntervall, type: 'sequence' });
    imageHeight = $('#small-slide_'+pageId+' div img').eq(0).attr("height");
    imageWidth = $('#small-slide_'+pageId+' div img').eq(0).attr("width");
    $('#small-slide-container_'+pageId).css("height", imageHeight+"px");
    $('#small-slide-container_'+pageId).css("width", imageWidth+"px");
}
function showPrintVersion() {
    $(".print_anchor").remove();
    url_prefix = $("url").attr("value");
    anchor_size = $("#content a").length-1;
    href = "";
    for(i=0;i <= anchor_size; i++) {
        print_link = $("#content a").eq(i).attr("title");
        if(print_link != "") {
            href = $("#content a").eq(i).attr("href");
            
            if(href != "") {
                if(href.indexOf("/") == 0){
                    $("#content a").eq(i).after("<span class='print_anchor'>(" + url_prefix + $("#content a").eq(i).attr("href") + ")</span>");
                }
                if(href.indexOf("http://") != -1) {
                    $("#content a").eq(i).after("<span class='print_anchor'>(" + $("#content a").eq(i).attr("href") + ")</span>");
                }
            }
        }
    }
    window.print();
}

//Navigation Treeview
   $(document).ready(function(){
        $("#navigation").treeview({
            persist: "location",
            collapsed: true,
            unique: false
        });
        $(".navipunkt").click(function() {
            if($(this).parent("li").parent("ul").hasClass("treeview")) {
                closeLastActiveNavigation(this);
            }
            
           if($(this).next().css("display") == "none") {
                /* Open Navigation */
                $(this).css("font-weight","bold");
                /* Level 1 */
                if($(this).parent("li").parent("ul").hasClass("treeview")) {
                    $(this).parent("li").css("background-color","#c2dce9");
                }
                /* Level 2 */
                if($(this).parent("li").parent("ul").hasClass("level3")) {
                    $(this).parent("li").css("background-color","#9ac5da");
                    $(this).parent("li").css("border-left","1px solid #FFFFFF");
                }
                /* Level 3 */
                if($(this).next().hasClass("level5")) {
                    $(this).parent("li").css("background-color","#71aecc");
                    $(this).parent("li").css("border-left","1px solid #D1D6DA");
                }
                $(this).next().css("display","block");
            } else {
                /* Close Navigation */
                closeNavigationTree(this);
            }
            setHeight('.setheight');
        });
    
        function closeLastActiveNavigation(current) {
            $(".treeview > li").each(function(i) {
                if($(current).text() != $(this).children("a").text()) {
                    //alert($(this).children("a").text());
                    closeNavigationTree($(this).children("a"));
                }
            });
        }
        
        function closeNavigationTree(current) {
            if($(current).parent("li").hasClass("active")) {
                $(current).parent("li").removeClass("active");
                $(current).parent("li").addClass("inactive");
            }
            if($(current).hasClass("active")) {
                $(current).removeClass("active");
                $(current).addClass("inactive");
            }
            $(current).css("font-weight","normal");
            $(current).next().find("ul").css("display","none");
            $(current).next().find("li").css("background-color","transparent");
            $(current).next().find("li").css("border-left","0");
            $(current).next().find("a").css("font-weight","normal");
            
            /* Level 1 */
            if($(current).parent("li").parent("ul").hasClass("treeview")) {
                $(current).parent("li").css("background-color","transparent");
            }
            /* Level 2 */
            if($(current).parent("li").parent("ul").hasClass("level3")) {
                $(current).parent("li").css("background-color","transparent");
                $(current).parent("li").css("border-left","0");
            }
            /* Level 3 */
            if($(current).next().hasClass("level5")) {
                $(current).parent("li").css("background-color","transparent");
                $(current).parent("li").css("border-left","0");
            }
            $(current).next().css("display","none");
        }    
    });

$(document).ready(function() {
    $('.generate-pdf').click(function() {
        filename_htm = $(this).attr('rel');
        filename = filename_htm.substr(0, filename_htm.lastIndexOf('.')) + '.pdf';
                                
        //window.location.href = ''+filename;
        window.open(''+filename);
    });
});

// Unter dem Produkt
function update_contact(org_structure) {
    var country_id = $('#country_product').val();
    $.post("get_contact_for_country.php", {country: country_id, organizationstructure:org_structure, type:0}, function(data) {
        if(data != '') {
            $("#contact_product").html(data);
            setHeight('.setheight');
        }
    });
}
        
// Von der rechten Leiste
function update_contact_right(org_structure) {
    var country_id = $('#country_right').val();
    $.post("get_contact_for_country.php", {country: country_id, organizationstructure:org_structure, type:1}, function(data) {
        if(data != '') {
            $("#contact_product_right").html(data);
            setHeight('.setheight');
        }
    });
}
