$('document').ready(function(){

	//---------------- input area ------------------
	$("input.sample").val("サイト内検索")
	   .css("color","#999");
	$("input.sample").focus(function(){
		if(this.value == "サイト内検索"){
			$(this).val("").css("color","#333");
		}
	});
	$("input.sample").blur(function(){
		if(this.value == ""){
			$(this).val("サイト内検索")
			     .css("color","#999");
		}
		if(this.value != "サイト内検索"){
			$(this).css("color","#333");
		}
	});
	
	//---------------- current location ------------------
	var current_navi = function(ele){
		$(ele).attr({'src':$(ele).attr('src').replace('.jpg','_c.jpg')});
		$(ele).removeClass('over');
	};
	if(location.href.length - location.hostname.length == 8){
		current_navi('#navi_home');
	}else if(location.href.indexOf('aboutus') > -1){current_navi('#navi_aboutus');
	}else if(location.href.indexOf('company') > -1){current_navi('#navi_company');
	}else if(location.href.indexOf('ir') > -1){current_navi('#navi_ir');
	}else if(location.href.indexOf('whatsnew') > -1){current_navi('#navi_whatsnew');
	}else if(location.href.indexOf('contact') > -1){current_navi('#navi_contact');
	}
		
	
	//---------------- roll over ------------------




  var conf = {
    className : 'over',
    postfix : '_o'
  };
  $('.'+conf.className).each(function(){
    this.originalSrc = this.src;
    this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, conf.postfix+"$1");
    preloadImage(this.rolloverSrc);
  }).hover(function(){
    this.src = this.rolloverSrc;
  },function(){
    this.src = this.originalSrc;
  });

	//------------- font size ---------------
	var change_lang = function(ele){
		$(ele).siblings().each(function(){
			$(this).children('img').attr({'src':$(this).children('img').attr('src').replace('_c.jpg','.jpg')});
		});
		$(ele).children('img').attr({'src':$(ele).children('img').attr('src').replace('_c.jpg','.jpg').replace('.jpg','_c.jpg')});
	};

	if($.cookie('font-size')){
		change_lang($('#font_'+$.cookie('font-size')).get(0));
		if($.cookie('font-size') == 's'){$('body').css({'font-size':'10px'})}
		if($.cookie('font-size') == 'm'){$('body').css({'font-size':'12px'})}
		if($.cookie('font-size') == 'l'){$('body').css({'font-size':'14px'})}
	}else{
		change_lang($('#font_m'));
	}

	$('#font_s').click(function(){
		$('body').css({'font-size':'10px'});
		$.cookie('font-size','s', {path: '/'});
		change_lang(this);
	});
	$('#font_m').click(function(){
		$('body').css({'font-size':'12px'});
		$.cookie('font-size','m', {path: '/'});
		change_lang(this);
	});
	$('#font_l').click(function(){
		$('body').css({'font-size':'14px'});
		$.cookie('font-size','l', {path: '/'});
		change_lang(this);
	});


	$('#font li img').css({'cursor':'pointer'});
	// class="click" をクリックしたときの処理
	$('.click').click(tabClick);
	
	// id="left"のimgをtab_01_c.jpgに指定する。
    $('#left').attr('src', [location.href, '/index_img/tab01_c.jpg'].join(''));


});

// class="click" をクリックしたときの処理
var tabClick = function(){
	$(this).parent().parent().siblings().children().children('img').each(function(){
		$(this).click(tabClick).hover(tabHover, tabHoverOut);
		var imgsrc = $(this).attr('src');
		if (imgsrc.substr(imgsrc.lastIndexOf('.')-2, 1) == '_') {
			var imgsrc_o = imgsrc.substr(0, imgsrc.lastIndexOf('.')-2) + imgsrc.substring(imgsrc.lastIndexOf('.'));
			$(this).attr('src',imgsrc_o);
		}
	});
	$(this).unbind('mouseenter', tabHover);
	$(this).unbind('mouseleave', tabHoverOut);
	$(this).unbind('click', tabClick);
	var src = $(this).attr('src');
	if (src.substr(src.lastIndexOf('.')-2, 1) == '_') {
		var src_o = src.substr(0, src.lastIndexOf('.')-2) + '_c'+src.substring(src.lastIndexOf('.'));
	} else {
		var src_o = src.substr(0, src.lastIndexOf('.')) + '_c'+src.substring(src.lastIndexOf('.'));
	}
	$(this).attr('src',src_o);
	// 表示切り替え処理を記述
};

var tabHover = function(){
	var src = $(this).attr('src');
	var src_o = src.substr(0, src.lastIndexOf('.')) + '_o' +src.substring(src.lastIndexOf('.'));
	$(this).attr('src',src_o);
};

var tabHoverOut = function(){
	$(this).click(tabClick);
	var src = 	$(this).attr('src');
	var src = src.substr(0, src.lastIndexOf('.')-2)+src.substring(src.lastIndexOf('.'));$(this).attr('src',src);
};


//プリロード
preloadedImages = [];
function preloadImage(url){
	var p = preloadedImages;
	var l = p.length;
	p[l] = new Image();
	p[l].src = url;
}


/**
 * 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
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        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(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        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 { // only name given, get cookie
        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]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/**
 * 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
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        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(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        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 { // only name given, get cookie
        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]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
