// #############################################################################
// 						content from objectinheritance.js
// #############################################################################

/*
Object inheritance framework from
http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html

Example implementation:

function Foo (a, b, c) {
	// do something
}

Bar.Inherits(Foo);
function Bar (a, b) {
	var c = 'blah';
	this.Inherits(Foo, a, b, c);
}

*/

/* Object.prototype.Inherits = function( parent )
	{
		if( arguments.length > 1 )
		{
			parent.apply( this, Array.prototype.slice.call( arguments, 1 ) );
		}
		else
		{
			parent.call( this );
		}
	}
*/

Function.prototype.Inherits = function( parent )
	{
		this.prototype = new parent();
		this.prototype.constructor = this;
	}

  // **************************************************************************************************
  // ****      I.E. DOM IMPLEMENTATION ISSUE FIX                                                   ****
  // **************************************************************************************************

  // Stub function
  function createElementWithName(){}

  // Anonymous function fills in stub automatically depending on browser implementation of name
  // attribute.  IE requires a non-standard call to document.createElement in order to set the name
  // attribute for elements, which is necessary for dynamically generated forms.
  (function(){
    try {
      var el=document.createElement( '<div name="foo">' );
      if( 'DIV'!=el.tagName ||
          'foo'!=el.name ){
        throw 'create element error';
      }
      createElementWithName = function( tag, name ){
        return document.createElement( '<'+tag+' name="'+name+'"></'+tag+'>' );
      }
    }catch( e ){
      createElementWithName = function( tag, name ){
        var el = document.createElement( tag );
        // setAttribute might be better here ?
        el.name = name;
		el.setAttribute("name",name);
        return el;
      }
    }
  })();

  // Add createElementWithName to document object as createNamedElement
  if (typeof(document.createNamedElement) == 'undefined') {
    document.createNamedElement = createElementWithName;
  }

// #############################################################################
// 						content from swfobjectWrapper.js
// #############################################################################

/*
Example usage:
	// Declare variables object
	var flashvars = {
		handle:'handletest'
		,flashVarText:'testing'
		,anothervar:'testing'
	};
	// Embed Flash object in page
	var so = new swfoWrapper('so_tester.swf','flashcontent',flashvars,300,300);
*/
swfoWrapper.Inherits(SWFObject);




//var swfoCoreURL = (swfoBaseURL.length > 0 ? window.location.protocol+"//"+swfoBaseURL : "");
//var swfoCoreURL = (swfoBaseURL.length > 0 ? window.location.protocol+"//"+swfoBaseURL : "") + "/flash/core.swf";

//var swfoCoreURL = swfoBaseURL.replace(/https:\/\//i,"http://") + "/flash/core.swf";
var swfoBaseURL = window.location.hostname + '/civilization2008';

function swfoWrapper (swf, container, vartable, width, height){
	// this = new SWFObject();
	// default required flash version, background color
	this.requiredversion = 8;
	this.backcolor = '#ffffff';
	// if width and height specified then set, otherwise default
	this.height = !isNaN(width) ? width : 944;
	this.width = !isNaN(height) ? height : 607;
	// parameters provided by default constructor
	this.swf = swf;//(/^http/).test(swf) ? swf :  swfoBaseURL+swf  ;
	this.container = container;
	// call the SWFObject constructor
	this.Inherits(SWFObject, this.swf, container + '_swf', this.height, this.width, this.requiredversion, this.backcolor);

	// add all variables!
	this.setAttribute('redirectUrl', 'http://www.cadillac.com.cn/error/getflash.html');

	//Add some variables and params from Refresh2
	this.addVariable( "handle",  location.pathname.replace(/\.(x|ht)ml$/,'')  );

	//-this.addParam('base',basePrefix+'/flash');

	//this.addParam('base',swfoBaseURL+'/flash');
	this.addVariable('base',swfoBaseURL);
	this.addParam('base',swfoBaseURL);


	//this.addVariable('url',window.location.protocol+"//"+window.location.host+window.location.pathname);
	/**
	need to encode the url passed in when we have parameters attached
	should revise this when url-rewrite is enabled
	//*/
	this.addVariable('url',encodeURIComponent(window.location));

	this.addParam('scale','noscale');
	this.addParam('bgcolor','#333333');
	//this.addParam('wmode','transparent');
	this.addParam('allowScriptAccess','always');


	for (var varitem in vartable) {
		if (typeof(vartable[varitem]) != 'function'){
			if(/^atr_/.test(varitem)){
				this.setAttribute(varitem.replace(/^atr_/,''),vartable[varitem]);
			}else if(/^param_/.test(varitem)){
				this.addParam(varitem.replace(/^param_/,''),vartable[varitem]);
			}else{
				this.addVariable(varitem,String(vartable[varitem]).replace(/&amp;/g,'%26').replace(/\+/g,'%2B'));
			}
		}
	}
	
	// so flash has its own id:
	this.addVariable( "htmlSwfId",  vartable['atr_id']||container + '_swf' );
	///this.addVariable('url',""); //#  TEST



	this.postform = function (action,query) {
		var fe = document.createElement("form");
		fe.id = "flashsearchform";
		fe.action = action;
		fe.enctype = "multipart/form-data";
		fe.encoding = "multipart/form-data";
		fe.method = "post";
		fe.style.display = "none";
		var qv = "";
		var qa = query.split(",");
		for (var i = 0; i < qa.length; i++) {
			qv += String.fromCharCode(qa[i])
		}

		var qps = qv.split("&");
		for (var i = 0; i < qps.length; i++) {
			var qp = qps[i].split("=");
			var qpe = document.createNamedElement("input",qp[0]);
			qpe.type = "hidden";
			var qpev = qp[1];
			qpe.value = qpev;
			fe.appendChild(qpe);
		}

		var qpcs = document.createNamedElement("input","_charset_");
		qpcs.type = "hidden";
		qpcs.value = "utf-8";
		fe.appendChild(qpcs);
		document.body.appendChild(fe);
		fe.submit();
	}

	this.write(this.container);
	return;
}

swfoWrapper.prototype.Inherits=function(parent){
	if( arguments.length > 1 ){
		parent.apply( this, Array.prototype.slice.call( arguments, 1 ) );
	}else{
		parent.call( this );
	}
}

var omHeight = 347;
function snapFlash(size) {
	//when snapping, we only increase space for main_mc in the middle
	//size: size of new main_mc
	if (size == omHeight) return;
	var oHeight = document.getElementById("core").offsetHeight;
	var nHeight = size - omHeight + oHeight;
	//alert(oHeight + '|' + nHeight);
	if ((document.getElementById("core")) && (document.getElementById("core_swf"))) {
		//document.getElementById("core").style.height=nHeight+"px";
		document.getElementById("core_swf").height = nHeight;
		document.getElementById("core_swf").style.height=nHeight+"px";
	}
	
	omHeight = size;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
