/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 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 (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
/* -----------------------------------------------------------------
- Original

+  jQuery_Auto.js
     http://sputnik.pl/code/javascript/jquery_auto

+  yuga.js
     http://kyosuke.jp/portfolio/javascript/yuga.html

+ heightLine.js
    http://blog.webcreativepark.net/2007/07/26-010338.html

----------------------------------------------------------------- */


// jQuery_Auto 0.9
// Automatic functions for webpages (using the wonderful jQuery library)

// Copyright: (c) 2006, Michal Tatarynowicz (tatarynowicz@gmail.com)
// Licenced as Public Domain (http://creativecommons.org/licenses/publicdomain/)
// $Id: jquery_auto.js 426 2006-05-06 19:54:39Z Michał $


// Initialization

$.auto = {
	init: function() {
		for (module in $.auto) {
			if ($.auto[module].init)
				$.auto[module].init();
		}
	}
};

$(document).ready($.auto.init);


// Auto-hidden elements

$.auto.hide = {
	init: function() {
		$('.noScript').hide();
	}
};


// Auto-submitting SELECTs

$.auto.submit = {
	init: function() {
		$('select.changeSubmit').bind('change', this.on_change);
	},

	on_change: function() {
		if (this.value) this.form.submit();
	}
};


// Auto-selected text in text fields after a label click

$.auto.select = {
	init: function() {
		$('label.fieldSelect').each(this.label_action);
		$('input.fieldSelect').bind('click', function(){ this.select(); });
	},

	label_action: function() {
		var field = $('#'+this.htmlFor).get(0);
		if (field && field.focus && field.select) {
			$(this).bind('click', function(){ field.focus(); field.select(); });
		}
	}
};


// Switches tabs on click
/*

$.auto.tabs = {

	init: function() {

		$('#newsArea').each(function(){
			var f = $.auto.tabs.click;
			var group = this;
			$('.tab li, li.tab', group).each(function(){
				this.group = group;
				$(this).click(f);
				$('#'+this.id+'Body').hide();
			}).filter(':first').trigger('click');
		});

	},

	click: function() {
		var tab = $('#'+this.id+'Body').get(0);
		$('.tab li, li.tab', this.group).each(function(){
			$(this).removeClass('active');
			$('#'+this.id+'Body').hide();
		});

		$(this).addClass('active');
		$(tab).show();
		this.blur();

		return false;
	}

};
*/


$(function(){
	var Tabs = $("ul.tab li a");
	var TabActive = "active";
	var TabContents = $("div#newsArea");
	$("div" , TabContents).hide();

	$(Tabs).click(function(e){
		e.preventDefault();
		$("div" , TabContents).hide();
		$($(this).attr("href")).fadeIn(100);
		$(Tabs).removeClass(TabActive);
		$(this).addClass(TabActive);
		$.cookie("contents", $(this).attr("href") , {expires: 7});
	});

	// クッキー読み込み
	var CookieName = $.cookie("contents");
	if (CookieName != null) {
		$(Tabs).removeClass(TabActive);
		$("a[href="+CookieName+"]").addClass(TabActive);
		$(CookieName).fadeIn(100);
	} else {
		$(".tab li a:first").addClass(TabActive);
		$("div:first" , TabContents).fadeIn(100);
	}
});


