
/*
 * jQuery.hoverImg
 * Copyright (c) 2008 Naoki Ueno
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Date: 6/10/2008
 *
 * @id jQuery.hoverImg
 *
 * @example jQuery.hoverImg();
 *
 * @example jQuery.hoverImg({ suffix : '_on' });
 *
 */
(function(jQuery){
jQuery.fn.extend({
	hoverImg : function(settings) {
		return this.each(function() {
			settings = jQuery.extend({
				suffix : '_o'
			}, settings);
			var imgsrc = this.src;
			var dot = imgsrc.lastIndexOf('.');
			var imgsrc_on = imgsrc.substr(0, dot) + settings.suffix + imgsrc.substr(dot);
			new Image().src = imgsrc_on;
			jQuery(this).hover(
				function() { this.src = imgsrc_on; },
				function() { this.src = imgsrc; }
			);
		});
	}
});
})(jQuery);

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
(function(jQuery){
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
})(jQuery);

/******************************************************************************************************/

(function(jQuery){
jQuery(function(){
	putSizeChangeBtn();
	jQuery('#changeButton .btnover').hoverImg();
	changeFS();
});
})(jQuery);

putSizeChangeBtn = function(elemId){(function(jQuery){
var moduleHTML;
moduleHTML  = '<div id="changeButton">';
moduleHTML += '<span class="fontsize_small"><a href="javascript:void(0);"><img src="/common/images/share_font_small.gif" alt="文字の大きさ「小」" width="28" height="21" class="btnover" /></a></span>';
moduleHTML += '<span class="fontsize_medium"><a href="javascript:void(0);"><img src="/common/images/share_font_medium.gif" alt="文字の大きさ「中」" width="29" height="21" class="btnover" /></a></span>';
moduleHTML += '<span class="fontsize_large"><a href="javascript:void(0);"><img src="/common/images/share_font_big.gif" alt="文字の大きさ「大」" width="28" height="21" class="btnover" /></a></span>';
moduleHTML += '<!-- / changeButton --></div>';
jQuery('#fontTools').html(moduleHTML);
})(jQuery)};


changeFS = function(){(function(jQuery){
	if(!document.getElementById('fontTools')){ return; }
	var suffix = '_o';
	var currenrSize;
	var cookieKey = 'jpSize';
	var fontSizeObj = {
		'fontsize_small' : '100%',
		'fontsize_medium': '120%',
		'fontsize_large' : '140%'
	};
	var container = document.getElementById('container');
	var initSize = jQuery.cookie(cookieKey);
	if(!initSize){ initSize = 'fontsize_small'; }
	else if(initSize!='fontsize_small' && initSize!='fontsize_medium' && initSize!='fontsize_large'){
		initSize = 'fontsize_small';
	}
	container.style.fontSize = fontSizeObj[initSize];
	jQuery('.'+initSize).find('.btnover').attr('src', function(){
		var imgsrc = this.src;
		var dot = imgsrc.lastIndexOf('.');
		return imgsrc.substr(0, dot) + suffix + imgsrc.substr(dot);
	}).unbind('mouseover').unbind('mouseout');
	currenrSize = initSize;
	
	jQuery('#changeButton span').mousedown().click(function(){
			container.style.fontSize = fontSizeObj[this.className];
			jQuery('.'+this.className).find('.btnover').unbind('mouseover').unbind('mouseout');
			if(this.className!=currenrSize) {
				jQuery('.'+currenrSize).find('.btnover').attr('src', function(){
					var imgsrc_on = this.src;
					var regObj = new RegExp(suffix+'\.');
					return imgsrc_on.replace(regObj, '.');
				}).hoverImg();
				currenrSize = this.className;
			}
			jQuery.cookie(cookieKey, this.className, { expires: 7, path : '/' });
	});
})(jQuery)};

