/* =======================================

	Common Javascript

 -----------------------------------------
	INDEX
 -----------------------------------------
 	1.Mouse Over
	
	2.Cookie Script
	
	3.Chenge Font Size
	
	4.Globalnavi & Localnavi
	
	5.History Back
	
	6.Pop Up
	
	7.List Color
	
	8.Jquery Flat Heights
		8-1.Setting
		
	9.Link Confirm

========================================== */


/* 1.Mouse Over
========================================== */
$(function() {
  var image_cache = new Object();
  $(".swap").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; });
  });
});


/* 2.Cookie Script
==========================================
http://www.quirksmode.org/js/cookies.html
========================================== */
function createCookie(name,value,days){
   if (days){
   var date = new Date();
   date.setTime(date.getTime()+(days*24*60*60*1000));
   var expires = "; expires="+date.toGMTString();
   }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name){
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++)
   {
   var c = ca[i];
   while (c.charAt(0)==' ') c = c.substring(1,c.length);
   if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}


/* 3.Chenge Font Size
========================================== */
$(function(){
	$('dl#changeFontSize dd').css('cursor','pointer');
	
	var currentstyle = readCookie('orixFontStyle');
	if (currentstyle){
		switchFont(currentstyle);
		
			if(currentstyle == "changeFontSizeL"){
				$(".sizeL img").css("display","none");
				$(".sizeM img").css("display","block");
				$(".sizeS img").css("display","block");
				//alert(currentstyle);
			}else 
			
			if(currentstyle == "changeFontSizeM"){
				$(".sizeL img").css("display","block");
				$(".sizeM img").css("display","none");
				$(".sizeS img").css("display","block");
				//alert(currentstyle);
			}else
			
			if(currentstyle == "changeFontSizeS"){
				$(".sizeL img").css("display","block");
				$(".sizeM img").css("display","block");
				$(".sizeS img").css("display","none");
				//alert(currentstyle);
			}
		
	}else{
		switchFont("changeFontSizeM");
		$(".sizeL img").css("display","block");
		$(".sizeM img").css("display","none");
		$(".sizeS img").css("display","block");
	};
		
	$(".sizeL").click(function(){
		switchFont("changeFontSizeL");
		$(".sizeL img").css("display","none");
		$(".sizeM img").css("display","block");
		$(".sizeS img").css("display","block");
		return false;
	});
	
	$(".sizeM").click(function(){
		switchFont("changeFontSizeM");
		$(".sizeL img").css("display","block");
		$(".sizeM img").css("display","none");
		$(".sizeS img").css("display","block");
		return false;
	});
	
	$(".sizeS").click(function(){
		switchFont("changeFontSizeS");
		$(".sizeL img").css("display","block");
		$(".sizeM img").css("display","block");
		$(".sizeS img").css("display","none");
		return false;
	});
});

function switchFont(className){
   $('#contents').removeAttr('class').addClass(className);
   $('#chengeFontSize').removeAttr('class').addClass(className);
   createCookie('orixFontStyle', className, 365);
};


/* 4.Globalnavi & Localnavi
========================================== */	
function localNaviDisplay(){
	localNavi_Array();
	
	var tag = document.getElementById("Logo").src.slice(0,document.getElementById("Logo").src.indexOf("common",0));
	
	var html = '<ul id="localNavi">'+"\n";
	for(i in localNavi){
		html += '<li><a href="' + tag + url[i] + '">\n' + localNavi[i] +"</a></li>\n";
		//alert(html);
	}
	html += '<!-- /#localNavi --></ul>'+"\n";
	
	$('#localNaviDisplay').html(html);
}

// Default（表示なし）
category = 99;
localNavi_Active = 99;

$(function(){
	if(category!=0 && category!=99){
		localNaviDisplay();
		$('#localNavi li:eq('+localNavi_Active+')').addClass('active');
		$('#globalNavi li:eq('+category+')').addClass('active');
	}/*else if(category==0 || category==99){
		alert(document.getElementById("localNaviDisplay"))//.display = "none";
	}*/
});	


/* 5.History Back
========================================== */
$(function(){
	$('#historyBack a').click(function(){
		history.back();
		return false;
	});
});


/* 6.Pop Up
========================================== */
$(function(){
	$('.popup01').click(function(){
		window.open($(this).attr('href'), '', 'width=500, height=430,menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});
	
	$('.popup02').click(function(){
		window.open($(this).attr('href'), '', 'width=780, menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});
	
	$('.popup03').click(function(){
		window.open($(this).attr('href'), '', 'width=350, height=420, menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});
	
	$('.popup04').click(function(){
		window.open($(this).attr('href'), '', 'width=400, height=300, menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});
	
	$('.popup05').click(function(){
		window.open($(this).attr('href'), '', 'width=750, height=400, menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});
	
	$('.popup06').click(function(){
		window.open($(this).attr('href'), '', 'width=900, height=450, menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});
	
	$('.popup07').click(function(){
		window.open($(this).attr('href'), 'popup07', 'width=300, height=350, menubar=no, toolbar=no, scrollbars=no, resizable=yes').focus();
		return false;
	});
	
	$('.popup08').click(function(){
		window.open($(this).attr('href'), '', 'width=800, height=700, menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});

	$('.popup09').click(function(){
		window.open($(this).attr('href'), '', 'width=780, menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});

	$('.popup10').click(function(){
		window.open($(this).attr('href'), '', 'width=780, height=400, menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});

	$('.popup11').click(function(){
		window.open($(this).attr('href'), '', 'width=780, height=700, menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});
	
	$('.popup12').click(function(){
		window.open($(this).attr('href'), '', 'width=940, height=810, menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
		return false;
	});

	$('.popupFaq').click(function(){
		window.open($(this).attr('href'), 'faq', 'width=860, menubar=no, toolbar=no, scrollbars=yes, resizable=yes').focus();
		return false;
	});
	
	$('.windowClose').click(function(){
		window.close();
		return false;
	});
});


/* 7.List Color
========================================== */
$(function(){
	$('.wordList:even').addClass('even');
	$('.wordList:odd').addClass('odd');
	$('.tableAlternate tr:even td').addClass('bgLightBlue');
});


/* 8.Jquery Flat Heights
==========================================
Version: 2007-08-01

Copyright (c) 2007, KITAMURA Akatsuki

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
====================================================================== */
/*
	$.changeLetterSize.addHandler(func)
	文字の大きさが変化した時に実行する処理を追加
*/

jQuery.changeLetterSize = {
	handlers : [],
	interval : 500,//定期処理を行う時間間隔。一応0.5秒で設定して有ります。1秒 = 1000
	currentSize: 0
};

(function($) {

	var self = $.changeLetterSize;

	/* 文字の大きさを確認するためのins要素 */
	var ins = $('<ins>M</ins>').css({
		display: 'block',
		visibility: 'hidden',
		position: 'absolute',
		padding: '0',
		top: '0'
	});

	/* 文字の大きさが変わったか */
	var isChanged = function() {
		
		ins.appendTo('body');
		var size = ins[0].offsetHeight;
		ins.remove();
		
		if (self.currentSize == size) return false;
		self.currentSize = size;
		
		return true;
	};

	/* 文書を読み込んだ時点で
	   文字の大きさを確認しておく */
	$(isChanged);

	/* 文字の大きさが変わっていたら、
	   handlers中の関数を順に実行 */
	var observer = function() {
		if (!isChanged()) return;
		
		$.each(self.handlers, function(i, handler) {
			handler();
		});
	};

	/* ハンドラを登録し、
	   最初の登録であれば、定期処理を開始 */
	self.addHandler = function(func) {
		self.handlers.push(func);
		if (self.handlers.length == 1) {
			setInterval(observer, self.interval);
		}
	};

})(jQuery);

/*
	$(expr).flatHeights()
	$(expr)で選択した複数の要素について、それぞれ高さを
	一番高いものに揃える
*/

(function($) {

	/* 対象となる要素群の集合 */
	var sets = [];

	/* 高さ揃えの処理本体 */
	var flatHeights = function(set) {
		var maxHeight = 0;
		set.each(function(){
			var height = this.offsetHeight;
			if (height > maxHeight) maxHeight = height;
		});
		set.css('height', maxHeight + 'px');
	};

	/* 要素群の高さを揃え、setsに追加 */
	jQuery.fn.flatHeights = function() {
		if (this.length > 1) {
			flatHeights(this);
			sets.push(this);
		}
		return this;
	};

	/* 文字の大きさが変わった時に、
	   setsに含まれる各要素群に対して高さ揃えを実行 */
	$.changeLetterSize.addHandler(function() {
		$.each(sets, function() {
			this.height('auto');
			flatHeights(this);
		});
	});

})(jQuery);

	/* 8-1.Setting
	---------------------------------------- */
	$(function(){
		$('#contents #serviceIndexBox01 .body01 .body01H').flatHeights();
		$('#contents #serviceIndexBox01 .serviceTxt').flatHeights();
		$('#contents .service .unit').flatHeights();
		$('#contents .service .unitH2').flatHeights();
		$('#contents #stockIndexBox04 .box .item').flatHeights();
		$('#column1Contents #supportContactContents .body .contsecBox').flatHeights();
	});


/* 9.Link Confirm
========================================== */
$(function(){
	
	/* スルガ銀行
	---------------------------------------- */
	$('.linkSurugabank').click(function(){
		res=confirm("ここから先は、スルガ銀行のホームページになります。\n"+
					"オリックス証券とスルガ銀行は別法人であり、ここから先のサービスその他一切はスルガ銀行に帰属するものとなります。\n"+
					"オリックス証券は、お客さまがスルガ銀行と行う取引に一切関係がありません。");
		if(res==true)window.open("http://www.surugabank.co.jp/netbank/orix/","new");
		return false;
	});
	
	/* ドットコモディティ
	---------------------------------------- */
	$('.linkCommodity').click(function(){
		res=confirm("ここから先は、ドットコモディティのホームページになります。\n"+
					"オリックス証券とドットコモディティは別法人であり、ここから先のサービスその他一切はドットコモディティに帰属するものとなります。\n"+
					"オリックス証券は、お客さまがドットコモディティと行う取引に一切関係がありません。");
		if(res==true)window.open("http://www.commodity.co.jp/entrance/20080916/","new");
		return false;
	});
});
