﻿// Downloads
var oldIndex = null;

$(document).ready(function(){

$(".downloadItem").each(function(index) {

    navigation = '<div><a class="downloadNavi_'+index+'" onclick="downloadNaviItemClicked(\''+index+'\'); return false;" href="">'+jQuery($(this).children()[0]).text()+'</a></div>';


    $('.navigationDownload').append(navigation);

    });

downloadNaviItemClicked(0);

});

function downloadNaviItemClicked(index){


$('.downloadNavi_'+oldIndex ).css('color', '#58585a');



text = jQuery(jQuery($(".downloadItem")[index]).children()[1]).text();
$('.textDownload').text(text);

image = jQuery(jQuery($(".downloadItem")[index]).children()[2]).text();
imagetext = jQuery(jQuery($(".downloadItem")[index]).children()[3]).text();

$('.downloadImage').attr('src', 'ResourceImage.aspx?raid='+image);
$('.downloadImage').attr('alt', imagetext);


$('.centerDownload h1').text('Download '+$('.downloadNavi_'+index).text());

flipbooklink = jQuery(jQuery($(".downloadItem")[index]).children()[5]).text() + '/?keepThis=true&TB_iframe=true&height='+jQuery(jQuery($(".downloadItem")[index]).children()[7]).text()+'&width='+jQuery(jQuery($(".downloadItem")[index]).children()[6]).text();
$('.flipbookLink').attr('href', flipbooklink);

pdflink = jQuery(jQuery($(".downloadItem")[index]).children()[4]).text();
target = jQuery(jQuery($(".downloadItem")[index]).children()[8]).text();

$('.downloadLink').attr('href', pdflink);
$('.downloadLink').attr('target', target);

$('.downloadNavi_'+index).css('color', '#912535');

oldIndex = index;
}

//GALLERY
function initGallery() {
    $(document).ready(function() {
        $(".gallery").each(function() {
            new gallery($(this));
        });
    });
};


function gallery(gal) {
    this.gal = gal;
    this.container = $(gal.find(".container")[0]);
    this.items = gal.find(".container .item");
    this.activePosition = 0;
    this.isInMotion = false;
    this.buttons = $(".buttons");
    var self = this;

    //INIT THE BUTTONS
    this.btnLeft = $(".buttons .right");
    this.btnRight = $(".buttons .left");

    var reInitElements = function() {
        this.items = gal.find(".container .item");
        this.container = $(gal.find(".container")[0]);
    }
    this.reInitElements = reInitElements;

    $(this.items[0]).before(this.items[this.items.length - 1]);
    this.reInitElements();

$(this.items[0]).find('.itemText').css('display', 'none');
$(this.items[2]).find('.itemText').css('display', 'none');

    $(this.items[2]).animate({ opacity: 0.25 }, { queue: false, duration: 1000 });
    $(this.items[0]).animate({ opacity: 0.25 }, { queue: false, duration: 1000 });

    
//$(".buttons").animate({ opacity: 0.0 }, { queue: false, duration: 1000 });

    this.gal.hover(function() {
        $(".buttons").stop();
        $(".buttons").show();        
        $(".buttons").css("opacity", "1");
$(".buttons").css('filter', null);
    });


    var btnLeftClicked = function(e) {
        var self = e.data.self;
        var container = self.container;
        var items = self.items;
        if (!self.isInMotion) {
            self.isInMotion = true;
            
            $(container.find('.item')[1]).animate({ opacity: 0.25 }, { queue: false, duration: 1000 });
$(container.find('.item')[2]).find('.itemText').css('display', 'none');
            $(container.find('.item')[2]).animate({ opacity: 1.00 }, { queue: false, duration: 1000 });
$(container.find('.item')[2]).find('.itemText').css('display', 'block');
            $(container.find('.item')[3]).animate({ opacity: 0.25 }, { queue: false, duration: 1000 });
$(container.find('.item')[3]).find('.itemText').css('display', 'none');

            items.animate({ left: '-=300' }, 1000, function() {
                var item = items[0];
                container.append(item);
                items.css("left", "-150px");
                $(item).css("opacity", "1");
                self.reInitElements();
                self.isInMotion = false;
            });
            self.activePosition += 1;
        }
    }

    //this.btnLeft.click(btnLeftClicked);
    this.btnLeft.bind("click", { self: this }, btnLeftClicked);

    var btnRightClicked = function(e) {
        var self = e.data.self;
        var container = self.container;
        var items = self.items;
        if (!self.isInMotion) {
            self.isInMotion = true;
            var item = items[items.length - 1];
            $(items[0]).before(item);
            $(item).css("opacity", "1");
            self.reInitElements();
            items.css("left", "-450px");

            $(container.find('.item')[0]).animate({ opacity: 0.25 }, { queue: false, duration: 1000 });
$(container.find('.item')[0]).find('.itemText').css('display', 'none');
            $(container.find('.item')[1]).animate({ opacity: 1.00 }, { queue: false, duration: 1000 });
            $(container.find('.item')[1]).find('.itemText').css('display', 'block');
            $(container.find('.item')[2]).animate({ opacity: 0.25 }, { queue: false, duration: 1000 });
            $(container.find('.item')[2]).find('.itemText').css('display', 'none');

            items.animate({ left: '+=300' }, 1000, function() {
                self.isInMotion = false;
            });
            self.activePosition += 1;
        }
    };

    this.btnRight.bind("click", { self: this }, btnRightClicked);
}
//GALLERY END

//IMAGEMAP
var imageMapItems = new Array();

function initImageMap() {
    $(document).ready(function() {
        $("#imageMap").each(function() {
            new imageMap($(this));
        });
    });

}

function imageMap(container) {
    this.map = $("#map");
    var items = imageMapItems;


    //CONTENT
    var headline = container.find(".right h2")[0];
    var image = container.find(".right img")[0];
    var rightImage = container.find(".right img.rightImage")[0];
    var imageHeadline = container.find(".right .imgHeadline")[0];
    var content = container.find(".right .content")[0];

    for (var i = 0; i < items.length; i++) {
        var item = items[i];
        var img = document.createElement("img");
        var imgJ = $(img);
        imgJ.attr("src", "/portaldata/5/images/kreis.png");
        imgJ.attr("height", item.r);
        imgJ.attr("width", item.r);
        imgJ.css("opacity", "0.0");
        imgJ.css("left", item.x + "px");
        imgJ.css("top", item.y + "px");



        imgJ.hover(
            function() {
                $(this).animate({ opacity: "0.5" }, 200);

            },
            function() {
                $(this).animate({ opacity: "0.0" }, 200);
            }
        );

        imgJ.data("item", item);

        imgJ.click(function(e) {
            setContent($(this));
        });

        this.map.append(img);
    }


if (navigator.userAgent.indexOf('MSIE') == -1) {

    var cursor = document.createElement("div");
    this.map.append(cursor);
    cursor = $(cursor);
    cursor.attr("class", "cursor");


    this.map.hover(
        function() {
            cursor.show();
        },
        function() {
            cursor.hide();
        }
    );
//Positionierung der Cursors
    this.map.mousemove(function(e) {
       cursor.css('left', e.clientX - 220).css('top', e.clientY - 385);

    });
}
else
{
this.map.css('cursor', 'crosshair');
}

    function setContent(img) {
        var item = img.data("item");
        container.find(".right").css("display", "block");
        headline.innerHTML = item.headline;

        image.src = item.image;
        //Rechtes Bild
        rightImage.src = item.rightImage;
        
        imageHeadline.innerHTML = item.imageHeadline;
        content.innerHTML = item.content;

    }
}

function addImageMapItem(item) {

    imageMapItems[imageMapItems.length] = item;

}
//IMAGEMAP END

//Ticker

function addTicker(day, TickDescritpion) {
    datum = new Date();
    datumValue = datum.getDay();
    var Wochentag = new Array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");
    if (day == Wochentag[datumValue]) {
        document.getElementById("tickerOpening").innerHTML = TickDescritpion;
    }
}
//Ticker End

//Download

//Download End

//PoPUp
/*function openWindow(UrlID) {

    fenster = window.open("desktopdefault.aspx/tabid-" + UrlID + "/", "PDF", "width=950,height=754,status=no,scrollbars=no,resizable=no");
  fenster.focus();
}*/

//PopUp End
//Printt
function OpenPrintWindow(PageID) {
 var path ="http://"+ window.location.host + "/desktopdefault.aspx/tabid-"+PageID+"/usetemplate-print/";
    var elmWin = window.open(path, "Printpreview", "width=650,height=650,left=100,top=200, scrollbars=yes, resizable=yes");
}
//Print
















































