﻿$(
    function() {
        $("a.lightbox").each(
            function() {
                $(this).fancybox({ width: 800, height: 600, type: "iframe" });
            }
		);
        $("a.img_lightbox").each(
            function() {
                var a = $(this);
                a.fancybox({
                    autoScale: false
                });
                a.append($('<div style="position:absolute;bottom:0;right:0;background:url(/Images/ImgScale/Lupe.png) no-repeat top left; width: 63px; height: 66px;" class="img_lightbox_lupe"></div>'));
                var cont = $('<div></div>');
                cont.css("position", "relative");
                a.wrap(cont);
            }
		);

        $("a.img_lightbox_noicon").each(
            function() {
                var a = $(this);
                a.fancybox({
                    autoScale: false
                });
            }
		);

        $("div.slidebox").each(
            function() {
                var box = $(this);
                var inner = box.find(".slideinner");
                var items = inner.find(".slideitem");
                var w = box.width();
                inner.css({
                    width: items.length * w + "px"
                });
                var buttons = box.find(".slidebuttons > a");
                var i = 0;
                buttons.each(
                    function() {
                        var x = i++;
                        $(this).click(
                            function() {
                                daegfa_slideTo(x, box, true);
                            }
                        );
                        $(this).attr("href", "javascript:void(0);");
                    }
                )

                daegfa_registerSlider(box);
            }
        );
    }
);

function navigateToPatientenArztsuche(){
	if(window){
		var w = window;
		if(window.parent){
			w = window.parent;
		}
		w.location = "/Patientenportal/Arztsuche.aspx";
		return true;
	}
	return false;
}

function daegfa_slideTo(index,box,deregister) {
    var inner = box.find(".slideinner");
    var w = box.width();

    inner.animate(
        {
            marginLeft: "-" + (index * w) + "px"
        },
        1000
    );
        if (deregister) {
            daegfa_deregisterSlider(box);
        }
}

function daegfa_printPage() {
    $("div").each(//CMS FIX, damit ModuleSlot-Wrapper Seiten beim Druck nicht abschneiden
        function() {
            if ($(this).css("display") == "inline-block") {
                $(this).css("display","inline");
            }
        }
    );
    window.print();
}

function daegfa_registerSlider(box) {
    if (!box.data("slideID")) {
        box.data("slideID", window.setInterval(
            function() {
                daegfa_slideShow(box);
            }, 10000));
    }
}

function daegfa_deregisterSlider(box) {
    if (box.data("slideID")) {
        window.clearInterval(box.data("slideID"));
        box.data("slideID", null);
    }
}

function daegfa_slideShow(box) {
    var index = (box.data("slideIndex") || 0) + 1;
    if (index >= box.find(".slideitem").length) {
        index = 0;
    }
    box.data("slideIndex", index);

    daegfa_slideTo(index, box,false);
}
