//<![CDATA[

//Roll Over
var btnRollFunction = function () {
	var thisType="";
	var thisImg = this.src;
	if(thisImg.contains("http://")){thisType="http://";}
	else if(thisImg.contains("file://")){thisType="file://";}
	thisImg = thisImg.replace(thisType,"");
	var thisPath = new Array();
	thisPath = thisImg.split("/");
	var thisFile = thisPath.pop();
	var tmpImg = thisFile.split(".");
	var baseName = tmpImg[0];
	if (!baseName.match("_on")) {
		baseName += '_on';
		var hoverName = baseName + '.' + tmpImg[1];
		var path = thisType+thisPath.join("/") + '/' + hoverName;
		this.src = path;
	}
}

var btnOutFunction = function () {
	var thisType="";
	var thisImg = this.src;
	var now = this.getParent().getParent().get('class');
	if(thisImg.contains("http://")){thisType="http://";}
	else if(thisImg.contains("file://")){thisType="file://";}
	thisImg = thisImg.replace(thisType,"");
	var thisPath = new Array();
	thisPath = thisImg.split("/");
	var thisFile = thisPath.pop();
	var tmpImg = thisFile.split(".");
	var baseName = tmpImg[0];
	if (!now.contains("current")) {
		baseName = baseName.replace("_on","");
		var hoverName = baseName + '.' + tmpImg[1];
		var path = thisType+thisPath.join("/") + '/' + hoverName;
		this.src = path;
	}
}

var btnHighlight = function (e) {
	var thisType="";
	var thisImg=e.get('src');
	if(thisImg.contains("http://")){thisType="http://";}
	else if(thisImg.contains("file://")){thisType="file://";}
	thisImg = thisImg.replace(thisType,"");
	var thisPath = new Array();
	thisPath = thisImg.split("/");
	var thisFile = thisPath.pop();
	var tmpImg = thisFile.split(".");
	var baseName = tmpImg[0];
	if (!baseName.match("_on")) {
		baseName += '_on';
		var hoverName = baseName + '.' + tmpImg[1];
		var path = thisType+thisPath.join("/") + '/' + hoverName;
		e.set('src', path);
		
	}
}

var fixRollOver = function () {
	$$('.btn').each(function(element) {
		var now = element.getParent().getParent().get('class');
		if (now.contains('current')){
			btnHighlight(element);
		} else {
			$$('.btn').addEvent('mouseover', btnRollFunction);
			$$('.btn').addEvent('mouseleave', btnOutFunction);
		}
	});
}

//External Link
var fixExternalLinks = function () {
	var contentOptions = {};
	$$('a').each(function(element) {
		if (element.getProperty('rel')) {
			if (element.getProperty('rel').contains(',')) {
				var tempArr = element.get('rel').split(',');
				tempArr.each(function (temp,i) {
					temp = temp.replace(' ', '');
					if(temp.contains(':')){
						var ta = temp.split(':');
						contentOptions[ta[0]] = ta[1];
					} else {
						if(temp == 'external') {
							contentOptions['linkType'] = 'external';
						}
					}
				},this);
				if (contentOptions['linkType'] == 'external') {
					if (contentOptions['width'] && contentOptions['height']) {
						if (contentOptions['width'] == 'max') {
							var winWidth = $(window).getSize();
							contentOptions['width'] = winWidth.x;
						}
						if (contentOptions['height'] == 'max') {
							var winWidth = screen.width;
							contentOptions['height'] = screen.height;
						}
						var option = 'scrollbars=yes, width='+contentOptions['width']+', height='+contentOptions['height'];
						element.addEvent('click', function(e) { 
							e = new Event(e);
							e.stop();
							window.open(element.getProperty('href'), 'newwin', option);
						});
					}
				}
			}
			else if (element.getProperty('rel') == 'external') {
				element.addEvent('click', function(e) { 
					e = new Event(e);
					e.stop();
					window.open(this.getProperty('href')); 
				}.bind(element)); 
			}
		}
	});
	var contentOptions = {};
	$$('area').each(function(element) {
		if (element.getProperty('rel')) {
			if (element.getProperty('rel').contains(',')) {
				var tempArr = element.get('rel').split(',');
				tempArr.each(function (temp,i) {
					temp = temp.replace(' ', '');
					if(temp.contains(':')){
						var ta = temp.split(':');
						contentOptions[ta[0]] = ta[1];
					} else {
						if(temp == 'external') {
							contentOptions['linkType'] = 'external';
						}
					}
				},this);
				if (contentOptions['linkType'] == 'external') {
					if (contentOptions['width'] && contentOptions['height']) {
						var option = 'scrollbars=yes, width='+contentOptions['width']+', height='+contentOptions['height'];
						element.addEvent('click', function(e) { 
							e = new Event(e);
							e.stop();
							window.open(element.getProperty('href'), 'newwin', option);
						});
					}
				}
			}
			else if (element.getProperty('rel') == 'external') {
				element.addEvent('click', function(e) { 
					e = new Event(e);
					e.stop();
					window.open(this.getProperty('href')); 
				}.bind(element)); 
			}
		}
	});
}

//Font Size Change
var varDomain = location.hostname;
var fontLFunction = function () {
	$$('body').setStyle('font-size', '16px');
	var myCookie = Cookie.write('fontsize', 'Large', {domain: varDomain, path: '/'});
}
var fontMFunction = function () {
	$$('body').setStyle('font-size', '13px');
	var myCookie = Cookie.write('fontsize', 'Middle', {domain: varDomain, path: '/'});
}
var fontSFunction = function () {
	$$('body').setStyle('font-size', '11px')
	var myCookie = Cookie.write('fontsize', 'Small', {domain: varDomain, path: '/'});
}
var fontChgFunction = function () {
	if ($('fontLarge')) { $('fontLarge').addEvent('click', fontLFunction); }
	if ($('fontMiddle')) { $('fontMiddle').addEvent('click', fontMFunction); }
	if ($('fontSmall')) { $('fontSmall').addEvent('click', fontSFunction); }
}
//Default Font Size
var iniDefFontFunction = function () {
	if ($('fontMiddle')) {
		if (Cookie.read("fontsize")) {
			var myCookie = Cookie.read("fontsize");
			if (myCookie == 'Small') {
				fontSFunction();
			} else if (myCookie == 'Large') {
				fontLFunction();
			}
		}
	}
}

//Dropdown Menu
var formatDropdown = function () {
	if ($$('.hasNavigation')) {
		$$('.hasNavigation').each(function(elm,idx) {
			var timer = null;
			var menuList = elm.getElement('ul.subNavElm');
			var fxMenu = new Fx.Slide(menuList, {
				duration : 400
			}).hide();
			menuList.setStyle('visibility', 'visible');
			elm.addEvents({
				'mouseenter' : function(){
					fxMenu.cancel();
					fxMenu.slideIn();
					if($chk(timer)) { $clear(timer); }
				},
				'mouseleave' : function(){
					fnc = function() { fxMenu.slideOut(); }
					timer = fnc.delay(400,this);
					
				}
			});
		});
	}
}

//Scroll Navigation
var scrollingNavi = function() {
	if ($('typeImage')) {
		var topAnchor = $('typeImage');
		var getScroll = 30;
		var move = new Fx.Morph(topAnchor,{});
		move.set({'top' : getScroll});
		var IntervalId = anchorScroller.periodical(1000,topAnchor,getScroll);
	} 
}

var anchorScroller = function (scroll){
	var movingImg = $('typeImage');
	var scrollHeight = window.getScroll().y;
	var targetImg = $('typeImage').getElement('img');
	var targetHeight = targetImg.getSize().y;
	var temp = $$('p.return');
	var tmpheight = $('typeSelect').getSize().y;
	var maxScroll = tmpheight - targetHeight + 30;
	var move = new Fx.Morph(movingImg,{
//		duration : 'long'
//		transition : Fx.Transitions.Sine.easeInOut
	});
	if (scroll >= scrollHeight) {
		move.start({'top' : scroll});
	} else if (scroll <= scrollHeight) {
		if (scrollHeight >= maxScroll) {
			move.start({'top' : maxScroll});
		} else {
			move.start({'top' : scrollHeight});
		}
	}
}

//planHighLight
var planHighLight = function() {
	if ($('typeImage')) {
		var prefix = 'plan_elv_';
		var dir = './img/';
		var targetImg = $('typeImage').getElement('img');
		var targetSrc = targetImg.get('src');
		var defaultSrc = targetSrc;
		var button = $('typeSelect');
		var buttons = Array();
		var buttonId = Array();
		var images = Array();
		buttons = button.getElements('li');
		buttons.each(function(e,i){
			buttonId.push(e.get('id'));
			var changeSrc = prefix+buttonId[i]+'.gif';
			images.push(dir+changeSrc);
			e.addEvent('mouseenter', function(){
				targetImg.setProperty('src', images[i]);
			});
			e.addEvent('mouseleave', function(){
				targetImg.setProperty('src', defaultSrc);
			});
		});
		var chgImages = new Asset.images(images);
	}
}

var windowCloseFunc = function () {
	if ($$('.close')) {
		var btn = $$('.close').getElements('a');
		btn.each(function(e) {
			e.addEvent('click', function() { window.close(); });
		});
	}
}

//
var bannerPositionFixed = function () {
	$$('#banner_reserve').setStyles({
		"position": "absolute",
		"left": 0,
		"top": window.getScrollTop()+window.getHeight()-220
	});
	window.addEvent("scroll", function(){
		$$('#banner_reserve').setStyle("top", window.getScrollTop()+window.getHeight()-220);
	});
	$$('#banner_reserve span').addEvent("click",function () {
		if($$('#banner_reserve').getStyle('left') == '0px'){
			$$('#banner_reserve').tween('left', '-590px');
			$$('#banner_reserve span').setStyle('background-image', 'url(./images/btn_open.gif)');
		}else{
			$$('#banner_reserve').tween('left', '0px');
			$$('#banner_reserve span').setStyle('background-image','url(./images/btn_close.gif)');
		}
	});
}



window.addEvent('domready', function() {

	//Default Font Size
	iniDefFontFunction();

	//Font Size Change
	fontChgFunction();

	//Roll Over
	fixRollOver();

	//Dropdown Menu
	formatDropdown();

	//External Link
	fixExternalLinks();

	//Scroll Navigation
	scrollingNavi();

	//planHighLight
	planHighLight();

	//closebtn
	windowCloseFunc();

	milkbox = new Milkbox();
	
	bannerPositionFixed();

});
//]]>
