//スプラッシュFLASH連携用：終了前処理
var externalBeforeSplashRemove;
//スプラッシュFLASH連携用：終了後処理
var externalAfterSplashRemove;

(function($){

	var options = {
		//メインコンテンツのid
		mainContentsId: "wrapper_outer",
		//最低幅
		minWidth: 1024,
		//最低高さ
		minHeight: 425,
		//スプラッシュの枠(外側)のid
		splashBaseId: "splash_base",
		//スプラッシュの枠(内側)のid ここにswfが読み込まれる
		splashContentsId: "splash_contents",
		//cookieをチェックするかどうか
		checkCookie: true,
		//保存するcookieの名前
		cookieKey : "splashed",
		//cookieの値
		cookieValue: 1,
		//cookie保存オプション
		cookieOptions:  { expires: null },
		//swf
		swfPath: "./swf/splash.swf",
		swfVersion: "9.0.0",
		swfExpressInstall: "",
		swfFlashvars: {},
		swfParams: {
			menu: "false",
			wmode: "transparent",
			allowScriptAccess : "always"
		},
		swfAttributes: {}
	}
	
	//メインコンテンツを非表示にしておく
	document.write('<style type="text/css"> #' + options.mainContentsId + '{ display: none; }</style>');
	
	//スプラッシュを表示
	function showSplash() {
		//cookieがセットされていれば終了
		if(options.checkCookie && $.cookie(options.cookieKey) == options.cookieValue) {
			return false;
		}
		
		//cookieをセット
		$.cookie(options.cookieKey, options.cookieValue, options.cookieOptions);
		
		//html, bodyのjQueryオブジェクト
		var $html = $("html");
		var $body = $("body");
		
		//メインコンテンツを非表示
		$mainContents = $("#" + options.mainContentsId).hide();
				
		//FLASH読み込み用の外枠を生成、全画面表示のためCSS調整しbodyに追加
		var $splashBase = $('<div id="' + options.splashBaseId + '">').css({
			height: "100%",
			width: "100%",
			position: "absolute",
			left: 0,
			top: 0,
			backgroundColor: "#e1dfca"
		}).appendTo($body);
	
		//FLASH読み込み用の内枠を生成、外枠に追加
		var $splashContents = $('<div id="' + options.splashContentsId + '">').appendTo($splashBase);
		
		//swf読み込み
		swfobject.embedSWF(
			options.swfPath,
			options.splashContentsId,
			"100%",
			"100%",
			options.swfVersion,
			options.swfExpressInstall,
			options.swfFlashvars,
			options.swfParams,
			options.swfAttributes
		);
		//swffit
		swffit.fit(options.splashContentsId, options.minWidth, options.minHeight);
		
		//スプラッシュ終了前処理
		externalBeforeSplashRemove = function() {
			//外枠の背景色を解除、コンテンツ表示
			$splashBase.css("background", "none");
			$mainContents.show();
			
			//スクロールバーの位置
			$html.scrollTop(0).scrollLeft(0);
		}
		
		//スプラッシュ終了後処理
		externalAfterSplashRemove = function() {
			//swffitを解除
			swffit.stopFit();

			//FLASHエリアを除去(removeするとIE7,8でエラー)
			$splashBase.hide();
		}

		return true;
	}
	
	//DOMReady
	$(function() {
		var splashed = false;
		//Flashバージョンが満たされて入る場合に実行
		if(swfobject && swfobject.hasFlashPlayerVersion(options.swfVersion)){
			//スプラッシュを表示
			splashed = showSplash();
		}

		if(!splashed){
			$("#" + options.mainContentsId).show();
		}
	});
})(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
 */
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;
    }
};




/* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-12-20 08:46:55 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4259 $
 *
 * Version: 1.2
 *
 * Requires: jQuery 1.2+
 */

(function($){
	
$.dimensions = {
	version: '1.2'
};

// Create innerHeight, innerWidth, outerHeight and outerWidth methods
$.each( [ 'Height', 'Width' ], function(i, name){
	
	// innerHeight and innerWidth
	$.fn[ 'inner' + name ] = function() {
		if (!this[0]) return;
		
		var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
		    borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
		
		return this.is(':visible') ? this[0]['client' + name] : num( this, name.toLowerCase() ) + num(this, 'padding' + torl) + num(this, 'padding' + borr);
	};
	
	// outerHeight and outerWidth
	$.fn[ 'outer' + name ] = function(options) {
		if (!this[0]) return;
		
		var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
		    borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
		
		options = $.extend({ margin: false }, options || {});
		
		var val = this.is(':visible') ? 
				this[0]['offset' + name] : 
				num( this, name.toLowerCase() )
					+ num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width')
					+ num(this, 'padding' + torl) + num(this, 'padding' + borr);
		
		return val + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
	};
});

// Create scrollLeft and scrollTop methods
$.each( ['Left', 'Top'], function(i, name) {
	$.fn[ 'scroll' + name ] = function(val) {
		if (!this[0]) return;
		
		return val != undefined ?
		
			// Set the scroll offset
			this.each(function() {
				this == window || this == document ?
					window.scrollTo( 
						name == 'Left' ? val : $(window)[ 'scrollLeft' ](),
						name == 'Top'  ? val : $(window)[ 'scrollTop'  ]()
					) :
					this[ 'scroll' + name ] = val;
			}) :
			
			// Return the scroll offset
			this[0] == window || this[0] == document ?
				self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
					$.boxModel && document.documentElement[ 'scroll' + name ] ||
					document.body[ 'scroll' + name ] :
				this[0][ 'scroll' + name ];
	};
});

$.fn.extend({
	position: function() {
		var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
		
		if (elem) {
			// Get *real* offsetParent
			offsetParent = this.offsetParent();
			
			// Get correct offsets
			offset       = this.offset();
			parentOffset = offsetParent.offset();
			
			// Subtract element margins
			offset.top  -= num(elem, 'marginTop');
			offset.left -= num(elem, 'marginLeft');
			
			// Add offsetParent borders
			parentOffset.top  += num(offsetParent, 'borderTopWidth');
			parentOffset.left += num(offsetParent, 'borderLeftWidth');
			
			// Subtract the two offsets
			results = {
				top:  offset.top  - parentOffset.top,
				left: offset.left - parentOffset.left
			};
		}
		
		return results;
	},
	
	offsetParent: function() {
		var offsetParent = this[0].offsetParent;
		while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static') )
			offsetParent = offsetParent.offsetParent;
		return $(offsetParent);
	}
});

function num(el, prop) {
	return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;
};

})(jQuery);
