new function() {
	
	var sortHref;
	if(location.search) {
		if(location.href.match(/sort/)){
			if(location.search.substr(2,6).match(/sort/)){
				sortHref = location.href.replace(/sort=[0-9]/,"sort=");
			}else{
				sortHref = location.href.replace(/&-sort=[0-9]/,"&-sort=");
			}
		}else{
			sortHref = location.href+"&-sort=";
		}
	}else{
		sortHref = location.href+"?-sort=";
	}
		
	function addEvent(elm,listener,fn) {
		try {
			elm.addEventListener(listener,fn,false);
		} catch(e) {
			elm.attachEvent("on"+listener,fn);
		}
	}	/* addEvent */
	
	/* styleswitcher.js by A List Apart (http://www.alistapart.com/) ここから */
	function setActiveStyleSheet(title) {
		var i, a, main;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(!a.rev && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title) a.disabled = false;
			}
		}
	}
	function getActiveStyleSheet() {
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
		}
		return null;
	}
	function getPreferredStyleSheet() {
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1
				&& a.getAttribute("rel").indexOf("alt") == -1
				&& a.getAttribute("title")
			) return a.getAttribute("title");
		}
		return null;
	}
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
	
	function setCookie_init() {
		var cookie = readCookie("style");
		var title = cookie ? cookie : getPreferredStyleSheet();
		setActiveStyleSheet(title);
	}
	function getCookie_init() {
		var title = getActiveStyleSheet();
		createCookie("style", title, 365);
	}
	/* styleswitcher.js ここまで */
	
	addEvent(window, "load", setCookie_init);
	addEvent(window, "unload", getCookie_init);
	
	function insertAfter(newElement,targetElement) {	/* 追加するエレメント,兄要素 */
		var parent = targetElement.parentNode;
		if(parent.lastChild==targetElement) {
			parent.appendChild(newElement);
		} else {
			parent.insertBefore(newElement,targetElement.nextSibling);
		}
	}	/* 任意のエレメントの後ろに新しいエレメントを追加 */
	
	function displayExtension() {
		if(!document.getElementById) return false;
		if(!document.getElementById("itemList")) return false;
		var contents = document.getElementById("contents");
		var h1 = contents.getElementsByTagName("h1")[0];
		
		var displaySwitch = document.createElement("div");
		displaySwitch.id = "displayswitch";
		insertAfter(displaySwitch, h1);
		
		/* 表示順の拡張ここから */
		var selector = document.createElement("ul");
		var selectorElm = document.createElement("li");
		var selectorTxt = document.createTextNode("表示順");
		var spanLeft = document.createElement("span");
		spanLeft.className = "spanLeft";
		var spanRight = document.createElement("span");
		spanLeft.appendChild(selectorTxt);
		spanRight.className = "collapse";
		spanRight.style.cursor = "pointer";
		var spanTitleCollapse = "クリックで表示順の切り替えメニューを開きます" 
		var spanTitleExpanded = "クッリクで表示順の切り替えメニューを閉じます";
		spanRight.title = spanTitleCollapse;
		selectorElm.appendChild(spanLeft);
		selectorElm.appendChild(spanRight);
		selector.appendChild(selectorElm);
		var selectorUl = document.createElement("ul");
		selectorUl.style.display = "none";
		var optValue = [2,3];
		var optNode = ["値段の安い順","値段の高い順"];
		for(var a=0; a<optValue.length; a++) {
			var li = document.createElement("li");
			var anc = document.createElement("a");
			anc.href = sortHref + optValue[a];
			var txt = document.createTextNode(optNode[a]);
			anc.appendChild(txt);
			li.appendChild(anc);
			selectorUl.appendChild(li);
		}
		selectorElm.appendChild(selectorUl);
		displaySwitch.appendChild(selector);
		spanRight.onclick = function() {
			selectorUl.style.display = (selectorUl.style.display!="none") ? "none" : "";
			this.title = (this.title!=spanTitleCollapse) ? spanTitleCollapse : spanTitleExpanded;
			this.className = (this.className!="expanded") ? "expanded" : "collapse";
		}
		spanRight.onmouseover = function() {
			this.className = (this.className!="expanded") ? "hover" : "expanded";
		}
		spanRight.onmouseout = function() {
			this.className = (this.className!="expanded") ? "collapse" : "expanded";
		}
		
		/* 表示切り替えスイッチここから */
		var btnhref = "javascript:void(0)";
		var btnid = ["dis_a", "dis_b"];
		var btntitle = ["画像のみを表示する", "説明付きの画像を表示する"];
		var btnsrc = ["../../img/shop/list_img.gif", "../../img/shop/list_txt.gif"];
		var btnalt = ["画像のみ", "画像と説明"];
		for(var b=0; b<2; b++) {
			var btnanchor = document.createElement("a");
			btnanchor.href = btnhref;
			btnanchor.id = btnid[b];
			btnanchor.title = btntitle[b];
			var btnimg = document.createElement("img");
			btnimg.src = btnsrc[b];
			btnimg.alt = btnalt[b];
			btnanchor.appendChild(btnimg);
			displaySwitch.appendChild(btnanchor);
		}
		var dis_a = document.getElementById("dis_a");
		dis_a.onclick = function() {
			setActiveStyleSheet("img");
			return false;
		}
		var dis_b = document.getElementById("dis_b");
		dis_b.onclick = function() {
			setActiveStyleSheet("txt");
			return false;
		}	
	}
	addEvent(window,"load",displayExtension);
}