/*
 * cit.js
 * 
 * 使用時は YUI Compressorで圧縮済みの cit.compressed.js を使用してください
 * java -jar yuicompressor-2.4.2.jar --charset UTF-8 -o cit.compressed.js cit.js
 *
 * @category   Car ITPack
 * @package    JavaScript
 * @author     $Author: d-watanabe $
 * @since      $Date: 2009-09-15 20:49:46 +0900 (火, 15  9月 2009) $
 * @version    $Rev: 713 $
 * @copyright  Copyright (c) 2002-2008 AIC Corporation All Rights Reserved.
 *             http://www.aic-co.jp
 * @see        YUI Compressor http://yuilibrary.com/ 
 * 
 * jQueryが必須です
 */

/**
 * load cookie plugin.
 *
 * @see        http://www.electrictoolbox.com/jquery-cookies/
 *             http://plugins.jquery.com/project/Cookie
 */
if( 'undefined' == typeof( jQuery.cookie))
{
	// load javascript (jQuery Cookie Plugin v1.0) 
	$('<script type="text/javascript" charset="utf-8" src="/js/lib/jquery.cookie.1.0.compressed.js"></script>').appendTo('head');
}

;( function($)
{
	/**
	 * cit
	 *
	 * @return jQuery
	 */
	$.fn.cit = function()
	{
		return $.extend( this, this.cit);
	};
	
	/**
	 * color switcher
	 *
	 * @param  jQuery css
	 * @param  object options
	 * @return jQuery
	 */
	$.fn.cit.color = function( css, options)
	{
		var btn = this;													// color buttons.
		var opt = $.extend({}, $.fn.cit.color.defaults, options || {});	// options.
		var scn;														// selected color name.
		function switcher()												// color switcher
		{
			// css (<link>タグ) 切り替え
			css.each( function()
			{
				$(this).attr('disabled','disabled');
				
				if( $(this).attr('href').match( scn))
				{
					$(this).removeAttr('disabled');
				}
			});
			// ボタン画像入れ替え
			btn.each(function()
			{
				if( $(this).attr('class') == scn)
				{
					$(this).css('background-image','url("/img/global/btn/color_' + $(this).attr('class') + '_on.jpg")');
				}
				else{
					$(this).css('background-image','url("/img/global/btn/color_' + $(this).attr('class') + '.jpg")');
				}
			});
		};
		
		// read cookie
		scn = $.cookie('color');
		if( ! scn){ scn = opt.color;}
		
		// init
		switcher();
		
		// set onclick event listener for color buttons.
		btn.each( function()
		{
			$(this).click( function()
			{
				scn = $(this).attr('class');
				switcher();
				$.cookie( 'color', scn, {path:'/', expires:365});
			});
		});
		
		return this;
	};
	// $.fn.cit.color default options.
	$.fn.cit.color.defaults =
	{
		color: 'blue'
	};
	
	/**
	 * font switcher
	 *
	 * @param  jQuery css
	 * @param  object options
	 * @return jQuery
	 */
	$.fn.cit.font = function( css, options)
	{
		var btn = this;													// font buttons.
		var opt = $.extend({}, $.fn.cit.font.defaults, options || {});	// options.
		var sfn;														// selected font name.
		function switcher()												// font switcher
		{
			// css (<link>タグ) 切り替え
			css.each( function()
			{
				$(this).attr('disabled','disabled');
				
				if( $(this).attr('href').match( sfn))
				{
					$(this).removeAttr('disabled');
				}
			});
			// ボタン画像入れ替え
			btn.each(function()
			{
				if( $(this).attr('class') == sfn)
				{
					$(this).css('background-image','url("/img/global/btn/font_' + $(this).attr('class') + '_on.jpg")');
				}
				else{
					$(this).css('background-image','url("/img/global/btn/font_' + $(this).attr('class') + '.jpg")');
				}
			});
		};
		
		// read cookie
		sfn = $.cookie('font');
		if( ! sfn){ sfn = opt.font;}
		
		// init
		switcher();
		
		// set onclick event listener for font buttons.
		btn.each( function()
		{
			$(this).click( function()
			{
				sfn = $(this).attr('class');
				switcher();
				$.cookie( 'font', sfn, {path:'/', expires:365});
			});
		});
		
		return this;
	};
	// $.fn.cit.font default options.
	$.fn.cit.font.defaults =
	{
		font: 'medium'
	};
// end of closure, bind to jQuery Object
})(jQuery);

