/* common.js
========================================================
URLを確認

 * yuga.js
----------------------------------------------- 
 *
 * yuga.js 0.3.0
 * Copyright (c) 2007 Kyosuke Nakamura (kyosuke.jp)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 *
----------------------------------------------- */


/* common.js内で使っているfunction群 */
var common = {
	// imageのプリローダー
	preloader: {
		loadedImages: [],
		load: function (url){
			var img = this.loadedImages;
			var l = img.length;
			img[l] = new Image();
			img[l].src = url;
		}
	},
	// URIを解析したオブジェクトを返すfunction
	URI: function(s){
		this.originalPath = s;
		
		//絶対パスを取得
		this.getAbsolutePath = function(path){
			var img = new Image();
			img.src = path;
			path = img.src;
			img.src = '#';
			return path;
		};
	
		this.absolutePath = this.getAbsolutePath(s);
	
		//同じ文書にリンクしているかどうか
		this.isSelfLink = (this.absolutePath == location.href);
	
		//絶対パスを分解
		var a = this.absolutePath.split('://');
		this.schema = a[0];
		var d = a[1].split('/');
		this.host = d.shift();
		var f = d.pop();
		this.dirs = d;
		this.file = f.split('?')[0].split('#')[0];
		var fn = this.file.split('.');
		this.fileExtension = (fn.length == 1) ? '' : fn.pop();
		this.fileName = fn.join('.');
		var fq = f.split('?');
		this.query = (fq[1]) ? fq[1].split('#')[0] : '';
		var ff = f.split('#');
		this.fragment = (ff[1]) ? ff[1].split('?')[0] : '';	
	}
};

$(function(){
	
	//class="notover"と、エントリ本文中の画像以外はロールオーバーを設定（src属性を_on付きのものに差し替える）
	$('a img.over').each(function(){
		this.originalSrc = $(this).attr('src');
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
		common.preloader.load(this.rolloverSrc);
	}).hover(function(){
		$(this).attr('src',this.rolloverSrc);
	},function(){
		$(this).attr('src',this.originalSrc);
	});

	//現在のページへのリンク （src属性を_on付きのものに差し替える）
	/*$('a[@href]').each(function(){
		var href = new common.URI(this.getAttribute('href'));
		if (href.isSelfLink && !href.fragment) {
			$(this).addClass('current');
			//img要素が含まれていたら現在用画像（_cr）に設定
			$(this).find('img').each(function(){
				//ロールオーバーが設定されていたら削除
				$(this).unbind('mouseover');
				$(this).unbind('mouseout');
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_on$1");
				$(this).attr('src',this.currentSrc);
			});
		}
	});*/

	// target属性を使わずに外部リンクを別ウィンドウ表示 MovableType対応版
$(document).ready( function () {
	$('a[@href^="http"]').not('[@href^="http://www.loco.jp/"]').click(function(){
	window.open(this.href, '');
	return false;
	});
	$('a[@href^="http"]').not('[@href^="http://www.loco.jp/"]').addClass("exLink");
});


/* //画像へ直リンクするとthickboxで表示(thickbox.js利用)
	tb_init('a[@href$=".jpg"], a[@href$=".gif"], a[@href$=".png"]'); */

	//奇数、偶数を自動追加
	$('ul').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});
	$('table').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');
	});
	
	//:first-child, :last-childをクラスとして追加
	$(':first-child').addClass('firstChild');
	$(':last-child').addClass('lastChild');
	
	//css3の:emptyをクラスとして追加
	$(':empty').addClass('empty');


});

















/**
 * jQuery (PNG Fix)
 * Microsoft Internet Explorer 24bit PNG Fix
 *
 * The MIT License
 * 
 * Copyright (c) 2007 Paul Campbell (pauljamescampbell.co.uk)
 * 
 * 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.
 *
 * @param		Object
 * @return		Array
 */
(function($) {
	
	$.fn.pngfix = function(options) {
		
		// ECMA scope fix
		var elements 	= this;
		// Plug-in values
		var settings 	= $.extend({
			imageFixSrc: 	false
		}, options);
		
		if(!$.browser.msie || ($.browser.msie &&  $.browser.version >= 7)) {
			return(elements); // Kill
		}
		
		function setFilter(el, path, mode) {
			// Apply filter to element, setting the MSDN properties:
			//		:src
			//		:enabled
			//		:sizingMethod  
			var fs 			= el.attr("filters");
			var alpha 		= "DXImageTransform.Microsoft.AlphaImageLoader";
			if (fs[alpha]) {
				with (fs[alpha]) { 
					enabled = true;
					src = path; 
					sizingMethod = mode;
			 	}
			} else {
				el.css("filter", 'progid:' + alpha + '(enabled="true", sizingMethod="' + mode + '", src="' + path + '")');			
			}
		}
		
		function forceWidth(el) {
			if(el.css("width") == "auto" & el.css("height") == "auto") {
				// Only force width of element if it's set to auto
				el.css("width", el.attr("offsetWidth") + "px");
			}
		}
		
		// __APPLY__
		
		return(
			elements.each(function() {
				
				var el = $(this);
				
				if(el.attr("tagName").toUpperCase() == "IMG" && (/.png"?$/).test(el.attr("src"))) {
					
					if(!settings.imageFixSrc) {
						// Wrap the <img> in a <span> then apply style/filters, 
						// removing the <img> tag from the final render 
						el.wrap("<span></span>");
						var par = el.parent();
						par.css({
							height: 	el.height(),
							width: 		el.width(),
							display: 	"inline-block"
						});
						setFilter(par, el.attr("src"), "scale");
						el.remove();
					} else if((/.gif$/).test(settings.imageFixSrc)) {
						// Replace the current image with a transparent GIF
						// and apply the filter to the background of the 
						// <img> tag (not the preferred route)
						forceWidth(el);
						setFilter(el, el.attr("src"), "image");
						el.attr("src", settings.imageFixSrc);
					}
					
				} else {
					var bg = el.css("backgroundImage");
					var matches = bg.match(/^url\("(.*)"\)$/);
					if(matches.length) {
						// Elements with a PNG as a backgroundImage have the
						// filter applied with a sizing method relevant to the 
						// background repeat type
						forceWidth(el);
						el.css("backgroundImage", "none");
						
						// Restrict scaling methods to valid MSDN defintions (or one custom)
						if(el.css("backgroundRepeat").indexOf("repeat") > -1) {
							var sc = settings.repeatMethod == "repeat" ? "repeat" : "scale";
						} else {
							var sc = "crop";
						}
						setFilter(el, matches[1], sc);
						
						// IE peek-a-boo for internal links
						el.find("a").each(function() {
							$(this).css("position", "relative");
						});
					}
				}
				
				
			}) // __END__
		);
	}

})(jQuery)




$(document).ready(function() {
$("img[@src$=png]").pngfix();
});









/*
 * IE PNG Fix v1.4
 * Copyright (c) 2006 Takashi Aida http://www.isella.com/aod2/
 * cssのPNGファイルをバックグラウンド指定してるクラスやIDに一行追加
 */
// IE5.5+ PNG Alpha Fix v1.0RC4
// (c) 2004-2005 Angus Turnbull http://www.twinhelix.com

// This is licensed under the CC-GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

if (typeof IEPNGFIX == 'undefined') {
//--============================================================================

var IEPNGFIX = {
	blank:  'http://www.isella.com/aod2/images/blank.gif',
	filter: 'DXImageTransform.Microsoft.AlphaImageLoader',

	fixit: function (elem, src, method) {
		if (elem.filters[this.filter]) {
			var filter = elem.filters[this.filter];
			filter.enabled = true;
			filter.src = src;
			filter.sizingMethod = method;
		}
		else {
			elem.style.filter = 'progid:' + this.filter +
				'(src="' + src + '",sizingMethod="' + method + '")';
		}
	},

	fixwidth: function(elem) {
		if (elem.currentStyle.width == 'auto' &&
			elem.currentStyle.height == 'auto') {
			elem.style.width = elem.offsetWidth + 'px';
		}
	},

	fixchild: function(elem, recursive) {
		if (!/MSIE (5\.5|6\.|7\.)/.test(navigator.userAgent)) return;

		for (var i = 0, n = elem.childNodes.length; i < n; i++) {
			var childNode = elem.childNodes[i];
			if (childNode.style) {
				if (childNode.style.position) {
					childNode.style.position = childNode.style.position;
				}
				else {
					childNode.style.position = 'relative';
				}
			}
			if (recursive && childNode.hasChildNodes()) {
				this.fixchild(childNode, recursive);
			}
		}
	},

	fix: function(elem) {
		if (!/MSIE (5\.5|6\.|7\.)/.test(navigator.userAgent)) return;

		var bgImg =
			elem.currentStyle.backgroundImage || elem.style.backgroundImage;

		if (elem.tagName == 'IMG') {
			if ((/\.png$/i).test(elem.src)) {
				this.fixwidth(elem);
				this.fixit(elem, elem.src, 'scale');
				elem.src = this.blank;
				elem.runtimeStyle.behavior = 'none';
			}
		}
		else if (bgImg && bgImg != 'none') {
			if (bgImg.match(/^url[("']+(.*\.png)[)"']+$/i)) {
				var s = RegExp.$1;
				this.fixwidth(elem);
				elem.style.backgroundImage = 'none';
				this.fixit(elem, s, 'scale'); // crop | image | scale

				if (elem.tagName == 'A' && elem.style) {
					if (!elem.style.cursor) {
						elem.style.cursor = 'pointer';
					}
				}

				this.fixchild(elem);
				elem.runtimeStyle.behavior = 'none';
			}
		}
	},

	hover: function(elem, hvImg) {
		var bgImg = elem.style.backgroundImage;

		if (!bgImg && elem.currentStyle) bgImg = elem.currentStyle.backgroundImage;

		if (elem.tagName == 'IMG' && hvImg) {
			var image = elem.src;
			elem.onmouseover = function() {
				elem.src = hvImg;
				IEPNGFIX.fix(elem);
			};
			elem.onmouseout = function() {
				elem.src = image;
				IEPNGFIX.fix(elem);
			};
		}
		else if (bgImg && bgImg != 'none' && hvImg) {
			elem.onmouseover = function() {
				elem.style.backgroundImage = 'url(' + hvImg + ')';
				IEPNGFIX.fix(elem);
			};
			elem.onmouseout = function() {
				elem.style.backgroundImage = bgImg;
				IEPNGFIX.fix(elem);
			};
		}

		IEPNGFIX.fix(elem);
	}
};

//--============================================================================
} // end if (typeof IEPNGFIX == 'undefined')










/* アコーディオン */

$(document).ready(function() {
	$("dl.qa dt").hover(function(){
		$(this).css("cursor","pointer"); 
	},function(){
		$(this).css("cursor","default");
		});
	$("dl.qa dd").css("display","none");
	$("dl.qa dt").click(function(){
		$(this).next().slideToggle("normal");
		//$(this).next().css("display","block");
	});
});	









$(function(){
	$('ul#dropDown li ul').css({display:'none'});
	
	$('ul#dropDown li').hover(
		function(){ // on
			$(this).find('ul').css({display:'block'});
		},function(){ // out
			$(this).find('ul').css({display:'none'});
		});
});




