﻿
/* ---------------------------------------------------------------
 * rollover
--------------------------------------------------------------- */
$(document).ready(function(){
	var image_cache = new Object();
		$('a.rollover img,img.rollover, input.rollover').each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '-on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		$(this).hover(
		function() { 
		this.src = imgsrc_on; 
		},
		function() { 
		this.src = imgsrc; 
		});
	});
});


/* ---------------------------------------------------------------
 * smooth scroll
--------------------------------------------------------------- */
$(document).ready(function(){
	$('a[href^=#], area[href^=#]').click(function() {
		var tabClass = $(this).parent().parent().parent().attr('class');
		if(tabClass != 'tab-navi'){
			var speed = 700;
			var href= $(this).attr('href');
			var target = $(href == '#' || href == '' ? 'html' : href);
			var position = target.offset().top;
			$($.browser.safari ? 'body' : 'html').animate({scrollTop:position}, speed, 'easeOutQuart');
			return false;
		}
	});
});


/* ---------------------------------------------------------------
 * header searchbox
--------------------------------------------------------------- */
$(document).ready(function(){
	$('input.head-searchbox').each(function(i) {
		var holder = $(this).attr('defaultValue');
		if( $(this).val() != holder ) $(this);
		$(this).focus(function() {
			if( $(this).val() == holder ) $(this).val('');
		});
		$(this).blur(function() {
			if( $(this).val() == '' ) $(this).val(holder);
		});
	});
});


/* ---------------------------------------------------------------
 * contents size & font size & block resize
--------------------------------------------------------------- */
$(document).ready(function(){
	
	var sideNaviSize = $('#side-navi').height();
	var mainContents = $('#main-contents').height();
	
	function contentResize(){
		if($('#side-navi') && $('#main-contents')) {
			
			$('#main-contents .main-body, #side-navi').css('height', 'auto');
			
			sideNaviSize = $('#side-navi').height();
			mainContents = $('#main-contents').height();
			
			if(sideNaviSize > mainContents) {
				$('#main-contents .main-body').css('height', sideNaviSize - 150 + 'px');
			} else {
				$('#side-navi').css('height', mainContents - 20 + 'px');
			}
		}
	}
	function blockAutoHeight(){
		if($('.column-area')) {
			$('.column-area .box .head .inner').css('min-height', '1px');
			$('.column-area .box .body .inner').css('min-height', '1px');
			$('.column-area .box .head .inner').css('height', 'auto');
			$('.column-area .box .body .inner').css('height', 'auto');
			$('.column-area .box .head .inner').autoHeight({column: 2});
			$('.column-area .box .body .inner').autoHeight({column: 2});
		}
	}
	
	
	var history = $.cookie('fontSize');
	var elm = $('body');
	
	//english
	var enFlag = false;
	
	if($('#page-head .font-size').attr('id') == 'font-en') {
		enFlag = true;
	}
	
	if(!history) {
		elm.addClass('font-normal');
		$('#font-normal').empty();
		if(enFlag) {
			$('#font-normal').append('<img src="/common/img/fontsize_normal-en-on.gif" alt="M" width="37" height="25" />');
		} else {
			$('#font-normal').append('<img src="/common/img/fontsize_normal-on.gif" alt="標準" width="37" height="25" />');
		}
	} else {
		elm.addClass(history);
		if(history == 'font-normal') {
			$('#font-normal').empty();
			if(enFlag) {
				$('#font-normal').append('<img src="/common/img/fontsize_normal-en-on.gif" alt="M" width="37" height="25" />');
			} else {
				$('#font-normal').append('<img src="/common/img/fontsize_normal-on.gif" alt="標準" width="37" height="25" />');
			}	
		} else {
			$('#font-large').empty();
			if(enFlag) {
				$('#font-large').append('<img src="/common/img/fontsize_large-en-on.gif" alt="L" width="37" height="25" />');
			} else {
				$('#font-large').append('<img src="/common/img/fontsize_large-on.gif" alt="大" width="37" height="25" />');
			}
		}
	}
	
	$('.font-size li.font-btn').click(function(){
		var setFontSize = this.id;
		$.cookie('fontSize', setFontSize);
		elm.removeClass().addClass(setFontSize);
		contentResize();
		blockAutoHeight();
		
		if(setFontSize == 'font-normal') {
			$('#font-normal').empty();
			$('#font-large').empty();
			if(enFlag) {
				$('#font-normal').append('<img src="/common/img/fontsize_normal-en-on.gif" alt="M" width="37" height="25" />');
				$('#font-large').append('<img src="/common/img/fontsize_large-en.gif" alt="L" width="37" height="25" class="link" />');
			} else {
				$('#font-normal').append('<img src="/common/img/fontsize_normal-on.gif" alt="標準" width="37" height="25" />');
				$('#font-large').append('<img src="/common/img/fontsize_large.gif" alt="大" width="37" height="25" class="link" />');
			}
		} else {
			$('#font-normal').empty();
			$('#font-large').empty();
			if(enFlag) {
				$('#font-normal').append('<img src="/common/img/fontsize_normal-en.gif" alt="M" width="37" height="25" class="link" />');
				$('#font-large').append('<img src="/common/img/fontsize_large-en-on.gif" alt="L" width="37" height="25" />');
			} else {
				$('#font-normal').append('<img src="/common/img/fontsize_normal.gif" alt="標準" width="37" height="25" class="link" />');
				$('#font-large').append('<img src="/common/img/fontsize_large-on.gif" alt="大" width="37" height="25" />');
			}
		}
	});
	
	$.fn.autoHeight = function(options){ var op = $.extend({ column  : 0, clear   : 0, height  : 'minHeight', reset   : '', descend : function descend (a,b){ return b-a; } },options || {}); var self = $(this); var n = 0, hMax, hList = new Array(), hListLine = new Array(); hListLine[n] = 0; self.each(function(i){ if (op.reset == 'reset') { $(this).removeAttr('style'); } var h = $(this).height(); hList[i] = h; if (op.column > 1) { if (h > hListLine[n]) { hListLine[n] = h; } if ( (i > 0) && (((i+1) % op.column) == 0) ) { n++; hListLine[n] = 0; }; } }); hList = hList.sort(op.descend); hMax = hList[0]; var browser = $.browser.version; if (op.column > 1) { for (var j=0; j<hListLine.length; j++) { for (var k=0; k<op.column; k++) { if (browser == '6.0') { self.eq(j*op.column+k).height(hListLine[j]); if (k == 0 && op.clear != 0) self.eq(j*op.column+k).css('clear','both'); } else { self.eq(j*op.column+k).css(op.height,hListLine[j]); if (k == 0 && op.clear != 0) self.eq(j*op.column+k).css('clear','both'); } } } } else { if (browser == '6.0') { self.height(hMax); } else { self.css(op.height,hMax); } } };
	
	blockAutoHeight();
	contentResize();
});

/* ---------------------------------------------------------------
 * jquery-auto-height.js
 * Copyright (c) 2010 Tomohiro Okuwaki (http://www.tinybeans.net/blog/)
 * Licensed under MIT Lisence:
 * http://www.opensource.org/licenses/mit-license.php
--------------------------------------------------------------- */


/* ---------------------------------------------------------------
 * popup window
--------------------------------------------------------------- */
$(document).ready(function(){
	$("a.popuplink").each(function() {
		var target = $(this);
		target.click(function(e) {
			e.preventDefault();
			var href = target.attr("href");
			if (href) {
				//window size
				window.open(href, '_blank', 'width=700, height=600, menubar=no, toolbar=no, scrollbars=yes');
			}
			return false;
		});
	});
	$("a.popuplink-m").each(function() {
		var target = $(this);
		target.click(function(e) {
			e.preventDefault();
			var href = target.attr("href");
			if (href) {
				//window size
				window.open(href, '_blank', 'width=900, height=600, menubar=no, toolbar=no, scrollbars=yes');
			}
			return false;
		});
	});
	$("a.popuplink-l").each(function() {
		var target = $(this);
		target.click(function(e) {
			e.preventDefault();
			var href = target.attr("href");
			if (href) {
				//window size
				window.open(href, '_blank', 'width=1100, height=600, menubar=no, toolbar=no, scrollbars=yes');
			}
			return false;
		});
	});
	$('a.pageclose').click(function() {
		window.close();
		return false;
	});
});

/* ---------------------------------------------------------------
 * pattern cell
--------------------------------------------------------------- */
$(document).ready(function(){
	//$('table.pat-tbl tr:even').addClass('color');
});



/* ---------------------------------------------------------------
 * load swf
--------------------------------------------------------------- */
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

