// JavaScript Document

/* ===============================================
  ROLL OVER
=============================================== */
	function initRollOverImages(){
		var image_cache = new Object();
		$("img.rover,input.rover").each(function(i){
			var imgsrc = this.src;
			var dot = this.src.lastIndexOf('.');
			var imgsrc_ro = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
			image_cache[this.src] = new Image();
			image_cache[this.src].src = imgsrc_ro;
			$(this).hover(
				function() { if(!$(this).hasClass("active")){this.src = imgsrc_ro;} },
				function() {if(!$(this).hasClass("active")){this.src = imgsrc; }})
		});
	}

/* ===============================================
  Menu_active
=============================================== */
	function Menu_active(id){
		if(id != ''){
			var target_img = "img#"+id;
			$(target_img).each(function(i){
				dot = this.src.lastIndexOf('.');
				var imgsrc_ro = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
				this.src = imgsrc_ro;
				//rewrite
				$(this).hover(function(){
					this.src = imgsrc_ro;
				},function(){
					this.src = imgsrc_ro;
				});
			});
		}
	}

/* ===============================================
  localMenu_active
=============================================== */
	function localMenu_active(id){
		if(id != ''){
			var target_img = "li#"+id;
			$(target_img).each(function(i){
				$(this).addClass("on");
			});
			var target_img = "dd#"+id;
			$(target_img).each(function(i){
				$(this).addClass("on");
			});
			var target_img = "dt#"+id;
			$(target_img).each(function(i){
				$(this).addClass("on");
			});
		}
	}

/* ===============================================
  localMenu_active_sub
=============================================== */
	function localMenu_active_sub(id){
		if(id != ''){
			var target_img = "li#"+id;
			$(target_img).each(function(i){
				$(this).addClass("on02");
			});
			var target_img = "dd#"+id;
			$(target_img).each(function(i){
				$(this).addClass("on02");
			});
			var target_img = "dt#"+id;
			$(target_img).each(function(i){
				$(this).addClass("on02");
			});
		}
	}
/* ===============================================
  input,textarea focus
=============================================== */
	function InputFocus(){
		$('input[type=text],input[type=password],textarea').addClass('input-usually');
		$('.input-usually').focus(function(){
			$(this).addClass('input-focus');
		});
		$('.input-usually').blur(function(){
			if($(this).find('.input-focus')){
				$(this).removeClass('input-focus');
			}
		});
	}

/* ===============================================
  FONT SIZE
=============================================== */
	function fontChanger(){
		var history = $.cookie('fontSize');
		var elm = $('#Container');
		if(history){
			elm.addClass(history);
		}else{
			elm.addClass('fontM');
			history = "fontM";
		}
		var active_btn = "#fontChange li#"+history;
		$(active_btn).find("img").addClass("active");
		$(active_btn).find("img").attr("src",$(active_btn).find("img").attr("src").replace(".jpg","_on.jpg"));
		$(active_btn).addClass('on');
		
		$('li','#fontChange').click(function(){
											 
			var setFontSize = this.id;
			$.cookie('fontSize', setFontSize);
			elm.removeClass().addClass(setFontSize);
			$('#fontChange li', this.group).each(function(){
				$(this).removeClass('on');
			});
			$("#fontChange li img").each(function(){
				this.src=this.src.replace("_on","");
				if($(this).hasClass("active")){
					$(this).removeClass("active");
				}
			});											 

			$(this).find("img").addClass("active");
			$(this).find("img").attr("src",$(this).find("img").attr("src").replace(".jpg","_on.jpg"));
			$(this).addClass('on');
		});
	}

/* =============================================== */
$(document).ready(function(){
	initRollOverImages();
	InputFocus();
	fontChanger();
});
