/**
 * product_style_small_sort.js
 * minification version
 *
 * version:0.2
 * $Date:2010-3-16
 */

var XlistContorller={options:{sortArray:["recom","lowPrice","highPrice","popular","new"],contentsID:"X_LIST_MODE_STYLE_SMALL",contentsCols:4,controllerID:"X_CONTROLLER_TOP",defaultSort:"recom",currentSort:"",currentURL:"",X_Obj:{},replTagNamesItem:{X_PDLINK:["href","detailURL"],X_PDLINKIMG:["href","detailURL"],X_PRICE:["innerHTML","price"],X_OLDPRICE:["innerHTML","oldPrice"],X_COLORVARIATION:["innerText","colors"],X_PDNAME:["innerText","itemName"],X_PRMARK:["src","topIcon"],X_SPMARK1:["src","bottomIcon1"],X_SPMARK2:["src","bottomIcon2"],X_SPMARK3:["src","bottomIcon3"],X_PDSTYLEIMAGE:["src","styleImageMiddleURL"]}},getOption:function(a){return this.options[a]},setOption:function(a,b){this.options[a]=b},replaceOption:function(a,e,d){var c=this.getOption(a);for(var b in c){c[b][0]=c[b][0].replace(e,d)}this.setOption(a,c)},setup:function(){this.XtrimDivHeight=new jp.co.mutow.trimHeight();if(Xua.mozilla){this.replaceOption("replTagNamesItem","innerText","textContent")}this.setOption("X_Obj",this.getXObjects([this.getOption("contentsID"),this.getOption("controllerID")],"X_","name"));this.setOption("currentURL",location.href.split("?")[0]);var a=this.getDefaultSort();var b=this.getRequestParameter("sort");if(b){a=b}this.setOption("defaultSort",a);this.update(a)},onControllerClick:function(a){var c=this.getOption("currentURL"),b=c+"?sort="+a;urchinTracker(b);this.AjaxRequest(b);this.update(a)},update:function(b){var a=this.getOption("currentSort");if(b==a){return false}this.setOption("currentSort",b);this.setController(b);this.setContents(b)},setController:function(a){var d=this.getOption("currentURL"),c=this.getOption("controllerID"),b=this.getOption("X_Obj")[c];this.setSortController(a,d,b)},setSortController:function(a,c,k){var j=this,e=this.getOption("sortArray");for(var b=0,f=e.length;b<f;b++){var d=null;var g=k["X_ORDER_"+e[b].toUpperCase()];if(e[b]!=a){d="./p1.html?sort="+e[b];this.hrefReplace(g,d);this.wrapStrong(g,false);this.currentReplace(g,false);g.sort=e[b];g.onclick=function(){j.onControllerClick(this.sort);return false}}else{this.hrefReplace(g,d);this.wrapStrong(g,true);this.currentReplace(g,true);g.onclick=null}}},setContents:function(b){var e=this.getOption("contentsID"),a=this.getOption("contentsCols"),c=this.getOption("X_Obj")[e],d=this.getSortData(b);this.setContentsHTML(d,b,e,c);this.XtrimDivHeight(e,a)},getSortData:function(sort){var data=eval(sort+"Data");return data},setContentsHTML:function(j,k,h,b){var q=this.getOption("replTagNamesItem");for(var e in b){var n=b[e],p=e.split("_"),a=p[0]+"_"+p[1],l=parseInt(p[2])-1;if(a=="X_NEWMARK"){var m=new Date();var f=new Date(j[l]["startDate"]);if(m.getTime()<f.getTime()+(14*86400000)){n.style.display="block"}else{n.style.display="none"}continue}var i=q[a][0];var o=q[a][1];var c=j[l][o];if(c==""){c=null}if(a=="X_PRICE"||a=="X_OLDPRICE"){var g=j[l]["flgOutletPrice"];if(!g){if(a=="X_PRICE"){c=j[l]["normalPrice"]}if(a=="X_OLDPRICE"){c=null}}else{if(a=="X_PRICE"){c=j[l]["outletPrice"]}if(a=="X_OLDPRICE"){c=j[l]["outletOldPrice"]}}}this[i+"Replace"](n,c);if(a=="X_PDSTYLEIMAGE"){this.altReplace(n,j[l]["itemName"])}}},getXObjects:function(b,a,h){var d={},j=a,c=h;var f=function(i){var m,k={};(!i)?m=document.body:m=document.getElementById(i);var l=function(q){if(q.nodeType!==1){return}var o=q.getAttribute(c);if(o&&o.indexOf(j)!==-1){k[o]=q}var n=q.childNodes.length;for(var p=0;p<n;p++){l(q.childNodes[p])}return k};d[i]=l(m)};for(var e=0,g=b.length;e<g;e++){f(b[e])}return d},altReplace:function(b,a){if(a==undefined){b.removeAttribute("alt")}else{b.setAttribute("alt",a)}},hrefReplace:function(b,a){if(a==null){b.removeAttribute("href")}else{b.setAttribute("href",a)}},onclickReplace:function(b,a){if(a==null){b.removeAttribute("onclick")}else{(Xua.msie)?b.setAttribute("onclick",new Function(a+"return false;")):b.setAttribute("onclick",a+"return false;")}},srcReplace:function(b,a){if(a==null){b.removeAttribute("src");b.style.display="none"}else{b.setAttribute("src",a);b.style.display="block"}},innerHTMLReplace:function(b,a){if(a==null){b.innerHTML="";b.style.display="none"}else{b.innerHTML=a;b.style.display="block"}},innerTextReplace:function(b,a){if(a==null){b.innerText="";b.style.display="none"}else{b.innerText=a;b.style.display="block"}},textContentReplace:function(b,a){if(a==null){b.textContent="";b.style.display="none"}else{b.textContent=a;b.style.display="block"}},wrapStrong:function(c,a){var b=c.innerHTML.replace(/<strong>/i,"").replace(/<\/strong>/i,"");if(a){b="<strong>"+b+"</strong>"}c.innerHTML=b},currentReplace:function(c,b){var a=(Xua.msie&&Xua.version<8)?"className":"class";c.setAttribute(a,(b)?"current":"")},getDefaultSort:function(){var e=this.getOption("defaultSort");var c=this.getOption("sortArray");var b=c.length;for(var d=0;d<b;d++){var a="X_SORT_"+c[d].toUpperCase();if(document.getElementById(a)){e=c[d];break}}return e},getRequestParameter:function(d){var c=document.location.search||document.location.hash;if(d==null){return c}if(c){var b=c.substring(1).split("&");for(var a=0;a<b.length;a++){if(b[a].substring(0,b[a].indexOf("="))==d){return b[a].substring((b[a].indexOf("=")+1))}}}return""},AjaxRequest:function(a){var c=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");c.open("GET",a,true);c.send(null);var b=c.responseXML},onChangePage:function(b){var a=(b.getAttribute("href"));location.href=a+"?sort="+this.getOption("currentSort")}};var changePage=function(a){XlistContorller.onChangePage(a);return false};addEvent(window,"domReady",function(){XlistContorller.setup()});