///////////////////////////////////////////////////////////////////////////////
//
//  CreateSilverlight.js   version 0.9
//
//  This file is provided by Microsoft as a helper file for websites that
//  incorporate Silverlight Objects. The default parameters below comply with 
//  Silverlight v1.0 Beta, which exposes 0.9 as its version number.     
//  This file is provided as is.
// 
// © 2007 Microsoft Corporation. All Rights Reserved.
//
// This file is licensed as part of the Silverlight 1.0 SDK
// , for details look here: http://go.microsoft.com/fwlink/?LinkID=89144&clcid=0x409
//
///////////////////////////////////////////////////////////////////////////////


// JScript source code

//contains calls to silverlight.js, examples are below

function createSilverlight()
{  
                                                               
    Silverlight.createObjectEx(
        {source: 'SimpleLabel.xml'
            , parentElement:  document.getElementById('theDiv')
            , id:'theHost'
            , properties:{width:'700'
                    , height:'700'
                    , background:'White'
                    , isWindowless:'false'
                    , framerate:'24'
                    , version:'0.90.0'}
            , events: {onError:null, onLoad: handleLoad}
            , context:null
         });
    
}
function handleLoad(sender,args,root)
{
    var _dde = new RHPConsulting.SilverlightDragDropExtender();
    
    // host control boundaries ...
    _dde.Initialize(root.findName("DragLabel"), root.findName("DragLabel"));
    _dde.set_Opacity(0.5);
    
    // tie events ...
    _dde.addEventListener("Dragging", handleDragDropDragging);
}
function handleDragDropDragging(sender,args, ext)
{
    // coordinates relative to parent element ...
    var coordinates = "X:=" + args.Left + ",Y:=" + args.Top;
    var banner = document.getElementById("Banner");
    banner.innerHTML = coordinates;
    
    // absolute coordinates ...
    var coordinates1 = ext.RootCanvasCoordinates(sender);
    var absoluteCoordinates = "(abs)(obj)X:=" + coordinates1.Left + ",(abs)(obj)Y:=" + coordinates1.Top;
    banner.innerHTML += "<br/>" + absoluteCoordinates;
    
    // absolute coordinates (mouse) ...
    var mouseCoordinates = "(mou)X:=" + args.MouseX + ",(mou)Y:=" + args.MouseY;
    banner.innerHTML += "<br/>" + mouseCoordinates;
    
    // evaluate overlap ...
    var rect1 = sender.findName("Rectangle1");
    var coordinates2 = ext.RootCanvasCoordinates(rect1);
    if ((args.MouseX >= coordinates2.Left && args.MouseX <= (coordinates2.Left + rect1.Width )) &&
        (args.MouseY >= coordinates2.Top  && args.MouseY <= (coordinates2.Top  + rect1.Height)))
    { rect1.Fill = "Blue"; } else { rect1.Fill = "Red"; }
    
}


if (!window.Silverlight) 
	window.Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
	return function() {
        return method.apply(instance, arguments);
    }
}
