/*globals  Class, $A, $$, Element, $, document, goButtonText, createButtonLayout*/
/** 
 *  LocalStoreDropdown using create SEO Enabled dropdwon for changing local store
 **/

var LocalStoreDropdown = Class.create({
    // this is the constructor of the class 
    initialize: function (clazzName) {
        this.clazzName = clazzName;
        // this is the function to be executed.
        this.execute();
    },
    execute: function () {
        if ($$('div.' + this.clazzName) !== null) {
            $A($$('div.' + this.clazzName)).each(function (div) {
                var el = new Element('select', {
                    'class': 'selectClass',
                    'id': 'localStore'
                });
                jStoreNames.each(function (inObject){
                    if (inObject !== null){
                        for (key in inObject) {
                            var opt = new Element('option');
                            opt.innerHTML = key;
                            opt.value = inObject[key];
                            el.insert(opt);
                        }
                    }
                });               
                // Create and add go button
                if (goButtonText === undefined) {
                    goButtonText = "GO";
                }
                var goButton = createButtonLayout(goButtonText, "jsButton_SelectStore_01", "button", "location.href = $F('localStore');");
                var goButtonContainer = new Element('div', {
                    'class': 'goButton toleft'
                });
                goButtonContainer.insert(goButton, null);
                if ($('changeStore') !== null) {
                    $('changeStore').insert(goButtonContainer);
                }
                div.insert(el, null);                
            });
        }
        $('storeHeaderContainer').show();
                if ($('storeManager') !== null) {
                    $('storeManager').show();
                }
    }
}); 

com.ikea.irw.localStore = {};

com.ikea.irw.localStore.ProductInfo = {

    productPartNumber : "",
    productDocs : new Hash(),
    
    LspLiteBoxData : new function () {
    //var LspLiteBoxData = new function () {
        return {
            productDocs : new Hash(),
            initialize: function () {
                productDocs = new Hash();
                this.count = 0;
                var blockId = "";
                var count = 0;
                var productWithBlock;
                this.products = {};
                this.length = 0;
                this.noOfThumbs = 9;
                this.thumbs = new Hash();
                this.partNumber = "";
                this.slideshowThumbs = "";
                this.startCount = 0;
                this.endCount = 0;
                this.selectedCount = 0;
                this.productList = [];
                this.containerStartTemplate = new Template('<div id=\"seolbContainer\" class=\"seolbContainer\"><div id=\"seolbleft\" class=\"seolbleftContent\">');
                this.nameDescTemplate = new Template('<div class=\"seolbprodName\">#{name}</div><div class=\"seolbprodDesc\">#{desc}</div>');
                this.oldPriceTemplate = new Template('<div class=\"seolbpriceField\">#{oldPrice}</div>');
                this.oldCrossedPriceTemplate = new Template('<div class=\"seolbOldPrice\">#{oldPrice}</div>');
                this.newPriceTemplate = new Template('<div class=\"seolbpriceField\">#{newPrice}</div>');
                this.slideshowThumbTemplate = new Template('<div id="thumb#{partNumber}" style=\"background-image:url(&quot;#{thumb}&quot;);width:40px;height:40px;\" onclick=\"com.ikea.irw.localStore.ProductInfo.LspLiteBoxData.changeProduct(\'#{partNumber}\')\" class=\"thumbContainer\"><a class=\"overlay\" title=\"#{name} #{desc} \">&nbsp;</a></div>');
                this.selectedSlideshowThumbTemplate = new Template('<div id="thumb#{partNumber}" style=\"background-image:url(&quot;#{thumb}&quot;);width:40px;height:40px;\" onclick=\"com.ikea.irw.localStore.ProductInfo.LspLiteBoxData.changeProduct(\'#{partNumber}\')\" class=\"thumbContainer thumbContainerActive\"><a class=\"overlay\" title=\"#{name} #{desc} \">&nbsp;</a></div>');
                this.emptySlideshowThumbTemplate = new Template('<div class=\"thumbContainer\"></div>');
                this.hiddenSlideshowThumbTemplate = new Template('<div class=\"thumbContainer\" style=\"display:none;\"></div>');
                this.btiIncludeBeforeDiv = '<div class=\"productBtiBack\"><div class=\"productBtiFront productSeoBtiWrapper\">';
                this.btiIncludeAfterDiv = '</div></div>';
                this.sizeTemplate = new Template('<div class=\"moreInfo\" id=\"moreInfo\"><div class=\"seolbDimensions\">#{size}</div><div class="clearAll"></div></div>');
                this.offerEndTemplate = new Template('<div class=\"offerDesc\"><div class=\"seoOfferText\">#{offerEndDate}</div></div>');
                this.pipImageTemplate = new Template('<img src="#{pipBigImg}" border=\"0\" id=\"seolbImg\" class=\"seolbImg\" />');
                this.slideShowLeftNavigationTemplateDiv = '<div><a onclick=\"com.ikea.irw.localStore.ProductInfo.LspLiteBoxData.navigate(\'left\');\" class=\"slideshowBtn\" id=\"slideshowLSPBtnPrev\">&nbsp;</a></div>';
                this.slideShowLeftInactiveNavigationTemplateDiv = '<div><a class=\"inactivePrevButton\" id=\"slideshowLSPBtnPrev\">&nbsp;</a></div>';
                this.slideShowRightNavigationTemplateDiv = '<div><a onclick=\"com.ikea.irw.localStore.ProductInfo.LspLiteBoxData.navigate(\'right\');\" class=\"slideshowBtn\" id=\"slideshowLSPBtnNext\">&nbsp;</a></div>';
                this.slideShowRightInactiveNavigationTemplateDiv = '<div><a onclick=\"com.ikea.irw.localStore.ProductInfo.LspLiteBoxData.navigate(\'right\');\" class=\"slideshowBtn inactiveNextButton\" id=\"slideshowLSPBtnNext\">&nbsp;</a></div>';
                this.clearTemplateDiv = '<div class=\"clear\"></div>';
                this.newTemplateDiv = '<div><img class=\"nlpImgSlideShow\"  border=\"0\" src="\/ms/' + irwstats_locale + '/img/icons/new_large.gif\" /></div>';
                this.nlpTemplateDiv = '<div><img class=\"nlpImgSlideShow\" src=\"/ms/img/nlp/' + irwstats_locale + '/nlp_04.png\" border=\"0\"/></div>';
                this.familyPriceTemplate = new Template('<div class=\"seolbFamilyPriceField\">' + $F('PPC_txt_ikeafamily') + '<br/><span class=\"seolbFamilyPrice\">#{familyPrice}</span></div>');
                this.articleNbrTemplate = new Template('<div class=\"seolbarticleNumber\">' + $F('ls_article_number_text') + ' #{articleNumber}</div>');
                this.coverTemplate = new Template('<div class=\"seolbprodDetail\">' + $F('ls_cover_txt') + ' #{cover}</div>');
                this.colourTemplate = new Template('<div class=\"seolbprodDetail\">' + $F('ls_colour_txt') + ' #{colour}</div>');
                this.designTemplate = new Template('<div class=\"seolbprodDetail\">' + $F('ls_design_txt') + ' #{design}</div>');
                this.patternTemplate = new Template('<div class=\"seolbprodDetail\">' + $F('ls_pattern_txt') + ' #{pattern}</div>');
                this.specLinkTemplate = new Template('<div id=\"specLink\"><a href=\"javascript:void(0)\" class=\"specLink\" onclick=\"com.ikea.irw.localStore.ProductInfo.LspLiteBoxData.changeDescText(\'product\');\">' + $F('ls_read_spec_text') + '</a></div>');
                this.featuresTemplate = new Template('<div class=\"descContent\" id=\"descContent\"><div class=\"left\"><div class=\"title\">&nbsp;&nbsp;' + $F('ls_key_features') + '</div><div class=\"content\">#{keyFeatures}</div></div><div class=\"right\"><div class=\"title\">' + $F('ls_good_to_know') + '</div><div class=\"content\">#{gtk}</div></div></div>');
                this.viewProductTemplateDiv = '<a href=\"javascript:void(0)\" class=\"specLink\" onclick=\"com.ikea.irw.localStore.ProductInfo.LspLiteBoxData.changeDescText(\'text\');\">' + $F('ls_view_product') + '</a>';
                this.readSpecificationTemplateDiv = '<a href=\"javascript:void(0)\" class=\"specLink\" onclick=\"com.ikea.irw.localStore.ProductInfo.LspLiteBoxData.changeDescText(\'product\');\">' + $F('ls_read_spec_text') + '</a>';
                this.loaderTemplate = new Template('<div id=\"seolbContainer\" class=\"seolbContainer\"><div class="seolbLoader">#{loadingText}<br/><br/><img src=\"/ms/img/loading.gif\" width=\"27\" height=\"27\"/></div></div>');
                
                
                for (count = 0; count < js_fn_SLIDE_SHOW_IDS.length; count++) {
                    productWithBlock = js_fn_SLIDE_SHOW_IDS[count].split("_");
                    if (productWithBlock[0] === productPartNumber) {
                        blockId = productWithBlock[1];
                    }
                }
            
                for (count = 0; count < js_fn_SLIDE_SHOW_IDS.length; count++) {
                    productWithBlock = js_fn_SLIDE_SHOW_IDS[count].split("_");
                    if (productWithBlock[1] === blockId) {
                        this.productList[this.productList.length] = productWithBlock[0];
                    }
                }
            
                this.length = this.productList.length;
                if (this.noOfThumbs > this.length) {
                    this.noOfThumbs = this.length;
                }
            
                this.endCount = this.noOfThumbs;
                return this.showProduct();
    		},
    		showProduct: function () {
    			
    			this.slideshowThumbs = "";
    			var partNo = productPartNumber;
    			var count;
    			//method to send data to web analytics
    			irwStatProductViewedFromSlideShow(partNo,'family');  
    			// for selecting the start and end position of slideshow elements in the slideshow container.
    			for (var pos = 0; pos < this.length; pos++) {
    				if (this.productList[pos] === partNo) {
    					this.startCount = pos - 1;
    					this.endCount = this.startCount + this.noOfThumbs;
    					this.selectedCount = pos;
    					break;
    				}
    			}
    			
    			for (count = this.startCount; count <= this.endCount; count++) {
    				var partNbr = this.productList[count];
    				if (partNbr !== undefined && this.thumbs.get(partNbr) === undefined) {
    					var prodUrl = productsURL + partNbr;
    					prodUrl = prodUrl + "?type=" + Iows.type + "&dataset=" + Iows.dataset;
    					var ajaxParams = {"url" : prodUrl, "contentType" : 'application/xml', "asyncFlag" : true, "singletonFlag" : false};
    					new Ajax.Request(ajaxParams.url, {
    						asynchronous: ajaxParams.asyncFlag, 
    						contentType: ajaxParams.contentType,
    						method: 'get',
    						onSuccess: function (response) {
    						    var docObj = com.ikea.irw.localStore.ProductInfo.displayLocalStoreProduct(response.responseXML);
    					        productDocs.set(docObj.presentation.partNo, docObj);
    						}
    					});
    				}
    			}
    			
    			// Wait for all ajax calls to be done before creating thumb templates and main template.
    			new PeriodicalExecuter (function(pe) {
    				if (Ajax.activeRequestCount <= 0) {
    					pe.stop();
                        for (count = this.startCount; count <= this.endCount; count++) {
                            this.partNumber = this.productList[count];
                            var thumbSlides = "";
                            if (this.partNumber === undefined && count < this.selectedCount) {
                                // empty thumbs for the first column when first product is selected.
                                thumbSlides = this.emptySlideshowThumbTemplate.evaluate();
                            } else if (this.partNumber === undefined && count > this.selectedCount) {
                                // hidden thumbs for the last columns
                                thumbSlides = this.hiddenSlideshowThumbTemplate.evaluate();
                            } else if (this.thumbs.get(this.partNumber) !== undefined) {
                                // load thumbs from thumbcache
                                var thumbObj = this.thumbs.get(this.partNumber);
                                if (this.partNumber === productPartNumber) {
                                    thumbSlides = this.selectedSlideshowThumbTemplate.evaluate(thumbObj);
                                } else {
                                    thumbSlides = this.slideshowThumbTemplate.evaluate(thumbObj);
                                }
                            } else {
                                // load product details from the productDocs hash
                                thumbSlides = this.getDomData(false, productDocs.get(this.partNumber));
                            }
                            this.slideshowThumbs += thumbSlides;
                            this.partNumber = "";
                            
                        }
                        // slide show elements creation part starts here
                        $('seolbContainer').update(this.getDomData(true, productDocs.get(productPartNumber)));
                        if ( $('seolbDetail').innerHTML === " " ) {
                            $('seolbDetail').remove();
                            $('specLink').style.marginTop = "5px"    
                        }    
                    }
                }.bind(this),.5);
    			
    		},
    		getDomData: function (show, tplObj) {
    			if (this.partNumber === undefined || this.partNumber === "") {
    				this.partNumber = productPartNumber;
    			}
    			
    			// Below ajax portion will fetch the product information with the given partnumber
    			
    			if (!show) {
    				// if the object is only for slideshow thumbnail display, then create only thumbslide.
    				return this.thumbSlideTemplates(tplObj);
    			}
    			// for creating the template of the product selected.
    			return this.contentTemplates(tplObj);
    		},
    		thumbSlideTemplates: function (tplObj) {
    			// this function will create the thumbslides from the thumbcache
    			var presentation = tplObj.presentation;
    			this.cacheThumb(presentation);
    			if (this.partNumber === productPartNumber) {
    				return this.selectedSlideshowThumbTemplate.evaluate(presentation);
    			} else {
    				return this.slideshowThumbTemplate.evaluate(presentation);
    			}
    			
    		},
    		contentTemplates: function (tplObj) {
    			var presentation = tplObj.presentation;
    						
    			var isNew = presentation.newItem;
    			
    			var pipBigImg = presentation.pipBigImg;
    			var isNlp = presentation.isNlp;
    			var isBti = presentation.isBti;
    			
    			// Left Side Contents Creation Starts Here
    			var leftSideContents = this.containerStartTemplate.evaluate();
    			if (isNew) {
    				// if the product is new, get 'this.newTemplateDiv'.
    				leftSideContents += this.newTemplateDiv;
    			}
    			if (presentation.showNlp) {
    				// if the product is nlp, get 'this.nlpTemplateDiv'.
    				leftSideContents += this.nlpTemplateDiv;
    			}
    			if (presentation.showBti) {
    				// if the product is bti, get 'btiIncludeBeforeDiv'.
    				leftSideContents += this.btiIncludeBeforeDiv; 
    			}
    			
    			// get 'this.nameDescTemplate' for displaying product name and description. 
    			leftSideContents += this.nameDescTemplate.evaluate(presentation);
    			
    			// Price template selection part.
    			if (presentation.oldPrice !== undefined && presentation.newPrice === undefined) {
    				leftSideContents += this.oldPriceTemplate.evaluate(presentation);
    			} else if (presentation.oldPrice !== undefined && presentation.newPrice !== undefined) {
    				// value must be crossed
    				leftSideContents += this.oldCrossedPriceTemplate.evaluate(presentation);
    			}
    			if (presentation.newPrice !== undefined) {
    				leftSideContents += this.newPriceTemplate.evaluate(presentation);
    			}
    			if (presentation.familyPrice !== undefined) {
    				leftSideContents += this.familyPriceTemplate.evaluate(presentation);
    			}
    			
    			if (presentation.showBti) {
    				leftSideContents += this.btiIncludeAfterDiv; 
    			}
    			
    			// get 'this.articleNbrTemplate' for displaying article number.
    			leftSideContents += this.articleNbrTemplate.evaluate(presentation);
    			
    			// cover, colour, design, pattern details
    			var externalDetails = tplObj.externalDetails;
    			leftSideContents += '<div class=\"seolbDetail\">';
    			if (externalDetails.cover !== undefined && externalDetails.cover !== null && 
    					externalDetails.cover !== "") {
    				leftSideContents += this.coverTemplate.evaluate(externalDetails);
    			}
    			if (externalDetails.colour !== undefined && externalDetails.colour !== null &&
    					externalDetails.colour !== "") {
    				leftSideContents += this.colourTemplate.evaluate(externalDetails);
    			}
    			if (externalDetails.design !== undefined && externalDetails.design !== null &&
    					externalDetails.design !== "") {
    				leftSideContents += this.designTemplate.evaluate(externalDetails);
    			}
    			if (externalDetails.pattern !== undefined && externalDetails.pattern !== null &&
    					externalDetails.pattern !== "") {
    				leftSideContents += this.patternTemplate.evaluate(externalDetails);
    			}
    			leftSideContents += '</div>';
    			
    			// get 'sizeTemplate' for displaying product size.
                if (presentation.size !== undefined && presentation.size !== null && presentation.size !== "") {
                    leftSideContents += this.sizeTemplate.evaluate(presentation);
                }
    			
    			// get 'this.specLinkTemplate' for displaying 'Read Specification' link.
    			leftSideContents += this.specLinkTemplate.evaluate();
    			
    			leftSideContents += '</div>';
    			
    			// Left Side Content Creation Ends Here
    			
    			// Right Side Content Creation Starts Here
    			var rightSideContents = "";
    			
    			rightSideContents += '<div class=\"seolbrightContent\">';
    			// get 'offerEndTemplate' for showing offer end details.
    			rightSideContents += this.offerEndTemplate.evaluate(presentation);
    			// get 'pipImageTemplate' for showing the product large/image.
    			rightSideContents += this.pipImageTemplate.evaluate(presentation);
    			// get 'this.featuresTemplate' for showing Key Features and Good to Know things.
    			rightSideContents += this.featuresTemplate.evaluate(presentation);
    			rightSideContents += '</div>';
    			// Right Side Content Creation Ends Here
    			
    			// Slideshow Creation Starts Here
    			var slideShowContents = "";
    			
    			slideShowContents += '<div id=\"contentSlideshowSeperatorLSP\"></div>';
    			
    			slideShowContents += '<div id=\"slideshowLSPNavigation\">';
    			if (this.selectedCount > 0) {
    				// get 'slideShowLeftNavigationTemplateDiv' for left navigation slideshow button
    				slideShowContents += this.slideShowLeftNavigationTemplateDiv;
    			} else {
    				// get 'slideShowLeftInactiveNavigationTemplateDiv' for left navigation slideshow button
    				slideShowContents += this.slideShowLeftInactiveNavigationTemplateDiv;
    			}
    			
    			// get slide show contents which is created in the showProduct()
    			slideShowContents += this.slideshowThumbs;
    			if (this.selectedCount < (this.length - 1)) {
    				// get 'slideShowRightNavigationTemplateDiv' for right navigation slideshow button
    				slideShowContents += this.slideShowRightNavigationTemplateDiv;
    			} else {
    				// get 'slideShowRightInactiveNavigationTemplateDiv' for right navigation slideshow button
    				slideShowContents += this.slideShowRightInactiveNavigationTemplateDiv;
    			}
    			
    			slideShowContents += '</div>';
    			
    			slideShowContents += this.clearTemplateDiv;
    			// Slideshow Creation Ends Here
    			
    			return leftSideContents + rightSideContents + slideShowContents;
    			
    		},		
    		navigate: function (direction) {
                if (direction === 'left') {
                    if (this.selectedCount > 0) {
                        this.changeProduct(this.productList[this.selectedCount - 1]);
                    }
                } else if (direction === 'right') {
                    if (this.selectedCount < this.length - 1) {
                        this.changeProduct(this.productList[this.selectedCount + 1]);
                    }
                }
    		},
            changeDescText : function (id) {
                if (id === 'product') {
                    // if Read Specification link is clicked in the litebox
                    $('specLink').innerHTML = this.viewProductTemplateDiv;
                    $('descContent').style.display = "block";
                    $('seolbImg').style.display = "none";
                } else {
                    // if View Product link is clicked.
                    $('specLink').innerHTML = this.readSpecificationTemplateDiv;
                    $('descContent').style.display = "none";
                    $('seolbImg').style.display = "block";
                }
            },
            changeProduct: function (partNo) {
                // When any product listed as thumbs in the slideshow portion is selected
                $('seolbContainer').update(this.loaderTemplate.evaluate({loadingText: 'Loading...'}));
                productPartNumber = partNo;
                var liteBoxContent = this.showProduct();
            },
            // Creates a thumb object and adds it to the thumbs cache object (a Hashmap)
    	    cacheThumb: function cacheThumb (obj) {
    	        var thumbObj = {"partNumber": obj.partNumber,
                        "thumb": obj.thumb,
                        "name": obj.name,
                        "desc": obj.desc};
                // Add obj to the thumbs cache object
                this.thumbs.set(obj.partNumber, thumbObj);
            }
    	};
    },
    
    displayLocalStoreProduct: function (doc) {
        try {
            var presentation = this.getBasicProductInfo(doc);
            var partNo = presentation.partNo;
            var htmlGtk = this.getGoodToKnowAsHtml(getGoodToKnow(doc));
            presentation.gtk = htmlGtk;
		
            var htmlKeyFeatures = this.getKeyFeaturesAsHtml(getKeyFeatures(doc));
            presentation.keyFeatures = htmlKeyFeatures;
		
            var externalDetails = this.getExternalDetails(doc);
            presentation = this.getOverridedLocalInfo(presentation);
		
            var showBti = false;
            var showNlp = false;
            var showFamily = false;
		
            if (presentation.isNlp && !presentation.isFamily) {
                showNlp = true;
            }

            if ((presentation.isBti && !presentation.isNlp) || (presentation.isBti && presentation.isFamily)) {
                showBti = true;
            }

            if (presentation.isFamily) {
                showFamily = true;
            }
		
            presentation.showBti = showBti;
            presentation.showNlp = showNlp;
            presentation.showFamily = showFamily;
		
            var docObj = {"presentation": presentation,
            	    "externalDetails": externalDetails};
            return docObj;
		
        } catch (err) {
                //An error occured when reading the product
        }
    },

    getBasicProductInfo: function(doc) {
	    var product = doc.getElementsByTagName("product")[0];
	    var item = doc.getElementsByTagName("item")[0];
	    var descriptiveAttributes = getDescriptiveAttributes(item);
	    var warningDescAttr = getDescAttributeByType(descAttrWarning, descriptiveAttributes);
	    var troStartDate = formatTRODate(doc.getElementsByTagName("priceNormal")[0].getAttribute("startDate"));
	    var troEndDate = formatTRODate(doc.getElementsByTagName("priceNormal")[0].getAttribute("endDate"));
	
	    var partNo = IowsCommon.getNodeVal(item, 'partNumber');
	
	    var images = item.getElementsByTagName("images")[0];
	
	    var size;
	    
	
	    var prices = item.getElementsByTagName("prices")[0];
	    var normalPriceObject = getPricePart("normal", prices);
	    var normalPrice = normalPriceObject.price;
	    var familyPriceObject =	getPricePart("family-normal", prices);
	    var familyPrice = familyPriceObject.price;
	
	    var isBtiItem = getElementValue("bti", item);
	    var isBti = false;
	    if (isBtiItem === "true") {
	        isBti = true;
	    }
	
	    var isNewItem = getElementValue("new", item);
	    var isNew = false;
	    if (isNewItem === "true") {
	        isNew = true;
	    }
	
	    
	    if (getElementValue("measure", item) !== null) {
	        size = getSize(item);
	    } else {
	        size = "";
	    }
	    return {
	        "partNo": partNo,
	        "pipLink": getElementValue("URL", item),
	        "pipBigImg": getElementPathValue("large/image", item),
	        "thumb": getElementPathValue("small/image", item),
	        "name": getElementValue("name", item),
	        "desc": getElementValue("facts", item),
	        "troStartDate": troStartDate,
	        "troEndDate": troEndDate,
	        "unit": doc.getElementsByTagName("priceNormal")[0].getAttribute("perUnit"),
	        "newItem": isNew,
	        "size": size,
	        "partNumber": getElementValue("partNumber", item),
	        
	        "isNLP": doc.getElementsByTagName("priceNormal")[0].getAttribute("nlp"),
	        "isBti": isBti
	    };
	},
	
	getGoodToKnowAsHtml: function (gtk) {
        var htmlGtk = "";
        for (var count = 0; count < gtk.length; count++) {
            htmlGtk += "<p>" + gtk[count] + "</p>";
        }
        return htmlGtk;
    },
    
    getKeyFeaturesAsHtml: function (keyFeatures) {
	    var htmlFeatures = "";
	    for (var count = 0; count < keyFeatures.length; count++) {
	        htmlFeatures += "<p>" + keyFeatures[count] + "</p>";
	    }
	    return htmlFeatures;
    },
	
	getExternalDetails: function (doc) {
	    var attributeItems = doc.getElementsByTagName("attributeItem");
	    var cover;
	    var colour;
	    var design;
	    var pattern;
	    if (attributeItems !== undefined && attributeItems !== null) {
	        for (var count = 0; count < attributeItems.length; count++) {
	            var attrElem = attributeItems[count];
	            var attrNode = getElementValue("value", attrElem);
	            var attrValue = attrElem.getAttribute("name");
	            if (attrValue === "cover") {
	                cover = attrNode;
	            } else if (attrValue === "colour") {
	                colour = attrNode;
	            } else if (attrValue === "design") {
	                design = attrNode;
	            } else if (attrValue === "pattern") {
	                pattern = attrNode;
	            }
	        }
	    }
	    return {
	        "cover": cover,
	        "colour": colour,
	        "design": design,
	        "pattern": pattern
	    }
    },
	
	getOverridedLocalInfo: function (presentation) {
	    for (var jProductPrice in jProductPrices) {
	        if (jProductPrice === presentation.partNumber) {
	            var jProduct = jProductPrices[jProductPrice];
	            var newPrice = jProduct.changedprice;
	            var oldPrice = jProduct.normalprice;
	            var familyPrice = jProduct.familyprice;
	            
	            var offerEndDate;
	            var articleNumber;
	            var isFamily = false;
	            var offerEnds;
			
	            
	            offerEnds = jProduct.offerends;
	            articleNumber = jProduct.articleNumber;
	            offerEndDate = $F('ls_price_valid_text') + ' ' + storeName + '. ';
	            if (offerEnds !== undefined && offerEnds !== null) {
	                offerEndDate += $F('ls_until_text') + ' ' + offerEnds;
	            }
			
	            presentation.newPrice = newPrice;
	            presentation.oldPrice = oldPrice;
	            presentation.familyPrice = familyPrice;
	            presentation.articleNumber = articleNumber;
	            presentation.offerEndDate = offerEndDate;
			
	            if (familyPrice !== null) {
	                isFamily = true;
			    }
	            presentation.isFamily = isFamily;
			
	            return presentation;
		    }
	    }
    }
}

/*
* Binding click events
*/
var LspLiteBox = Class.create({
    initialize: function () {
        this.startTemplate = new Template('<div id=\"seolbContainer\" class=\"seolbContainer\">&nbsp;</div>');
        this.loaderTemplate = new Template('<div id=\"seolbContainer\" class=\"seolbContainer\"><div class="seolbLoader">#{loadingText}<br/><br/><img src=\"/ms/img/loading.gif\" width=\"27\" height=\"27\"/></div></div>');
        this.bindMouseDown();
    },
    bindMouseDown: function () {
        $$(".productsContainer .productContainer").each(function (obj) {
            var ele = obj;
            Event.observe(obj, 'click', function (e) { 
	            var lb = new Litebox({id: 'litebox', content: this.startTemplate.evaluate()});
	            $('seolbContainer').update(this.loaderTemplate.evaluate({loadingText: 'Loading...'}));
	            productPartNumber = ele.down('.cartContainer').id.replace("cartContainer","");
	            var liteBoxContent = com.ikea.irw.localStore.ProductInfo.LspLiteBoxData.initialize();
            }.bind(this));
        }.bind(this));
    }
});

document.observe('dom:loaded', function () {
	var lspDropdown = new LocalStoreDropdown('selectJS');
    var litebox = new LspLiteBox(); 
});



