﻿/**
 * 
 * Progression
 * 
 * @author Copyright (c) 2007-2008 taka:nium, supported by Spark project.
 * @version 3.0.0 Beta
 * @see http://progression.jp/
 * @see http://progression.libspark.org/
 * 
 * Developed by taka:nium
 * @see http://nium.jp/
 * 
 * Hosted by Spark project
 * @see http://www.libspark.org/
 * 
 * Progression Framework is (c) 2007-2008 taka:nium and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */

var Progression = function( targetVersion ) {
	this.targetVersion = targetVersion;
};
Progression.prototype = {
	targetVersion:null,
	
	checkVersion:function( version ) {
		var list = version.split( " " );
	    
	    var os = list[0];
	    var ver = list[1];
	    
	    var ver1 = ver.split( "," );
	    var ver2 = this.targetVersion.split( "." );
	    
	    var n1 = parseInt( ver1[0] || "0" ) - parseInt( ver2[0] || "0" );
	    var n2 = parseInt( ver1[1] || "0" ) - parseInt( ver2[1] || "0" );
	    var n3 = parseInt( ver1[2] || "0" ) - parseInt( ver2[2] || "0" );
	    var n4 = parseInt( ver1[3] || "0" ) - parseInt( ver2[3] || "0" );
	    
	    if(n1 < 0) return false;
	    if(n1 > 0) return true;
	    
	    if(n2 < 0) return false;
	    if(n2 > 0) return true;
	    
	    if(n3 < 0) return false;
	    if(n3 > 0) return true;
	    
	    if(n4 < 0) return false;
	    return true;
	},
	
	init:function() {
		var owner = this;
		var d = document;
		var content = d.getElementById( "attention" );
		var time = 0;
		
		content.style.visibility = "hidden";
		
		var timer = setInterval( function() {
			if ( window.__progressionFlashPlayerVersion ) {
				clearInterval( timer );
				content.style.visibility = "visible";
				
				var version = window.__progressionFlashPlayerVersion;
				window.__progressionFlashPlayerVersion = undefined;
				
				if ( !owner.checkVersion( version ) ) { return; }
				
				owner.onLoad();
			}
			
			if ( time++ > 50 ) {
				clearInterval( timer );
				
				content.style.visibility = "visible";
			}
		}, 100 );
		
		var html = ''
			+ '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="1" height="1" id="external_version">'
			+ '<param name="allowScriptAccess" value="sameDomain" />'
			+ '<param name="movie" value="contents/objects/version.swf" />'
			+ '<embed src="contents/objects/version.swf" name="external_version" width="1" height="1" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
			+ '</object>';
		d.write( html );
		
	},
	
	onLoad:function() {
	}
};

