﻿//=========================================================
//
//	jQuery SAVAGE.JS
//	CorporateCAST(R)
//	
//	(C) 2010 E2, Inc. All Rights Reserved.
//	http://www.e-2.co.jp
//
//=========================================================
(function($) {
	$.svg = {

////////////////////////////////////////////////////
//
//　UL TABLEの行毎にCLASSを付加
//
////////////////////////////////////////////////////
		basic:function(options) {
			$('ul, ol, table, table tr dt dl').each(function(){
				//TARGET [UL/OL li]
				$(this).children('li:even').addClass('list_odd');   // 奇数行 【開始行は0の為CLASSを逆に】
				$(this).children('li:odd').addClass('list_even');   // 偶数行
				//TARGET [TABLE TR]
				$(this).children('table tr:even').addClass('line_odd');   // 奇数行
				$(this).children('table tr:odd').addClass('line_even');   // 偶数行
				//TARGET [TABLE TH TD]
				$(this).children('th:even, td:even').addClass('cell_odd');  // 奇数行
				$(this).children('th:odd, td:odd').addClass('cell_even');   // 偶数行

				$('li:first-child, table tr:first-child, th:first-child, td:first-child, dl dt:first-child, dd:first-child').addClass('first-child'); // 開始行
				$('li:last-child, table tr:last-child, th:last-child, td:last-child, dl dt:last-child, dd:last-child').addClass('last-child');	   // 最終行
			});
		},


////////////////////////////////////////////////////
//
//　INPUT[TYPE=TEXT]、TEXTAREAのFOCUS時にCLASSを付加
//
////////////////////////////////////////////////////
		inputFocus:function(options) {
			$('input[type=text],input[type=file],textarea')
				.focus(function(){
					$(this).addClass('focus');
				})
				.blur(function(){
					$(this).removeClass('focus');
				});
		},


////////////////////////////////////////////////////
//
//　IMGタグのロールオーバー制御[_rv]→[ + _ov]
//
////////////////////////////////////////////////////
		imgRollover:function(options) {
			$("img[src*='_rv']").hover(function(){
				$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_ov$2"))
			}, function(){
				$(this).attr("src",$(this).attr("src").replace(/^(.+)_ov(\.[a-z]+)$/, "$1$2"));
			});
		},


////////////////////////////////////////////////////
//
//　ページ内リンクのスクロール制御
//
////////////////////////////////////////////////////
		pageScroll:function(options) {
			jQuery.easing.quart = function (x, t, b, c, d) {
				return -c * ((t=t/d-1)*t*t*t - 1) + b;
			};
			$('a[href*=#]:not(ul.svg_tab li a)').click(function() {
				if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
					var $target = $(this.hash);
					$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
					if ($target.length) {
						var targetOffset = $target.offset().top;
						$('html,body').animate({ scrollTop: targetOffset }, 1200, 'quart');
						return false;
					}
				}
			});
		},


////////////////////////////////////////////////////
//
//　DROPDOWN の制御
//
////////////////////////////////////////////////////
		dropDown:function(options) {
			$('ul.svg_dd li ul').hide();
			$("ul.svg_dd li").hover(function(){
				$(this).addClass("ov");
				$('ul:first:not(:animated)',this).slideDown("fast")
		    }, function(){
				$(this).removeClass("ov");
				$('ul:first',this).slideUp("fast")
			});
		    $('ul.svg_dd li ul li:has(ul)').find('a:first').append('<span class="childarrow">&#9658;</span>');
		},



////////////////////////////////////////////////////
//
//　TAB PANEL の制御
//
////////////////////////////////////////////////////
		tabPanel:function(options) {
			$('ul.svg_tab_panel li:not('+$('ul.svg_tab li a.active').attr('href')+')').hide();
			$('ul.svg_tab li a').click(function(){
				$('ul.svg_tab li a').removeClass('active');
				$(this).addClass('active');
				$('ul.svg_tab_panel li').hide();
				$($(this).attr('href')).fadeIn('fast');
				return false;
			});
		},



////////////////////////////////////////////////////
//
//　ACCORDION の制御
//
////////////////////////////////////////////////////
		accordion:function(options) {// 縦タイプ ////////////////////////////////////////
//			$('dl.svg_acdn dd:not(:first)').css('display', 'none'); //1段目の初期状態を展開にする場合
//			$('dl.svg_acdn dt:first').addClass('active');		//1段目の初期状態を展開にする場合
			$('dl.svg_acdn dd').css('display', 'none');		//1段目の初期状態を展開にする場合は削除
				$('dl.svg_acdn dt').click(function(){
				if ($(this).hasClass('active')){		    //クリック毎にすべて展開する場合は削除
					$(this).removeClass('active');			//クリック毎にすべて展開する場合は削除
					$('+dd',this).slideUp('normal');		//クリック毎にすべて展開する場合は削除
				} else {					    //クリック毎にすべて展開する場合は削除
					var d = {height:'toggle', opacity:'toggle'};
					$('dl.svg_acdn dt').removeClass('active');	//クリック毎にすべて展開する場合は削除
					$('dl.svg_acdn dd').slideUp('normal');		//クリック毎にすべて展開する場合は削除
					$(this).toggleClass('active');
					$('+dd',this).animate(d);
				}						    //クリック毎にすべて展開する場合は削除
		 		}).mouseover(function(){
					$(this).addClass('ov');
				}).mouseout(function(){
					$(this).removeClass('ov');
				});
		},

		accordionSide:function(options) {// 横タイプ ////////////////////////////////////////
			$('dl.svg_acdn_side dd:not(:first)').css("width", "0px");
			$('dl.svg_acdn_side dt:first span').addClass("active");
			$('dl.svg_acdn_side dt').click(function(){
				if($("+dd",this).css("width")=="0px"){
					$("dl.svg_acdn_side dt:has(.active) +dd").animate({"width":"0px"})
					$("+dd",this).animate({"width":"660px"});
					$("dl.svg_acdn_side dt span").removeClass("active");
					$('span', this).addClass("active");
				}
			}).mouseover(function(){
				$('span', this).addClass("ov");
			}).mouseout(function(){
				$('span', this).removeClass("ov");
			});
		},



////////////////////////////////////////////////////
//
//　MODAL WINDOW の制御
//
////////////////////////////////////////////////////
		modalWindow:function(options) {
			$('ul#mdlw_list li').each(function(){
				$(this).children('a').addClass('mdlw');
			});

			var extension = $.extend({
				kind: 'a[href$=".jpg"], a[href$=".gif"], a[href$=".png"], a[href$=".bmp"], a[href$=".html"], a[href$=".htm"]'
			});

			$(extension.kind).each(function(){
				var ultimate = $(this).attr('href');

				$('a.mdlw').click(function(){
					if(ultimate.match(/.(jpg|gif|png|bmp)$/)){
						if(document.getElementById("MDL_overlay") === null){
								$('html').css('overflow','hidden');
								$('body').append('<div id="MDL_overlay"></div>');
								$("#MDL_overlay").click(MDL_remove);

								if($.browser.msie && $.browser.version < 7){
									$('body','html').css({height: '100%', width: '100%'});
									$('#MDL_overlay').css('position','absolute')
													 .css('top',$(document).scrollTop());
								}
						}
						if(document.getElementById("MDL_window") === null){
								$('body').append('<div id="MDL_window"><img src="img/ph01.jpg" alt="" /></div>');

								if($.browser.msie && $.browser.version < 7){
									$('#MDL_window').css('position','absolute')
													.css('top',($(document).scrollTop() + $(window).height()/2) + "px");
								}
						}
						$('#MDL_overlay').show();
						$('#MDL_window').slideDown('normal').html('<a href="javascript:void(0);" id="MDL_close">閉じる</a><img src="' + $(this).attr('href') + '" />');
						$('#MDL_close').click(MDL_remove);
						return false;
					} else if(ultimate.match(/.(html|htm)$/)) { //リンク先がHTMLファイルだった場合
/*
						if(document.getElementById("MDL_html") === null){
								$('body').append('<div id="MDL_overlay"></div>');
								$("#MDL_overlay").click(MDL_remove);
								$('html').css('overflow','hidden');

								if($.browser.msie && $.browser.version < 7){
									$('body','html').css({height: '100%', width: '100%'});
									$('#MDL_overlay').css('position','absolute')
													 .css('top',$(document).scrollTop());
								}
						}
						if(document.getElementById("MDL_window") === null){
								$('body').append('<div id="MDL_window"><a href="modal.html"></a></div>');

								if($.browser.msie && $.browser.version < 7){
									$('#MDL_window').css('position','absolute')
													.css('top',($(document).scrollTop() + $(window).height()/2) + "px");
								}
						}
						$('#MDL_overlay').show();
						$('#MDL_window').slideDown('normal').html('<a href="javascript:void(0);" id="MDL_close">閉じる</a><a href="' + $(this).attr('href') + '" />');
						$('#MDL_close').click(MDL_remove);
						return false;
*/
					};
				});
			});
			return this;

			function MDL_remove() {
				if($.browser.msie && $.browser.version < 7){
					$("body","html").css({height: "auto", width: "auto"});
				};
				$('#MDL_window').slideUp('normal');
				$('#MDL_overlay').fadeOut('slow');
				$('html').css('overflow','');
			};
		},



////////////////////////////////////////////////////
//
//　RADIUS [CSS ONLY 角丸]
//
////////////////////////////////////////////////////
		cssRadius:function(options) {
			$('.radius').prepend('<span class="rd-head"><span class="rd1"></span><span class="rd2"></span><span class="rd3"></span><span class="rd4"></span><span class="rd5"></span></span>');
			$('.radius').append('<span class="rd-bottom"><span class="rd6"></span><span class="rd7"></span><span class="rd8"></span><span class="rd9"></span><span class="rd0"></span></span>');
		}



////////////////////////////////////////////////////
////////////////////////////////////////////////////
	}; //$.svg
	$(function() {
		$.svg.basic();
		$.svg.inputFocus();
		$.svg.imgRollover();
		$.svg.pageScroll();
		$.svg.dropDown();
		$.svg.tabPanel();
		$.svg.accordion();
		$.svg.accordionSide();
		$.svg.modalWindow();
		$.svg.cssRadius();
	});
})(jQuery);
