/*------------------------------
font size
------------------------------*/
/**
 * 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
 *
 */
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;
    }
};
$(function(){//common function start
					 
    $(function(){
			var ChildElements=$('#wrapper'+','+'footer');
			var fontSizeSet =100;
			
			if($.cookie('fontSize') == null) { 
				$(ChildElements).css('font-size',fontSizeSet+"%");
				$('#fontS a').addClass('current');
			}
			else if($.cookie('fontSize')){
				fontSizeSet = $.cookie('fontSize');
				$(ChildElements).css('font-size',fontSizeSet+"%");
				
				switch(fontSizeSet){
				case '100':
					$('#fontL a').removeClass('current');
					$('#fontS a').addClass('current');
					break;
				case '117':
					$('#fontS a').removeClass('current');
					$('#fontL a').addClass('current');
					break;
				};
			}
			$('#fontSize dd').click(function(){
				var size =$(this).attr('id');		
				switch(size){
				case 'fontS':
					$(fontSizeSet = 100);
					break;
				case 'fontL':
					$(fontSizeSet = 117);
					break;
				};
				$(ChildElements).css('font-size',fontSizeSet+"%");
				$('#fontSize dd a').removeClass('current');
				$(this).children('a').toggleClass('current');
				$.cookie('fontSize', fontSizeSet,{ expires: 7 , path:'/'});
			});
		});
/*------------------------------
roll over
------------------------------*/
    $.fn.rollover = function(postfix) {
        postfix = postfix || '_on';
        return this.not('[src*="'+ postfix +'."]').each(function() {
            var img = $(this);
            var src = img.attr('src');
            var src_on = [
                src.substr(0, src.lastIndexOf('.')),
                src.substring(src.lastIndexOf('.'))
            ].join(postfix);
            img.hover(
                function() {
                    img.attr('src', src_on);
                },
                function() {
                    img.attr('src', src);
                }
            );
        });
    };
		$('.on').rollover();
/*------------------------------
header nav
------------------------------*/
    var currentPath = location.pathname;
    var pathSlash = currentPath;
    str =pathSlash;
    $('#header .nav li').each(function(){
    var global = $(this).find ('a').attr('href');
    if(global && global.indexOf("http")==0){
        global = global.replace(/https?:\/\/[^\/]+/, '');
        c = global.indexOf("/",1)
        global = global.substring(0,c)
    }

		if(str.indexOf(global)==0){
			$(this).toggleClass('current selectedLava');
			if($(this).parent().parent().hasClass('current')){
				$(this).parent().parent().removeClass('current');
			}
		}
	});

    $(".lavaLamp").lavaLamp({ fx: "easeOutCubic", speed: 400 })
/*------------------------------
sNav
------------------------------*/
	$('#navIr ul ul').hide();
	$('#aside .nav li a').each(function(){
		var dir = $(this).attr('href');
		
		if($(location).attr('href').match(dir)) {
			$(this).addClass('current')
		}
	});
/*------------------------------
scrollto
------------------------------*/
		$('a[href*=#header]').click(function() {
			if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
				var target = $(this.hash);
				target = target.length && target;
				if (target.length) {
					var sclpos = 30;
					var scldurat = 1200;
					var targetOffset = target.offset().top - sclpos;
					$('html,body')
						.animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
					return false;
				}
			}
		});
/* ------------------------------
modSelecter
------------------------------ */
    $('div.modSelecter').each(function(){
        var hash = window.location.hash;
        var self = $(this);
        var select = $('a.select', self);
        var pulldown = $('.pulldown', self);
        var data = $('input:hidden', self);
        var out =$("#" + self.attr("id") + "_value");
        var select_value = $('span', select);
                
        select.click(function(e){
            $('.pulldown').hide();
            pulldown.show();
            
            $(this).addClass('select_focus');
            
            e.stopPropagation();
            return false;
        });
        
        var clickFunc = function(e, __self){
            if(!__self){
                var __self = this;
            };
            var value = $(__self).attr('href').replace('#', '');
            if(value.indexOf("/")== 0){
                return true;
            }
            var text = $(__self).text();
            
            select_value.text(text);
            data.val(value);
            if(out){
                out.val(value);
            }
            $('a.selected',pulldown).removeClass('selected');
            $('a.select_focus').removeClass('select_focus');
            $(__self).addClass('selected');
            pulldown.hide();
            
            return false;
        };
        
        $('a', pulldown).click(clickFunc);
        
        $('body').click(function(){
            $('a.select_focus').removeClass('select_focus');
            $('.pulldown').hide();
        });
        
        // URLハッシュの値でセレクトボックスを選択させる
        if(hash){
            clickFunc(null, $("[href=\""+hash+"\"]"), self);
        }
    });

});


$(function (){
var node_a = document.getElementsByTagName('a');
for (var i in node_a) {
if(node_a[i].className == 'popup_fixsize'){
node_a[i].onclick = function() {
return winOpen(this.href, this.rel)
};
}
}
});

function winOpen(url, rel) {
var split = rel.split(',') ;
window.open(
url,'popup',
'width='+ split[0] +',height='+ split[1] +',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
return false;
};

