/*
 * Ersteller: Adam Beres-Deak
 * Erstellt am: 13.08.2007
 *
*/


function PresseFinden()
{
    this.Bubble = null;

    // Load JS Dateien in Laufzeit
    this.IncludeJS = function(jsfilename)
    {
        var script = "<script type=\"text/javascript\" src=\"" + jsfilename + "\" ></script>";
        document.write(script);
    }
}

// Init Methode
PresseFinden.prototype.Init = function()
{
    var Covers = BC.split("|");
    if(Covers.length == 1) return;
}

// Gibt die entsprechende URL auf die Titelseite zurueck, die zu der ID des Zeitschriftes gehoert.
// Size: 0 - kleine, 1 - mittelgross, 2 - gross
PresseFinden.prototype.GetImageURL = function(ID, Size)
{
    var URL, Ext;
    if (Size == 0)
    {
        URL = "http://www.pressekatalog.de/cover/imageurls/";
        Ext = ".gif";
    }
    else if (Size == 1)
    {
        URL = "http://www.pressekatalog.de/cover/imageurls/";
        Ext = ".jpg";
    }
    else if (Size == 2)
    {
        URL = "http://www.pressekatalog.de/cover/jpgsgross/";
        Ext = ".jpg";
    }
    
    return URL + ID + Ext;
}

/*
 * Die Klasse zum Paging die Trefferliste.
 *
 *
 */
function ResultPager()
{
    this.RowsPerPage = 3;
    this.PagerDiv = $("PresseBilderPager");
    
    var firstLink = null;
    var lastLink = null;
    var pagesLink = new Array();

    this.CurrentPage = 0;
    
    function GetRowDivs()
    {
        var divs = document.getElementsByTagName("div");
        var rows = new Array();
        for(var i = 0; i < divs.length; i++)
        {
            if (divs[i].id.substring(0, 15) == "PresseBilderRow")
                rows.push(divs[i]);
        }
        return rows;
    }
    
    // Gibt die Anzahl der Seiten zurueck.
    this.PageCount = function()
    {
        return Math.ceil(GetRowDivs().length / this.RowsPerPage);
    }
    
    // Zeigt die entsprechende Reihen in der Ergebnisliste.
    function ShowRows(startRow, endRow)
    {
        var rows = GetRowDivs();
        for (var i = 0; i < rows.length; i++)
        {
            if ((i < startRow) || (i > endRow))
            {
                $(rows[i]).style.display = "none";
            }
            else
            {
                $(rows[i]).style.display = "block";
            }
        }
    }

    // Malt den Pager an der Seite.
    this.CreatePager = function()
    {
        var pageCount = this.PageCount();
        var elements = new Array();
        if (pageCount > 1)
        {
            firstLink = document.createElement("a");
            firstLink.href = "javascript:Pager.Page(" + 0 + ");";
            var text = document.createTextNode("\u00a0|<\u00a0");
            firstLink.setAttribute("onclick", "Pager.Page(" + 0 + ");");
            firstLink.appendChild(text);
            
            var gotoPage = pageCount - 1;
            lastLink = document.createElement("a");
            lastLink.href = "javascript:Pager.Page(" + gotoPage + ");";
            var text = document.createTextNode("\u00a0>|\u00a0");
            lastLink.setAttribute("onclick", "Pager.Page(" + gotoPage + ");");
            lastLink.appendChild(text);
        }
        
        for (var i = 0; i< pageCount; i++)
        {
            var link = document.createElement("a");
            link.href = "javascript:Pager.Page(" + i + ");";
            var pg = i + 1;
            var text = document.createTextNode("\u00a0" + pg + "\u00a0");
            link.setAttribute("onclick", "Pager.Page(" + pg + ");");
            link.appendChild(text);
            pagesLink.push(link);
        }
    }
    
    // Bei jedem Seitenwechsel wird der Pager aktualisiert.
    this.RefreshPager = function(currentPage)
    {
        var pageCount = this.PageCount();
        while (this.PagerDiv.childNodes[0])
        {
            this.PagerDiv.removeChild(this.PagerDiv.childNodes[0]);
        }
        
        if (pageCount > 1)
        {
            if (currentPage != 0)
            {
                this.PagerDiv.appendChild(firstLink);
            }   
        }

        for (var i=0; i< pageCount; i++)
        {
            if( i != currentPage)
                this.PagerDiv.appendChild(pagesLink[i]);
            else
            {
                var p = document.createElement("span");
                var pg = i + 1;
                var tx = document.createTextNode("\u00a0" + pg + "\u00a0");
                p.appendChild(tx);
                this.PagerDiv.appendChild(p);
            }
        }
    
        if (pageCount > 1)
        {
            if ((currentPage + 1) != pageCount)
            {
                this.PagerDiv.appendChild(lastLink);
            }
        }

    }
    
    // Wechselt die Seite.
    // 0 ist die erste Seite
    this.Page = function(pageNum)
    {
        this.CurrentPage = pageNum;
        if (this.PageCount() > 1)
        {
            ShowRows(pageNum * this.RowsPerPage, ((pageNum + 1) * this.RowsPerPage) - 1);
            this.RefreshPager(pageNum);
        }
    }

}

/*
 * Zeigt bei dem Dealer liegenden Zeitschriften an.
 *
 */
function ShowDealersMagazines(Magazines, Name) 
{

    var imgs = document.getElementsByTagName("img");
    var ctr = 0;
    for (var i = 0; i < imgs.length; i++)
    {
        if(imgs[i].id.substring(0, 11) == "PresseBild_") ctr++;
    }
    if (ctr == 1) return;


    function GetMagazines(m)
    {
        var ms = new Array();
        ms = m.split("|");
        
        var magazines = new Array();
        var al = "";
        for (var i = 0; i < ms.length; i++)
        {
            if(ms[i].charAt(0) != "E") continue;
            magazines.push(ms[i].substring(1, ms[i].length));
        }
        
        
        var allms = new Array();
        allms = BC.split("|");
        var mags = new Array();
        for(var i = 0; i < allms.length; i++)
        {
            if(allms[i].charAt(0) != "E") continue;
            mags.push(allms[i].substring(1, allms[i].length));
        }
        
        // magazines - mags
        
        var intersect = new Array();
        for(var i = 0; i < mags.length; i++)
        {
            for(var j = 0; j < magazines.length; j++)
            {
                if(mags[i] == magazines[j]) 
                {
                    intersect.push(mags[i]);
                    break;
                 }
            }
        }
        magazines = intersect;
        
        return magazines;
    }

    function GetRowDivs()
    {
        var divs = document.getElementsByTagName("div");
        var rows = new Array();
        for(var i = 0; i < divs.length; i++)
        {
            if (divs[i].id.substring(0, 15) == "PresseBilderRow")
                rows.push(divs[i]);
        }
        return rows;
    }
    
    function HideOriginalRows()
    {
        var rows = GetRowDivs();
        for (var i = 0; i < rows.length; i++)
            rows[i].style.display = "none";
    }


    function RemoveRows()
    {
    
        var divs = document.getElementsByTagName("div");
        var rows = new Array();
        var toremove = new Array();
        for(var i = 0; i < divs.length; i++)
        {
            if (divs[i].id.substring(0, 16) == "_PresseBilderRow")
            {
                var row = divs[i];
                $(row).remove();
            }
        }
        
        
    }

    function CreateNewRows()
    {
        var RowsPerPage = 3;
        var HitsPerRow = 4;
        var div = null;
        var magazines = GetMagazines(Magazines);

        for (var i = 0; i < magazines.length; i++)
        {
            if (i % HitsPerRow == 0)
            {
                div = document.createElement("div");
                div.id = "_PresseBilderRow" + (i / HitsPerRow);
                //div.style.pixelPadding = 5;
                $("PresseBilder").appendChild(div);
                //$("PresseBilder").style.
                //var st = div.getAttribute("style");
                //if (st == null) st = "";
                //st += "margin-top:-1px;margin-left:1px;";
                div.style.pixelWidth = 448;
                div.style.pixelHeight = 142;
                //div.setAttribute("style", st);
                //alert(div.clientWidth + " / " + div.clientHeight);
            }
            
            var img = document.createElement("img");
            img.id = "PresseBild_" + magazines[i];
            if (magazines.length > 0)
            {
                img.src = "http://www.pressekatalog.de/cover/imageurls/" + magazines[i] + ".jpg";
                //img.setAttribute("style", "height:120px;width:auto;");
                img.setAttribute("style", "border:10px solid #FFFFFF;max-height:120px;margin-left:2px;margin-right:1px;width:auto;");
                img.style.pixelHeight = 120;
                img.style.pixelWidth = 87;
            }
            else if(magazines.length == 1)
            {
                img.src = "http://www.pressekatalog.de/cover/jpgsgross/" + magazines[i] + ".jpg";
                img.style.pixelHeight = 575;
                img.style.height = "auto";
                //img.style.pixelWidth = 87;
        }
            div.appendChild(img);
            if (i >= ((RowsPerPage * HitsPerRow) - 1)) break;
        }
    }



    function HidePager()
    {
        document.getElementById("PresseBilderPager").style.display = "none";    
    }
    
    HideOriginalRows();
    RemoveRows();
    CreateNewRows();
    HidePager();
    $("PresseBildBoxHeader").firstChild.data = "Bei " + Name + " finden Sie:";

}

/*
 * Kehrt zurueck zur originalen Coveranzeige.
 *
 */
 
function ShowAllMagazines()
{
    var imgs = document.getElementsByTagName("img");
    var ctr = 0;
    for (var i = 0; i < imgs.length; i++)
    {
        if(imgs[i].id.substring(0, 11) == "PresseBild_") ctr++;
    }
    if (ctr == 1) return;
    // Änderung Anzeige: Alle zum Stichwort gefundenen Zeitschriften anzeigen

    function RemoveRowDivs()
    {
        var divs = document.getElementsByTagName("div");
        var rows = new Array();
        for(var i = 0; i < divs.length; i++)
        {
            if (divs[i].id.substring(0, 16) == "_PresseBilderRow")
            {
                divs[i].style.display = "none";
            }
        }
        return rows;
    }

    function GetRowDivs()
    {
        var divs = document.getElementsByTagName("div");
        var rows = new Array();
        for(var i = 0; i < divs.length; i++)
        {
            if (divs[i].id.substring(0, 15) == "PresseBilderRow")
                rows.push(divs[i]);
        }
        return rows;
    }

    function RenameOriginalRowsBack()
    {
        var rows = GetTmpRowDivs();
        for (var i = 0; i < rows.length; i++)
        {
            rows[i].id = rows[i].id.substring(4);
        }
    }
    
    function ShowPager()
    {
        /*$("PresseBilderPager").innerHTML = "";
        var oldCurrPage = Pager.CurrentPage;
        Pager = new ResultPager();
        Pager.CreatePager();
        Pager.Page(oldCurrPage);*/
        $("PresseBilderPager").style.display = "block";
    }

    function ShowOroginalRows()
    {
        var rows = GetRowDivs();
        for (var i = 0; i < rows.length; i++)
        {
            rows[i].style.display = "block";
        }
    }

    RemoveRowDivs();
    ShowOroginalRows();
    ShowPager();
    $("PresseBildBoxHeader").firstChild.data = "W\u00e4hlen Sie einen Titel und erfahren Sie mehr";
}


function GetDataFromPresseDoc(doc, tagname)
{
    try
    {
        var fields = doc.getElementsByTagName("field");
        for (var i = 0; i < fields.length; i++)
        {
            if (fields[i].getAttribute("n") == tagname)
            {
                var tx = fields[i].firstChild.data;
                tx = "";
                var children = fields[i].childNodes;
                for (var j = 0; j < children.length; j++)
                {
                    if (children[j].nodeName == "#text") tx += children[j].data;
                    else if (children[j].nodeName == "hit") tx += "<strong style=\"background-color:yellow;\">" + children[j].firstChild.data + "</strong>";
                    else tx += children[j].firstChild.data;
                }
                tx = tx.replace(/\n\n/g, " &nbsp;<strong>|</strong>&nbsp; ");
                tx = tx.replace(/\n/g, " &nbsp;*&nbsp; ");
                return tx;
            }
        }
        return "";
    }
    catch(e)
    {
        return "";
    }
};

function GetPresseDoc(Ebinr, CatchWord, OnSuccess)
{
    var url = "../../Partners/PresseFinden/AjaxRequest.aspx?EBINR=" + encodeURIComponent(Ebinr) + "&PressCatchword=" + encodeURIComponent(CatchWord);
    new Ajax.Request(url, {method: 'get', onSuccess: OnSuccess});
};

PresseFinden.prototype.OneCover = function()
{
    function ResizeDiv()
    {
        var OCDHeight = $("OneCoverDiv").clientHeight;//.getHeight();
        if (OCDHeight == 0) OCDHeight = $("OneCoverDiv").getHeight();
        $("PresseBilder").style.pixelHeight = (600 + OCDHeight);
    }
    
    function Refresh(transfer)
    {
        var Textdiv = $("OneCoverDiv");
        var doc = transfer.responseXML.documentElement;
        var title = GetDataFromPresseDoc(doc, "title");
        var subtitle = GetDataFromPresseDoc(doc, "subtitle");
        var appear = GetDataFromPresseDoc(doc, "interval");
        //var single = GetDataFromPresseDoc(doc, "issueprice");
        var single = GetDataFromPresseDoc(doc, "printissueprice");
        var singlecurr = "EUR(D)";
        var vol = GetDataFromPresseDoc(doc, "number") + "/" + GetDataFromPresseDoc(doc, "year");
        var actcont = GetDataFromPresseDoc(doc, "cover");
        var publisher = GetDataFromPresseDoc(doc, "publisher");
        var keywords = GetDataFromPresseDoc(doc, "keywords");
        var category = GetDataFromPresseDoc(doc, "category");
        var coverid = GetDataFromPresseDoc(doc, "ebinr");
        var profile = GetDataFromPresseDoc(doc, "profile");
        
        Textdiv.innerHTML = "";
        Textdiv.innerHTML += "<p id=\"title\" class=\"title\">" + title + "</p>";
        Textdiv.innerHTML += "<span id=\"subtitle\" class=\"subtitle\"><strong>" + subtitle + "</strong></span><br />";
        Textdiv.innerHTML += "<br /><span id=\"profile\" class=\"profile\"><strong>Profil:&nbsp;</strong>" + profile + "</span><br />";
        Textdiv.innerHTML += "<br /><strong>Aktuelle Ausgabe:&nbsp;</strong><span id=\"actcont\" class=\"actcont\">" + vol + "<br />" + actcont + "</span><br /><br/>";
        Textdiv.innerHTML += "<span id=\"appear\" class=\"appear\"><strong>Erscheint:</strong> &nbsp;" + appear + "</span><br />";
        Textdiv.innerHTML += "<span id=\"single\" class=\"single\"><strong>Einzelheft:</strong>&nbsp;" + single + "&nbsp;" + singlecurr + "</span><br />";
        Textdiv.innerHTML += "<span id=\"publisher\" class=\"publisher\"><strong>Verlag:&nbsp;</strong>" + publisher + "</span><br />";
        Textdiv.innerHTML += "<span id=\"keywords\" class=\"keywords\"><strong>Schlagwort:&nbsp;</strong>" + keywords + "</span><br />";
        Textdiv.innerHTML += "<span id=\"category\" class=\"category\"><strong>Kategorie:&nbsp;</strong>" + category + "</span><br />";
        ResizeDiv();
    }
    
    var Textdiv = null;
    var Covers = BC.split("|");
    if (Covers.length == 1)
    {
        var Textdiv = document.createElement("div");
        Textdiv.id = "OneCoverDiv";
        $("PresseBilder").appendChild(Textdiv);
        Textdiv.innerHTML = "Daten werden geladen...";
        ResizeDiv();
        var Ebinr = Covers[0].substring(1, Covers[0].length);
        GetPresseDoc(Ebinr, PressCatchword, Refresh);
    }
}

PresseFinden.prototype.Scroll = function()
{
    function GetElementTop(Obj)
    {
        Obj = $(Obj);
        var Curtop = 0;
	    if (Obj.offsetParent)
	    {
    		Curtop = Obj.offsetTop
	    	while (Obj = Obj.offsetParent)
		    {
    		    Curtop += Obj.offsetTop ? Obj.offsetTop : 0;
	        }
        }
	    return Curtop;   
    }
    
    function PageTop()
    {
        return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : 
            document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : 
                document.body.scrollTop ? document.body.scrollTop : 
                    0;
    }
    
    OrigiTop = 485; // GetElementTop($("PresseBildBox")) - 23;
    var MoveTo = OrigiTop; //485;
    
    var PageHeight = $("PresseBackground").getHeight();
    var BoxHeight = $("PresseBildBox").getHeight();
    
    
    if (document.getElementById("Backlink") != null)
    {
        $("PresseBildBox").style.position = "relative";
        $("PresseBildBox").style.pixelTop = 0;
    }
    else 
    {
        $("PresseBildBox").style.position = "absolute";
        $("PresseBildBox").style.top = OrigiTop + "px";
    }
    
    function OnScroll(e)
    {   
        if (document.getElementById("Backlink") != null) return;
        if (PageTop() > OrigiTop)
        {
            if (PageTop() + BoxHeight > PageHeight) MoveTo = PageHeight - BoxHeight + 55;
            else MoveTo = PageTop();
        }
        else MoveTo = OrigiTop;
        
        MoveTo = Math.max(OrigiTop, MoveTo);
        
        if (MoveTo != GetElementTop("PresseBildBox"))
        {
            setTimeout(function(){$("PresseBildBox").style.top = MoveTo + "px";}, 240);
        }
    }
    
    if (BC.split('|').length > 1)
        window.onscroll = OnScroll;
    else
    {
        $("PresseBildBox").style.position = "relative";
        $("PresseBildBox").style.top = null;
    }
}

PresseFinden.prototype.DarkScreen = null;

PresseFinden.prototype.ShowDarkScreen = function()
{
    var div = document.createElement("div");
    div.id = "DarkScreen";
    document.body.appendChild(div);
    div.style.position = "absolute";
    div.style.zIndex = 10000;
    div.style.left = "0px";
    div.style.top = "0px";
    div.style.width = document.body.clientWidth + 16 + "px";
    div.style.height = document.body.clientHeight + 100 + "px";
    div.style.backgroundColor = "#000000";
    if (div.style.filter != null) div.style.filter = "alpha(opacity=75)";
    else div.style.opacity = 0.75;
    this.DarkScreen = div;
    div.onclick = PF.HideDarkScreen;
};

PresseFinden.prototype.HideDarkScreen = function()
{
    if (this.DarkScreen != null)
    {
        this.DarkScreen.parentNode.removeChild(this.DarkScreen);
        this.DarkScreen = null;
        $("FlashDiv").parentNode.removeChild($("FlashDiv"));
        $("DetailDiv").parentNode.removeChild($("DetailDiv"));
        $("FrameDiv").parentNode.removeChild($("FrameDiv"));
    }
};

PresseFinden.prototype.ShowDarkContent = function(Ebinr)
{
    function PageTop()
    {
        return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : 
            document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : 
                document.body.scrollTop ? document.body.scrollTop : 
                    0;
    }
    
    function PageLeft()
    {
        return typeof window.pageXOffset != 'undefined' ?  window.pageXOffset : 
            document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : 
                document.body.scrollLeft ? document.body.scrollLeft : 
                    0;
    }

    function PageWidth()
    {
        if (document.documentElement.clientWidth) return document.documentElement.clientWidth;
        else if (window.innerWidth) return window.innerWidth;
        else if (window.clientWidth) return window.clientWidth;
        else if (document.body.clientWidth) return document.body.clientWidth;
        else return 0;
    }
    
    function PageHeight()
    {
        if (document.documentElement.clientHeight) return document.documentElement.clientHeight;
        else if (window.innerHeight) return window.innerHeight;
        else if (window.clientHeight) return window.clientHeight;
        else if (document.body.clientHeight) return document.body.clientHeight;
        else return 0;
    }

    function Scroll(Trg)
    {
        function ScrollHandler(e)
        {
            e = e ? e : window.event;
            var wheelData = e.detail ? e.detail * -1 : e.wheelDelta / 40;
            var Delta = wheelData * 10;
            if (Delta < 0)
            {
                if (this.clientHeight + this.scrollTop + Delta <= this.scrollHeight)
                    this.scrollTop -= Delta;
                else
                    this.scrollTop = this.scrollHeight - this.clientHeight;
            }
            else
            {
                if (this.scrollTop - Delta >= 0)
                    this.scrollTop -= Delta;
                else
                    this.scrollTop = 0;
            }
            
            this.style.visibility = "hidden";
            this.style.visibility = "visible";
            
            if(e.stopPropagation) e.stopPropagation();
            if(e.preventDefault) e.preventDefault();
            e.returnValue = false;
            e.cancelBubble = true;
            return false;
        }
        
        if (window.addEventListener)
        {
            Trg.addEventListener('DOMMouseScroll',ScrollHandler, false);
        }
        else if (window.attachEvent)
        {
            Trg.onmousewheel = ScrollHandler;
        }

    };
    
    function FlashCanPlay()
    {
        /*
        var MM_contentVersion = 6;
		var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
		if ( plugin ) {
				var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			    for (var i = 0; i < words.length; ++i)
			    {
				if (isNaN(parseInt(words[i])))
				continue;
				var MM_PluginVersion = words[i]; 
			    }
			var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
		}
		else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
		   && (navigator.appVersion.indexOf("Win") != -1)) {
			document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
			document.write('on error resume next \n');
			document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
			document.write('</SCR' + 'IPT\> \n');
		}
		return MM_FlashCanPlay;
		*/
		
		return (flashinstalled == 2 /* && flashversion >= 6*/);
    }
    
    var FrameDiv = document.createElement("div");
    FrameDiv.id = "FrameDiv";
    document.body.appendChild(FrameDiv);
    FrameDiv.style.position = "absolute";
    
    FrameDiv.style.width = Math.min(Math.round(PageWidth() * 0.98), 900) + "px";
    FrameDiv.style.height = Math.min(Math.round(PageHeight() * 0.98), 900) + "px";
    
    FrameDiv.style.backgroundColor = "#ffffff";
    FrameDiv.style.border = "4px solid #999";
    FrameDiv.style.zIndex = 30000;
    FrameDiv.style.left = PageLeft() + ((PageWidth() - FrameDiv.offsetWidth) / 2) + "px";
    FrameDiv.style.top = PageTop() + ((PageHeight() - FrameDiv.offsetHeight) / 2) + "px";
    FrameDiv.style.overflow = "hidden";
    
    var FlashDiv = document.createElement("div");
    FrameDiv.appendChild(FlashDiv);
    FlashDiv.style.position = "absolute";
    FlashDiv.style.zIndex = 31000;
    FlashDiv.style.width = "800px";
    
    FlashDiv.style.top = "40px";
    FlashDiv.style.left = (FrameDiv.offsetWidth - FlashDiv.offsetWidth) / 2 + "px";
    
    FlashDiv.id = "FlashDiv";
    FlashDiv.style.backgroundColor = "#ffffff";
    
    if (!FlashCanPlay())
    {
        var Img = document.createElement("img");
        Img.src = PF.GetImageURL(Ebinr, 2);
        Img.style.width = "290px";
        Img.style.height = "450px";
        Img.style.border = "2px solid rgb(153, 170, 187)";
        Img.style.zIndex = "1000";
        Img.style.position = "relative";
        FlashDiv.appendChild(Img);
    }
    else
    {
        var Rnd = (new Date()).getTime();
        var so = new SWFObject("../../Partners/PresseFinden/Layout/Flash/coverflow.swf?" + Rnd, "flash", "600", "450", "8", "#ffffff");
        so.id = "FlashObject";
	    so.addVariable("coverConfigFile", "../../Partners/PresseFinden/Layout/Flash/coverConfig.xml");
	    so.addVariable("coverFeedFile", "/PK/coverFeedNeu.asp");
	    so.addVariable("current", 0);
	    so.addVariable("coverFeedFileParameters", "LIST=PUBLISHER|PartnerID=PF20476|Ebinr=" + Ebinr);
	    so.write("FlashDiv");

        var Span = document.createElement("span");
        Span.style.position = "absolute";
        Span.style.top = "0px";
        Span.style.zIndex = 35000;
        Span.style.left = "0px";
        Span.style.width = FlashDiv.clientWidth + "px";
        Span.style.textAlign = "left";
        Span.style.color = "#FF4200";
        Span.style.fontWeight = "bold";
        Span.innerHTML = "St&ouml;bern Sie hier im Regal und &uuml;bernehmen Sie per Klick den Zeitschriftentitel in die Suche.";
        FlashDiv.style.overflow = "visible";
        FlashDiv.appendChild(Span);
        
        var Flash = document.getElementById("flash");
        Flash.style.position = "absolute";
        Flash.style.top = "20px";
        Flash.style.left = (FlashDiv.offsetWidth - Flash.offsetWidth) / 2 + "px";
        
    }
    
    
    var A = document.createElement("a");
    A.href = "#";
    FrameDiv.appendChild(A);
    A.style.position = "absolute";
    A.style.left = FrameDiv.offsetWidth - 50 + "px";
    A.style.top = 15 + "px";
    A.style.zIndex = 32000;
    
    A.onclick = function(e)
        {
            e = e || window.event;
            PF.HideDarkScreen();
            e.cancelBubble = true;
            e.returnValue = false;
        };


    var CloseButton = document.createElement("div");
    CloseButton.style.background = "url(../../Partners/PresseFinden/Layout/Images/Custom/closebox.png)";
    CloseButton.style.width = "30px";
    CloseButton.style.height = "30px";
    A.innerHTML = '<span style="position: absolute;left:-83px;font-size:12pt;top:8px;font-weight:bold;">Schlie&#xDF;en</span>';
    A.appendChild(CloseButton);
    
    var DetailDiv = document.createElement("div");
    DetailDiv.id = "DetailDiv";
    DetailDiv.style.position = "absolute";
    FrameDiv.appendChild(DetailDiv);
    
    DetailDiv.style.zIndex = 31000;
    DetailDiv.style.opacity = 1;
    
    DetailDiv.style.width = "100%"; //Math.round(FrameDiv.clientWidth * 0.9) + "px";
    DetailDiv.style.height = "300px";
    DetailDiv.style.top = "350px";
    
    //DetailDiv.style.padding = "15px";
    DetailDiv.style.left = "0px";//(FrameDiv.offsetWidth - DetailDiv.offsetWidth) / 2 + "px";
    
    /*DetailDiv.style.paddingLeft = "10px";
    DetailDiv.style.paddingRight = "10px";
    */
    
    DetailDiv.style.overflow = "auto";
    
    DetailDiv.style.backgroundColor = "#ffffff";
    
    
    FlashDiv.style.height = "460px";
    var H = FrameDiv.clientHeight - 12;
    H -= FlashDiv.offsetHeight;
    var S = 0;
    
    if (H > 272)
    {
        DetailDiv.style.height = "260px";
        H -= DetailDiv.offsetHeight;
        S = Math.round(H / 3);
    }
    else
    {
        DetailDiv.style.height = H - 12 + "px";
        H = 0;
        S = 0;
    };
    
    FlashDiv.style.top = S + "px";
    DetailDiv.style.top = 2*S + FlashDiv.offsetHeight + "px";
    DetailDiv.style.height = DetailDiv.offsetHeight + S + "px";
    
    Scroll(DetailDiv);
    
    DetailDiv.innerHTML = "Daten werden geladen...";
    
    GetPresseDoc(Ebinr, PressCatchword, 
        function(transfer)
        {
            var doc = transfer.responseXML.documentElement;
            var title = GetDataFromPresseDoc(doc, "title");
            var subtitle = GetDataFromPresseDoc(doc, "subtitle");
            var appear = GetDataFromPresseDoc(doc, "interval");
            var single = GetDataFromPresseDoc(doc, "printissueprice");
            var singlecurr = "EUR(D)";
            var vol = GetDataFromPresseDoc(doc, "number") + "/" + GetDataFromPresseDoc(doc, "year");
            var actcont = GetDataFromPresseDoc(doc, "cover");
            var publisher = GetDataFromPresseDoc(doc, "publisher");
            var keywords = GetDataFromPresseDoc(doc, "keywords");
            var category = GetDataFromPresseDoc(doc, "category");
            var coverid = GetDataFromPresseDoc(doc, "ebinr");
            var profile = GetDataFromPresseDoc(doc, "profile");
            
            DetailDiv.innerHTML = "";
            
            var TitleDiv = document.createElement("div");
            TitleDiv.id = "infotitle";
            TitleDiv.style.width = DetailDiv.offsetWidth - 6 + "px";
            TitleDiv.innerHTML = '<span style="margin-left:40px; margin-top:10px; position:relative; top:10px;">' + title + '</title>';
            
            var SubtitleDiv = document.createElement("div");
            SubtitleDiv.id = "infosubtitle";
            SubtitleDiv.style.width = DetailDiv.offsetWidth - 6 + "px";
            SubtitleDiv.innerHTML = '<span style="margin-top:10px; position:relative; left:40px; top:0px; font-weight:bold; margin-right:20px;">' + subtitle + '</title>';

            var LeftRight = document.createElement("div");
            LeftRight.id = "leftright";
            LeftRight.style.width = DetailDiv.offsetWidth - 6 + "px";
            
            
            var LeftDiv = document.createElement("div");
            LeftDiv.id = "infoleft";
            LeftDiv.innerHTML = '<span style="color:#3a6d98;font-weight:bold;font-size:14pt;"> Aktuelle Ausgabe:&nbsp;</span>' + '<span style="color:#555555;font-weight:bold;font-size:14pt;">' + vol + '</span><br /><br />';
            LeftDiv.innerHTML += '<span style="color:#555555;font-size:11pt;line-height:17px;">' + actcont + '</span>';
            
            var RightDiv = document.createElement("div");
            RightDiv.id = "inforight";
            
            RightDiv.innerHTML = '<span class="name">Erscheint: &nbsp;</span><span class="desc">' + appear + '</span><br />';
            RightDiv.innerHTML += '<span class="name">Einzelheft: &nbsp;</span><span class="desc">' + single + '&nbsp;' + singlecurr + '</span><br />';
            RightDiv.innerHTML += '<span class="name">Verlag: &nbsp;</span><span class="desc">' + publisher + '</span><br />';
            RightDiv.innerHTML += '<span class="name">Kategorie: &nbsp;</span><span class="desc">' + category + '</span><br />';
            RightDiv.innerHTML += '<span class="name">Schlagwort: &nbsp;</span><span class="desc">' + keywords + '</span><br />';
            RightDiv.innerHTML += '<br />';
            RightDiv.innerHTML += '<span class="name">Profil: &nbsp;</span><span class="desc">' + profile + '</span><br />';
            
            DetailDiv.appendChild(TitleDiv);
            DetailDiv.appendChild(SubtitleDiv);
            LeftRight.appendChild(LeftDiv);
            LeftRight.appendChild(RightDiv);
            DetailDiv.appendChild(LeftRight);
            
            LeftRight.style.height = DetailDiv.offsetHeight - LeftRight.offsetTop + "px";
            
        }    
    );
    
    
};

PresseFinden.prototype.OnCover = function(ImgNodeID, SearchLink)
{
    var Img = document.getElementById(ImgNodeID);
    if (Img == null) return;
    
    //Img.style.border = "6px solid #ff4200";
    
    var Ebinr = ImgNodeID.substring(11);
    var InfoShown = false;
    
    var div = document.getElementById(ImgNodeID + "InfoDiv");
    if (div == null) div = document.createElement("div");
    else
    {
        if (div.TimeoutID != null) clearTimeout(div.TimeoutID);
        return;
    }
    div.innerHTML = "<a href=\"#\" class=\"underlinedlink\">H&auml;ndler finden</a><br /><a href='#'  class=\"underlinedlink\">Titelinfo finden</a>";
    //div.innerHTML = "<a href=\"#\" class=\"underlinedlink\">Fach-H&auml;ndler anzeigen</a><br /><a href='#'  class=\"underlinedlink\">Mehr Infos zur Zeitschrift</a>";
    div.style.paddingLeft = "1px";
    div.style.paddingRight = "1px";
    
    div.id = ImgNodeID + "InfoDiv";
    Img.parentNode.appendChild(div);

    div.onmouseover = function()
    {
        if (div.TimeoutID != null) clearTimeout(div.TimeoutID);
        InfoShown = true;
        //Img.style.border = "6px solid #ff4200";
        return;
    };

    div.onmouseout = function()
    {
        div.TimeoutID = setTimeout(function(){div.parentNode.removeChild(div);}, 400);
    };

    var A = div.getElementsByTagName("a");
    A[0].href = SearchLink + Ebinr;
    A[1].onclick = function(e)
    {
        e = e || window.event;
        
        PF.ShowDarkScreen();
        PF.ShowDarkContent(Ebinr);
        
        e.returnValue = false;
        e.cancelBubble = true;
    };
    
    div.style.display = "none";
    div.style.position = "absolute";
    div.style.top = Img.offsetTop + 80 + "px";
    div.style.width = "84px";
    div.style.left = Img.offsetLeft + ((Img.offsetWidth - 88) / 2) + "px";
    //div.style.backgroundColor = "#FFFFFF";
    div.style.border = "1px solid #000000";

    div.style.color = "#000000";
    div.style.backgroundColor = "#FF4200";


    setTimeout(function()
        {
            try
            {
                new Effect.BlindDown(div, {duration: 0.25});
                //div.setAttribute("style", "color:#000000;background-color:#e4e4e4;padding-left:1px;padding-right:1px;position:absolute;");

            }
            catch(E){};
        }, 200);
};

PresseFinden.prototype.OutCover = function(ImgNodeID)
{
    var Img = document.getElementById(ImgNodeID);
    if (Img == null) return;
    
    //Img.style.border = "6px solid Transparent";

    var div = document.getElementById(ImgNodeID + "InfoDiv");
    if (div) 
    {
        div.TimeoutID = setTimeout(function(){div.parentNode.removeChild(div);}, 400);
    }
};


PF = new PresseFinden();
PF.Init();
PF.OneCover();
Pager = new ResultPager();
Pager.CreatePager();
Pager.Page(0);

var T = GetElementCoords4($("MapControlFrame"))[3];
$("PresseBildBox").style.pixelTop = 485;//T - 10;

PF.Scroll();


function selected(Titel)
{
    document.SearchForm.PressCatchword.value = Titel;
    //document.SearchForm.submit();
    PF.HideDarkScreen();
    window.scroll(0,0);
    return false;
};


function ShowCovers(CoversList, Start)
{
    if (CoversList.length > 1)
    {
        if (Start == null) Start = 0;
        var Box = document.getElementById("PresseBilder");
        Box.innerHTML = "";
        //var SearchLink = "Poi.aspx?ClearGroups=Paging,MapNav&ClearParas=WhereCondition,CLux,Luy,Rlx,Rly&QT=1&View=5&PressCatchword=&SessionGuid=" + SessionGuid;
        
        if(Start > CoversList.length) return;
        
        var End = Start + 12;
        if (End > CoversList.length) End = CoversList.length;
        
        for (var i = Start; i < End; i++)
        {
            var Row;
            if ((i % 4) == 0)
            {
                Row = document.createElement("div");
                Row.id = "PresseBilderRow" + Math.floor(i / 4);
                Row.style.width = "448px";
                Row.style.height = "142px";
                Row.style.display = "block";
                Box.appendChild(Row);
            }
            
            var Img = document.createElement("img");
            Img.src = "http://www.pressekatalog.de/cover/imageurls/" + CoversList[i].substring(1) + ".jpg";
            Img.className = "PresseBild";
            Img.id = "PresseBild_" + CoversList[i].substring(1);
            Img.Ebinr = CoversList[i].substring(1);
            Img.onmouseover = function(){if (PF) PF.OnCover(this.id, SearchLink)};
            Img.onmouseout = function(){if (PF) PF.OutCover(this.id);};
            
            Row.appendChild(Img);
        }
    }
    else
    {
        var Img = document.createElement("img");
        Img.src = "http://www.pressekatalog.de/cover/jpgsgross/" + CoversList[0].substring(1) + ".jpg";
        Img.id = "PresseBild_" + CoversList[0].substring(1);
        Img.Ebinr = CoversList[0].substring(1);
        
        var Box = document.getElementById("PresseBilder");
        
        Box.insertBefore(Img, Box.firstChild);
        
        var PagerDiv = document.getElementById("PresseBilderPager");
        PagerDiv.style.display = "none";
        document.onmousemove = null;
    }
};


function Paging(Covers)
{
    var PagerDiv = document.getElementById("PresseBilderPager");
    PagerDiv.innerHTML = "";
    var PageCount = Math.ceil(Covers.length / 12);
    
    var AArr = new Array();

    function AClick(e)
    {
        ShowCovers(Covers, this.Start);
        
        for (var j = 0; j < AArr.length; j++)
        {
            if (AArr[j].Start == this.Start)
                AArr[j].style.color = "#333333";
            else 
                AArr[j].style.color = "#ffffff";
        }
        
        e = e ? e : window.event;
        if (e) e.returnValue = false;
        return false;
    };
    
    for (var i = 0; i < PageCount + 2; i++)
    {
        var A = document.createElement("a");
        A.href = "#";
        A.Start = (i == PageCount + 1) ? PageCount-1 : Math.max(i - 1, 0);
        A.Start *= 12;
        if (i == 0 || i == 1) A.style.color = "#333333";
        PagerDiv.appendChild(A);
        AArr.push(A);
        
        if (i == 0) A.innerHTML = "&nbsp;|<&nbsp;";
        else if (i == PageCount + 1) A.innerHTML = "&nbsp;>|&nbsp;";
        else A.innerHTML = "&nbsp;" + i + "&nbsp;";
        
        A.onclick = AClick;
    }
    
    AArr[0].onclick();
    
};
    
Paging(Covers);

function MouseMove(e)
{
    var Box = document.getElementById("PresseBilder");
    var Imgs = Box.getElementsByTagName("img");
    for (var i = 0; i < Imgs.length; i++)
        Imgs[i].style.border = "10px solid Transparent";
    
    e = e ? e : window.event;
    
    var Trg = e.target || e.srcElement;
    
    if (Trg!= null && Trg.id != null && Trg.id.substring(0, 11) == "PresseBild_")
    {
        if (Trg!= null && Trg.id != null && Trg.id.indexOf("InfoDiv") > 0)
        {
            var Start = Trg.id.indexOf("PresseBild_");
            var End = Trg.id.indexOf("InfoDiv");
            Trg = document.getElementById(Trg.id.substring(Start, End));
        }
    }
    else 
    {
        Trg = Trg.parentNode;
        if (Trg != null && Trg.id != null)
        {
            if (Trg.id.indexOf("InfoDiv") > 0)
            {
                var Start = Trg.id.indexOf("PresseBild_");
                var End = Trg.id.indexOf("InfoDiv");
                Trg = document.getElementById(Trg.id.substring(Start, End));
            }
            else Trg = null;
        }
    }
    
    if (Trg != null && Trg.id!= null && Trg.nodeName == "IMG")
    {
        Trg.style.border = "10px solid #ff4200";
    }
};

document.onmousemove = MouseMove;
