/***
 * A "manager" module that handles interaction with the accoridon widget on "Template Q"-style pages.
 * 
 * @author Adam J. McIntyre
 */

AccordionManager=function(){var PRODUCT_ROW_CHARS=90;var pageLink='/';var currentEl=null;return{setUrlPrefix:function(p){pageLink=p;},formatter:function(eName,args){var targetNode=YAHOO.util.Dom.getFirstChild(args[0]);var response=args[1].responseXML;var that=arguments[2];var pList=document.createElement('ol');pList.className='products';var template='<li id="row_product_{productId}" class="row {evenOdd}"><div class="container_new {isNew}">&nbsp;</div>'+'<div class="container_l"><a href="{productUrl}" class="none"><img class="list_product" width="47" height="40" src="{productImage}"/></a></div>'+'<h4><a href="{productUrl}" class="none">{productName}</a></h4><h5><a href="{productUrl}" class="none">{productDesc}</a></h5>'+'<div class="container_r"><a id="link_{productId}" href="javascript:void(0);" onclick="AccordionManager.showQuickView(event,\'{productId}\')">'+nikonLabel.quickView+'</a>'+'<div id="quickView_data_{productId}" class="noD">'+'<div class="hd"><a class="closeIcon" href="javascript:AccordionManager.hideQuickView()">&nbsp;</a>'+'<h3 class="nkYellow">{productName}</h3></div>'+'<div class="bd"><div class="shim"> </div>'+'<a href="{productUrl}" id="data_url_{productId}" class="none">'+'<img width="160" height="136" src="{productImage}" alt="{productName}" id="item_{productId}_img" class="pop"/></a>'+'<div class="col"><div id="data_bullets_{productId}">{productBullets}</div>'+'<strong id="data_price_{productId}" class="shift">{productPrice}</strong></div><div class="clear"> </div></div>'+'<a href="{productUrl}" class="more">'+nikonLabel.findOutMore+'</a><div class="ft">&nbsp;</div></div>'+'</div></li>';var products=response.getElementsByTagName('Product');var tmpHtml='';for(var i=0;i<products.length;i++){var p=products[i];var evenOdd,isNew,productId,productImage,productName,productDesc;if(i%2==0)
evenOdd='even';else
evenOdd='odd';if(i==products.length-1)
evenOdd+=' last';if('text'in p.getElementsByTagName('Image')[0]){if(p.getAttribute('New')=='true'){isNew='is_new';}
else{isNew='';}
productId=p.getAttribute('ProductId');var imgText=p.getElementsByTagName('Image')[0].text;productImage=imgText.substr(0,imgText.lastIndexOf(productId))+'160_'+imgText.substr(imgText.lastIndexOf(productId));productName=p.getElementsByTagName('Title')[0].text;productDesc=that._formatDescriptionText(productName,p.getElementsByTagName('Overview')[0].text);productBullets=p.getElementsByTagName('Bullets')[0].text;productPrice=that._formatPriceText(p.getElementsByTagName('Price')[0].text,p.getElementsByTagName('ReducedPrice'),p.getAttribute('Reduced'),true);productUrl=that._formatUrl(p.getElementsByTagName('URL')[0].text,p.getElementsByTagName('QueryString'),p.getElementsByTagName('isProduction'),true);}
else{if(p.getAttribute('New')=='true'){isNew='is_new';}
else{isNew='';}
productId=p.getAttribute('ProductId');var imgText=p.getElementsByTagName('Image')[0].textContent;productImage=imgText.substr(0,imgText.lastIndexOf(productId))+'160_'+imgText.substr(imgText.lastIndexOf(productId));productName=p.getElementsByTagName('Title')[0].textContent;productDesc=that._formatDescriptionText(productName,p.getElementsByTagName('Overview')[0].textContent);productBullets=p.getElementsByTagName('Bullets')[0].textContent;productPrice=that._formatPriceText(p.getElementsByTagName('Price')[0].textContent,p.getElementsByTagName('ReducedPrice'),p.getAttribute('Reduced'),false);productUrl=that._formatUrl(p.getElementsByTagName('URL')[0].textContent,p.getElementsByTagName('QueryString'),p.getElementsByTagName('isProduction'),false);}
tmpHtml+=template.replace('{evenOdd}',evenOdd).replace(/{productId}/g,productId).replace('{isNew}',isNew).replace(/{productImage}/g,productImage).replace(/{productName}/g,productName).replace('{productDesc}',productDesc).replace('{productBullets}',productBullets).replace(/{productPrice}/g,productPrice).replace(/{productUrl}/g,productUrl);}
pList.innerHTML=tmpHtml;targetNode.appendChild(pList);},_formatDescriptionText:function(name,desc){var remainingChars=PRODUCT_ROW_CHARS-name.length;var strippedHtml=desc.replace(/<(.|\n)*?>/ig,'');if(strippedHtml.length>=remainingChars){return strippedHtml.substr(0,remainingChars-3)+'...';}
else{return strippedHtml;}},showQuickView:function(e,id){if(!e)e=window.event;YAHOO.util.Event.preventDefault(e);YAHOO.util.Event.stopPropagation(e);var y=YAHOO.util.Event.getPageY(e);var qv=document.getElementById('quickView');this.hideQuickView();qv.innerHTML=document.getElementById('quickView_data_'+id).innerHTML;var el=YAHOO.util.Selector.query('div.hd h3','quickView',true);if(el.innerHTML.length>25){el.innerHTML=el.innerHTML.substr(0,25)+'&hellip;'}
var linkEl=document.getElementById('link_'+id)
var x=YAHOO.util.Dom.getX(linkEl);var yPos=y;if(yPos+qv.offsetHeight>YAHOO.util.Dom.getClientRegion().bottom){yPos=yPos-qv.offsetHeight+linkEl.offsetHeight}
YAHOO.util.Dom.setY(qv,yPos);YAHOO.util.Dom.setX(qv,x-qv.offsetWidth);},hideQuickView:function(){YAHOO.util.Dom.setStyle('quickView','left','-4000px');},_formatPriceText:function(price,reducedPrice,isReduced,isIE){if(reducedPrice.length>0){if(isIE)var rp=reducedPrice[0].text;else var rp=reducedPrice[0].textContent;if(isReduced){if(rp.length>0){return'Now: $'+rp;}
else{return"";}}
else{if(rp.length>0){return'Price: $'+rp;}
else{return"";}}}
else{if(price.length>0){return'Price: $'+price;}
else{return"";}}},_formatUrl:function(u,q,isProduction,isIE){var qs="";if(u.indexOf('/')==0)u=u.substr(1);if(q.length>0){if(isIE){qs=q[0].text;}
else{qs=q[0].textContent;}}
if(isProduction.length>0){if(isIE){if(isProduction[0].text){return pageLink+u;}
else{return pageLink+u+'?'+qs;}}
else{if(isProduction[0].textContent){return pageLink+u;}
else{return pageLink+u+'?'+qs;}}}
else{return pageLink+u;}},handleBeforeDataLoad:function(type,args){var hd=args[1];if(YAHOO.util.Dom.hasClass(hd.parentNode,'remote')&&!YAHOO.util.Dom.hasClass(hd.parentNode,'loaded')){var loadingDiv=YAHOO.util.Dom.getElementsByClassName('loading','div',hd)[0];var productName=hd.parentNode.getElementsByTagName('h2')[0].innerHTML;YAHOO.util.Dom.addClass(hd,'opening');loadingDiv.innerHTML='<label>'+nikonLabel.loading+' '+productName+' '+nikonLabel.products+'</label> <img src="/static/images/icons/icon_loadingBar_trans.gif" width="170" height="19" alt="'+nikonLabel.loading+'..."/>';}},handleAfterDataLoad:function(type,args){var hd=args[1];if(YAHOO.util.Dom.hasClass(hd.parentNode,'remote')&&YAHOO.util.Dom.getElementsByClassName('loading','div',hd).length>0){var loadingDiv=YAHOO.util.Dom.getElementsByClassName('loading','div',hd)[0];setTimeout(function(){var anim=new YAHOO.util.Anim(loadingDiv,{height:{to:0},opacity:{to:0}},0.15);anim.onStart.subscribe(function(){var ht=YAHOO.util.Dom.getStyle(hd,'height').substr(0,YAHOO.util.Dom.getStyle(hd,'height').indexOf('px'))
new YAHOO.util.Anim(hd,{height:{to:(ht-loadingDiv.offsetHeight)}},0.15).animate();});anim.onComplete.subscribe(function(){YAHOO.util.Dom.removeClass(hd,'opening');loadingDiv.parentNode.removeChild(loadingDiv);var pEl=hd.parentNode;if(YAHOO.util.Dom.hasClass(pEl,'last')){YAHOO.util.Dom.addClass(pEl,'last_open');currentEl=pEl;}
else{currentEl=null;}});anim.animate();},250);}
else{var pEl=hd.parentNode;if(YAHOO.util.Dom.hasClass(pEl,'last')){YAHOO.util.Dom.addClass(pEl,'last_open');currentEl=pEl;}
else{currentEl=null;}}},handleShowAll:function(type,args){document.getElementById('viewAll').onclick=function(){acc.hideAll();};document.getElementById('viewAll_text').innerHTML=nikonLabel.hideAll;document.getElementById('viewAll_toggle').src="/static/images/icons/sro/icon_accClose_lt.gif";},handleHideAll:function(type,args){document.getElementById('viewAll').onclick=function(){acc.showAll();}
document.getElementById('viewAll_text').innerHTML=nikonLabel.viewAll;document.getElementById('viewAll_toggle').src="/static/images/icons/sro/icon_accOpen.gif";},handleElClick:function(e){YAHOO.util.Event.stopPropagation(e);var linkEl=YAHOO.util.Selector.query('div.container_r div a.more',this,true);if(linkEl){window.location.href=linkEl.getAttribute('href');}
else{linkEl=YAHOO.util.Selector.query('a.catLink',this,true);if(linkEl)
window.location.href=linkEl.getAttribute('href');}}}}();