/* $Header: /usr/local/cvsroot/scottmadden.com/elements/scripts/script.js,v 1.4 2009/04/09 19:16:20 tngsandiego Exp $ */
/* Layer */
function layerON(url,title){
	top.layerEvent.location.href = url;
	var titObj = document.getElementById('layerTitle');
	titObj.innerHTML = title;
	top.display('bigKahuna');
	top.display('layerDrag');
	top.display('layerCloser');
	//top.doAllFixes();
}
function layerVIEW(){
	top.display('bigKahuna');
	top.display('layerDrag');
	top.display('layerCloser');
	//top.doAllFixes();
}
function layerOFF(){
	top.layerEvent.location.href= "about:blank";
	top.hide('bigKahuna');
	top.hide('layerDrag');
	top.hide('layerCloser');
}
function layerONDynamic(url,title){
	// Dimension
	var startW = 1;
	var startH = 1;
	var endW = 980;
	var endH = 600;
	// Position
	var startX = 1;
	var startY = 1;
	var endX = ((_getWidth() - endW) / 2);
	var endY = _getY();

	// Gen
	var doneX = false;
	var doneY = false;
	var doneW = false;
	var doneH = false;

	var tmpX = startX;
	var tmpY = startY;
	var tmpW = startW;
	var tmpH = startH;

	var speed = 0.8;

	moveObj('layerDrag',tmpX,tmpY);
        resizeObj('layerDrag',tmpW,tmpH);

	top.display('bigKahuna');
	top.display('layerDrag');
	//top.display('layerCloser');
	var timeId = setInterval(function(){
	        if(doneX && doneY && doneW && doneH){
	                clearTimeout(timeId);
	                top.layerEvent.location.href = url;
			var titObj = document.getElementById('layerTitle');
			titObj.innerHTML = title;
	        }
	        if(!doneX){
		        tmpX = parseFloat(number_format((tmpX / speed), 1, ".", ""));
		        if(tmpX<endX){
		        	moveX('layerDrag',tmpX);
		        }else{
		        	moveX('layerDrag',endX);
		        	doneX=true;
		        }
	        }
	        if(!doneY){
		        tmpY = number_format((tmpY / speed), 1, ".", "");
		        if(tmpY<endY){
		        	moveY('layerDrag',tmpY);
		        }else{
		        	moveY('layerDrag',endY);
		        	doneY=true;
		        }
	        }
	        if(!doneW){
		        tmpW = number_format((tmpW / speed), 1, ".", "");
		        if(tmpW<endW){
		        	resizeWidth(tmpW,'layerDrag');
		        }else{
		        	resizeWidth(endW,'layerDrag');
		        	doneW=true;
		        }
	        }
	        if(!doneH){
			tmpH = number_format((tmpH / speed), 1, ".", "");
		        if(tmpH<endH){
		        	resizeHeight(tmpH,'layerDrag');
		        }else{
		        	resizeHeight(endH,'layerDrag');
		        	doneH=true;
		        }
		}

	},100);
}
/* Displaying Elements */
function display(element) {
	var but = document.getElementById(element);
	but.style.display = 'block';
}
function hide(element) {
	var but = document.getElementById(element);
	but.style.display = 'none';
}
function hidedisplay(element){
	var but = document.getElementById(element);
	if(but.style.display == 'block'){
		but.style.display = 'none';
	}else{
		but.style.display = 'block';
	}
}
/* Flash Managing */
function visibleFlash(){
	var obj = top.document.getElementsByTagName("object");
	var emb = top.document.getElementsByTagName("embed");
	obj.style.visibility = 'visible';
	emb.style.visibility = 'visible';
}
function invisibleFlash(){
	var obj = top.document.getElementsByTagName("object");
	var emb = top.document.getElementsByTagName("embed");
	obj.style.visibility = 'hidden';
	emb.style.visibility = 'hidden';
}
function spitFlash(filename,width,height){
	if(!width) var width='100%';
	if(!height) var height='100%';
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" name="artist" id="artist" align="middle">');
		document.write('<param name="loop" value="false">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="' + filename + '" />');
		document.write('<param name="wmode" value="transparent">');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="bgcolor" value="#FFFFFF" />');
		document.write('<embed src="' + filename + '" loop="false" quality="high" width="'+width+'" height="'+height+'" name="artist" wmode="transparent" bgcolor="#FFFFFF" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
function spitVarFlash(filename,data,width,height){
	if(!width) var width='100%';
	if(!height) var height='100%';
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" name="artist" id="artist" align="middle">');
		document.write('<param name="loop" value="false">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="' + filename + '" />');
		document.write('<param name="wmode" value="transparent">');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="bgcolor" value="#FFFFFF" />');
		document.write('<param name="FlashVars" value="xml=' + escape(data) + '">');
		document.write('<embed src="' + filename + '" loop="false" FlashVars="xml=' + escape(data) + '" quality="high" width="'+width+'" height="'+height+'" name="artist" wmode="transparent" bgcolor="#FFFFFF" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

/* Sizes */
function getHeight(id){
	var thisOne = document.getElementById(id);
	return thisOne.style.height;
}
function getWidth(id){
	var thisOne = document.getElementById(id);
	return thisOne.style.width;
}

function resizeHeight(id, val){
	var totVal = parseInt(val);
	var thisOne = document.getElementById(id);
	thisOne.style.height = totVal + "px";
}
function resizeWidth(id, val){
	var totVal = parseInt(val);
	var thisOne = document.getElementById(id);
	thisOne.style.width = totVal + "px";
}
/* Margins */
function setMarginTop(id, val){
	var margine = parseInt(val);
	var thisOne = document.getElementById(id);
	thisOne.style.marginTop = margine + "px";
}
function setMarginBottom(id, val){
	var margine = parseInt(val);
	var thisOne = document.getElementById(id);
	thisOne.style.marginBottom = margine + "px";
}
function setMarginLeft(id, val){
	var margine = parseInt(val);
	var thisOne = document.getElementById(id);
	thisOne.style.marginLeft = margine + "px";
}
function setMarginRight(id, val){
	var margine = parseInt(val);
	var thisOne = document.getElementById(id);
	thisOne.style.marginRight = margine + "px";
}
/* Distances */
function findX(obj, relativeTo){
	if(eval(relativeTo)){ var difference = document.getElementById(relativeTo).offsetLeft; }else{ var difference = 0; }
	var curleft = 0;
	if(obj.offsetParent){
		while(1){
			curleft += obj.offsetLeft;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	}else if(obj.x){
		curleft += obj.x;
	}
	curleft -= difference;
	
	return curleft;
}
function findY(obj, relativeTo){
	if(eval(relativeTo)){ var difference = document.getElementById(relativeTo).offsetTop; }else{ var difference = 0; }
	var curtop = 0;
	if(obj.offsetParent){
		while(1){
			curleft += obj.offsetTop;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	}else if(obj.y){
		curtop += obj.y;
	}
	curtop -= difference;

	return curtop;
}
function setTop(id, val){
	var totVal = parseInt(val);
	document.getElementById(id).style.top = totVal + "px";
}
function setBottom(id, val){
	var totVal = parseInt(val);
	document.getElementById(id).style.bottom = totVal + "px";
}
function setLeft(id, val){
	var totVal = parseInt(val);
	document.getElementById(id).style.left = totVal + "px";
}
function getLeft(id){
	return document.getElementById(id).style.left;
}
function setRight(id, val){
	var totVal = parseInt(val);
	document.getElementById(id).style.right = totVal + "px";
}
function getRight(id){
	return document.getElementById(id).style.right;
}
/* Window */
function getWindowPosTop(){
	var hackSafari = parseInt(document.body.scrollTop);
	var winTop = parseInt(document.documentElement.scrollTop);
	if(winTop == 0) winTop = hackSafari;
	
	return winTop;
}
function getWindowPosLeft(){
	var hackSafari = parseInt(document.body.scrollLeft);
	var winLeft = parseInt(document.documentElement.scrollLeft);
	if(winLeft == 0) winLeft = hackSafari;

	return winLeft;
}
/* Body */
function getBodyH(){
	var hackSafari = parseInt(document.body.clientHeight);
	var size = parseInt(document.documentElement.clientHeight);
	if(size == 0) size = hackSafari;

	return winLeft;
}
function getBodyW(){
	var hackSafari = parseInt(document.body.clientWidth);
	var size = parseInt(document.documentElement.clientWidth);
	if(size == 0) size = hackSafari;

	return winLeft;
}