//class Resize
function Resize(){
}//end function

Resize.prototype.init=function Resize_init(q_MENUSTRIP,q_SLIDE,q_INTERACTION,q_IMAGESCROLL){
this.resizeIsEnabled=true;
this.q_MENUSTRIP=q_MENUSTRIP;
this.q_SLIDE=q_SLIDE;
this.q_INTERACTION=q_INTERACTION;
this.myImagescroll=q_IMAGESCROLL;
this.myScale=1;
this.isFlipped="0";
this.q_FORM=this.readCoords();
this.originalSlideCoords=this.getCoords("slide");	this.originalVideoCoords=this.getCoords("video");
this.originalInteractionCoords=this.getCoords("inter");	
this.myMasterMorphPhase=0;
this.myLastResize=now()-10000;
}//end function

Resize.prototype.readCoords=function Resize_readCoords(){
var q_form=new Array();
//list layer objects
var divs = document.getElementsByTagName("IMG");
for(var q_ix=0;q_ix<divs.length;q_ix++){
	if(this.q_isRelevantObject(divs[q_ix].id)){
		q_form[q_form.length]=this.q_getObjectCoords(divs[q_ix]);
	}//end if
}//next
var divs = document.getElementsByTagName("DIV");
for(var q_ix=0;q_ix<divs.length;q_ix++){
	if(this.q_isRelevantObject(divs[q_ix].id)){
		q_form[q_form.length]=this.q_getObjectCoords(divs[q_ix]);
	}//end if
}//next
var divs = document.getElementsByTagName("SPAN");
for(var q_ix=0;q_ix<divs.length;q_ix++){
	if(this.q_isRelevantObject(divs[q_ix].id)){
		q_form[q_form.length]=this.q_getObjectCoords(divs[q_ix]);
	}//end if
}//next
var divs = document.getElementsByTagName("A");
for(var q_ix=0;q_ix<divs.length;q_ix++){
	if(this.q_isRelevantObject(divs[q_ix].id)){
		q_form[q_form.length]=this.q_getObjectCoords(divs[q_ix]);
	}//end if
}//next
return q_form;
}//end function

//public
Resize.prototype.addCoord=function Resize_addCoord(idname){
if(!this.existsCoord(idname)){
	this.q_FORM[this.q_FORM.length]=this.q_getObjectCoords(idname);
}//end if
}//end function

//public
Resize.prototype.existsCoord=function Resize_existsCoord(idname){
for(var q_ix=0;q_ix<this.q_FORM.length;q_ix++){
if(this.q_FORM[q_ix][0]==idname){
	return true;
}//end if
}//next
return false;
}//end function

//public
Resize.prototype.setCoord=function Resize_setCoord(idname,q_rec){
for(var q_ix=0;q_ix<this.q_FORM.length;q_ix++){
if(this.q_FORM[q_ix][0]==idname){
	this.q_FORM[q_ix]=q_rec;
	return true;
}//end if
}//next
return false;
}//end method

//Private method
Resize.prototype.q_isRelevantObject=function (q_id){
if(q_id=="Rollerstatus"){
	return (!(div("Rollerstatus").offsetTop==2));//not in menu
}else if(q_id>""){
	return ((",servcom,stat,resize,preload,Notes,MenustripGraphic,Menustrip_pynt,Menustrip_menu,Roller,action," ).indexOf(","+q_id+",")==-1);
}else{
	return false;
}//end if
}//end function

Resize.prototype.q_getObjectCoords=function (d){
if(d.style.fontSize){
	return new Array(d.id,d.style.visibility,d.offsetLeft,d.offsetTop,d.offsetWidth,d.offsetHeight,parseInt(d.style.fontSize));
}else{
	return new Array(d.id,d.style.visibility,d.offsetLeft,d.offsetTop,d.offsetWidth,d.offsetHeight,null);
}//end if
}//end function

Resize.prototype.resizeForm=function Resize_resizeForm(){
if(this.resizeIsEnabled==true){
	this.myLastResize=now();
	var q_master=this.getCoords("master");
	var	q_xscale=windowWidth()/q_master[4];
	if(this.q_MENUSTRIP){
		var q_yscale=(windowHeight()-20)/q_master[5];
	}else{
		var q_yscale=windowHeight()/q_master[5];
	}//end if
	var	q_scale=Math.min(q_xscale,q_yscale);
	this.myScale=q_scale;
	this.resizeDivs(q_scale);
	resetYellowmessage();
	this.q_adjustQuicktimeSize();
	if(this.q_MENUSTRIP){
		this.q_MENUSTRIP.resize(q_scale*this.getCoords("master")[4],q_scale);
	}//end if
	if(this.q_SLIDE){
		var q_slideCoords=this.getCoords("slide");
		this.q_SLIDE.resize(q_scale*q_slideCoords[4],q_scale*q_slideCoords[5]);
	}//end if
	if(this.q_INTERACTION){
		this.q_INTERACTION.resize(q_scale);
	}//end if
	if(div("imagescrollframe")){
		if(this.myImagescroll){
			this.myImagescroll.resize( div("imagescroll").offsetWidth,div("imagescroll").offsetHeight,q_scale);
		}//end if
	}//end if
	if(div("masterimg")){
		var expectedName=gStat.getField("PRODUCER_ID")+"_"+gStat.getField("FOLDERNAME");
		if((window.name=="Mainshow"||window.name==expectedName)&&!IE()){
			this.resizeIsEnabled=false;//deny the next resize
			logga("aspect adjustment "+div("masterimg").offsetWidth+"x"+div("masterimg").offsetHeight);
			setWindowToContent(div("masterimg").offsetWidth, div("masterimg").offsetHeight);
		}//end if
	}//end if
}else{
	this.resizeIsEnabled=true;
}//end if
}//end function

Resize.prototype.getCoords=function (q_id){
for(q_ix=0;q_ix<this.q_FORM.length;q_ix++){
	if(this.q_FORM[q_ix][0]==q_id){
		return this.q_FORM[q_ix];
	}//end if
}//next
return null;
}//end function

Resize.prototype.resizeDivs=function Resize_resizeDivs(q_scale){
for(q_ix=0;q_ix<this.q_FORM.length;q_ix++){
try{
	this.q_setLayer(this.q_FORM[q_ix][0],this.q_FORM[q_ix],q_scale);
}catch(errObj){
logga(errObj.description);
}//end catch
}//next
}//end function

Resize.prototype.q_setLayer=function (q_id,q_coords,q_scale){
try{
this.q_setObjectStyle(q_id+"img",q_coords,q_scale);
this.q_setObjectStyle(q_id,q_coords,q_scale);
}catch(errObj){
logga("q_setLayer("+q_id+",q_coords,"+q_scale+") "+errObj.description);
}//end catch
}//end function

Resize.prototype.q_setObjectStyle=function (q_id,q_coords,q_scale){
if(div(q_id)){
	if(q_coords){
		if(q_scale){
			if(q_scale>0 && q_scale<10.0){
				return this.q_scaleObjectStyle(q_id,q_coords,q_scale);
			}else{
				return this.q_scaleObjectStyle(q_id,q_coords,1.0);
			}//end if
		}else{
			return this.q_scaleObjectStyle(q_id,q_coords,1.0);
		}//end if
	}//end if
}//end if
}//end function

Resize.prototype.q_scaleObjectStyle=function (q_id,q_coords,q_scale){
var q_layerstyle=div(q_id).style;
if(q_id=="videoimg"){
	div(q_id).width=q_coords[4]+"px";
	div(q_id).height=q_coords[5]+"px";
	if(WIN()&&FX()){
		setTimeout("repeatVideoSize()",500);//Workaround for Firefox resize bug
	}//end if
}//end if
q_layerstyle.width=(q_scale * q_coords[4])+"px";
q_layerstyle.height=(q_scale * q_coords[5])+"px";
if(!endswith(q_id,"img")){
	q_layerstyle.left=(q_scale * q_coords[2])+"px";
	q_layerstyle.top=(q_scale * q_coords[3])+"px";
}//end if
if(q_coords[6]){
   q_layerstyle.fontSize=q_scale * q_coords[6];
}//end if
}//end function

function repeatVideoSize(){
	logga("repeatVideoSize");
	div("videoimg").style.width=div("video").offsetWidth+"px";
	div("videoimg").style.height=div("video").offsetHeight+"px";
}//end function

//Private method
Resize.prototype.q_adjustQuicktimeSize=function (){
try{
var q_v=div("videoimg");
	if(q_v.SetRectangle){
		//q_v.SetRectangle("0,0,"+parseInt(document.getElementById("video").style.width)+ ","+parseInt(document.getElementById("video").style.height));
		q_v.SetRectangle("0,0,"+div("video").offsetWidth+ ","+div("video").offsetHeight);
	}//end if
}catch(errObj){
}//end catch
}//end function

Resize.prototype.flip=function Resize_flip(q_mode){
return this.doMorflip(q_mode);
//q_mode "0" is normal, "1" is flipped
if(q_mode){
}else{
	q_mode=(this.isFlipped=="1")?"0":"1";
}//end if
if(this.isFlipped!=q_mode){
	if(q_mode=="0"||q_mode=="normal"||q_mode=="flipback"){
		this.originalSlideCoords[0]="slide";
		this.originalVideoCoords[0]="video";
		this.isFlipped="0";
	}else{
		this.originalSlideCoords[0]="video";
		this.originalVideoCoords[0]="slide";
		this.isFlipped="1";
	}//end if
	this.q_setLayer("video",this.getCoords("video"),this.myScale);
	this.q_setLayer("slide",this.getCoords("slide"),this.myScale);
	if(this.q_SLIDE){
		var q_slideCoords=this.getCoords("slide");
		this.q_SLIDE.resize(this.myScale*q_slideCoords[4],this.myScale*q_slideCoords[5]);
	}//end if
	this.q_adjustQuicktimeSize();
}//end if
}//end function

Resize.prototype.doMorflip=function Resize_doMorflip(q_mode){
if(q_mode){
}else{
	q_mode=(this.isFlipped=="1")?"0":"1";
}//end if
if(this.isFlipped!=q_mode){

	var objectname="master";
	var easing="accelerate";
	var startpos=0;
	var distance=100;
	var a=new Array(this.originalSlideCoords.copy(),this.originalVideoCoords.copy());
	this.scaleCoords(a[0],this.myScale);
	this.scaleCoords(a[1],this.myScale);
	var b=new Array(a[1].copy(),a[0].copy());
	b[0][0]="slide";
	b[1][0]="video";
	if(q_mode=="0"||q_mode=="normal"||q_mode=="flipback"){
		gSourceArray=b;
		gDestArray=a;
		this.isFlipped="0";
	}else{
		gSourceArray=a;
		gDestArray=b;
		this.isFlipped="1";
	}//end if
	
	gAnimate.setAnimation(objectname,600,30,easing,startpos,distance,"setCircularMorph");
	//this.q_adjustQuicktimeSize();
}//end if
}//end function

//Private method
Resize.prototype.scaleCoords=function (arr,scale){
arr[2]=arr[2]*scale;
arr[3]=arr[3]*scale;
arr[4]=arr[4]*scale;
arr[5]=arr[5]*scale;
}//end function

//------------------Layout Morphing---------------
var gSourceArray,gDestArray;

function doStraightMorph(){
gAnimate.setAnimation("master",1000,20,"linear",0,100,"setStraightMorph");
}//end function

function doCircularMorph(){
gAnimate.setAnimation("master",1000,20,"linear",0,100,"setCircularMorph");
}//end function

function setStraightMorph(objectname,percentValue,behavior){
gResize.setGlobalMorph(objectname,percentValue,"straight");
}//end function

function setCircularMorph(objectname,percentValue,behavior){
gResize.setGlobalMorph(objectname,percentValue,"circular");
}//end function

Resize.prototype.setGlobalMorph=function setGlobalMorph(objectname,percentValue,behavior){
try{
	var appear=percentValue/100;
	var phase=this.getMorphPhase(appear);
	if(phase==5&&gDestArray[0][0]=="master"){
		this.resizeIsEnabled=false;
		try{
			setWindowToContent(gDestArray[0][4],gDestArray[0][5]);
		}catch(errObj){
		}//end catch
		//this.resizeIsEnabled=true;
	}//end if
	for(var ix=0;ix<gSourceArray.length;ix=ix+1){
		this.setItemMorph(gSourceArray,gDestArray,ix,appear,behavior,phase);
	}//next
}catch(errObj){
	logga(errObj.message);
}//end catch
}//end function

Resize.prototype.setItemMorph=function (gSourceArray,gDestArray,ix,appear,behavior,phase){
if(gSourceArray[ix][1]!="hidden"){
	var iy=gDestArray.seekCol(0,gSourceArray[ix][0]);
	if(inList(gSourceArray[ix][0], "master,videoplay,videostop,videopause,videoup,videodown,videofull,videoflip,slidenext,slideprev,slide")){
		this.setImageMorph(gSourceArray[ix],gDestArray[ix],appear,phase);
	}//end if
	if(gSourceArray[ix][0]!="master"&&iy>=0){
		if(!this.isSameCoordinate(gSourceArray[ix],gDestArray[iy])){
			if(behavior=="straight"){
				this.setLayoutCoords( gSourceArray[ix],gDestArray[iy],appear,phase);
			}else{
				this.setLayoutCircularCoords( gSourceArray[ix],gDestArray[iy],appear);
			}//end if	
		}//end if
	}//end if
}else{

}//end if
}//end function

Resize.prototype.isSameCoordinate=function (sourceRow,destRow){
return (sourceRow[1]==destRow[1]&&sourceRow[2]==destRow[2]&&sourceRow[3]==destRow[3]&&sourceRow[4]==destRow[4]&&sourceRow[5]==destRow[5]);
}//end function

Resize.prototype.setImageMorph=function(sourceItem,destItem,appear,phase){
var z=this.doRound8(1-0.8*Math.sin(Math.PI*appear));
var divBg=div(sourceItem[0]);
var divFront=div(sourceItem[0]+"img");
setOpacity(divFront,z*100);
if(phase==0){
	if(destItem[6]>""){
		divBg.style.backgroundImage="url("+destItem[6]+")";
	}//end if
}else if(phase==3){
	if(sourceItem[6]>""){
		divBg.style.backgroundImage="";
	}//end if
	if(destItem[1]=="hidden"){
		divBg.style.visibility="hidden";
		divFront.style.visibility="hidden";
	}else if(destItem[6]>""){
		divFront.src=destItem[6];
	}//end if
}//end if
}//end function

Resize.prototype.getMorphPhase=function (appear){
switch(this.myMasterMorphPhase){
case 0:
	this.myMasterMorphPhase=1;
	return 0;
case 1:
	if(appear>0.1){
		this.myMasterMorphPhase=2;
		return 2;
	}else{
		return -1;
	}//end if
case 2:
	if(appear>0.5){
		this.myMasterMorphPhase=3;
		return 3;
	}else{
		return -1;
	}//end if
case 3:
	if(appear>0.9){
		this.myMasterMorphPhase=4;
		return 4;
	}else{
		return -1;
	}//end if
case 4:
	if(appear>0.95){
		this.myMasterMorphPhase=5;
		return 5;
	}else{
		return -1;
	}//end if
default: 
	return -1;
}//end switch
}//end function

Resize.prototype.setLayoutCoords=function (sourceItem,destItem,appear,phase){
var disappear=1-appear;
var left=(sourceItem[2]*disappear+destItem[2]*appear);
var top=(sourceItem[3]*disappear+destItem[3]*appear);
var width=(sourceItem[4]*disappear+destItem[4]*appear);
var height=(sourceItem[5]*disappear+destItem[5]*appear);
this.setObjectCoords(sourceItem[0]+"img",left,top,width,height);
this.setObjectCoords(sourceItem[0],left,top,width,height);
if(phase==5){
	//set image size within iframe
	//this.setIframeTargetSize(sourceItem[0],left,top,width,height);
}//end if
}//end function

Resize.prototype.setIframeTargetSize=function (objname,left,top,width,height){
try{
	var imgObj=window.slideimg.document.getElementById("slideimg");
	if(imgObj.offsetWidth!=width){
		imgObj.style.width=width+"px";
		imgObj.style.height=height+"px";
	}//end if

}catch(errObj){
}//end catch
}//end function

Resize.prototype.setObjectCoords=function (objname,left,top,width,height){
if(div(objname)){
	var objstyle=div(objname).style;
	objstyle.left=left+"px";
	objstyle.top=top+"px";
	objstyle.width=width+"px";
	objstyle.height=height+"px";
}//end if
}//end function

Resize.prototype.getCenterPoint=function (){
var center=this.getWindowInnerSize();
center.x=center.x/2;
center.y=center.y/2;
return center;
}//end function

Resize.prototype.getWindowInnerSize=function (){
var c=new Object();
if(self.innerWidth){
	c.x=self.innerWidth;
	c.y=self.innerHeight;
}else if(document.documentElement && document.documentElement.clientWidth){
	c.x=document.documentElement.clientWidth;
	c.y=document.documentElement.clientHeight;
}else if(document.body){
	c.x=document.body.clientWidth;
	c.y=document.body.clientHeight;
}else{
	c.x=1024;
	c.y=768;
}//end if
return c;
}//end function

Resize.prototype.setLayoutCircularCoords=function (sourceItem,destItem,appear){
//instead of linear move, this move rotates around a xyz axis
var disappear=1-appear;
var centerPoint=this.getCenterPoint();

var s=this.getItem2CenterPoint(sourceItem,centerPoint);
s=this.getCoord2Polar(s);
var d=this.getItem2CenterPoint(destItem,centerPoint);
d=this.getCoord2Polar(d);
var r=new Object();
r.angle=s.angle*disappear+d.angle*appear;
r.amp=s.amp*disappear+d.amp*appear;
r=this.getPolar2Coord(r);
var z=this.doRound8(1-0.6*Math.sin(Math.PI*appear));
//r.y=z*r.y;
var width=z*(sourceItem[4]*disappear+destItem[4]*appear);
var height=z*(sourceItem[5]*disappear+destItem[5]*appear);
var left=r.x+centerPoint.x-width/2;
var top=r.y+centerPoint.y-height/2;

var objstyle=div(sourceItem[0]).style;
objstyle.left=left+"px";
objstyle.top=top+"px";
objstyle.width=width+"px";
objstyle.height=height+"px";
var img=div(sourceItem[0]+"img");
if(img){
	img.style.width=width+"px";
	img.style.height=height+"px";
	if(FX()&&sourceItem[0]=="slide"){
		try{
			this.q_SLIDE.resize(width,height);
		}catch(errObj){
		}//end catch
	}//end if
	//if(sourceItem[0]!="video"){
//		setOpacity(img,z*100);
	//}//end if
}//end if

}//end function

Resize.prototype.doRound8=function (x){
return Math.round(x*100000000)/100000000;
}//end function

Resize.prototype.getItem2CenterPoint=function (sourceItem,centerPoint){
var p=new Object();
p.x=sourceItem[2]+sourceItem[4]/2-centerPoint.x;
p.y=sourceItem[3]+sourceItem[5]/2-centerPoint.y;
return p;
}//end function

Resize.prototype.getCoord2Polar=function (p){
p.amp=Math.sqrt(p.x*p.x+p.y*p.y);
p.angle=Math.atan2(p.y,p.x);
return p;
}//end function

Resize.prototype.getPolar2Coord=function (p){
p.x=p.amp*Math.cos(p.angle);
p.y=p.amp*Math.sin(p.angle);
return p;
}//end function

//end class Resize