//flashAds.js
//Extension lib for dynamic flash ads
//created by Lucas Short
//last modified on 2009.04.07
//version 1.5.2
//REQUIRES ls.js
//////////////////////////////////////////////
var ad_z=1000;
var ad_fps=20;
var ad_version='1.5.2';
var ad_actions=new Object();
function adSetFPS(val){ad_fps=val;}
function adSetZ(val){ad_z=val;}
function adGetVersion(){return ad_version;}
function adSize(div,h,w){
	if(typeof(div)=='object')div=div.id;
	var rnd=rndInt(1000,9999);
	ad_actions[div]='adSize'+rnd;
	get(div).style.zIndex=get_next_z_index(get(div).style.zIndex);
	ad_set_container_size(div,h,w,"absolute","adSize"+rnd);
}
function adSizeNice(div,h,w){
	if(typeof(div)=='object')div=div.id;
	var rnd=rndInt(1000,9999);
	ad_actions[div]='adSizeNice'+rnd;
	get(div).style.zIndex=get_next_z_index(get(div).style.zIndex);
	ad_set_container_size(div,h,w,"relative","adSizeNice"+rnd);
}
function adSlide(div,h,w,d){
	if(typeof(div)=='object')div=div.id;
	var rnd=rndInt(1000,9999);
	ad_actions[div]='adSlide'+rnd;
	get(div).style.zIndex=get_next_z_index(get(div).style.zIndex);
	ad_animate_resize(div,h,w,d,"absolute","adSlide"+rnd)
}
function adPush(div,h,w,d){
	if(typeof(div)=='object')div=div.id;
	var rnd=rndInt(1000,9999);
	ad_actions[div]='adPush'+rnd;
	get(div).style.zIndex=get_next_z_index(get(div).style.zIndex);
	ad_animate_resize(div,h,w,d,"relative","adPush"+rnd)
}
function adSetCoords(div,yReg,xReg){
	if(typeof(div)=='object')div=div.id;
	adUnsetCoords(div);
	yReg=yReg.toLowerCase();
	xReg=xReg.toLowerCase();
	if(yReg=='bottom')get(div).style.bottom='0px';
	else get(div).style.top='0px';
	if(xReg=='right')get(div).style.right='0px';
	else get(div).style.left='0px';
}
function adUnsetCoords(div){
	if(typeof(div)=='object')div=div.id;
	get(div).style.top='';
	get(div).style.bottom='';
	get(div).style.left='';
	get(div).style.right='';
}
function adTeleportTo(div,xCoord,yCoord){
	if(typeof(div)=='object')div=div.id;
	ad_move_container(div,xCoord,yCoord);
}
function adTeleportBy(div,xCoord,yCoord){
	if(typeof(div)=='object')div=div.id;
	ad_move_container(div,xCoord+ad_get_current_X(div),yCoord+ad_get_current_Y(div));
}
function adMoveTo(div,xCoord,yCoord,d){
	if(typeof(div)=='object')div=div.id;
	var orgX=ad_get_current_X(div);
	var orgY=ad_get_current_Y(div);
	var frameCount=d*ad_fps;
	get(div).style.zIndex=get_next_z_index(get(div).style.zIndex);
	for(i=1;i<frameCount+1;i++)
		setTimeout('ad_move_container("'+div+'",'+Math.round((xCoord-orgX)*(i/frameCount)+orgX)+','+Math.round((yCoord-orgY)*(i/frameCount)+orgY)+',"relative");',i*Math.round(1000/ad_fps));
}
function adMoveBy(div,xDistance,yDistance,d){
	if(typeof(div)=='object')div=div.id;
	var orgX=ad_get_current_X(div);
	var orgY=ad_get_current_Y(div);
	var frameCount=d*ad_fps;
	get(div).style.zIndex=get_next_z_index(get(div).style.zIndex);
	for(i=1;i<frameCount+1;i++)
		setTimeout('ad_move_container("'+div+'",'+Math.round(xDistance*(i/frameCount)+orgX)+','+Math.round(yDistance*(i/frameCount)+orgY)+', "relative");',i*Math.round(1000/ad_fps));
}
function ad_peelBack(src,original_height,original_width,expanded_height,expanded_width,anchor_side){
	anchor_side=def(anchor_side,'right');
	var embed=new Object({src:src,width:expanded_width,height:expanded_height,style:'float:'+anchor_side+';'});
	var container=new Object({width:expanded_width,height:original_height,position:"absolute"});
	var wrapper='height:'+original_height+'px;width:'+original_width+'px;z-index:9998;position:relative;top:0px;'+anchor_side+':0px;float:'+anchor_side+';';
	var properties=new Array(new Object({key:anchor_side,val:"0px"}),new Object({key:"zIndex",val:"9999"}));
	ad_build(wrapper,container,embed,properties);
}
function ad_expandingBox(src,original_height,original_width,expanded_height,expanded_width,anchor_side){
	anchor_side=def(anchor_side,'right');
	var embed=new Object({src:src,width:expanded_width,height:expanded_height,style:'float:'+anchor_side+';'+anchor_side+':0px;position:absolute;'});
	var container=new Object({width:original_width, height:original_height, position:"absolute"});
	var wrapper='height:'+original_height+'px;width:'+original_width+'px;z-index:'+get_next_z_index()+';position:relative;';
	var properties=new Array(new Object({key:anchor_side,val:"0px"}));
	ad_build(wrapper,container,embed,properties);
}
function ad_slidingBillboard(src,original_height,original_width,expanded_height,expanded_width){
	var embed=new Object({src:src,width:expanded_width,height:expanded_height,style:""});
	var container=new Object({width:original_width,height:original_height,position:"relative"});
	var wrapper='height:'+original_height+'px;width:'+original_width+'px;z-index:'+get_next_z_index()+';';
	ad_build(wrapper,container,embed);
}
function ad_walkOut(src,height,width,down,left,inline){
	inline=def(inline,'absolute');
	var embed=new Object({src:src,width:width,height:height,style:''});
	var container=new Object({width:width,height:height,position:"relative"});
	var wrapper='height:'+height+'px;width:'+width+'px;z-index:'+get_next_z_index()+';position:'+inline+';top:'+down+'px;left:'+left+'px;z-index:4999;';
	var properties=new Array(new Object({key:"zIndex",val:"5000"}));
	adSetCoords(ad_build(wrapper,container,embed,properties),"top","left");
}
function ad_build(wrapper,container,embed,properties){
	if(typeof(properties)=='undefined')properties=new Array();
	var generatedID='cnad_'+rndInt(container['height']*container['width'],embed['height']*embed['width']);
	echo('<div style="'+wrapper+'">');
	echo('<div id="'+generatedID+'">');
	echo('<embed height="'+embed['height']+'" width="'+embed['width']+'" src="'+embed['src']+'?containerID='+generatedID+'" wmode="transparent" allowSrciptAccess="always" style="'+embed['style']+'"></embed>');
	echo('</div></div>');
	echo('<scr'+'ipt type="text/javascript">');
	echo('get(\''+generatedID+'\').style.overflow="hidden";');
	echo('get(\''+generatedID+'\').style.position="'+container['position']+'";');
	echo('get(\''+generatedID+'\').style.height="'+container['height']+'px";');
	echo('get(\''+generatedID+'\').style.width="'+container['width']+'px";');
	for(i=0;i<properties.length;i++)
		echo('get(\''+generatedID+'\').style.'+properties[i]['key']+'="'+properties[i]['val']+'";\n\r');
	echo('<\/scr'+'ipt>');
	return generatedID;
}
function ad_set_container_size(div,h,w,p,t){
	if(typeof(div)=='object')div=div.id;
	if(ad_actions[div]!=t)return;
	get(div).style.width=w+"px";
	get(div).style.height=h+"px";
	get(div).style.position=p;
}
function ad_move_container(div,xCoord,yCoord){
	if(typeof(div)=='object')div=div.id;
	if(get(div).style.top!='')get(div).style.top = yCoord+'px';
	if(get(div).style.bottom!='')get(div).style.bottom = yCoord+'px';
	if(get(div).style.left!='')get(div).style.left = xCoord+'px';
	if(get(div).style.right!='')get(div).style.right = xCoord+'px';
}
function ad_animate_resize(div,h,w,d,p,t){
	if(typeof(div)=='object')div=div.id;
	get(div).style.position=p;
	if(p=='relative'){
		get(div).parentNode.style.height='';
		get(div).parentNode.style.width='';
	}
	var frameCount=d*ad_fps;
	for(i=1;i<frameCount+1;i++)
		setTimeout('ad_set_container_size("'+div+'",'+Math.round((h-get(div).offsetHeight)*(i/frameCount)+get(div).offsetHeight)+','+Math.round((w-get(div).offsetWidth)*(i/frameCount)+get(div).offsetWidth)+',"'+p+'","'+t+'");',i*Math.round(1000/ad_fps));
}
function ad_get_current_X(div){
	if(typeof(div)=='object')div=div.id;
	var org=0;
	if(get(div).style.left!='')org=get(div).offsetLeft;
	if(get(div).style.right!='')org=get(div).offsetLeft;
	return org;
}
function ad_get_current_Y(div){
	if(typeof(div)=='object')div=div.id;
	var org=0;
	if(get(div).style.top!='')org=get(div).offsetTop;
	if(get(div).style.bottom!='')org=get(div).offsetTop;
	return org;
}
function get_next_z_index(currentZ){
	if(typeof(currentZ)=='undefined')currentZ=0;
	if(currentZ>ad_z)return currentZ;
	return ad_z++;
}