﻿/**
 * 
 * Progression
 * 
 * @author Copyright (C) 2007-2008 taka:nium
 * @version 3.1.0
 * @see http://progression.jp/
 * 
 * Developed by taka:nium
 * @see http://nium.jp/
 * 
 * Progression is (C) 2007-2008 taka:nium and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */

var progression, Progression, SWFObject;
( function() {
	progression = function() {};
	
	var $ = function( id ) { return document.getElementById( id ); };
	var $t = function( tagName ) { return document.getElementsByTagName( tagName ); };
	var $i = function( value, defaultValue ) {
		switch ( value ) {
			case null		:
			case undefined	: { return defaultValue; }
		}
		return value;
	};
	
	var _id = "external_flashcontent";
	var _config = {
		url					:"preloader.swf",
		replaceElementId	:"attention",
		width				:640,
		height				:480,
		adjustHorizontal	:false,
		adjustVertical		:false,
		centering			:true,
		version				:"9.0.45",
		useExpressInstall	:true,
		flashvars			:{},
		params				:{
			bgcolor				:"#FFFFFF",
			wmode				:"window",
			allowfullscreen		:true,
			allowscriptaccess	:"samedomain"
		},
		attributes			:{}
	};
	
	var _initialize = function() {
		( ( $( "disabled_javascript" ) || {} ).style || {} ).display = "none";
		
		if ( SWFForceSize ) {
			var fs = new SWFForceSize( $( "flashcontent" ), _config.width, _config.height );
			fs.onLoadDiv();
		}
	};
	
	progression.embedSWF = function( config ) {
		if ( !swfobject ) { return; }
		
		var oc = _config;
		var op = oc.params;
		var oa = oc.attributes;
		
		var tc = config;
		var tp = tc.params;
		var ta = tc.attributes;
		
		oc.url = $i( tc.url, oc.url );
		oc.replaceElementId = $i( tc.replaceElementId, oc.replaceElementId );
		oc.width = $i( tc.width, oc.width );
		oc.height = $i( tc.height, oc.height );
		oc.adjustHorizontal = $i( tc.adjustHorizontal, oc.adjustHorizontal );
		oc.adjustVertical = $i( tc.adjustVertical, oc.adjustVertical );
		oc.centering = $i( tc.centering, oc.centering );
		oc.version = $i( tc.version, oc.version );
		oc.useExpressInstall = $i( tc.useExpressInstall, oc.useExpressInstall );
		oc.flashvars = $i( tc.flashvars, oc.flashvars );
		op.bgcolor = $i( tp.bgcolor, op.bgcolor );
		op.wmode = $i( tp.wmode, op.wmode );
		op.allowfullscreen = $i( tp.allowfullscreen, op.allowfullscreen );
		op.allowscriptaccess = $i( tp.allowscriptaccess, op.allowscriptaccess );
		
		oa.id = _id;
		oa.name = _id;
		
		var centeringX = ( _config.centering && !_config.adjustHorizontal );
		var centeringY = ( _config.centering && !_config.adjustVertical );
		
		var width = _config.adjustHorizontal ? "100%" : _config.width + "px";
		var height = _config.adjustVertical ? "100%" : _config.height + "px";
		var left = centeringX ? "50%" : "0";
		var top = centeringY ? "50%" : "0";
		var marginLeft = centeringX ? "-" + Math.ceil( _config.width / 2 ) + "px" : "0";
		var marginTop = centeringY ? "-" + Math.ceil( _config.height / 2 ) + "px" : "0";
		var xiURL = _config.useExpressInstall ? "contents/scripts/swfobject/expressInstall.swf" : undefined;
		
		var content = $t( "body" )[0];
		if ( content ) { content.style.background = _config.params.bgcolor; }
		else { swfobject.createCSS( "body", "background:" + _config.params.bgcolor + ";" ); }
		
		var content = $( "flashcontent" );
		if ( content ) {
			content.style.width = width;
			content.style.height = height;
			content.style.left = left;
			content.style.top = top;
			content.style.marginLeft = marginLeft;
			content.style.marginTop = marginTop;
		}
		else { swfobject.createCSS( "#flashcontent", "width:" + width + "; height:" + height + "; left:" + left + "; top:" + top + "; margin-left:" + marginLeft + "; margin-top:" + marginTop + ";" ); }
		
		swfobject.embedSWF( _config.url, _config.replaceElementId, "100%", "100%", _config.version, xiURL, _config.flashvars, _config.params, _config.attributes );
		swfobject.addLoadEvent( _initialize );
	};
	
	
	
	var _url, _version, _width, _height, _useSWFForceSize, _flashvars, _params, _attributes;
	
	Progression = function( version ) {
		( ( $( "enableJavaScript" ) || {} ).style || {} ).display = "none";
		_version = version;
		document.write( '<link rel="stylesheet" type="text/css" href="contents/styles/progression.css" />' );
	};
	Progression.prototype = {
		onLoad:function() {},
		init:function() {
			_useSWFForceSize = ( this.onLoad.toString().indexOf( "var forceSize = new SWFForceSize" ) > 0 );
			this.onLoad();
		}
	};
	
	SWFObject = function( url, id, width, height ) {
		_url = url;
		_width = width;
		_height = height;
		_flashvars = {};
		_params = {};
		_attributes = {};
	};
	SWFObject.prototype = {
		useExpressInstall:function( path ) {},
		setAttribute:function( name, value ) { _attributes[name] = value; },
		getAttribute:function( name ) { return _attributes[name]; },
		addParam:function( name, value ) { _params[name] = value; },
		getParams:function() { return _params[name]; },
		addVariable:function( name, value ) { _flashvars[name] = value; },
		getVariable:function( name ) { return _flashvars; },
		getVariables:function() { return _flashvars; },
		getVariablePairs:function() {},
		getSWFHTML:function() {},
		write:function( id ) {
			var html = $t( "head" )[0].innerHTML;
			html = html.split( " " ).join( "" ).split( "\t" ).join( "" );
			
			if ( !_useSWFForceSize ) { SWFForceSize = null; }
			
			progression.embedSWF( {
				url:_url,
				version:_version,
				width:parseInt( _width ),
				height:parseInt( _height ),
				adjustHorizontal:( _width == "100%" ),
				adjustVertical:( _height == "100%" ),
				centering:( html.indexOf( "left:50%;" ) > 0 && html.indexOf( "top:50%;" ) > 0 ),
				flashvars:{},
				params:{
					bgcolor:_params["bgcolor"],
					wmode:_params["wmode"],
					allowscriptaccess:_params["allowScriptAccess"]
				},
				attributes:{}
			} );
			return false;
		}
	};
} )();
