/*
 * jQuery plugin 
 * adds class that works as :hover,:active,:focus,:target
 * to specific elements
 */
jQuery.fn.sfToggle = function() {
	jQuery(this).toggle(
		function() {jQuery(this).addClass("sfToggle");},
		function() {jQuery(this).removeClass("sfToggle");}
	)
	return this
}

jQuery.fn.sfHover = function() {
	jQuery(this).hover(
		function() {jQuery(this).addClass("sfHover");},
		function() {jQuery(this).removeClass("sfHover");}
	)
	return this
}
jQuery.fn.sfFocus = function() {
	jQuery(this).each(function(i) {
		jQuery(this).bind("focus", function() {jQuery(this).addClass('sfFocus');});
		jQuery(this).bind("blur", function() {jQuery(this).removeClass('sfFocus');});
	});
	return this;
}
jQuery.fn.sfActive = function() {
	jQuery(this).each(function(i) {
		jQuery(this).mousedown (function() {jQuery(this).addClass('sfActive');})
		jQuery(this).mouseup (function() {$(this).removeClass('sfActive');})
	});
	return this;
}
jQuery.fn.sfTarget = function() {
	jQuery(this).each(function(i) {
		jQuery(this).click(
			function() {
				jQuery(".sfTarget").removeClass('sfTarget');
				elem = jQuery(this).attr("href");
				if(elem) {jQuery(elem).addClass('sfTarget');}
				return this
			}
		)
	});
	return this;
}

// add tags here

$(document).ready(function() {


	$('input[type="text"]').sfFocus();
	$('input[type="password"]').sfFocus();
	$('textarea').sfFocus();

	//ul li:first-child
	$("ul").each(function(){$( $(this).children()[0]).addClass('fchild');});

	//dl dt:first-child
	$('dl').each(function(){$( $(this).children()[0]).addClass('noBorder');});

	//dl dd:first-child
	$('dl').each(function(){$( $(this).children()[1]).addClass('noBorder');});

	//itemList
	$('#itemList > ul li.menuBox dl.headline').click(function(){$(this).next().slideToggle('fast');});
	$("ul.itemList").each(function(){$( $(this).children()[0]).addClass('fchild');});
	$("ul.itemList li.menuBox:last").addClass("lchild");
	$("ul.cate2").each(function(){$( $(this).children()[0]).addClass('fchild');});
	$('dl.headline').sfHover();




});



$(function(){
/*	ラベル処理
------------------------------------------- */
	if(jQuery.browser.msie){	//　IEのlabel内の画像対応
		$('label img').click(function(){
			var target = $(this).parents('label');
			var jumpEle = target.attr('for');
			$('#'+jumpEle).focus();
		});
		
	}else if(jQuery.browser.safari){	//	Safariのlabelタグ対応
		$('label').click(function(){
			var target = $(this);
			var jumpEle = target.attr('for');
			$('#'+jumpEle).focus();
		}).hover(function(){
			$(this).css('cursor','pointer');
		},function(){
			$(this).css('cursor','default');
		});
	}
});