MainWindow.prototype.RootName = "MainWindow";
MainWindow.prototype.s = null;


MainWindow.prototype.dragRotateAnimation = null;
MainWindow.prototype.enableDragRotation = true;


function MainWindow(s)
{
    //alert("MW: s = " + s);
    this.s = s;
    this.plugin = plugin;//s.getHost();
	this.MainCanvas = this.s.findname("MainCanvas");
    this.DebugBox =this.s.findname("DebugBox");
    this.xamlObject = this.s.findname(this.RootName);

    this.MouseMoveToken = MainCanvas.addEventListener("MouseMove", this.OnMouseMove);
    
    this.EnableMouseListeners();
    
    if (!showVideo)
    {
        this.SetupTopStripAnims();
    }
}

MainWindow.prototype.MouseEnabled = false;

MainWindow.prototype.EnableMouseListeners = function()
{
    //MainWindow["IsHitTestVisible"] = true;
    //return;
    //------------------------------------
    if (this.enableDragRotation)
    {
        this.MouseEnabled = true;
        if (this.MouseLeftButtonDownToken == null)
        {
            //alert("enabling 'em: " + this.MouseLeftButtonDownToken);
            this.MouseLeftButtonDownToken = this.xamlObject.addEventListener("MouseLeftButtonDown", this.OnMouseLeftButtonDown);
            this.MouseLeftButtonUpToken = this.xamlObject.addEventListener("MouseLeftButtonUp", this.OnMouseLeftButtonUp);
        }
   }
}

MainWindow.prototype.DisableMouseListeners = function()
{
    //MainWindow["IsHitTestVisible"] = false;
    //return;
    //--------------------------
    //alert("Disable: " + this.MouseLeftButtonDownToken);
    this.MouseEnabled = false;
    return;

    alert("REMOVING");
    if (this.MouseLeftButtonDownToken != null) try { this.xamlObject.removeEventListener(this.MouseLeftButtonDownToken) } catch (e) { };
    if (this.MouseLeftButtonUpToken != null) try { this.xamlObject.removeEventListener(this.MouseLeftButtonUpToken) } catch (e) {};
    
    this.MouseLeftButtonDownToken = null;
    this.MouseLeftButtonUpToken  = null;
    
    //alert("done");
}

MainWindow.prototype.OnBeginMain = function()
{
    //alert("MainWindow.OnBeginMain  downloadComplete = " + downloadComplete + " videoWindow.videoComplete = " + videoWindow.videoComplete);
    if (!downloadComplete)
        return;
        
    videoWindow.xamlObject["Visibility"] = "Collapsed";
    mainWindow.xamlObject["Opacity"] = "1";
    MainCanvas.findname("Frosted")["Opacity"] = 0.7;
    //mainWindow.SetBackground("img/360_0001.jpg");
    
    var slinkAway = new Animation("slinkAway", videoWindow.xamlObject, "Canvas.Left", 0, 720, 0.8);
	
	MainCanvas.findname("NavBarGroup")["Visibility"] = "Visible";
	MainCanvas.findname("NavBarGroup")["Opacity"] = 1;
	
    var navTop = navBar.xamlObject["Canvas.Top"];
    var navHeight = navBar.xamlObject["Height"];
    var newNavTop = 294 - navBarSettings["height"];
    var navDip = new Animation("navDip", navBar.xamlObject, "Canvas.Top", navTop, newNavTop, 0.5);
    //dd("navTop = " + navTop + " navHeight = " + navHeight + "     navBarSettings[height] = " + navBarSettings["height"]);
    //navDip.Play();	
	
    slinkAway.OnStopAnimation = navDip;
    slinkAway.Play();
    
    mainWindow.SetupTopStripAnims();
    
    slinkAway.OnStopScript = function () { mainWindow.ShowHideBillboards(true); }
    
        
    dialog.ShowHide(-1, -1, 1);
}

MainWindow.prototype.SetupTopStripAnims = function()
{
    
    MainCanvas.findname("MainWindow")["Opacity"] = 1;
    MainCanvas.findname("TopStrip")["Opacity"] = 1;
    
    //MainCanvas.findname("TopStrip2")["Opacity"] = 0.5;
   
    var topStripAnim = new Animation("topstripslide", MainCanvas.findname("TopStripScale"), "ScaleX",
        1, 1.5, 12);
    topStripAnim.ease = false;
    topStripAnim.easeFunction = function(inVal) { return (1 + Math.sin(2 * Math.PI * inVal))/2; };
    //topStripAnim.OnStopScript = function() { var buf = this.startValue; this.startValue = this.currentValue; this.endValue = buf; this.duration = this.duration * 0.9; }
    topStripAnim.OnStopAnimation = topStripAnim;

    var topStripAnim2 = new Animation("topstripslide2", MainCanvas.findname("TopStripScale"), "CenterX",
        0.77, 0.4, 29);
    topStripAnim2.ease = false;
    topStripAnim2.easeFunction = function(inVal) { return (1 + Math.sin(2 * Math.PI * inVal))/2; };
    topStripAnim2.OnStopAnimation = topStripAnim2;
    
    /*
    var topStrip2Anim = new Animation("topstri2pslide", MainCanvas.findname("TopStrip2Scale"), "ScaleX",
        1.1, 0.7, 9);
    topStrip2Anim.ease = false;
    topStrip2Anim.easeFunction = function(inVal) { return (1 + Math.sin(2 * Math.PI * inVal))/2; };
    //topStripAnim.OnStopScript = function() { var buf = this.startValue; this.startValue = this.currentValue; this.endValue = buf; this.duration = this.duration * 0.9; }
    topStrip2Anim.OnStopAnimation = topStrip2Anim;

    var topStrip2Anim2 = new Animation("topstrip2slide2", MainCanvas.findname("TopStrip2Scale"), "CenterX",
        0.52, 0.8, 39);
    topStrip2Anim2.ease = false;
    topStrip2Anim2.easeFunction = function(inVal) { return (1 + Math.sin(2 * Math.PI * inVal))/2; };
    topStrip2Anim2.OnStopAnimation = topStrip2Anim2;
    */
    
    if (animateSkinkles)
    {
        topStripAnim.Play();
        topStripAnim2.Play();
        //topStrip2Anim.Play();
        //topStrip2Anim2.Play();  
    }  
}

MainWindow.prototype.MouseLeftButtonDownToken = null;
MainWindow.prototype.MouseLeftButtonUpToken = null;
MainWindow.prototype.MouseMoveToken = null;
MainWindow.prototype.mouseDown = false;
MainWindow.prototype.showCoords = false;

MainWindow.prototype.EnableMouseCoords = function(val)
{
    mainWindow.showCoords = val;
    
    if (val == false) dd("");
    //dd("val = " + val +"    this.showCoords = " + mainWindow.showCoords);
}

MainWindow.prototype.OnMouseMove = function(sender,e)
{    
    var mx = e.GetPosition(null).x;
    var my = e.GetPosition(null).y;
//dd("edr =" + this.enableDragRotation + "       mw.edr = " + mainWindow.enableDragRotation);
    
    if (!mainWindow.enableDragRotation || slider.mouseDown)
    {       
        slider.OnMouseMove(sender,e);
    }
    else
    {
       if (house.selectedRoom >= 0)
        return;
        
       if (house.selectedRoom >= 0)
            alert("dragging and moving in room: " + house.selectedRoom);
       //if (!MainWindow.mouseDown) dd("mouse not down          " + mx);
       
       if (mainWindow.mouseDown && mainWindow.enableDragRotation)
        {
            var useVelocity = false;
            
            if (!useVelocity)
            {
                var dx = mx - this.mouseDownX;
                var dy = my - this.mouseDownY;
                
                var fx = dx / 720;  
                
                var currentF = backgroundMovie.CurrentFrame / 32;
                
                //dd("downX = " + this.mouseDownX + "     x = " + mx + "       dx = " + dx +"    fx = " + fx + " cf = " + currentF);
                
                var newF = fx + this.mouseDownBGFrac;//currentF + fx;
                var was = -2;
                
                if (newF < 0)
                {
                    was = newF; 
                    newF = newF + 1;
                }
                else if (newF > 1)
                {
                    was = newF; 
                    newF = newF - 1;
                }
                
                if (newF < 0 || newF > 1)
                {
                    alert("Was = " + was + "         now = " + newF);
                }
                
                backgroundMovie.SetBackgroundIndexAsFloat(newF * 32);
            }
            else
            {
                // Compute the angular velocity based on mouse down/current position.
                var dx = mx - this.mouseDownX;
                var dy = my - this.mouseDownY;
                
                var vx = dx / this.plugin.content.actualWidth;
                var vy = dy / this.plugin.content.actualHeight;
                
                this.angularVelocity = vx;
                mainWindow.angularVelocity = vx;
    //dd(mx + ", " + my + "    " + "       mw.edr = " + mainWindow.enableDragRotation + " angVel = " + mainWindow.angularVelocity); 
                
                if (mainWindow.enableDragRotation)
                { 
	                if (mainWindow.dragRotateAnimation != null && !mainWindow.dragRotateAnimation.IsPlaying )
	                {
	                    mainWindow.dragRotateAnimation.Play();
	                }
                }
                //dd("ang vel = " + this.angularVelocity);
            }
        }
    }
     //dd("this.showCoords = " + mainWindow.showCoords);
    if (mainWindow.showCoords == true)
    {
        dd( "" + mx + ", " + my);// e.GetPosition(MainCanvas.xamlObject).x + ", " + e.GetPosition(MainCanvas.xamlObject).y );
    }
       
}

MainWindow.prototype.angularVelocity = 0;
MainWindow.prototype.mouseDownX = -1;
MainWindow.prototype.mouseDownY = -1;
MainWindow.prototype.mouseDownBGFrac = -1;

MainWindow.prototype.LockOutDragNavigation = false;

MainWindow.prototype.OnMouseLeftButtonDown = function(sender,e)
{
    //alert("MW.mousedown -- slider.mouseDown = " + slider.mouseDown);
    
    if (slider.mouseDown || e.GetPosition(null).y > (294-22) )
    {
        return;
    }

    if (mainWindow.LockOutDragNavigation || house.selectedRoom >= 0)
    {
        //dd("LOCKED");
        return;
    }    
    //dd("down");
    
    this.mouseDown = true;
    mainWindow.mouseDown = true;
    this.mouseDownX = e.GetPosition(null).x;
    this.mouseDownBGFrac = backgroundMovie.CurrentFrame / 32.0;

    if (mainWindow.enableDragRotation) mainWindow.StartDragRotation();
    
    sender.CaptureMouse();
}

MainWindow.prototype.OnMouseLeftButtonUp = function(sender,e)
{
//dd("MainWindow.OnMouseLeftButtonUp");
    if (slider.mouseDown)
    {
        return;
    }

    if (mainWindow.LockOutDragNavigation || house.selectedRoom >= 0)
    {
        //dd("LOCKED");
        return;
    }    

        //dd("up");
    this.mouseDownX = -1;
    this.mouseDownY = -1;
    
    sender.ReleaseMouseCapture();
    this.mouseDown = false;
    mainWindow.mouseDown = false;
    
    if (mainWindow.enableDragRotation) mainWindow.StopDragRotation();
    
    if (slider.mouseDown)
        slider.OnMouseLeftButtonUp(sender, e);
}

MainWindow.prototype.MouseDragStartPosition = new Object();
MainWindow.prototype.MouseDragEndPosition = new Object();

MainWindow.prototype.StartDragRotation = function()
{
    //alert("STARTED");
    var startFrame = backgroundMovie.CurrentFrame;
    var endFrame = startFrame + Math.floor((6 * mainWindow.angularVelocity * 2) );

    mainWindow.dragRotateAnimation = new Animation("rotateAnim", 
	    backgroundMovie, "BackgroundFraction", startFrame, endFrame, 0.4);
	mainWindow.dragRotateAnimation.ease = false;
	
	mainWindow.dragRotateAnimation.OnPreFractionScript = function(frac)
	    {
	        if (frac < this.lastFraction)
	        {
	            //dd("ang vel = " + mainWindow.angularVelocity);
	            this.startValue = backgroundMovie.CurrentFrame;
	            
	            var frameCount = backgroundMovie.FrameCount;
	            var start = this.startValue;
	            var end = start + Math.floor(6 * mainWindow.angularVelocity * 2); 
                
//dd("angvel = " + mainWindow.angularVelocity + "         " + start + ",  " + end);
                //var flippedAtLeft = (mainWindow.angularVelocity < 0) && (end < 0);
                //if (flippedAtLeft) dd("FLIPPED LEFT");
                
                if (start >= 0 && start < frameCount && end >= 0 && end < frameCount)
                {
                    // no adjustment needed
                }
                else if (start >= 0 && start < frameCount && end >= frameCount)
                {
                    start = 0
                    end = end - frameCount;//frameCount - 1;
                }
                else if (start >= 0 && start < frameCount && end < 0)
                {
                    //dd("FLIP");
                    start = frameCount;//frameCount + end;
                    end = frameCount;//end = 0;
                }
                
//dd("startValue = " + start + "                 endValue = " + end);
                
                this.startValue = start;
	            this.endValue = end;

	        }
	        return frac;
	    }
	mainWindow.dragRotateAnimation.OnFractionScript = backgroundMovie.Update;//Silverlight.createDelegate(backgroundMovie, backgroundMovie.Update);
	//mainWindow.dragRotateAnimation.OnStopAnimation = mainWindow.dragRotateAnimation;
	mainWindow.dragRotateAnimation.Play();
}

MainWindow.prototype.StopDragRotation = function()
{
    mainWindow.angularVelocity = 0;
    
    if (mainWindow.dragRotateAnimation != null)
    {
        mainWindow.dragRotateAnimation.OnStopAnimation = null;
        mainWindow.dragRotateAnimation.Stop();
    }
}

MainWindow.prototype.OnSize = function()
{
    // Snap to the bottom of the frame.
    var windowHeight = this.plugin.content.actualHeight;
    var windowWidth = this.plugin.content.actualWidth;


    this.xamlObject["Width"] = windowWidth;
    this.xamlObject["Height"] = windowHeight;
    
    if (house != null && house.rooms != null)
    {
        for (var i = 0; i < house.rooms.length; i++)
        {
            MainCanvas.findname(house.rooms[i].name)["Width"] = windowWidth;
            MainCanvas.findname(house.rooms[i].name)["Height"] = windowHeight;
            MainCanvas.findname(house.rooms[i].name)["Canvas.Top"] = this.xamlObject["Canvas.Top"];
            MainCanvas.findname(house.rooms[i].name)["Canvas.Left"] = this.xamlObject["Canvas.Left"];    
        }
    }
    
    
    this.Setup3D();
    
//    MainCanvas.findname("HomeOffice")["Width"] = windowWidth;
//    MainCanvas.findname("HomeOffice")["Height"] = windowHeight;
//    MainCanvas.findname("HomeOffice")["Canvas.Top"] = this.xamlObject["Canvas.Top"];
//    MainCanvas.findname("HomeOffice")["Canvas.Left"] = this.xamlObject["Canvas.Left"];    
}

MainWindow.prototype.Show = function(anObj, val)
{
    var obj = anObj;
    if (obj == null) obj = this.s.findname(this.RootName);
    
    if (val == true)
    {
        obj["Visibility"] = "Visible";
    }
    else
    {
        obj["Visibility"] = "Collapsed";
    }
}

MainWindow.prototype.imageLibrary = null;

MainWindow.prototype.SetBackground = function(path)
{
    var justFilename = path;
    if (justFilename.indexOf("/") != -1)
        justFilename = justFilename.substring(justFilename.indexOf("/") + 1, justFilename.length);
        
    //dd("imageLibrary = " + this.imageLibrary + " Going to set to " + justFilename + " return = " + this.imageLibrary.FindObject(justFilename));
    var setFromLibrary = false;
    
    if (this.imageLibrary != null)
    {
        var objFromLibrary = this.imageLibrary.FindObject(justFilename);
        // Remove the current image and add the library-retrieved image in its place.
        //alert("found [" + justFilename + "] in library: " + objFromLibrary);        
        
        this.xamlObject.FindName("MainWindowImageContainer").children.clear();
        //objFromLibrary["Visibility"] = "Visible";
        this.xamlObject.FindName("MainWindowImageContainer").children.add(objFromLibrary);
        
        setFromLibrary = true;
    }
    
    if (!setFromLibrary)
    {
        this.xamlObject.findname("MainWindowImage")["Source"] = path;
    }
}

MainWindow.prototype.SetBackgroundZoom = function(zoomFactor)
{
    var bgScale = this.xamlObject.findname("BGScale");
    bgScale["ScaleX"] = zoomFactor;
    bgScale["ScaleY"] = zoomFactor;
}

MainWindow.prototype.GetWindowState = function()
{
    if (this.xamlObject.findname("HomeOffice")["Opacity"] == 1.0)
        return 1;
        
    return 0;
}

MainWindow.prototype.throb = null;



MainWindow.prototype.m_View = null;
MainWindow.prototype.m_Projection = null;
MainWindow.prototype.m_CameraPosition = null;
MainWindow.prototype.m_DotPositions = null;
MainWindow.prototype.m_NearClip = 1.0;
MainWindow.prototype.m_FarClip = 200.0;
MainWindow.prototype.m_Angle = 0;

MainWindow.prototype.m_WindowWidth = 550;
MainWindow.prototype.m_WindowHeight = 400;
MainWindow.prototype.m_AspectRatio = this.m_WindowHeight / this.m_WindowWidth;
MainWindow.prototype.m_DotPositions = null;
MainWindow.prototype.RotateFrameCount = 32;

MainWindow.prototype.RepositionHUD = function(frac)
{
    var frameIndex = Math.floor(frac * this.RotateFrameCount);
    var frameFrac = frameIndex / this.RotateFrameCount;
    this.m_Angle = frameFrac * 360 * Math.PI/180;
    var world = Matrix_RotationY(this.m_Angle);	//world = the rotation matrix of the scene

    var viewProj = this.m_View.Multiply(this.m_Projection);//could be stored once in constructor since camera never moves
    var worldViewProjection = world.Multiply(viewProj);
		
    {
	    var p3D = this.m_DotPositions[0];
	    var p4D = Vector3_Transform(p3D, worldViewProjection);
	    var pScreen = p4D.ProjectionToScreenCoordinates(this.m_WindowWidth, this.m_WindowHeight, p4D);//screen coordinates (x & y), with extra z & w for depth info
   	
   	    //dd("          " + pScreen.X + ",  " + pScreen.Y + ",   " + pScreen.Z);
	    this.DrawCoord(pScreen, "Origin");
    }
    
   //Transform and draw!
    {
	    var p3D = this.m_DotPositions[1];
	    var p4D = Vector3_Transform(p3D, worldViewProjection);
	    var pScreen = p4D.ProjectionToScreenCoordinates(this.m_WindowWidth, this.m_WindowHeight, p4D);//screen coordinates (x & y), with extra z & w for depth info
   	
	    this.DrawCoord(pScreen, "LivingRoomBB");
    }
    {
	    var p3D = this.m_DotPositions[2];
	    var p4D = Vector3_Transform(p3D, worldViewProjection);
	    var pScreen = p4D.ProjectionToScreenCoordinates(this.m_WindowWidth, this.m_WindowHeight, p4D);//screen coordinates (x & y), with extra z & w for depth info
   	
	    this.DrawCoord(pScreen, "HomeOfficeBB");
    }    
    {
	    var p3D = this.m_DotPositions[3];
	    var p4D = Vector3_Transform(p3D, worldViewProjection);
	    var pScreen = p4D.ProjectionToScreenCoordinates(this.m_WindowWidth, this.m_WindowHeight, p4D);//screen coordinates (x & y), with extra z & w for depth info
   	
	    this.DrawCoord(pScreen, "GameRoomBB");
    }    
}

		
MainWindow.prototype.Setup3D = function()
{
    this.m_WindowWidth = this.plugin.content.actualWidth;
    this.m_WindowHeight = this.plugin.content.actualHeight;
    //dd("hhhh = " + this.m_WindowHeight);
    this.m_AspectRatio = this.m_WindowHeight / this.m_WindowWidth;
    
    //Set the camera position:
    // y is up, z into the screen, x is positive to the right. left hand.
    this.m_CameraPosition = new Vector3(-0.372, 0, -4.806);//2 up, 4 back meters back from origin

    //coordinates to draw
    this.m_DotPositions = new Array();
    //the origin:
    this.m_DotPositions.push(new Vector3(0,0,0));
    //eight corners of a boxL
    this.m_DotPositions.push(new Vector3(
        livingRoomDialogSettings["bbx"], 
        livingRoomDialogSettings["bby"],
         livingRoomDialogSettings["bbz"]
         ));
    this.m_DotPositions.push(new Vector3(
        homeOfficeDialogSettings["bbx"], 
        homeOfficeDialogSettings["bby"], 
        homeOfficeDialogSettings["bbz"]
        ));
    this.m_DotPositions.push(new Vector3(
        gameRoomDialogSettings["bbx"], 
        gameRoomDialogSettings["bby"], 
        gameRoomDialogSettings["bbz"]
        ));
        
    
    
    this.m_DotPositions.push(new Vector3(1.0, 0, 1.0));
    this.m_DotPositions.push(new Vector3(-1.0, 3.0, -1.0));
    this.m_DotPositions.push(new Vector3(1.0, 3.0, -1.0));
    this.m_DotPositions.push(new Vector3(-1.0, 3.0, 1.0));
    this.m_DotPositions.push(new Vector3(1.0, 3.0, 1.0));

    //Create the view matrix (since m_CameraPosition never changes, storing -- if it changes, compute per frame)
    this.m_View = Matrix_LookAt(this.m_CameraPosition, new Vector3(0, 0, 0), new Vector3(0, 1.0, 0));
	
	//Create the projection matrix (would only change if the size of the screen or the field-of-view change)
    this.m_Projection = Matrix_PerspectiveFovLH(Math.PI / 4.0, this.m_AspectRatio, this.m_NearClip, this.m_FarClip);
	//dd("ar = " + this.m_AspectRatio + " near = " + this.m_NearClip + " far = " + this.m_FarClip + " this.m_Projection.M11 = " + this.m_Projection.M11);		
    
    if (this.throb == null)
    {
        this.throb = new RadarThrob();
        this.throb.Build();
        MainCanvas.children.add(this.throb.xamlObject);
        this.throb.xamlObject["Opacity"] = 0;
    }
    
    
    
    this.SetupThrobs();
    
    if (this.m_AspectRatio > 0)
    {
        this.RepositionHUD(0);
    }
}

MainWindow.prototype.SetupThrobs = function()
{
    var del = Silverlight.createDelegate(this, this.OnBBClicked);
    
    var tok = MainCanvas.findname("LivingRoomBB").addEventListener("MouseLeftButtonDown", del);
    tok = MainCanvas.findname("GameRoomBB").addEventListener("MouseLeftButtonDown", del);
    tok = MainCanvas.findname("HomeOfficeBB").addEventListener("MouseLeftButtonDown", del);

    var del2 = Silverlight.createDelegate(this, this.OnBBMouseEnter);
    var tok = MainCanvas.findname("LivingRoomBB").addEventListener("MouseEnter", del2);
    tok = MainCanvas.findname("GameRoomBB").addEventListener("MouseEnter", del2);
    tok = MainCanvas.findname("HomeOfficeBB").addEventListener("MouseEnter", del2);
    //alert("tok = " + tok);
}

MainWindow.prototype.throbbing = false;

MainWindow.prototype.lastSparked = null;

MainWindow.prototype.OnBBMouseEnter = function(sender, e)
{
    return;
    
    
    if (this.throb.IsSparking() 
    //|| (this.lastSparked != null && sender.name == this.lastSparked.name) 
     )
    {
        return;
    }
    
    this.lastSparked = sender;
    
    this.throb.Spark(sender, 1).Play();
}

MainWindow.prototype.OnBBClicked = function(sender, e)
{
    var roomName = sender.name;
    if (roomName.indexOf("BB") != -1) roomName = roomName.substring(0, roomName.length - 2);
    
    //dd("sender = " +roomName + "   throbbing = " + this.throbbing);
    if (this.throbbing)
    {
        //alert("alread!");
        return;
    }
    
    if (this.throb.IsSparking())
    {
        this.throb.sparkAnim.Stop();
        this.throb.SetupSpark(false);
    }
    
    this.throb.xamlObject["Canvas.Left"] = sender["Canvas.Left"] + sender.children.getItem(0)["Width"]/2;
    this.throb.xamlObject["Canvas.Top"] = sender["Canvas.Top"] + sender.children.getItem(0)["Height"]/2;
    this.throb.xamlObject["Visibility"] = "Visible";
    this.throb.xamlObject["Opacity"] = "1";
    
    var throbAnim = this.throb.Throb(-1);
    throbAnim.OnPlayScript = function () { mainWindow.throb.xamlObject["Visibility"] = "Collapsed"; mainWindow.throbbing = true; };
    throbAnim.OnStopScript = function () 
        {  
            mainWindow.throb.xamlObject["Visibility"] = "Collapsed";
            mainWindow.throbbing = false;
            navBar.GoToRoom(roomName);
        };
    throbAnim.Play();
}

MainWindow.prototype.ShowHideBillboards = function(val)
{
    if (!val)
    {
        this.throb.xamlObject["Visibility"] = "Collapsed";
        this.throb.xamlObject["Opacity"] = "0";
        MainCanvas.findname("LivingRoomBB")["Visibility"] = "Collapsed";
        MainCanvas.findname("GameRoomBB")["Visibility"] = "Collapsed";
        MainCanvas.findname("HomeOfficeBB")["Visibility"] = "Collapsed";
    }
    else
    {
        MainCanvas.findname("LivingRoomBB")["Visibility"] = "Visible";
        MainCanvas.findname("GameRoomBB")["Visibility"] = "Visible";
        MainCanvas.findname("HomeOfficeBB")["Visibility"] = "Visible";
    }
}

MainWindow.prototype.DrawCoord = function(p, name)
{
	//a dumb measure of the depth, for coloring the circle (not based on any knowledge of appropriate values or depths)
	var depthFactor = -(p.Z - 1.0) * 40.0;
	
	var obj = MainCanvas.findname(name);
	
	obj["Canvas.Left"] = p.X - MainCanvas.findname(name)["Width"]/2;
	obj["Canvas.Top"] = p.Y;
	
//	if (obj.name.indexOf("BB") != -1)
//	{
//        obj.RenderTransform["ScaleX"] = p.W * 25;
//        obj.RenderTransform["ScaleY"] = p.W * 25;
//    }
    
	/*
	var color:uint = Color.interpolateColor(0x0, 0xffffff, depthFactor);
	
	graphics.lineStyle(2, color);
	graphics.drawCircle(p.X - CircleRadius, p.Y - CircleRadius, CircleRadius*2);
	*/
}
		