
function onFlockingBirdSilverlightError(sender, args)
{
    var appSource = "";
    if (sender != null && sender != 0)
    {
        appSource = sender.getHost().Source;
    }

    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    if (errorType == "ImageError" || errorType == "MediaError")
    {
        return;
    }

    var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

    errMsg += "Code: " + iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError")
    {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError")
    {
        if (args.lineNumber != 0)
        {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}

function FlockingBirds()
{
    this.Element = null;

    function Flock()
    {
        this.Element = $("#" + flockingHTMLEltID);
        var l_html = "<div id='birdsSilverlightHost' style='z-index:0; width:_w_; height:_h_; position:absolute; left:_l_; top:_t_; background-color:transparent;'>\
        <object data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='100%' height='100%'>\
		  <param name='source' value='/architecture/SL/Birds/SLFlockingBirds2.xap'/>\
		  <param name='onError' value='onFlockingBirdSilverlightError' />\
		  <param name='background' value='transparent' />\
		  <param name='windowless' value='true' />\
		  <param name='minRuntimeVersion' value='3.0.40624.0' />\
		  <param name='autoUpgrade' value='true' />\
		  <param name='initParams' value='ButtonX=200,ButtonY=275,bannerEltID=" + flockingHTMLEltID + "' />\
	    </object></div>";
        l_html = l_html.replace('_w_', this.Element.width() + "px").replace('_h_', this.Element.height() + "px").replace('_l_', this.Element.position().left + "px").replace('_t_', this.Element.position().top + "px");
        this.SLOverlayElt = $("body").append(l_html);
    }

    Flock();
}

$(window).load(function()
{
    var l_flockingMgr = new FlockingBirds();
});
