if(!rarebrick) var rarebrick = new Object();

if(rarebrick.alertFlashDone==true) {
	rarebrick.timeInit = new Date().getTime();

	rarebrick.flashDone = function() {
		var elapse = (new Date().getTime()) - rarebrick.timeInit;
		alert('time: ' + elapse);
	}
}

rarebrick.useFlash = function() {
	if(rarebrick.getCookieVal('flash') == 'false') return false;
	return(swfobject.hasFlashPlayerVersion("9.0.0"));
}

if(rarebrick.useFlash()) {
	swfobject.createCSS("#"+rarebrick.flashHeaderDiv, "visibility:hidden;");
	swfobject.createCSS("#"+rarebrick.flashHeaderDiv, "overflow:hidden;");
	swfobject.createCSS("#"+rarebrick.flashHeaderDiv, "width:" + rarebrick.headerWidth + ";");
	swfobject.createCSS("#"+rarebrick.flashHeaderDiv, "height:" + rarebrick.headerHeight + ";");
	swfobject.createCSS("#"+rarebrick.flashHeaderDivReplace, "overflow:hidden;");
	swfobject.createCSS("#"+rarebrick.flashHeaderDivReplace, "width:" + rarebrick.headerWidth + ";");
	swfobject.createCSS("#"+rarebrick.flashHeaderDivReplace, "height:" + rarebrick.headerHeight + ";");
}

rarebrick.addFlash = function() {
	swfobject.createCSS("#"+rarebrick.flashHeaderDivReplace, "width:" + rarebrick.headerWidth + ";");
	swfobject.createCSS("#"+rarebrick.flashHeaderDivReplace, "height:" + rarebrick.headerHeight + ";");
	var flashvars = {};
	flashvars.isIntro = rarebrick.isIntro;
	flashvars.theUrl = rarebrick.getLocation();
	flashvars.baseURL = rarebrick.baseURL;
	flashvars.baseURLLinks = rarebrick.baseURLLinks;
	flashvars.baseURLPics = rarebrick.baseURLPics;
	flashvars.alertFlashDone = rarebrick.alertFlashDone;
	flashvars.soundPath = rarebrick.soundPath;
	var params = {};
	params.allowScriptAccess = "always";
	params.wmode = "transparent";
	var attributes = {};
	attributes.id = rarebrick.flashHeaderDivReplace;
	
	swfobject.embedSWF(rarebrick.baseURL+rarebrick.flashHeaderName, rarebrick.flashHeaderDiv, rarebrick.headerWidth, rarebrick.headerHeight, '9.0.0', rarebrick.baseURL+'swf/expressInstall.swf', flashvars, params, attributes);
	
	swfobject.createCSS("#"+rarebrick.flashHeaderDivReplace, "visibility:visible;");
}

rarebrick.getLocation = function() {
	return document.location.href;
}

rarebrick.getXMLElementByIDXX = function(id) {
	var bodyNode = rarebrick.xml.getElementsByTagName('body')[0];
	var node_tags = bodyNode.getElementsByTagName('*');
	for (i=0;i<node_tags.length;i++) {
		if (node_tags[i].hasAttribute('id')) {
			if (node_tags[i].getAttribute('id') == id) {
				return node_tags[i];
			}
		}
	}
	return null;
}

rarebrick.addFlashButtons = function() {
	//alert('flashbuttons');
	var elem = document.getElementById('content');
	//alert('elem: ' + elem);
	//find p.buttons
	for(i=0; i<elem.childNodes.length; i++) {
		var child = elem.childNodes[i];
		if(child.attributes && child.attributes['class'] && child.attributes['class'].value=='buttons') {
			rarebrick.doFlashButtons(child);
		}
	}
}

rarebrick.doFlashButtons = function(elem2) {
	//alert('doFlashButtons');
	for(j=0; j<elem2.childNodes.length; j++) {
		var child2 = elem2.childNodes[j];
		if(child2.attributes && child2.attributes['class'] && child2.attributes['class'].value=='button') {
			rarebrick.makeFlashButton(child2);
		}
	}
}

//create a flash button
rarebrick.makeFlashButton = function(elem) {
	//alert('makeFlashButton');
	var flashid;
	if(!elem.attributes['id']) {
		flashid = elem.attributes['class'].value + Math.random();
		elem.setAttribute('id', flashid);
	} else {
		flashid = elem.attributes['id'].value;
	}
	var xmlHtml = rarebrick.html2xml.getXmlByObject(elem);
	
	var flashvars = {};
	flashvars.xmlHtml = xmlHtml;
	flashvars.id = flashid;
	flashvars.isLocal = location.href.indexOf('http://')==-1;
	var params = {};
	params.allowScriptAccess = "always";
	params.wmode = "transparent";
	var attributes = {};
	attributes.id = flashid+'_swf';
	
	swfobject.embedSWF('swf/button.swf', flashid, '100', '46', '9.0.0', 'swf/expressInstall.swf', flashvars, params, attributes);
	//alert(flashid);
}

rarebrick.clearInside = function() {
	if(!rarebrick.useFlash()) return;
	var elemId = 'flashHeaderInside';
	var elem = document.getElementById(elemId);
	if(elem) {
		elem.style.display = 'none';
	}
}

function setFlashElem(elemId, val, which) {
	val = '' + Math.round(val) + 'px';
	elemId = elemId+'_swf';
	var elem = document.getElementById(elemId);
	//alert('setWidth: ' + elem);
	if(elem) {
		elem.style[which] = val;
	}
}

if(rarebrick.useFlash() == true) {
	swfobject.addDomLoadEvent(rarebrick.addFlash);
	if(rarebrick.addFlashButtonsFlag==true) swfobject.addDomLoadEvent(rarebrick.addFlashButtons);
	//if(rarebrick.addFlashHeadlinesFlag==true) swfobject.addDomLoadEvent(rarebrick.addFlashHeadlines);
}
