///////////////////////////////////////////////////////////////////////////////
//
//  File: InkSample.js
//
//  JavaScript event handlers for the Silverlight 1.0 Ink Sample
//  Demonstrates the usage of the InkCanvas class defined in inkCanvas.js
//
//  http://blogs.msdn.com/gavingear/archive/2007/10/08/silverlight-ink-sdk-sample-available-on-microsoft-downloads.aspx
//
//  http://www.thedatafarm.com/silverlightink/
//  http://www.thedatafarm.com/silverink/
//
///////////////////////////////////////////////////////////////////////////////

var silverLight; var silverlightObj;
var inkCanvas;
var root;
var cursorCache;

function root_Loaded(sender, args) 
{
    // Initialize global variables
    silverLight = document.getElementById("SilverlightControl");
    root = silverLight.content.findname("canvasInk");
    
    // Get the InkPresenter defined in xaml
    var inkPresenter;
    inkPresenter = silverLight.content.findname("inkPresenterElement");
    
    // Create and initialize the InkCanvas object (defined in InkCanvas.js)
    inkCanvas = new InkCanvas(inkPresenter, silverLight, null, null);
    inkCanvas.setEditingMode("Ink");
    var da = silverLight.content.createFromXaml("<DrawingAttributes Color='Purple' OutlineColor='White' Width='2' Height='2'/>");    
    inkCanvas.setDefaultDrawingAttributes(da);
}

// Event handler for the pen button on the pen toolbar
function onInk(sender, args)
{
    inkCanvas.setEditingMode("Ink");
    var da = silverLight.content.createFromXaml("<DrawingAttributes Color='Purple' OutlineColor='White' Width='2' Height='2'/>");    
    inkCanvas.setDefaultDrawingAttributes(da);
    root.cursor = "Stylus";     
}

// Event handler for the highlighter button on the pen toolbar
function onHighlight(sender, args)
{
    inkCanvas.setEditingMode("Ink");        
    var da = silverLight.content.createFromXaml("<DrawingAttributes Color='#80ffff00' Width='10' Height='20'/>");    
    inkCanvas.setDefaultDrawingAttributes(da);
    root.cursor = "Stylus";     
}

// Event handler for the selection lasso button on the pen toolbar
function onSelect(sender, args)
{
    inkCanvas.setEditingMode("Select");        
    root.cursor = "Hand";     
}

// Event handler for the eraser button on the pen toolbar
function onErase(sender, args)
{
    inkCanvas.setEditingMode("EraseByStroke");   
    root.cursor = "Eraser";     
}

// Event handler pen toolbar mouse enter
function panelMouseEnter(sender,args)
{
    cursorCache = root.cursor;
    root.cursor = "Hand";
    sender.findName("panel").Opacity = 1;
}

// Event handler pen toolbar mouse leave
function panelMouseLeave(sender, args)
{
    root.cursor = cursorCache ;
    sender.findName("panel").Opacity = 0.7; 
}
