
MJL.event.add(window, "load", function(event){
	// MJL に関係するコードはこの中に記述
	MJL.enable.flash("flash");
	MJL.enable.tab("tabs",{cookie:null});
	MJL.enable.tab("tabs-mercury",{cookie:null});
	
	//現在のページはロールオーバーしない
	$(function(){
		var host = 'http://' + location.hostname;
		var path = location.pathname;
		path = path.replace('index.html', '');
		path = host + path.replace(/\/\//, '/').replace(/^\/ja\//,'/');
		
		$('.roll:not("#common-nav") a').each(function(){
			var link = this.href;
			link = link.replace('/(\?|\#)(.*)$/', '').replace('index.html', '');
			
			if(link == path || (link != host + '/' && path.indexOf(link) > -1)){
				$(this).children('img').each(function(){
					this.src = this.src.replace(/(\.[^\.]+)$/g,"_o$1");
					//$(this).addClass('unroll');
				})
				$(this).addClass('unroll');
			}
		});
	});
	
	MJL.enable.rollover("roll",{disable:"unroll"});

	//tabs image current > tabs image no rollover only
	$(function(){
		var _tab_list = $('div.tabContainer > ul.tabList');
		var _tab_current = $('>li.active', _tab_list);
		$(_tab_current).each(function(){
			var _tab_current_img = $('img', this);
			if(_tab_current_img.length == 1){
				var _img_current = _tab_current_img.attr('src').replace(/([^/]+?)\.([^/]*?)/, "$1_o\.$2");
				_tab_current_img.attr('src', _img_current);
			}
		});
		var _tab_anchor = $('>li a', _tab_list);
		$(_tab_anchor).click(function(){
			$(this).parents('li').siblings('li').each(function(){
				var _tab_other_img = $('img', this);
				if(_tab_other_img.length == 1){
					var _tab_current = _tab_other_img.attr('src').replace(/([^/]+?)_o\.([^/]*?)/, "$1\.$2");
					_tab_other_img.attr('src', _tab_current);
				}
			});
			var _img_hover = $('img[src$="_o.gif"]', this);
			if(_img_hover.length == 0){
				var _tab_current_img = $('img', this);
				if(_tab_current_img.length == 1){
					var _tab_current = _tab_current_img.attr('src').replace(/([^/]+?)\.([^/]*?)/, "$1_o\.$2");
					_tab_current_img.attr('src', _tab_current);
				}
			}
		});
	});

}, false);

// MJL と無関係なコードはこの先に記述
//run
$(document).ready(function(){

	//set height
	
	$('#contents ul.photo-gallery-list01 li').set_height({items_per_row:4, group_by_parent:'ul.photo-gallery-list01'});
	$('#contents ul.photo-gallery-list01 li p.photo-image').set_height({items_per_row:4, group_by_parent:'ul.photo-gallery-list01'});
	$('#contents ul.plan-list01 li').set_height({items_per_row:6, group_by_parent:'ul.plan-list01'});
	$('#contents ul.image-list03 li p.image').set_height({items_per_row:4, group_by_parent:'ul.image-list03'});
	$('#contents ul.image-list03 li').set_height({items_per_row:4, group_by_parent:'ul.image-list03'});
	$('#contents ul.image-list04 li').set_height({items_per_row:4, group_by_parent:'ul.image-list04'});

	/* IE bg cache */
	try{document.execCommand('BackgroundImageCache', false, true);}catch(e){}

	//swith image
	$(function(){
		$('#contents div.image-switch').each(function(){
			$('img', 'ul.switch-list01', this).hover(function(){
				var _switch_object = $(this).parents('div.image-switch').find('.switch-object img');
				var _switch_former = $(this).attr('src').replace(/([^/]+?)_s\.([^/]*?)/, "$1\.$2");
				var _switch_img = _switch_object.attr('src').replace(/(.*)/, ''+_switch_former+'');
				_switch_object.attr('src', _switch_img);
			});
		});
	});

	//portal en marcury
	$(function(){
		var _weather_unit = $('#portal.top-en #nav-contents p.weather-unit span');
		var _degrees_f = $('#portal.top-en table.weather-table div.degrees-f');
		var _degrees_c = $('#portal.top-en table.weather-table div.degrees-c');
		_weather_unit.hover(
			function(){$(this).css({'color':'#ff6701'});},
			function(){$(this).css({'color':'#666666'});}
		);
		_weather_unit.each(function(){
			$(this).click(function(){
				_weather_unit.removeClass('active');
				$(this).addClass('active');
				if($('#degrees-c').attr('class') == 'active'){_degrees_f.hide();_degrees_c.show();	}
				if($('#degrees-f').attr('class') == 'active'){_degrees_f.show();_degrees_c.hide();	}
			});
		});
	});
});

//select switch
function navi(obj){
	var url = obj.options[obj.selectedIndex].value;
	if(url != ""){
		location.href = url;
	}
}

// set height
(function(A){A.fn.set_height=function(P){var G={items_per_row:false,one_height:false,delay:1000,group_by_parent:false};if(P){jQuery.extend(G,P)}if(A("#js_etalon").length){var N=A("#js_etalon").get(0)}else{var N=A("body").append('<span style="position:absolute;left:-9999px;top:0;" id="js_etalon">?</span>').find("#js_etalon").get(0)}var E=function(S,R){for(var Q=0;Q<S.length;Q++){if(S[Q]==R){return }}S.push(R)};var B=this;var F=[];var L=[];var K=[];var J=function(){for(var S=0;S<F.length;S++){var R=0;var T=F[S][0].currentStyle?parseInt(F[S][0].currentStyle.paddingTop)+parseInt(F[S][0].currentStyle.paddingBottom):parseInt(document.defaultView.getComputedStyle(F[S][0],null).getPropertyValue("padding-top"))+parseInt(document.defaultView.getComputedStyle(F[S][0],null).getPropertyValue("padding-bottom"));for(var Q=0;Q<F[S].length;Q++){F[S][Q].style.height="auto";R=Math.max(F[S][Q].offsetHeight-T,R)}for(var Q=0;Q<F[S].length;Q++){F[S][Q].style.height=R+"px"}}};var M=function(){var Y=0;var W=0;var Q=null;var T=null;F[Y]=[];var Z=false;for(var U=0;U<B.length;U++){if(G.group_by_parent){Q=A(B[U]).parents(G.group_by_parent)[0];if(U>0&&Q!=T&&!Z){F[++Y]=[];W=0}T=Q}if(G.items_per_row){B[U].className+=" nb"+parseInt(W%G.items_per_row+1);if(!(W%G.items_per_row)&&W>0){F[++Y]=[];W=0;Z=true}}F[Y][W++]=B[U];Z=false}for(var U=0;U<F.length;U++){if(!F[U][0].offsetHeight){var X=F[U][0];while(X.style.display!="none"){X=X.parentNode}L.push(X)}for(var S=0;S<F[U].length;S++){var V=F[U][S].getElementsByTagName("img");for(var R=0;R<V.length;R++){E(K,V[R].src)}}}};if(B.length){M();var D=N.offsetHeight;var C=setInterval(function(){var S=N.offsetHeight;if(S!=D){D=S;J()}for(var R=0;R<L.length;R++){if(L[R].style.display!="none"){J();L=[];for(var Q=0;Q<F.length;Q++){if(!F[Q][0].offsetHeight){var T=F[Q][0];while(T.style.display!="none"){T=T.parentNode}L.push(T)}}}}},G.delay);J();if(K.length){var H=[];var O=0;for(var I=0;I<K.length;I++){H[I]=document.createElement("img");H[I].onload=function(){O++;if(O==K.length){J()}};H[I].src=K[I]}}}if(navigator.userAgent.match("MSIE 5.5")&&B.length){setTimeout(function(){main(B),0})}return this}})(jQuery);


// --------------------------------------------------------------------
// Author  : mashimonator
// Create  : 2009/02/06
// Update  : 2009/04/20
//         : 2009/05/17 プルダウン選択時にonchangeイベント呼び出し処理を追加
//         : 2009/10/15 プルダウン表示位置の判定処理を追加
//         : 2009/10/15 selected属性に対応
//         : 2009/10/15 optgroup要素に対応
//         : 2009/11/16 value=""の場合に選択出来なくなるバグを修正
// Description : IEでプルダウンのリストが切れるのを防ぐ
// --------------------------------------------------------------------

/*@cc_on 
var doc = document;
eval('var document = doc');
@*/
var stretchDropdown = {
	//-----------------------------------------
	// 設定値
	//-----------------------------------------
	conf : {
		// 対象のクラス名（指定無しの場合は全select要素対象）
		targetClass : 'stretchDropdown',
		// プルダウンに一度に表示する最大行数（超えた場合はスクロールバーが表示される）
		maxRow : 10,
		// 以下 編集不可
		selectSerial : 'stretchDropdownBlock_###_target',
		shimSerial : 'stretchDropdownBlock_###_shim',
		idBaseStr : 'stretchDropdownBlock',
		viewingSerial : null,
		viewingMenu : null,
		viewingShim : null,
		count : 0
	},
	//-----------------------------------------
	// 初期処理
	//-----------------------------------------
	init : function() {
		// IEチェック
		if ( !stretchDropdown.isIE() ) {
			return;
		}
		// 対象のselect要素を取得
		var selects;
		if ( stretchDropdown.conf.targetClass && stretchDropdown.conf.targetClass != '' ) {
			selects = stretchDropdown.getTargetElements('select', stretchDropdown.conf.targetClass);
		} else {
			selects = document.getElementsByTagName('select');
		}
		var len = selects.length;
		for ( var i = 0; i < len; i++ ) {
			// select要素にシリアルを付加
			selects[i].className += ' ' + stretchDropdown.getSelectSerial();
			// イベントに関数を付加
			selects[i].onmousedown = function() {
				var str = this.className.split('_');
				stretchDropdown.createPulldown(str[1]);
			}
			// カウントアップ
			stretchDropdown.conf.count += 1;
		}
		// 疑似プルダウンの削除処理を付加
		stretchDropdown.addEvent( document, 'click', stretchDropdown.removePulldown );
	},
	//-----------------------------------------
	// 疑似プルダウンを表示する
	//-----------------------------------------
	createPulldown : function( serial ) {
		// 既に表示中のmenuがあれば削除する
		if ( stretchDropdown.removePulldownInCreate(serial) ) {
			// クリックされた要素がプルダウン表示中のselect要素であれば抜ける
			return;
		}
		// クリックされたselect要素を取得
		var targetSerial = stretchDropdown.conf.selectSerial.replace( '###', serial );
		var select = stretchDropdown.getTargetElements( 'select', targetSerial );
		// 使用不可
		select[0].disabled = true;
		if ( select[0] ) {
			// div要素を生成
			var div = document.createElement('div');
			div.id = stretchDropdown.conf.idBaseStr + '_menu';
			div.className = stretchDropdown.conf.idBaseStr;
			div.style.zIndex = '150';
			// ul要素を生成
			var ul = document.createElement('ul');
			ul.className = stretchDropdown.conf.idBaseStr + '_list';
			// ---select要素にoptgroup要素が含まるか否かで分岐
			if ( !stretchDropdown.existOptgroup(select[0]) ) {
				var optLen = select[0].options.length;
				for ( var i = 0; i < optLen; i++ ) {
					// li要素を生成
					var li = document.createElement('li');
					li.className = stretchDropdown.conf.idBaseStr + '_value';
					if ( select[0].options[i].selected ) {
						// span要素を生成
						var span = document.createElement('span');
						span.className = stretchDropdown.conf.idBaseStr + '_selected';
						span.innerHTML = select[0].options[i].text;
						// span要素をli要素に追加
						li.appendChild(span);
					} else {
						// a要素を生成
						var a = document.createElement('a');
						a.className = stretchDropdown.conf.idBaseStr + '_link';
						a.innerHTML = select[0].options[i].text;
						// href属性をセット
						a.setAttribute('href',"javascript:stretchDropdown.setSelectValue('" + select[0].options[i].value + "');");
						// a要素をli要素に追加
						li.appendChild(a);
					}
					// li要素をul要素に追加
					ul.appendChild(li);
				}
			} else {
				// select要素の子要素を取得
				var children = select[0].childNodes;
				var len = children.length;
				for (var i = 0; i < len; i++) {
					if ( children[i].nodeType == '1' && children[i].nodeName.match(/optgroup/i) ) {
						//--- optgroup要素の場合
						// li要素を生成
						var li = document.createElement('li');
						li.className = stretchDropdown.conf.idBaseStr + '_value';
						// span要素を生成
						var span = document.createElement('span');
						span.className = stretchDropdown.conf.idBaseStr + '_label';
						span.innerHTML = children[i].getAttribute('label');
						// span要素をli要素に追加
						li.appendChild(span);
						// li要素をul要素に追加
						ul.appendChild(li);
						// optgroup要素の子要素を取得
						var grandchildren = children[i].childNodes;
						var len2 = grandchildren.length;
						for (var x = 0; x < len2; x++) {
							if ( grandchildren[x].nodeType == '1' && grandchildren[x].nodeName.match(/option/i) ) {
								// li要素を生成
								var li = document.createElement('li');
								li.className = stretchDropdown.conf.idBaseStr + '_value';
								if ( grandchildren[x].selected ) {
									// span要素を生成
									var span = document.createElement('span');
									span.className = stretchDropdown.conf.idBaseStr + '_selected';
									span.innerHTML = grandchildren[x].text;
									span.style.paddingLeft = '20px';
									// span要素をli要素に追加
									li.appendChild(span);
								} else {
									// a要素を生成
									var a = document.createElement('a');
									a.className = stretchDropdown.conf.idBaseStr + '_link';
									a.innerHTML = grandchildren[x].text;
									a.style.paddingLeft = '20px';
									// href属性をセット
									a.setAttribute('href',"javascript:stretchDropdown.setSelectValue('" + grandchildren[x].value + "');");
									// a要素をli要素に追加
									li.appendChild(a);
								}
								// li要素をul要素に追加
								ul.appendChild(li);
							}
						}
					}
				}
			}
			// ul要素をdiv要素に追加
			div.appendChild(ul);
			div.style.position = 'absolute';
			div.style.visibility = 'hidden';
			div.style.top = '0px';
			div.style.left = '0px';
			// htmlに反映
			document.body.appendChild(div);
			// select要素のポジション・サイズを取得
			var pos = stretchDropdown.getElementPosition( select[0] );
			var size = stretchDropdown.getElementSize( select[0] );
			var divSize = stretchDropdown.getElementSize( div );
			// div要素の幅をセット
			if ( size.width > divSize.width ) {
				div.style.width = size.width;
				divSize.width = size.width;
			}
			// div要素の高さをセット
			if ( select[0].options.length > stretchDropdown.conf.maxRow && li ) {
				var liSize = stretchDropdown.getElementSize( li );
				div.style.overflowY = 'scroll';
				div.style.borderRight = 'none';
				div.style.height = (liSize.height * stretchDropdown.conf.maxRow) + 'px';
			}
			// ブラウザの画面サイズを取得
			var browserSize = stretchDropdown.getBrowserSize();
			var tmpTop = 0;
			var tmpLeft = 0;
			// プルダウン表示位置（横）設定
			if ( (pos.left + size.width + divSize.width) <= browserSize.width ) {
				// 収まる場合
				tmpLeft = pos.left;
			} else {
				// はみ出る場合
				tmpLeft = (pos.left - (divSize.width - size.width));
			}
			// プルダウン表示位置（縦）設定
			if ( (pos.top + size.height + divSize.height) <= browserSize.height ) {
				// 収まる場合
				tmpTop = (pos.top + size.height + 1);
			} else {
				// はみ出る場合
				tmpTop = (pos.top - (divSize.height + 1));
			}
			// 高さと幅をセット
			div.style.left = tmpLeft + 'px';
			div.style.top = tmpTop + 'px';
			// 擬似プルダウンを表示
			div.style.visibility = 'visible';
			// 表示中の疑似プルダウンを保持
			stretchDropdown.conf.viewingMenu = div;
			// 疑似プルダウンを表示中のselect要素のシリアルを保持
			stretchDropdown.conf.viewingSerial = serial;
			// shimを生成
			stretchDropdown.createShim( tmpTop, tmpLeft, div.scrollWidth, div.scrollHeight, true );
			// focusを移動
			div.focus();
		}
	},
	//-----------------------------------------
	// 疑似プルダウンで選択された値をselect要素にセットする
	//-----------------------------------------
	setSelectValue : function( index ) {
		// 対象のselect要素を取得
		var targetSerial = stretchDropdown.conf.selectSerial.replace( '###', stretchDropdown.conf.viewingSerial );
		var select = stretchDropdown.getTargetElements( 'select', targetSerial );
		// 擬似プルダウンを削除
		stretchDropdown.removePulldown();
		if ( index != undefined && index != null && select[0] ) {
			// 選択された値をselect要素に反映
			var optLen = select[0].options.length;
			for ( var i = 0; i < optLen; i++ ) {
				if ( select[0].options[i].value == index ) {
					select[0].selectedIndex = i;
				}
			}
			// focusを移動
			select[0].focus();
			// onchangeイベントを呼び出し
			if ( select[0].onchange ) {
				select[0].onchange();
			}
		}
	},
	//-----------------------------------------
	// 疑似プルダウンを削除する（新規プルダウン生成時）
	//-----------------------------------------
	removePulldownInCreate : function ( serial ) {
		var state = false;
		// 既に表示中のmenuがあれば削除する
		if ( stretchDropdown.conf.viewingSerial ) {
			var viewingSerial = stretchDropdown.conf.viewingSerial;
			document.body.removeChild(stretchDropdown.conf.viewingMenu);
			stretchDropdown.conf.viewingMenu = null;
			document.body.removeChild(stretchDropdown.conf.viewingShim);
			stretchDropdown.conf.viewingShim = null;
			stretchDropdown.changeSelectDisabled( stretchDropdown.conf.viewingSerial, false);
			stretchDropdown.conf.viewingSerial = null;
			if ( viewingSerial == serial ) {
				// クリックされた要素がプルダウン表示中のselect要素であればtrueをセット
				state = true;
			}
		}
		return state;
	},
	//-----------------------------------------
	// 疑似プルダウンを削除する
	//-----------------------------------------
	removePulldown : function( event ) {
		var element;
		// イベント発生元の要素を取得
		if ( event && event.target ) {
			element = event.target;
		} else if ( window.event && window.event.srcElement ) {
			element = window.event.srcElement;
		}
		if ( element ) {
			// 擬似プルダウンがイベント発生元の場合は抜ける
			if ( stretchDropdown.checkEventTarget(element) ) {
				return;
			}
		}
		// 擬似プルダウンを削除
		if ( stretchDropdown.conf.viewingSerial ) {
			document.body.removeChild(stretchDropdown.conf.viewingMenu);
			stretchDropdown.conf.viewingMenu = null;
			document.body.removeChild(stretchDropdown.conf.viewingShim);
			stretchDropdown.conf.viewingShim = null;
			stretchDropdown.changeSelectDisabled( stretchDropdown.conf.viewingSerial, false);
			stretchDropdown.conf.viewingSerial = null;
		}
	},
	//-----------------------------------------
	// shimを生成する
	//-----------------------------------------
	createShim : function( top, left, width, height, flg ) {
		// iframe要素を生成
		var iframe = document.createElement('iframe');
		// idを設定
		if ( flg ) {
			iframe.id = stretchDropdown.conf.idBaseStr + '_shim';
		}
		// 基本スタイル設定
		iframe.setAttribute('frameBorder', '0');
		iframe.setAttribute('scrolling', 'no');
		iframe.style.border = 'none';
		iframe.style.zIndex = '100';
		// 透明度設定
		if ( !stretchDropdown.isUnderIE7() ) {
			iframe.style.opacity = .00;
			iframe.style.filter = 'alpha(opacity=0)';
			iframe.alpha = 0;
			iframe.allowTransparency = 'true';
		}
		// サイズ設定
		iframe.style.width = width + 'px';
		if ( flg ) {
			iframe.style.height = height + 'px';
		} else {
			iframe.style.height = ( height + 2 ) + 'px';
		}
		// ポジション設定
		iframe.style.position = 'absolute';
		iframe.style.top = top + 'px';
		iframe.style.left = left + 'px';
		// htmlに反映
		document.body.appendChild(iframe);
		if ( flg ) {
			stretchDropdown.conf.viewingShim = iframe;
		}
	},
	//-----------------------------------------
	// select要素のdisabledを切り替える
	//-----------------------------------------
	changeSelectDisabled : function( serial, state ) {
		serial = stretchDropdown.conf.selectSerial.replace( '###', serial );
		var select = stretchDropdown.getTargetElements( 'select', serial );
		var len = select.length;
		for (var i = 0; i < len; i++) {
			select[i].disabled = state;
		}
	},
	//-----------------------------------------
	// イベント発生元が擬似プルダウンかを判定する
	//-----------------------------------------
	checkEventTarget : function( element ) {
		var result = false;
		if ( element.nodeType == '1' && element.className.match(stretchDropdown.conf.idBaseStr) ) {
			result = true;
		}
		return result;
	},
	//-----------------------------------------
	// select要素にoptgroupが含まれるかを返す
	//-----------------------------------------
	existOptgroup : function( element ) {
		var optgroup = element.getElementsByTagName('OPTGROUP');
		if ( optgroup.length && optgroup.length > 0 ) {
			return true;
		} else {
			return false;
		}
	},
	//-----------------------------------------
	// selected属性が指定されているoption要素のテキストを返す
	//-----------------------------------------
	getSelectedOption : function( element ) {
		var result = false;
		var opt = element.getElementsByTagName('OPTION');
		var len = opt.length;
		for (var i = 0; i < len; i++) {
			if ( opt[i].selected ) {
				result = opt[i].innerHTML;
				break;
			}
		}
		return result;
	},
	//-----------------------------------------
	// select要素用シリアルを返す
	//-----------------------------------------
	getSelectSerial : function() {
		return stretchDropdown.conf.selectSerial.replace( '###', stretchDropdown.conf.count );
	},
	//-----------------------------------------
	// 対象要素のサイズを取得する
	//-----------------------------------------
	getElementSize : function( element ) {
		var w = element.offsetWidth;
		var h = element.offsetHeight;
		return ({ 'width': w, 'height': h });
	},
	//-----------------------------------------
	// ブラウザの画面サイズを取得する
	//-----------------------------------------
	getBrowserSize : function() {
		var w = 0;
		var h = 0;
		if ( window.innerWidth ) {
			w = window.innerWidth;
		} else if ( document.documentElement && document.documentElement.clientWidth != 0 ) {
			w = document.documentElement.clientWidth;
		} else if ( document.body ) {
			w = document.body.clientWidth;
		}
		w = (document.documentElement.scrollLeft || document.body.scrollLeft) + w;
		if ( window.innerHeight ) {
			h = window.innerHeight;
		} else if ( document.documentElement && document.documentElement.clientHeight != 0 ) {
			h = document.documentElement.clientHeight;
		} else if ( document.body ) {
			h = document.body.clientHeight;
		}
		h = (document.documentElement.scrollTop || document.body.scrollTop) + h;
		return ({ 'width': w, 'height': h });
	},
	//-----------------------------------------
	// 対象要素のポジションを取得する
	//-----------------------------------------
	getElementPosition : function( element ) {
		var offsetTrail = (typeof element == 'string') ? document.getElementById(element): element;
		var x = 0;
		var y = 0;
		while (offsetTrail) {
			x += offsetTrail.offsetLeft;
			y += offsetTrail.offsetTop;
			offsetTrail = offsetTrail.offsetParent;
		}
		if ( navigator.userAgent.indexOf('Mac') != -1 && typeof doc.body.leftMargin != 'undefined' ) {
			x += document.body.leftMargin;
			y += document.body.topMargin;
		}
		return ({ 'left': x, 'top': y });
	},
	//-----------------------------------------
	// ターゲットタグを取得する
	//-----------------------------------------
	getTargetElements : function( tag, cls ) {
		var elements = new Array();
		var targetElements = document.getElementsByTagName(tag.toUpperCase());
		var len = targetElements.length;
		for ( var i = 0; i < len; i++ ) {
			if ( targetElements[i].className && targetElements[i].className.match(cls) ) {
				elements[elements.length] = targetElements[i];
			}
		}
		return elements;
	},
	//-----------------------------------------
	// IE判定
	//-----------------------------------------
	isIE : function() {
		IE='\v'=='v';
		if(IE){
			return true;
		}else{
			return false;
		}
	},
	//-----------------------------------------
	// IE7以下判定
	//-----------------------------------------
	isUnderIE7 : function() {
		IE='\v'=='v';
		if ( IE ) {
			if ( document.documentMode ) {
				if ( document.documentMode == '7' || document.documentMode == '5' ) {
					return true;
				} else {
					return false;
				}
			} else {
				return true;
			}
		} else {
			return false;
		}
	},
	//-----------------------------------------
	// イベントに関数を付加する
	//-----------------------------------------
	addEvent : function( target, event, func ) {
		try {
			target.addEventListener(event, func, false);
		} catch (e) {
			target.attachEvent('on' + event, func);
		}
	}
}
// 実行
stretchDropdown.addEvent( window, 'load', stretchDropdown.init );


// thick box
/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley(http://www.codylindley.com)
 * Copyright(c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
		  
var tb_pathToImage = "/common/css/images/thickbox_loadingAnimation.gif";

/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call tb_init
$(document).ready(function(){   
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
});

//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	tb_show(t,a,g);
	this.blur();
	return false;
	});
}

function tb_show(caption, url, imageGroup){//function called when the user clicks on a thickbox link
	try{
		if(typeof document.body.style.maxHeight === "undefined"){//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if(document.getElementById("TB_HideSelect") === null){//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   
	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
				
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_FoundURL = false;
			if(imageGroup){
				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
				for(TB_Counter = 0;((TB_Counter < TB_TempArray.length) &&(TB_NextHTML === "")); TB_Counter++){
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						if(!(TB_TempArray[TB_Counter].href == url)){						
							if(TB_FoundURL){
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
							} else{
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
							}
						} else{
							TB_FoundURL = true;
							TB_imageCount = "Image " +(TB_Counter + 1) +" of "+(TB_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if(imageWidth > x){
				imageHeight = imageHeight *(x / imageWidth); 
				imageWidth = x; 
				if(imageHeight > y){ 
					imageWidth = imageWidth *(y / imageHeight); 
					imageHeight = y; 
				}
			} else if(imageHeight > y){ 
				imageWidth = imageWidth *(y / imageHeight); 
				imageHeight = y; 
				if(imageWidth > x){ 
					imageHeight = imageHeight *(x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			$("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src='/common/css/images/lightpop-btn-close.gif' alt='CLOSE' /></a></div>"); 		
			
			$("#TB_closeWindowButton").click(tb_remove);
			
			if(!(TB_PrevHTML === "")){
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;	
				}
				$("#TB_prev").click(goPrev);
			}
			
			if(!(TB_NextHTML === "")){		
				function goNext(){
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
					return false;	
				}
				$("#TB_next").click(goNext);
				
			}

			document.onkeydown = function(e){ 	
				if(e == null){ // ie
					keycode = event.keyCode;
				} else{ // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			tb_position();
			$("#TB_load").remove();
			$("#TB_ImageOff").click(tb_remove);
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
			};
			
			imgPreloader.src = url;
		}else{//code to show html
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );

			TB_WIDTH =(params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT =(params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					$("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src='/common/css/images/lightpop-btn-close.gif' alt='CLOSE' /></a></div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					}else{//iframe modal
					$("#TB_overlay").unbind();
						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
			}else{// not an iframe, ajax
					if($("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'><img src='/common/css/images/lightpop-btn-close.gif' alt='CLOSE' /></a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{//ajax modal
						$("#TB_overlay").unbind();
						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent")[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle").html(caption);
					}
			}
					
			$("#TB_closeWindowButton").click(tb_remove);
			
				if(url.indexOf('TB_inline') != -1){	
					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
					$("#TB_window").unload(function(){
						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					$("#TB_load").remove();
					$("#TB_window").css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if($.browser.safari){//safari needs help because it will not fire iframe onload
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});
					}
				}else{
					$("#TB_ajaxContent").load(url += "&random=" +(new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						$("#TB_load").remove();
						tb_init("#TB_ajaxContent a.thickbox");
						$("#TB_window").css({display:"block"});
					});
				}
			
		}

		if(!params['modal']){
			document.onkeyup = function(e){ 	
				if(e == null){ // ie
					keycode = event.keyCode;
				} else{ // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		}
		
	} catch(e){
		//nothing here
	}
}

//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

function tb_remove(){
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if(typeof document.body.style.maxHeight == "undefined"){//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_position(){
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if( !(jQuery.browser.msie && jQuery.browser.version < 7)){ // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function tb_parseQuery( query ){
   var Params ={};
   if( ! query ){return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for( var i = 0; i < Pairs.length; i++ ){
      var KeyVal = Pairs[i].split('=');
      if( ! KeyVal || KeyVal.length != 2 ){continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth ||(de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight ||(de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function tb_detectMacXFF(){
  var userAgent = navigator.userAgent.toLowerCase();
  if(userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1){
    return true;
  }
}
