var flagFloorPlanLoaded = false;
var flagToolbarLoaded = false;

function createCanvas()
{  
    Silverlight.createObject(
        "/EN/directory/Documents/FloorPlan.xaml",                  // Source property value.
        SilverlightHostElement,                  // DOM (Document Object Model) reference to hosting DIV tag.
        "mapSilverLightPlugin",         // Unique plug-in ID value.
        {                               // Per-instance properties.

            width:'100%',                // Width of rectangular region of 
                                        // plug-in area in pixels.
            height:'100%',               // Height of rectangular region of 
                                        // plug-in area in pixels.
            inplaceInstallPrompt:false, // Determines whether to display 
                                        // in-place install prompt if 
                                        // invalid version detected.
            background:'white',       // Background color of plug-in.
            isWindowless:'false',       // Determines whether to display plug-in 
                                        // in Windowless mode.
            framerate:'24',             // MaxFrameRate property value.
            version:'1.0'               // Silverlight version to use.
        },
        {
            onError:null,               // OnError property value -- 
                                        // event handler function name.
            onLoad:FloorPlanLoaded        // OnLoad property value -- 
                                        // event handler function name.
        },
        null);                          // Context value -- event handler function name.

    Silverlight.createObject(
        "/_layouts/cfretail/scripts/Createtoolbar.xaml",                  // Source property value.
        document.getElementById('navSilverlightIndex'),                  // DOM (Document Object Model) reference to hosting DIV tag.
        "ToolbarSilverlightPlugin",         // Unique plug-in ID value.
        {                               // Per-instance properties.
            width:'100%',                // Width of rectangular region of 
                                        // plug-in area in pixels.
            height:'100%',               // Height of rectangular region of 
                                        // plug-in area in pixels.
            inplaceInstallPrompt:false, // Determines whether to display 
                                        // in-place install prompt if 
                                        // invalid version detected.
            background:'white',       // Background color of plug-in.
            isWindowless:'false',       // Determines whether to display plug-in 
                                        // in Windowless mode.
            framerate:'24',             // MaxFrameRate property value.
            version:'1.0'               // Silverlight version to use.
        },
        {
            onError:null,               // OnError property value -- 
                                        // event handler function name.
            onLoad:ToolbarLoaded                 // OnLoad property value -- 
                                        // event handler function name.
        },
        null);                          // Context value -- event handler function name.
}

function FloorPlanLoaded()
{
	var str= String(location);
	var bilingualSwitch = 0;
	var newName = "";

	if ((str.indexOf("/FR/") != -1) || (str.indexOf("/fr/") != -1) || (str.indexOf("/Fr/") != -1) || (str.indexOf("/fR/") != -1))
	{
		bilingualSwitch = 1;
	}
	else if ((str.indexOf("/EN/") != -1)  || (str.indexOf("/en/") != -1) || (str.indexOf("/En/") != -1) || (str.indexOf("/eN/") != -1))
	{
		bilingualSwitch = 0;
	}

	var parent = _plugin.content.findName('model.viewport');
	var childrenCount = parent.children.count;

	for (var i = 0; i < childrenCount; i++)
	{
		var child = parent.children.getItem(i);
		if (child.toString() == 'TextBlock') 
			if (String(child.text).indexOf('|') != -1)
			{
				newName = String(child.text).split("|");
				child.text = newName[bilingualSwitch];
			}
	}

	flagFloorPlanLoaded = true;
	
	if (flagFloorPlanLoaded && flagToolbarLoaded)
	{
		toolBarLoad2();
	}
}
function ToolbarLoaded()
{
	flagToolbarLoaded = true;
	
	if (flagFloorPlanLoaded && flagToolbarLoaded)
	{
		toolBarLoad2();
	}
}

function toolBarLoad()
{
}

function toolBarLoad2()
{
	var positionX=11;
	var positionY=170;
	var ToolBarCanvas = document.getElementById("ToolbarSilverlightPlugin");
	var canvas = getByName('FloorPlanLevels');
	var str= String(location);
	var bilingualSwitch = 0;
	var newName = "";
	if ((str.indexOf("/FR/") != -1) || (str.indexOf("/fr/") != -1) || (str.indexOf("/Fr/") != -1) || (str.indexOf("/fR/") != -1))
	{
		bilingualSwitch = 1;
	}
	else if ((str.indexOf("/EN/") != -1)  || (str.indexOf("/en/") != -1) || (str.indexOf("/En/") != -1) || (str.indexOf("/eN/") != -1))
	{
		bilingualSwitch = 0;
	}


	if (canvas.children.count > 2)
	{
		for (var i=0; i<canvas.children.count;i++)
		{
			if ((String(canvas.children.getItem(i).Name)).indexOf("|") == -1)
			{
				var Levels = '<TextBlock Name="' + canvas.children.getItem(i).Name + '" Cursor = "hand" MouseLeftButtonDown = "ZoomIn" MouseEnter = "SelectHighlight" MouseLeave = "UnSelectHighlight" Foreground = "white" TextDecorations="Underline" FontWeight="Bold" FontSize="10" Canvas.Top="'+positionY+ '" Canvas.Left="'+positionX+'" Text="'+canvas.children.getItem(i).Name+'" />';
			}
			else
			{
				newName = (String(canvas.children.getItem(i).Name)).split("|");
				var Levels = '<TextBlock Name="' + canvas.children.getItem(i).Name + '" Cursor = "hand" MouseLeftButtonDown = "ZoomIn" MouseEnter = "SelectHighlight" MouseLeave = "UnSelectHighlight" Foreground = "white" TextDecorations="Underline" FontWeight="Bold" FontSize="10" Canvas.Top="'+positionY+ '" Canvas.Left="'+positionX+'" Text="'+newName[bilingualSwitch]+'" />';
			}
			var e = ToolBarCanvas.content.createFromXaml(Levels);
			positionY = positionY + 12;
			ToolBarCanvas.content.root.children.Add(e);
		}
	}else{
		
		if ((String(canvas.children.getItem(0).Name)).indexOf("|") == -1)
			{
				var Levels = '<TextBlock Name="' + canvas.children.getItem(0).Name + '" Cursor = "hand" MouseLeftButtonDown = "ZoomIn" MouseEnter = "SelectHighlight" MouseLeave = "UnSelectHighlight" Foreground = "white" TextDecorations="Underline" FontWeight="Bold" FontSize="10" Canvas.Top="'+positionY+ '" Canvas.Left="'+positionX+'" Text="'+canvas.children.getItem(0).Name+'" />';
			}
			else
			{
				newName = (String(canvas.children.getItem(0).Name)).split("|");
				var Levels = '<TextBlock Name="' + canvas.children.getItem(0).Name + '" Cursor = "hand" MouseLeftButtonDown = "ZoomIn" MouseEnter = "SelectHighlight" MouseLeave = "UnSelectHighlight" Foreground = "white" TextDecorations="Underline" FontWeight="Bold" FontSize="10" Canvas.Top="'+positionY+ '" Canvas.Left="'+positionX+'" Text="'+newName[bilingualSwitch]+'" />';
			}
		var e = ToolBarCanvas.content.createFromXaml(Levels);
		positionY = positionY + 12;
		ToolBarCanvas.content.root.children.Add(e);
	}

	LoadZoom();
	PopulateDropDown2();
}


