$(function(){
		$("select.searchSelect").sb();
		$('._subNav,._subNavB').hover(
			function(){
				hov = $(this).attr("name");
				if(hov =='collection'){
					$('#collectionMenuBlock').fadeIn('fast');
				}
				else{
					$('#collectionMenuBlock').hide();
					$(this).children('.subNav').fadeIn('fast');
				}
		});
		$('._subNav,#collectionMenuBlock').hover(
			function(){
			},
			function(){
				$('.subNav,#collectionMenuBlock').hide();
			}
		);
		
		$('._subNavC').hover(
			function(){
				$('.subNav,#collectionMenuBlock').hide();
			}
		);



		
		$('._hover').hover(
			function(){
				$(this).fadeTo(10, 0.7);
			},
			function(){
				$(this).fadeTo(500, 1.0);
			}
		);
		
		if ( $('#mainLeftArea').height() > $('#mainRightArea').height() ){
			var hh = $('#mainLeftArea').height() + 20 + 'px';
			 $('#mainRightArea').css({"height":hh});
		}
		chkSelect();
		chkSelectHead();
});


function chkSelect(){
	var itemSelect = $('#selectItemType').val();
	var genderSelect = $('#selectItemGender').val();
	if(itemSelect != 'none' && genderSelect != 'none'){
		$('#submitSearch').fadeIn();
		$('#submitSearchOff').hide();
 }
	else {
		$('#submitSearch').hide();
		$('#submitSearchOff').fadeIn();
	}
}

function chkSelectHead(){
	var itemSelect = $('#selectItemTypeHead').val();
	var genderSelect = $('#selectItemGenderHead').val();
	if(itemSelect != 'none' && genderSelect != 'none'){
		$('#submitSearchHead').fadeIn();
		$('#submitSearchOffHead').hide();
 }
	else {
		$('#submitSearchHead').hide();
		$('#submitSearchOffHead').fadeIn();
	}
}

function popupBorneoV(){
 	window.open(
			'/japanese/collection/charity/_mov/index.php',
			'charityvideo',
			'width=715, height=400, menubar=no, toolbar=no, scrollbars=no'
		);
}

function wrhiteGTopMvSWF(param){
 var rnd = '?r=' + Math.random();
	var movSwfSrc  = '';
	    movSwfSrc += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="600" height="700" id="mv_01" align="middle">';
	    movSwfSrc += '<param name="allowScriptAccess" value="sameDomain" />';
	    movSwfSrc += '<param name="allowFullScreen" value="false" />';
	    movSwfSrc += '<param name="movie" value="/_common_new/swf/mv_01.swf' + rnd + '" />';
	    movSwfSrc += '<param name="quality" value="high" />';
	    movSwfSrc += '<param name="scale" value="noscale" />';
	    movSwfSrc += '<param name="salign" value="lt" />';
	    movSwfSrc += '<param name="wmode" value="transparent" />';
	    movSwfSrc += '<param name="bgcolor" value="#ffffff" />';
	    movSwfSrc += '<param name="FlashVars" value="' + param + '" />';
	    movSwfSrc += '<embed src="/_common_new/swf/mv_01.swf' + rnd + '" FlashVars="' + param +'" quality="high" scale="noscale" salign="lt" wmode="transparent" bgcolor="#ffffff" width="600" height="700" name="mv_01" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer_jp" />';
	    movSwfSrc += '</object>';
	$('#gTopMvModule').html(movSwfSrc);
 	
}

function showSP1(){
 	window.open(
			'/japanese/collection/battue_surpass/sp.php',
			'special01',
			'width=950, height=610, menubar=no, toolbar=no, scrollbars=no'
		);
}

function showSP2(){
//   window.location.href = '/japanese/news/donate_one_dollar1.php';
 	window.open(
			'/japanese/collection/charity_goods/sp/',
			'special03',
			'width=760, height=600, menubar=no, toolbar=no, scrollbars=yes'
		);
}

function showSP4(lang){
	if(lang == 'english'){
		swf = 'sp_en.php';
	}
	else if(lang == 'chinese'){
		swf = 'sp_ch.php';
	}
	else if(lang == 'korean'){
		swf = 'sp_kr.php';
	}
  else {
		swf = 'sp.php';
	}
	window.open(
	'/' + lang + '/collection/battue_surpass/'+swf,
	'special01',
	'width=950, height=610, menubar=no, toolbar=no, scrollbars=no'
	);
}

function launch(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=yes');
}

function launch2008(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=yes');
}

function launchJOB(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=yes');
}

function launch20080201(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=yes');
}


function launch2(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=yes');
}

function launch2_20080201(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=yes');
}

function launchPrintAll(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=yes');
}

function launch3(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=yes');
}

function launch4(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=no');
}

function launchPost(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=yes');
	window.document.searchdata.target = i;
	window.document.searchdata.submit();
}

function launchPrint(URL,i,w,h) {
	window.open(URL, i, 'width='+ w + ', height=' + h + ', menubar=no, toolbar=no, scrollbars=yes');
	window.document.searchdata.target = i;
	window.document.searchdata.submit();
}

//collectionTitleArea
function collectionTitle (src){
	var	swfSrc		= '<object ';
					swfSrc	+= 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
					swfSrc	+= 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
					swfSrc	+= 'width="762" ';
					swfSrc	+= 'height="29" ';
					swfSrc	+= 'id="collection_body_title_001" ';
					swfSrc	+= 'align="middle">';
					swfSrc	+= '<param name="allowScriptAccess" value="sameDomain" />';
					swfSrc	+= '<param name="movie" value="' + src + '" />';
					swfSrc	+= '<param name="quality" value="high" />';
					swfSrc	+= '<param name="salign" value="lt" />';
					swfSrc	+= '<param name="wmode" value="transparent" />';
					swfSrc	+= '<param name="bgcolor" value="#ffffff" />';
					swfSrc	+= '<embed src="' + src + '" ';
					swfSrc	+= 'quality="high" ';
					swfSrc	+= 'salign="lt" ';
					swfSrc	+= 'wmode="transparent" ';
					swfSrc	+= 'bgcolor="#ffffff" ';
					swfSrc	+= 'width="762" ';
					swfSrc	+= 'height="29" ';
					swfSrc	+= 'name="collection_body_title_001" ';
					swfSrc	+= 'align="middle" ';
					swfSrc	+= 'allowScriptAccess="sameDomain" ';
					swfSrc	+= 'type="application/x-shockwave-flash" ';
					swfSrc	+= 'pluginspage="http://www.macromedia.com/go/getflashplayer" />';
					swfSrc	+= '</object>';

	document.write(swfSrc);
	
}


(function(){ var easing = 0.25; var interval = 20; var d = document; var targetX = 0; var targetY = 0; var targetHash = ''; var scrolling = false; var splitHref = location.href.split('#'); var currentHref_WOHash = splitHref[0]; var incomingHash = splitHref[1]; var prevX = null; var prevY = null; addEvent(window, 'load', init); function init(){ setOnClickHandler(); if(incomingHash){ if(window.attachEvent && !window.opera){ setTimeout(function(){scrollTo(0,0);setScroll('#'+incomingHash);},50); }else{ scrollTo(0, 0); setScroll('#'+incomingHash); } } } function addEvent(eventTarget, eventName, func){ if(eventTarget.addEventListener){ eventTarget.addEventListener(eventName, func, false); }else if(window.attachEvent){ eventTarget.attachEvent('on'+eventName, function(){func.apply(eventTarget);}); } }  function setOnClickHandler(){ var links = d.links; for(var i=0; i<links.length; i++){ var link = links[i]; var splitLinkHref = link.href.split('#'); if(currentHref_WOHash == splitLinkHref[0] && d.getElementById(splitLinkHref[1])){ addEvent(link, 'click', startScroll); } } }  function startScroll(event){ if(event){ event.preventDefault(); }else if(window.event){ window.event.returnValue = false; } setScroll(this.hash); }  function setScroll(hash){ var targetEle = d.getElementById(hash.substr(1)); if(!targetEle)return; var ele = targetEle; var x = 0; var y = 0; while(ele){ x += ele.offsetLeft; y += ele.offsetTop; ele = ele.offsetParent; } targetX = x; targetY = y; targetHash = hash; if(!scrolling){ scrolling = true; scroll(); } }  function scroll(){ var currentX = d.documentElement.scrollLeft||d.body.scrollLeft; var currentY = d.documentElement.scrollTop||d.body.scrollTop; var vx = (targetX - currentX) * easing; var vy = (targetY - currentY) * easing; var nextX = currentX + vx; var nextY = currentY + vy; if((Math.abs(vx) < 1 && Math.abs(vy) < 1) || (prevX === currentX && prevY === currentY)){ scrollTo(targetX, targetY); scrolling = false; location.hash = targetHash; prevX = prevY = null; return; }else{ scrollTo(parseInt(nextX), parseInt(nextY)); prevX = currentX; prevY = currentY; var scope = this; setTimeout(function(){scroll.apply(scope)},interval); } }  }());

/** /////////////////////////////////////
プルダウンメニューの装飾
//////////////////////////////////// **/
(function($,window,undefined ){$.fn.borderWidth=function(){return $(this).outerWidth() - $(this).innerWidth();};$.fn.paddingWidth=function(){return $(this).innerWidth() - $(this).width();};$.fn.extraWidth=function(){return $(this).outerWidth(true) - $(this).width();};$.fn.offsetFrom=function(e ){var $e=$(e);return{left:$(this).offset().left - $e.offset().left,top:$(this).offset().top - $e.offset().top};};$.fn.maxWidth=function(){var max=0;$(this).each(function(){if($(this).width()>max){max=$(this).width();}});return max;};$.fn.triggerAll=function(event,params){return $(this).each(function(){$(this).triggerHandler(event,params);});};var aps=Array.prototype.slice,randInt=function(){return Math.floor(Math.random() * 999999999);};$.proto=function(){var name=arguments[0],clazz=arguments[1],klazz=clazz,extOpt={},undefined;opts=$.extend({elem:"elem",access:"access",init:"init",instantAccess:false},arguments[2]);if(clazz._super){extOpt[opts.init]=function(){};klazz=clazz.extend(extOpt);}$.fn[name]=function(){var result,args=arguments;$(this).each(function(){var $e=$(this),obj=$e.data(name),isNew=!obj;if(isNew){obj=new klazz();if(clazz._super){obj[opts.init]=clazz.prototype.init;}obj[opts.elem]=$e[0];if(obj[opts.init]){obj[opts.init].apply(obj,opts.instantAccess?[]:aps.call(args,0));}$e.data(name,obj);}if(!isNew||opts.instantAccess){if(obj[opts.access]){obj[opts.access].apply(obj,aps.call(args,0));}if(args.length>0){if($.isFunction(obj[args[0]])){result=obj[args[0]].apply(obj,aps.call(args,1));}else if(args.length===1){if($.getObject){result=$.getObject(args[0],obj);}else{result=obj[args[0]];}}else{if($.setObject){$.setObject(args[0],args[1],obj);}else{obj[args[0]]=args[1];}}}else if(result===undefined){result=$e.data(name);}}});if(result===undefined){return $(this);}return result;};};var falseFunc=function(){return false;},SelectBox=function(){var self=this,o={},$orig=null,$label=null,$sb=null,$display=null,$dd=null,$items=null,searchTerm="",cstTimeout=null,delayReloadTimeout=null,resizeTimeout=null,loadSB,createOption,focusOrig,blurOrig,destroySB,reloadSB,delayReloadSB,openSB,centerOnSelected,closeSB,positionSB,positionSBIfOpen,delayPositionSB,clickSB,clickSBItem,keyupSB,keydownSB,focusSB,blurSB,addHoverState,removeHoverState,addActiveState,removeActiveState,getDDCtx,getSelected,getEnabled,selectItem,clearSearchTerm,findMatchingItem,selectMatchingItem,selectNextItemStartsWith,closeAll,closeAllButMe,closeAndUnbind,blurAllButMe,stopPageHotkeys,flickerDisplay,unbind;loadSB=function(){$sb=$("<div class='sb "+o.selectboxClass+" "+$orig.attr("class")+"' id='sb"+randInt()+"'></div>").attr("role","listbox").attr("aria-has-popup","true").attr("aria-labelledby",$label.attr("id")?$label.attr("id"):"");$("body").append($sb);var displayMarkup=$orig.children().size()>0?o.displayFormat.call($orig.find("option:selected")[0],0,0):"&nbsp;";$display=$("<div class='display "+$orig.attr("class")+"' id='sbd"+randInt()+"'></div>").append($("<div class='text'></div>").append(displayMarkup)).append(o.arrowMarkup);$sb.append($display);$dd=$("<ul class='"+o.selectboxClass+" items "+$orig.attr("class")+"' role='menu' id='sbdd"+randInt()+"'></ul>").attr("aria-hidden","true");$sb.append($dd).attr("aria-owns",$dd.attr("id"));if($orig.children().size()===0){$dd.append(createOption());}else{$orig.children().each(function(i ){var $opt,$og,$ogItem,$ogList;if($(this).is("optgroup")){$og=$(this);$ogItem=$("<li class='optgroup'>"+o.optgroupFormat.call($og[0],i+1)+"</li>").addClass($og.is(":disabled")?"disabled":"").attr("aria-disabled",$og.is(":disabled")?"true":"");$ogList=$("<ul class='items'></ul>");$ogItem.append($ogList);$dd.append($ogItem);$og.children("option").each(function(){$opt=createOption($(this),i).addClass($og.is(":disabled")?"disabled":"").attr("aria-disabled",$og.is(":disabled")?"true":"");$ogList.append($opt);});}else{$dd.append(createOption($(this),i));}});}$items=$dd.find("li").not(".optgroup");$sb.attr("aria-active-descendant",$items.filter(".selected").attr("id"));$dd.children(":first").addClass("first");$dd.children(":last").addClass("last");if(!o.fixedWidth){var largestWidth=$dd.find(".text,.optgroup").maxWidth()+$display.extraWidth()+1;$sb.width(o.maxWidth?Math.min(o.maxWidth,largestWidth):largestWidth);}else if(o.maxWidth && $sb.width()>o.maxWidth){$sb.width(o.maxWidth);}$orig.before($sb).addClass("has_sb").hide().show();positionSB();flickerDisplay();$dd.hide();if(!$orig.is(":disabled")){$orig.bind("blur.sb",blurOrig).bind("focus.sb",focusOrig);$display.mouseup(addActiveState).mouseup(clickSB).click(falseFunc).focus(focusSB).blur(blurSB).hover(addHoverState,removeHoverState);getEnabled().click(clickSBItem).hover(addHoverState,removeHoverState);$dd.find(".optgroup").hover(addHoverState,removeHoverState).click(falseFunc);$items.filter(".disabled").click(falseFunc);if(!$.browser.msie||$.browser.version>=9){$(window).resize($.throttle?$.throttle(100,positionSBIfOpen):delayPositionSB);}}else{$sb.addClass("disabled").attr("aria-disabled");$display.click(function(e ){e.preventDefault();});}$sb.bind("close.sb",closeSB).bind("destroy.sb",destroySB);$orig.bind("reload.sb",reloadSB);if($.fn.tie && o.useTie){$orig.bind("domupdate.sb",delayReloadSB);}};delayPositionSB=function(){clearTimeout(resizeTimeout);resizeTimeout=setTimeout(positionSBIfOpen,50);};positionSBIfOpen=function(){if($sb.is(".open")){positionSB();openSB(true);}}
createOption=function($option,index ){if(!$option){$option=$("<option value=''>&nbsp;</option>");index=0;}var $li=$("<li id='sbo"+randInt()+"'></li>").attr("role","option").data("orig",$option[0]).data("value",$option?$option.attr("value"):"").addClass($option.is(":selected")?"selected":"").addClass($option.is(":disabled")?"disabled":"").attr("aria-disabled",$option.is(":disabled")?"true":""),$inner=$("<div class='item'></div>"),$text=$("<div class='text'></div>").html(o.optionFormat.call($option[0],0,index+1));return $li.append($inner.append($text));};focusOrig=function(){blurAllButMe();$display.triggerHandler("focus");};blurOrig=function(){if(!$sb.is(".open")){$display.triggerHandler("blur");}};destroySB=function(internal ){$sb.remove();$orig.unbind(".sb").removeClass("has_sb");$(window).unbind("resize",delayPositionSB);if(!internal){$orig.removeData("sb");}};reloadSB=function(){var isOpen=$sb.is(".open"),isFocused=$display.is(".focused");closeSB(true);destroySB(true);self.init(o);if(isOpen){$orig.focus();openSB(true);}else if(isFocused){$orig.focus();}};delayReloadSB=function(){clearTimeout(delayReloadTimeout);delayReloadTimeout=setTimeout(reloadSB,30);};closeAndUnbind=function(){$sb.removeClass("focused");closeSB();unbind();};unbind=function(){$(document).unbind("click",closeAndUnbind).unbind("keyup",keyupSB).unbind("keypress",stopPageHotkeys).unbind("keydown",stopPageHotkeys).unbind("keydown",keydownSB);};closeAll=function(){$(".sb.open."+o.selectboxClass).triggerAll("close");};blurAllButMe=function(){$(".sb.focused."+o.selectboxClass).not($sb[0]).find(".display").blur();};closeAllButMe=function(){$(".sb.open."+o.selectboxClass).not($sb[0]).triggerAll("close");};closeSB=function(instantClose ){if($sb.is(".open")){$display.blur();$items.removeClass("hover");unbind();$dd.attr("aria-hidden","true");if(instantClose===true){$dd.hide();$sb.removeClass("open");$sb.append($dd);}else{$dd.fadeOut(o.animDuration,function(){$sb.removeClass("open");$sb.append($dd);});}}};getDDCtx=function(){var $ddCtx=null;if(o.ddCtx==="self"){$ddCtx=$sb;}else if($.isFunction(o.ddCtx)){$ddCtx=$(o.ddCtx.call($orig[0]));}else{$ddCtx=$(o.ddCtx);}return $ddCtx;};getSelected=function(){return $items.filter(".selected");};getEnabled=function(){return $items.not(".disabled");};centerOnSelected=function(){$dd.scrollTop($dd.scrollTop()+getSelected().offsetFrom($dd).top - $dd.height()/2+getSelected().outerHeight(true)/2);};flickerDisplay=function(){if($.browser.msie && $.browser.version<8){$("."+o.selectboxClass+" .display").hide().show();}};openSB=function(instantOpen ){var dir,$ddCtx=getDDCtx();blurAllButMe();$sb.addClass("open");$ddCtx.append($dd);dir=positionSB();$dd.attr("aria-hidden","false");if(instantOpen===true){$dd.show();centerOnSelected();}else if(dir==="down"){$dd.slideDown(o.animDuration,centerOnSelected);}else{$dd.fadeIn(o.animDuration,centerOnSelected);}$orig.focus();};positionSB=function(){var $ddCtx=getDDCtx(),ddMaxHeight=0,ddX=$display.offsetFrom($ddCtx).left,ddY=0,dir="",ml,mt,bottomSpace,topSpace,bottomOffset,spaceDiff,bodyX,bodyY;$dd.removeClass("above");$dd.show().css({maxHeight:"none",position:"relative",visibility:"hidden"});if(!o.fixedWidth){$dd.width($display.outerWidth() - $dd.extraWidth()+1);}bottomSpace=$(window).scrollTop()+$(window).height() - $display.offset().top - $display.outerHeight();topSpace=$display.offset().top - $(window).scrollTop();bottomOffset=$display.offsetFrom($ddCtx).top+$display.outerHeight();spaceDiff=bottomSpace - topSpace+o.dropupThreshold;if($dd.outerHeight()<bottomSpace){ddMaxHeight=o.maxHeight?o.maxHeight:bottomSpace;ddY=bottomOffset;dir="down";}else if($dd.outerHeight()<topSpace){ddMaxHeight=o.maxHeight?o.maxHeight:topSpace;ddY=$display.offsetFrom($ddCtx).top - Math.min(ddMaxHeight,$dd.outerHeight());dir="up";}else if(spaceDiff>=0){ddMaxHeight=o.maxHeight?o.maxHeight:bottomSpace;ddY=bottomOffset;dir="down";}else if(spaceDiff<0){ddMaxHeight=o.maxHeight?o.maxHeight:topSpace;ddY=$display.offsetFrom($ddCtx).top - Math.min(ddMaxHeight,$dd.outerHeight());dir="up";}else{ddMaxHeight=o.maxHeight?o.maxHeight:"none";ddY=bottomOffset;dir="down";}ml=(""+$("body").css("margin-left")).match(/^\d+/)?$("body").css("margin-left"):0;mt=(""+$("body").css("margin-top")).match(/^\d+/)?$("body").css("margin-top"):0;bodyX=$().jquery>="1.4.2"?parseInt(ml):$("body").offset().left;bodyY=$().jquery>="1.4.2"?parseInt(mt):$("body").offset().top;$dd.hide().css({left:ddX+($ddCtx.is("body")?bodyX:0),maxHeight:ddMaxHeight,position:"absolute",top:ddY+($ddCtx.is("body")?bodyY:0),visibility:"visible"});if(dir==="up"){$dd.addClass("above");}return dir;};clickSB=function(e ){if($sb.is(".open")){closeSB();}else{openSB();}return false;};selectItem=function(){var $item=$(this),oldVal=$orig.val(),newVal=$item.data("value");if(o.useTie && $.fn.tie){$orig.find("option").old_removeAttr("selected");$($item.data("orig")).old_attr("selected","selected");}else{$orig.find("option").removeAttr("selected");$($item.data("orig")).attr("selected","selected");}$items.removeClass("selected");$item.addClass("selected");$sb.attr("aria-active-descendant",$item.attr("id"));$display.find(".text").attr("title",$item.find(".text").html());$display.find(".text").html(o.displayFormat.call($item.data("orig")));if(oldVal !==newVal){$orig.change();}};clickSBItem=function(e ){closeAndUnbind();$orig.focus();selectItem.call(this);return false;};clearSearchTerm=function(){searchTerm="";};findMatchingItem=function(term ){var i,t,$tNode,$available=getEnabled();for(i=0;i<$available.size();i++){$tNode=$available.eq(i).find(".text");t=$tNode.children().size()==0?$tNode.text():$tNode.find("*").text();if(term.length>0 && t.toLowerCase().match("^"+term.toLowerCase())){return $available.eq(i);}}return null;};selectMatchingItem=function(text ){var $matchingItem=findMatchingItem(text);if($matchingItem !==null){selectItem.call($matchingItem[0]);return true;}return false;};stopPageHotkeys=function(e ){if(e.ctrlKey||e.altKey){return;}if(e.which===38||e.which===40||e.which===8||e.which===32){e.preventDefault();}};selectNextItemStartsWith=function(c ){var i,t,$selected=getSelected(),$available=getEnabled();for(i=$available.index($selected)+1;i<$available.size();i++){t=$available.eq(i).find(".text").text();if(t !=="" && t.substring(0,1).toLowerCase()===c.toLowerCase()){selectItem.call($available.eq(i)[0]);return true;}}return false;};keydownSB=function(e ){if(e.altKey||e.ctrlKey){return false;}var $selected=getSelected(),$enabled=getEnabled();switch(e.which){case 9:closeSB();blurSB();break;case 35:if($selected.size()>0){e.preventDefault();selectItem.call($enabled.filter(":last")[0]);centerOnSelected();}break;case 36:if($selected.size()>0){e.preventDefault();selectItem.call($enabled.filter(":first")[0]);centerOnSelected();}break;case 38:if($selected.size()>0){if($enabled.filter(":first")[0] !==$selected[0]){e.preventDefault();selectItem.call($enabled.eq($enabled.index($selected)-1)[0]);}centerOnSelected();}break;case 40:if($selected.size()>0){if($enabled.filter(":last")[0] !==$selected[0]){e.preventDefault();selectItem.call($enabled.eq($enabled.index($selected)+1)[0]);centerOnSelected();}}else if($items.size()>1){e.preventDefault();selectItem.call($items.eq(0)[0]);}break;default:break;}};keyupSB=function(e ){if(e.altKey||e.ctrlKey){return false;}if(e.which !==38 && e.which !==40){searchTerm+=String.fromCharCode(e.keyCode);if(selectMatchingItem(searchTerm)){clearTimeout(cstTimeout);cstTimeout=setTimeout(clearSearchTerm,o.acTimeout);}else if(selectNextItemStartsWith(String.fromCharCode(e.keyCode))){centerOnSelected();clearTimeout(cstTimeout);cstTimeout=setTimeout(clearSearchTerm,o.acTimeout);}else{clearSearchTerm();clearTimeout(cstTimeout);}}};focusSB=function(){closeAllButMe();$sb.addClass("focused");$(document).click(closeAndUnbind).keyup(keyupSB).keypress(stopPageHotkeys).keydown(stopPageHotkeys).keydown(keydownSB);};blurSB=function(){$sb.removeClass("focused");$display.removeClass("active");$(document).unbind("keyup",keyupSB).unbind("keydown",stopPageHotkeys).unbind("keypress",stopPageHotkeys).unbind("keydown",keydownSB);};addHoverState=function(){$(this).addClass("hover");};removeHoverState=function(){$(this).removeClass("hover");};addActiveState=function(){$display.addClass("active");$(document).bind("mouseup",removeActiveState);};removeActiveState=function(){$display.removeClass("active");$(document).unbind("mouseup",removeActiveState);};this.init=function(opts ){if($.browser.msie && $.browser.version<7){return;}$orig=$(this.elem);if($orig.attr("id")){$label=$("label[for='"+$orig.attr("id")+"']:first");}if(!$label||$label.size()===0){$label=$orig.closest("label");}if($orig.hasClass("has_sb")){return;}o=$.extend({acTimeout:800,animDuration:200,ddCtx:'body',dropupThreshold:150,fixedWidth:false,maxHeight:false,maxWidth:false,selectboxClass:'selectbox',useTie:false,arrowMarkup:"<div class='arrow_btn'><span class='arrow'></span></div>",displayFormat:undefined,optionFormat:function(ogIndex,optIndex ){if($(this).size()>0){var label=$(this).attr("label");if(label && label.length>0){return label;}return $(this).text();}else{return "";}},optgroupFormat:function(ogIndex ){return "<span class='label'>"+$(this).attr("label")+"</span>";}},opts);o.displayFormat=o.displayFormat||o.optionFormat;loadSB();};this.open=openSB;this.close=closeSB;this.refresh=reloadSB;this.destroy=destroySB;this.options=function(opts ){o=$.extend(o,opts);reloadSB();};};$.proto("sb",SelectBox);}(jQuery,window));

