// frankiezafe.net flash bg with overlaying divs
// frankiezafe.net flash logo below floating divs
// these scripts use browser.js => must be called before

//------------------------------------------------------
//GENERAL FUNCTIONS
//------------------------------------------------------

function cleanVar(x) { var tmp=x.toString(); if (tmp.indexOf('px')>-1) { tmp=tmp.substring(0,tmp.indexOf('px')); x=parseInt(tmp); } return x; }
function getAbsoluteLeft(objectId) {
	var o = document.getElementById(objectId); var oLeft = o.offsetLeft ;
	while(o.offsetParent!=null) { oParent = o.offsetParent; oLeft += oParent.offsetLeft; o = oParent; }
	return oLeft; }
function getAbsoluteTop(objectId) {
	var o = document.getElementById(objectId); var oTop = o.offsetTop;
	while(o.offsetParent!=null) { oParent = o.offsetParent; oTop += oParent.offsetTop; o = oParent; }
	return oTop; }

//------------------------------------------------------
//FLASH BACKGROUND WITH ANIMATED DIVS
//------------------------------------------------------

var flashbgLoaded = false;
var animAr = new Array();
function pushInAnimAr(ar) {
	var pos = -1;
	for (var i=0; i<animAr.length; i++) { if ((animAr[i].id==ar.id)&&(animAr[i].type==ar.type)) { pos = i; break;}}
	if (pos==-1) { animAr.push(ar); } else { animAr[i]=ar; }
}
function positionAllContentBoxes() { if (flashbgLoaded) { for (var i=0; i<animAr.length; i++) { if (animAr[i].type=='position') { positionContentBox(animAr[i]); }}}}
function positionContentBox(ar) {
	//position;
	if (flashbgLoaded) {
		if (ar.type=='position') {
		document.getElementById(ar.id).style.position = 'absolute';
		document.getElementById(ar.id).style.top = (getAbsoluteTop(config['flash_bg_id'])+ar.top)+'px';
		document.getElementById(ar.id).style.left = (ar.left)+'px';
		}
	}
}
function sizeContentBox(id,w,h,anim) {
	if (document.getElementById(id)) {
		if (document.getElementById(id).style.display!='block') {document.getElementById(id).style.display='block';}
		if (document.getElementById(id).style.overflow!='hidden') {document.getElementById(id).style.overflow='hidden';}
		if (document.getElementById(id).style.marginTop!='0px') {document.getElementById(id).style.marginTop = '0px';}
		if (document.getElementById(id).style.marginRight!='0px') {document.getElementById(id).style.marginRight = '0px';}
		if (document.getElementById(id).style.marginBottom!='0px') {document.getElementById(id).style.marginBottom = '0px';}
		if (document.getElementById(id).style.marginLeft!='0px') {document.getElementById(id).style.marginLeft = '0px';}
		if (anim) {
			var pos = -1;
			for (var i=0; i<animAr.length; i++) { if (animAr[i].id==id) { pos = i; break;}}
			var tmp = new Array();
			tmp.id = id; tmp.type = 'size';
			tmp.startW = cleanVar(document.getElementById(id).style.width);
			tmp.startH = cleanVar(document.getElementById(id).style.height);
			tmp.endW = w;
			tmp.endH = h;
			tmp.endOverFlow = 'auto';
			tmp.currentW = tmp.startW;
			tmp.currentH = tmp.startH;
			tmp.done = false;
			if ((tmp.endW!=tmp.currentW)&&(tmp.endH!=tmp.currentH)) { 
				pushInAnimAr(tmp);
				document.getElementById(id).style.overflow = 'hidden';}
		}
		else {document.getElementById(id).style.width = w+'px';document.getElementById(id).style.height = h+'px';}
	}
}

function adaptContent() {
	if (OS == 'Windows') {
	if ((browser)&&((browser=='Internet Explorer')||(browser=='Opera')||(browser=='Netscape Navigator'))) {
	if ((document.getElementById(config['flash_bg_id']))
		&&(document.getElementById(config['flash_bg_img_id']))
		&&(document.getElementById(config['default_content_id']))) {
		css_hack();
		var oldContent = document.getElementById(config['flash_bg_id']).innerHTML;
		var bgImg = document.getElementById(config['flash_bg_img_id']).src;
		var so = new SWFObject(config['flash_file']+'?img='+bgImg, config['flash_id'], '870', '500', '7', '');
		so.addParam("allowScriptAccess", "always");
		so.write(config['flash_bg_id']);
		if (document.getElementById(config['flash_bg_id']).innerHTML != oldContent) { flashbgLoaded = true; }
		if (flashbgLoaded) {
			document.getElementById(config['flash_bg_id']).style.display='block';
			if (browser!='Internet Explorer') {
				document.getElementById(config['default_content_id']).style.background = 'none';
				document.getElementById(config['default_content_id']).style.width='0px';
				document.getElementById(config['default_content_id']).style.height='0px';
			} else {
				var thml = document.getElementById(config['default_content_id']).innerHTML;
				document.getElementById(config['default_content_id']).innerHTML = '';
				document.getElementById(config['default_content_id']).style.display = 'none';
				document.getElementById(config['flash_bg_id']).innerHTML += thml;
			}
			var tmp = new Array();
			for (var i=0; i<config['all'].length; i++) {
				if (document.getElementById(config['all'][i])) {
				var tmp = new Array();
				tmp.id = config['all'][i]; tmp.type = 'position'; tmp.top = config[tmp.id].top; tmp.left = config[tmp.id].left; tmp.done = false; 
				pushInAnimAr(tmp);
			}	}
			for (var i=0; i<animAr.length; i++) {
				positionContentBox(animAr[i]);
				sizeContentBox(animAr[i].id,0,0,false);
			}
		}
	}
	}
	}
}
var animTotal = 0; var animFinished = 0;
function anim() {
	if (flashbgLoaded) {
		if (animAr.length>0) {
			var newAr = new Array();
			for (var i=0; i<animAr.length; i++) {
				if (animAr[i].type=='size') {
					if (animAr[i].currentW!=animAr[i].endW) {
						animAr[i].currentW += Math.ceil((animAr[i].endW-animAr[i].currentW)/5);
						if (Math.abs(animAr[i].endW-animAr[i].currentW)<2) { animAr[i].currentW = animAr[i].endW; }
					}
					if (animAr[i].currentH!=animAr[i].endH) {
						animAr[i].currentH += Math.ceil((animAr[i].endH-animAr[i].currentH)/5);
						if (Math.abs(animAr[i].endH-animAr[i].currentH)<2) { animAr[i].currentH = animAr[i].endH; }
					}
					if ((animAr[i].currentW==animAr[i].endW)&&(animAr[i].currentH==animAr[i].endH)) {
						animAr[i].done = true;
						animFinished++;
					} else { newAr.push(animAr[i]); }
					sizeContentBox(animAr[i].id,animAr[i].currentW,animAr[i].currentH,false);
					if (animAr[i].done) {
						document.getElementById(animAr[i].id).style.overflow = animAr[i].endOverFlow;
					}
				} else { newAr.push(animAr[i]); }
			}
			if ((animTotal>0)&&(animFinished==animTotal)) { 
				document.getElementById(config['flash_id']).launchSecondPart();
				animTotal = 0; }
			animAr = newAr;
		} 
	}
}
window.setInterval('anim()',30);

function DipslayTitle() { if (document.getElementById(config['pagetitle_id'])) { animTotal++; sizeContentBox(config['pagetitle_id'],config[config['pagetitle_id']].width,config[config['pagetitle_id']].height,true);} }
function DipslayBody() { if (document.getElementById(config['pagebody_id'])) { animTotal++; sizeContentBox(config['pagebody_id'],config[config['pagebody_id']].width,config[config['pagebody_id']].height,true);} }
function DipslayMenu() { if (document.getElementById(config['pagemenu_id'])) { animTotal++; sizeContentBox(config['pagemenu_id'],config[config['pagemenu_id']].width,config[config['pagemenu_id']].height,true);} }


//------------------------------------------------------
//FLASH LOGO BELOW FLOATING DIVS
//------------------------------------------------------

function adaptLogo() {
	if ((browser)&&((browser=='Internet Explorer')||(browser=='Opera')||(browser=='Netscape Navigator'))) {
	if ((document.getElementById('flash_logo_div'))&&(document.getElementById('flash_logo_wrapper'))) {
		var oldContent = document.getElementById('flash_logo_div').innerHTML;
		var so = new SWFObject('fileadmin/templates/images/logo_header4.swf', 'flash_logo', '509', '140', '7', '');
		so.write('flash_logo_div');
		if (document.getElementById('flash_logo_div').innerHTML != oldContent) {
			if ((browser=='Opera')||(browser=='Netscape Navigator')) { document.getElementById('flash_logo_wrapper').style.width = '100%'; }
			document.getElementById('header').style.background='url(fileadmin/templates/images/spacer.gif)';
		}
	}}
}
