﻿//

hoverImages = {
    // HoverImages v0.1 is Copyright (c) by Philipp Rheinstädter and Martin Preiß. It's  
    // released under the MIT License: http://www.opensource.org/licenses/mit-license.php
    srcDelimiter : "#",
    preloadimages : new Array(),
    preload : function(imgsrc) {
        var img = new Image();
        img.src = imgsrc;
        return this.preloadimages.push(img);
    },
    init : function() {
        regExpTest = new RegExp(this.srcDelimiter);
        regExpFind = new RegExp("(.*)" + this.srcDelimiter + "(.*)");    
        for (i = 0; i < document.images.length; i++) {
            img = document.images[i];
            if(regExpTest.test(img.getAttribute('src'))) {
                 img.setAttribute('src_reg', regExpFind.exec(img.getAttribute('src'))[1]);
                 img.setAttribute('src_ovr', regExpFind.exec(img.getAttribute('src'))[2]);
                 img.onmouseover = function(){ this.setAttribute('src', this.getAttribute('src_ovr')); };    
                 img.onmouseout = function(){ this.setAttribute('src', this.getAttribute('src_reg')); };
                 img.onmouseout();
                 this.preload(img.getAttribute('src_ovr'));
            }
        }
    }
};
cssHelper = {
    setChildNodeClasseNames : function(p) {
        if (p.keepLastClass) lastNode = p.rootNode.childNodes[ p.rootNode.childNodes.length - ((typeof p.rootNode.lastChild.className == 'undefined')?2:1) ];
        var childNode = p.rootNode.firstChild;
        var i = 0;
        while (childNode != null) {
            if (typeof childNode.className != 'undefined') {
                
                childNode.className = p.classeNames[i];
                if (++i >= p.classeNames.length) i = 0;
                
            }
            childNode = childNode.nextSibling;
            if (p.keepLastClass && childNode == lastNode) break;
        }
    },
    setClassOfChildElement : function(p) {
        //{rootnode:DOMnode,index:0,className:'active'}
        var n = $A(p.rootnode.childNodes);
        var j = p.index;
        for (var i=0; i<n.length; i++) 
            if (((n[i].nodeType!=3)?--j:j)==-1) n[i].className = p.className;
    },
    setHeightOfChildElements : function(p) {
        childElements = p.rootNode.getElementsByTagName(p.childTagName);
        if(childElements.length > 0){
            for(var i=0; i<= childElements.length-1; i++){                
                childElements[i].style.height = (p.rootNode.clientHeight-p.offset) + 'px';                                    
            }
        } else {p.rootNode.style.height = '17px';}
    }
}
domHelper = {
    sortSelectOptions : function(p) {
        //{select:selectField,start:0}
        var a = new Array();
        while (p.select.options[p.start]!= null) { a.push([p.select.options[p.start].text, p.select.options[p.start].value]); p.select.options[p.start] = null; }
        a.sort(function(a, b) { return(a[0]>b[0])?1:-1; });
        $A(a).each(function(n) { p.select.options[p.select.length] = new Option(n[0], n[1], false) } )
    }
}
documentViewHelper = {
    init : function() { 
        hoverImages.init();
    }
}
popupHelper = {
    openImagePopup : function(p){ //{width:,height:,alt:,url:}
        newWindow = window.open("","","height="+(p.height+20)+",width="+(p.width+20)+",left="+((screen.width/2)-((p.width+20)/2))+",top="+((screen.height/2)-((p.height+20)/2))+",status=0");
        newWindow.document.open();
        newWindow.document.write('<'+'html'+'><'+'head'+'><'+'title'+'>'+((typeof(p.alt)=="undefined")?'':p.alt)+'</'+'title'+'></'+'head'+'><'+'body style="margin:0px;padding:10px;cursor:pointer;height:'+p.height+40+';" onclick="window.close()"><img src="'+p.url+'" alt="'+((typeof(p.alt)=="undefined")?'':p.alt)+'" align="center"></'+'body'+'></'+'html'+'>');
        newWindow.document.close();
        newWindow.focus();
        return void(0);
    },
    open360DegPopup : function(p){ //{features:,width:,height:,name:,url:}
        if(p.width > screen.width || p.height > screen.height) {
            x = y = 0; 
            p.width = screen.width-10; 
            p.height = screen.height-60;
        } else {
            x=(screen.width/2)-(p.width/2)
            y=(screen.height/2)-(p.height/2)
        }
        window.open(p.url, p.name,"width="+ p.width +",height="+ p.height +",toolbar=no,menubar=no,left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y +","+ p.features);
        return void(0);
    }
}
ajaxHelper = {
    insertPageSnippets : function(p) {
        for (var i=0; i<p.snippets.length; i++){
            var pageURL = p.snippetPrefix+p.snippets[i]+p.snippetSuffix;
        
            new Ajax.Request(pageURL, 
                            {evalScripts:true, asynchronous:false, method:'get',
                                 onComplete: function(transport) {
                                     if (200 == transport.status){
                                        new Insertion.Bottom(p.container,transport.responseText);
                                        //p.container.innerHTML = p.container.innerHTML + transport.responseText;
                                        //new Ajax.Updater(p.container, pageURL, {evalScripts:true, asynchronous:false, insertion: Insertion.Bottom });   
                                    }  
                                }    
                            }
            );
        }     
    }
}

function winopen(theURL, wname, width, height, features){
    if(width > screen.width || height > screen.height) {
        positionx = 0;
        positiony = 0;
        width = screen.width-10;
        height = screen.height-60;
    } else {
        positionx=(screen.width/2)-(width/2)
        positiony=(screen.height/2)-(height/2)
    }
    window.open(theURL, wname,"width="+ width +",height="+ height +",toolbar=no,menubar=no,left=" + positionx + ",top=" + positiony + ",screenX=" + positionx + ",screenY=" + positiony +","+ features);
}

// JFA 11 Feb 2008, Helper Class For IndexTools
itHelper = {                    
                                                  
    getDocumentInfo : function() {            
            var rx =  /<a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?<\/a>/gi ;                
            var code, val, grp, contGrp = new Array();    
            if (document.getElementById("breadcrumbs") == null) {
                code = document.body.innerHTML.match(/topnavhistory(.*)<\/td>/i);
                code = code[1];
                this.documentname = itHelper.formatVar(code.toString().split(" &gt; ").pop());
            } else {
                var bc = document.getElementById("breadcrumbs").childNodes;
                for (var nd=0; nd<bc.length; nd++) {
                    if (bc[nd].nodeType == 1) {
                        code = bc[nd].innerHTML;
                        break;
                    }
                }
            }                    
            while (val = rx.exec(code)) contGrp.push(itHelper.formatVar(val[2]));            
            if (contGrp[contGrp.length-1] != "Zubehör")
                if ((document.URL.replace(/(_+br_+|_|\-)/gi,"").search(/(leistungsmerkmale|lieferumfang|technischedaten|auszeichnungen|details|softwareupdates|firmwareupdates|testversion|photoshop|vorlagenfuerfruehlingundsommer|3dkunsteffekte)/i) != -1) && (contGrp[2] != "Kundenservice Kameras")){
                    contGrp.push(itHelper.formatVar(contGrp[contGrp.length-1]+" ["+RegExp.$1+"]"));                                        
                } else {                      
                    if (document.URL.replace(/(_+br_+|_|\-)/gi,"").search(/(zubehoer[0-9]+\.htm)/i) != -1)    
                        contGrp.push(itHelper.formatVar(contGrp[contGrp.length-1]+" [zubehoer]"));
              };
            if (document.getElementById("breadcrumbs") != null) this.documentname = itHelper.formatVar(contGrp.pop());            
            contGrp.shift();                        
            if (contGrp.length == 1) {
                    contGrp.push(this.documentname);
                    this.documentname = this.documentname + " Home";
            }            
            this.documentgroup = (contGrp.length == 0) ? ((this.documentname == "Kamera") ? "Home" : "Specials/Other") : contGrp[1];            
            if (contGrp.length == 0) {
                    contGrp.push("Kamera");
                    contGrp.push(this.documentgroup);       
            }
            this.documentpath = contGrp;
            this.domains = "www.olympus.de, search.olympus-europa.com, consumer.olympus-europa.com";
            if (document.body.innerHTML.search(/productstage/) > -1) {
                this.documenttype = "productpage";
                if (document.body.innerHTML.match(/articleid:'(.*)',/gi) != null)
                    this.articleid = RegExp.$1;                    
            }
            return this;            
        },
        
        formatVar : function(p) {
            return p.substr(0,75).replace(/[\'<>#&:;\?\-\*~`´\)\(=%!""\.]/ig,"_");
        },
        
        debug : function() {                        
            var out = "DOCUMENTNAME: " + DOCUMENTNAME + "\n";
            out = out + "DOCUMENTGROUP: " + DOCUMENTGROUP + "\n";
                        if (typeof ACTION != "undefined")
                out = out + "ACTION: " + ACTION + "\n";
            if (typeof _S_SKU != "undefined")
                out = out + "_S_SKU: " + _S_SKU + "\n";
            for (var j=1; j<9; j++)
                try {
                    eval("_s_cf0" + j);
                    out = out + "_s_cf0" + j + ": " + eval("_s_cf0" + j) + "\n";
                } catch (e) {                                                    
                    // break;
                }   
                if (typeof console == "object") console.info(out);
                if (typeof Debug == "object") Debug.writeln(out+"\n");                                             
        },            
                             
        setVariables : function() {                        
                _s_cf08 = "Consumer";  
                _s_cf13 = "Consumer";              
                DOCUMENTNAME = this.documentname;                        
                DOCUMENTGROUP = this.documentgroup;
                DOMAINS = this.domains;                            
                        if (this.documenttype == "productpage") {
                            ACTION = "PRODUCT_VIEW";                  
                            _S_SKU = this.articleid;
              }
                        for (var i=1; i<=5; i++) 
                            if (this.documentpath.length > 0) {
                                eval("_s_cf0"+i+"='"+this.documentpath.shift()+"';");                                           
                            } else {
                                eval("_s_cf0"+i+"='[sub-category not applicable]';");                                           
                            }
                },
                
                captureLead : function(p) { //{action:,sku:}
                        var tracking_object = createITT();
                        tracking_object.ACTION = p.action;
                        tracking_object._S_SKU = p.sku;
                        tracking_object.submit_action();
                }
                
}