﻿var zoom_Scale = 1;
var zoom_Scale_Step = 1;
var zoom_Scale_Start = zoom_Scale;
var zoom_Scale_End = 9;
var zoom_Pointer_Step = 5;
var zoom_Pointer_Start = 290;
var move_Step = 30;
var style;
var objectFlag = 0;
var objectVideoFlag = 0;
var cursor;
var cursorstyle = "l";
var cursoricon = "m";
var projectToggle = 0;
var siteToggle = 0;
var offerToggle = 0;
var status = "a";

var p17v = 0;
var p19v = 0;

var _id = "";
// **************************************************************
var beginX;
var beginY;
var trackingMouseMove = false;
cursor = cursoricon + cursorstyle;
function onMouseDown(sender, mouseEventArgs) {
    beginX = mouseEventArgs.getPosition(null).x;
    beginY = mouseEventArgs.getPosition(null).y;

    trackingMouseMove = true;
    //sender.Opacity *= .5;
    sender.captureMouse();
    sender.Cursor = "Hand";
}
var coordY = "y"; var coordX = "x";

function onMouseUp(sender, mouseEventArgs) {
    trackingMouseMove = false;
    //sender.Opacity *= 2;
    sender.releaseMouseCapture();
    sender.Cursor = "Arrow";
}
style = coordX + status + cursor;
var pageCltre = $get("PageCulture");
if (pageCltre.value == "ru-RU")
{ style = style + "ru." + style; }
else if (pageCltre.value == "en-US")
{ style = style + "en." + style; }

function onMouseMove(sender, mouseEventArgs) {
    if (trackingMouseMove == true) {
        var currentX = mouseEventArgs.getPosition(null).x;
        var currentY = mouseEventArgs.getPosition(null).y;

        //sender["Canvas.Left"] += currentX - beginX;
        //sender["Canvas.Top"] += currentY - beginY;

        var map_Canvas = this.control.content.findName("map_Canvas");
        map_Canvas["Canvas.Left"] += currentX - beginX;
        map_Canvas["Canvas.Top"] += currentY - beginY;

        beginX = currentX;
        beginY = currentY;
    }
}
// **************************************************************

var beginX_Zoom;
var beginY_Zoom;
var trackingMouseMove_Zoom = false;

function onMouseDown_Zoom(sender, mouseEventArgs) {
    beginX_Zoom = mouseEventArgs.getPosition(null).x;
    beginY_Zoom = mouseEventArgs.getPosition(null).y;

    trackingMouseMove_Zoom = true;
    //sender.Opacity *= .5;
    sender.captureMouse();
    sender.Cursor = "Hand";
}

function onMouseUp_Zoom(sender, mouseEventArgs) {
    trackingMouseMove_Zoom = false;
    //sender.Opacity *= 2;
    sender.releaseMouseCapture();
    sender.Cursor = "Arrow";
}

function onMouseMove_Zoom(sender, mouseEventArgs) {
    if (trackingMouseMove_Zoom == true) {
        //var currentX = mouseEventArgs.getPosition(null).x;
        var currentY = mouseEventArgs.getPosition(null).y;

        if (currentY > beginY_Zoom) {
            if (zoom_Scale != zoom_Scale_Start) {
                this.handle_map_Canvas_Zoom("ZoomOut");
            }
        }
        else {
            if (zoom_Scale != zoom_Scale_End) {
                this.handle_map_Canvas_Zoom("ZoomIn");
            }
        }

        //var zoom_Rectangle = this.control.content.findName("zoom_pointer_Rectangle");
        //zoom_Rectangle["Rectangle.Left"] += currentX - beginX_Zoom;
        //zoom_Rectangle["Canvas.Top"] += currentY - beginY_Zoom;

        //beginX_Zoom = currentX;
        //beginY_Zoom = currentY;
    }
}

// **************************************************************
function onFullScreenChange(sender, args) {
    var host = sender.getHost();
    var resizer = host.content.findName("parentCanvas_ScaleTransform");

    if (host.content.FullScreen) {
        resizer.scaleX = host.content.actualWidth / host.content.findName("MapJS").width;
        resizer.scaleY = host.content.actualHeight / host.content.findName("MapJS").height;

        var texter = host.content.findName("FullScreen_Text");
        var pageCltre = $get("PageCulture");
        if (pageCltre.value == "ru-RU") { texter.text = "Свернуть"; }
        else if (pageCltre.value == "en-US") { texter.text = "Window"; }
    }
    else {
        resizer.scaleX = 1;
        resizer.scaleY = 1;

        var texter = host.content.findName("FullScreen_Text");
        var pageCltre = $get("PageCulture");
        if (pageCltre.value == "ru-RU") { texter.text = "Развернуть"; }
        else if (pageCltre.value == "en-US") { texter.text = "Full Screen"; }
    }
}

// **************************************************************

if (!window.Intelterra_Tiburon_Scheme)
    window.Intelterra_Tiburon_Scheme = {};

Intelterra_Tiburon_Scheme.Page = function() {
}

Intelterra_Tiburon_Scheme.Page.prototype =
{
    handleLoad: function(control, userContext, rootElement) {
        this.control = control;
        this.root = control.content.findName("navigation_Canvas");

        new whl().wheelScrolled = Silverlight.createDelegate(this, this.handleMouseWheel);

        //        var handleMouseWheel = Silverlight.createDelegate(this, this.handleMouseWheel);

        //        if (window.addEventListener)
        //            window.addEventListener('DOMMouseScroll', handleMouseWheel, false);
        //        window.onmousewheel = document.onmousewheel = handleMouseWheel;

        this.control.content.findName("fullscreen_Canvas").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.fullscreen_handleMouseUp));
        this.control.content.findName("fullscreen_Canvas").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.fullscreen_handleMouseEnter));
        this.control.content.findName("fullscreen_Canvas").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.fullscreen_handleMouseLeave));

        this.control.content.onFullScreenChange = onFullScreenChange;
        this.screenchange();

        this.control.content.findName("project_17_video").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.video_onMouseUp));
        this.control.content.findName("project_19_video").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.video_onMouseUp));

        this.control.content.findName("info_Hide").addEventListener("Completed", Silverlight.createDelegate(this, this.Completed_Hide));

        this.control.content.findName("navigation_Canvas").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, onMouseDown));
        this.control.content.findName("navigation_Canvas").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, onMouseUp));
        this.control.content.findName("navigation_Canvas").addEventListener("MouseMove", Silverlight.createDelegate(this, onMouseMove));

        this.control.content.findName("zoom_pointer_Rectangle").addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, onMouseDown_Zoom));
        this.control.content.findName("zoom_pointer_Rectangle").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, onMouseUp_Zoom));
        this.control.content.findName("zoom_pointer_Rectangle").addEventListener("MouseMove", Silverlight.createDelegate(this, onMouseMove_Zoom));

        this.control.content.findName("move_up_Button").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.move_up_Button_MouseLeftButtonUp));
        this.control.content.findName("move_left_Button").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.move_left_Button_MouseLeftButtonUp));
        this.control.content.findName("move_down_Button").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.move_down_Button_MouseLeftButtonUp));
        this.control.content.findName("move_right_Button").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.move_right_Button_MouseLeftButtonUp));
        this.control.content.findName("move_original_Button").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.move_original_Button_MouseLeftButtonUp));

        this.control.content.findName("zoom_in_Button").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.zoom_in_Button_MouseLeftButtonUp));
        this.control.content.findName("zoom_out_Button").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.zoom_out_Button_MouseLeftButtonUp));

        this.control.content.findName("site_Canvas").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.site_Canvas_MouseLeftButtonUp));
        this.control.content.findName("site_Canvas").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.site_Canvas_MouseEnter));
        this.control.content.findName("site_Canvas").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.site_Canvas_MouseLeave));

        this.control.content.findName("project_Canvas").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.project_Canvas_MouseLeftButtonUp));
        this.control.content.findName("project_Canvas").addEventListener("MouseEnter", Silverlight.createDelegate(this, this.project_Canvas_MouseEnter));
        this.control.content.findName("project_Canvas").addEventListener("MouseLeave", Silverlight.createDelegate(this, this.project_Canvas_MouseLeave));

        var pageIdHF = $get("PageID");

        if (pageIdHF.value == "66" || pageIdHF.value == "65" || pageIdHF.value == "67" || pageIdHF.value == "245" || pageIdHF.value == "244" || pageIdHF.value == "246") {
            this.control.content.findName("info_details").Visibility = "Visible";
        }
        else {
            this.control.content.findName("info_details").Visibility = "Collapsed";
        }

        if (pageIdHF.value == "66" || pageIdHF.value == "245") {
            this.project_Canvas_MouseLeftButtonUp();
            this.offer_Canvas_MouseLeftButtonUp();
        }

        if (pageIdHF.value == "65" || pageIdHF.value == "244") {
            this.site_Canvas_MouseLeftButtonUp();
            this.offer_Canvas_MouseLeftButtonUp();
        }

        if (pageIdHF.value == "67" || pageIdHF.value == "246") {
            this.project_Canvas_MouseLeftButtonUp();
            this.site_Canvas_MouseLeftButtonUp();
        }

        this.control.content.findName("site_00001").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
	this.control.content.findName("site_00002").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00003").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00004").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00005").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00006").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00007").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
	this.control.content.findName("site_00008").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00009").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00010").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00011").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00012").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00013").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00014").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
	this.control.content.findName("site_00015").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00016").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00017").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00018").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00019").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00020").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00021").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00022").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00023").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("site_00024").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
	this.control.content.findName("site_00025").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));

        this.control.content.findName("project_00001").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("project_00002").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("project_00003").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("project_00005").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));

        this.control.content.findName("offer_1").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("offer_2").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("offer_3").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("offer_4").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("offer_5").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
        this.control.content.findName("offer_6").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
	this.control.content.findName("offer_9").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));

        var p17 = this.control.content.findName("project_00017");

        if (p17 != null) {
            p17.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUpVideo));
            this.control.content.findName("project_00019").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUpVideo));
        }

        var content = this.control.content;

        content.findName("info_details").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUpInfoDetails));
        content.findName("info_close").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUpInfoClose));
    },

    screenchange: function() {
        var scrchange = this.control.createObject("downloader");
        scrchange.addEventListener("completed", Silverlight.createDelegate(this, this.changeCompleted));
        scrchange.open("GET", style);
        scrchange.send();
    },

    handleMouseWheel: function(delta) {
        if (delta < 0) {
            if (zoom_Scale != zoom_Scale_Start) {
                this.handle_map_Canvas_Zoom("ZoomOut");
            }
        }
        else {
            if (zoom_Scale != zoom_Scale_End) {
                this.handle_map_Canvas_Zoom("ZoomIn");
            }
        }
    },

    handleMouseUpInfoDetails: function(sender, eventArgs) {

        //document.URL = "default.aspx?oppID=" + _id;

        var name = _id;
        //alert(name);
        var _ = name.indexOf("_");
        var len = name.length;
        var val = name.substring(_ + 1, len);
        //alert(val);
        var type = name.substr(0, _);
        //alert(type);

        var ppp = Sys.WebForms.PageRequestManager.getInstance();

        if (type == "p") {
            //find pid hiddenfield
            var pidnamehf = $get("pidName");
            var pidhf = $get(pidnamehf.value);
            if (pidhf == null) return;
            pidhf.value = val;
            var prjUpd = $get("prjUpd");
            ppp._doPostBack(prjUpd.value, '');

        }
        if (type == "s") {
            //find sid hiddenfield
            var sidnamehf = $get("sidName");
            var sidhf = $get(sidnamehf.value);
            if (sidhf == null) return;
            sidhf.value = val;
            var sitUpd = $get("sitUpd");
            ppp._doPostBack(sitUpd.value, '');

        }
        if (type == "o") {
            //find sid hiddenfield
            var oidnamehf = $get("oidName");
            var oidhf = $get(oidnamehf.value);
            if (oidhf == null) return;
            oidhf.value = val;
            var ofrUpd = $get("ofrUpd");
            ppp._doPostBack(ofrUpd.value, '');
        }
    },

    handleMouseUpInfoClose: function(sender, eventArgs) {
        this.control.content.findName("object_animation").Stop();
        this.control.content.findName("info_Hide").Begin();
    },

    handle_map_Canvas_Zoom: function(action) {
        var zoom_pointer_Rectangle_Y = this.control.content.findName("zoom_pointer_Rectangle");

        if (action == "ZoomIn") { zoom_pointer_Rectangle_Y["Canvas.Top"] = zoom_pointer_Rectangle_Y["Canvas.Top"] - zoom_Pointer_Step; }
        if (action == "ZoomOut") { zoom_pointer_Rectangle_Y["Canvas.Top"] = zoom_pointer_Rectangle_Y["Canvas.Top"] + zoom_Pointer_Step; }
        if (action == "Start") { zoom_pointer_Rectangle_Y["Canvas.Top"] = zoom_Pointer_Start; }

        var map_Canvas_ScaleX_Start = this.control.content.findName("map_Canvas_ScaleX_Start");
        var map_Canvas_ScaleX_End = this.control.content.findName("map_Canvas_ScaleX_End");

        var map_Canvas_ScaleY_Start = this.control.content.findName("map_Canvas_ScaleY_Start");
        var map_Canvas_ScaleY_End = this.control.content.findName("map_Canvas_ScaleY_End");

        map_Canvas_ScaleX_Start["Value"] = zoom_Scale;
        map_Canvas_ScaleY_Start["Value"] = zoom_Scale;

        if (action == "ZoomIn") { zoom_Scale = zoom_Scale + zoom_Scale_Step; }
        if (action == "ZoomOut") { zoom_Scale = zoom_Scale - zoom_Scale_Step; }
        if (action == "Start") { zoom_Scale = zoom_Scale_Start; }

        map_Canvas_ScaleX_End["Value"] = zoom_Scale;
        map_Canvas_ScaleY_End["Value"] = zoom_Scale;

        this.control.content.findName("map_Canvas_Scale").Begin();
    },

    changeCompleted: function(sender, eventArgs) {
        var xamlItem = sender.getResponseText("");
        var top = 0;
        var left = 0;
        var sc = this.control.content.createFromXaml(xamlItem, true);
        this.root.children.add(sc);
        new Tiburon.object(this.control, sc, left, top);
    },

    handleMouseUp: function(sender, eventArgs) {
        //            if (objectFlag == 0)
        //                {
        //                objectFlag = 1;

        var name = sender.Name;

        this.control.content.findName("imageForSite").Source = "Images/000000000.png";

        this.control.content.findName("object_animation").Stop();

        var objan = this.control.content.findName("object_animation_target");
        objan["Storyboard.TargetName"] = sender.Name;

        this.control.content.findName("object_animation").Begin();

        var pageCltre = $get("PageCulture");

        if (pageCltre.value == "ru-RU") {
            if (sender.Name == "site_00001") { _id = "s_1"; this.control.content.findName("textForSite").Text = "№00001"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000001.jpg"; }
            if (sender.Name == "site_00002") { _id = "s_2"; this.control.content.findName("textForSite").Text = "№00002"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000002.jpg"; }
            if (sender.Name == "site_00003") { _id = "s_3"; this.control.content.findName("textForSite").Text = "№00003"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000003.jpg"; }
            if (sender.Name == "site_00004") { _id = "s_4"; this.control.content.findName("textForSite").Text = "№00004"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000004.jpg"; }
            if (sender.Name == "site_00005") { _id = "s_5"; this.control.content.findName("textForSite").Text = "№00005"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000005.jpg"; }
            if (sender.Name == "site_00006") { _id = "s_6"; this.control.content.findName("textForSite").Text = "№00006"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000006.jpg"; }
            if (sender.Name == "site_00007") { _id = "s_7"; this.control.content.findName("textForSite").Text = "№00007"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000007.jpg"; }
            if (sender.Name == "site_00008") { _id = "s_8"; this.control.content.findName("textForSite").Text = "№00008"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000008.jpg"; }
            if (sender.Name == "site_00009") { _id = "s_9"; this.control.content.findName("textForSite").Text = "№00009"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000009.jpg"; }
            if (sender.Name == "site_00010") { _id = "s_10"; this.control.content.findName("textForSite").Text = "№000010"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000010.jpg"; }
            if (sender.Name == "site_00011") { _id = "s_11"; this.control.content.findName("textForSite").Text = "№000011"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000011.jpg"; }
            if (sender.Name == "site_00012") { _id = "s_12"; this.control.content.findName("textForSite").Text = "№000012"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000012.jpg"; }
            if (sender.Name == "site_00013") { _id = "s_13"; this.control.content.findName("textForSite").Text = "№000013"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000013.jpg"; }
            if (sender.Name == "site_00014") { _id = "s_14"; this.control.content.findName("textForSite").Text = "№000014"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000014.jpg"; }
            if (sender.Name == "site_00015") { _id = "s_15"; this.control.content.findName("textForSite").Text = "№000015"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000015.jpg"; }
            if (sender.Name == "site_00016") { _id = "s_16"; this.control.content.findName("textForSite").Text = "№000016"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000016.jpg"; }
            if (sender.Name == "site_00017") { _id = "s_17"; this.control.content.findName("textForSite").Text = "№000017"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000017.jpg"; }
            if (sender.Name == "site_00018") { _id = "s_18"; this.control.content.findName("textForSite").Text = "№000018"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000018.jpg"; }
            if (sender.Name == "site_00019") { _id = "s_19"; this.control.content.findName("textForSite").Text = "№000019"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000019.jpg"; }
            if (sender.Name == "site_00020") { _id = "s_20"; this.control.content.findName("textForSite").Text = "№000020"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000020.jpg"; }
            if (sender.Name == "site_00021") { _id = "s_21"; this.control.content.findName("textForSite").Text = "№000021"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000021.jpg"; }
            if (sender.Name == "site_00022") { _id = "s_22"; this.control.content.findName("textForSite").Text = "№000022"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000022.jpg"; }
            if (sender.Name == "site_00023") { _id = "s_23"; this.control.content.findName("textForSite").Text = "№000023"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000023.jpg"; }
            if (sender.Name == "site_00024") { _id = "s_24"; this.control.content.findName("textForSite").Text = "№000024"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000024.jpg"; }
            if (sender.Name == "site_00025") { _id = "s_97"; this.control.content.findName("textForSite").Text = "№000025"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000025.jpg"; }

            if (sender.Name == "project_00001") { _id = "p_1"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000001.jpg"; }
            if (sender.Name == "project_00002") { _id = "p_2"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000002a.jpg"; }
            if (sender.Name == "project_00003") { _id = "p_3"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000003a.jpg"; }
            if (sender.Name == "project_00005") { _id = "p_5"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000005.jpg"; }

	    if (sender.Name == "offer_1") { _id = "o_1"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000009b.jpg"; }
            if (sender.Name == "offer_2") { _id = "o_2"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "ImageData/Offers/of000000002.jpg"; }
	    if (sender.Name == "offer_4") { _id = "o_4"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000004a.jpg"; }
	    if (sender.Name == "offer_5") { _id = "o_5"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000008.jpg"; }
	    if (sender.Name == "offer_6") { _id = "o_6"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000010b.jpg"; }
            if (sender.Name == "offer_9") { _id = "o_9"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "ImageData/Offers/of000000007.jpg"; }

        }
        else if (pageCltre.value == "en-US") {
            if (sender.Name == "site_00001") { _id = "s_71"; this.control.content.findName("textForSite").Text = "#00001"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000001.jpg"; }
            if (sender.Name == "site_00002") { _id = "s_72"; this.control.content.findName("textForSite").Text = "#00002"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000002.jpg"; }
            if (sender.Name == "site_00003") { _id = "s_73"; this.control.content.findName("textForSite").Text = "#00003"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000003.jpg"; }
            if (sender.Name == "site_00004") { _id = "s_74"; this.control.content.findName("textForSite").Text = "#00004"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000004.jpg"; }
            if (sender.Name == "site_00005") { _id = "s_75"; this.control.content.findName("textForSite").Text = "#00005"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000005.jpg"; }
            if (sender.Name == "site_00006") { _id = "s_76"; this.control.content.findName("textForSite").Text = "#00006"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000006.jpg"; }
            if (sender.Name == "site_00007") { _id = "s_77"; this.control.content.findName("textForSite").Text = "#00007"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000007.jpg"; }
            if (sender.Name == "site_00008") { _id = "s_78"; this.control.content.findName("textForSite").Text = "#00008"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000008.jpg"; }
            if (sender.Name == "site_00009") { _id = "s_79"; this.control.content.findName("textForSite").Text = "#00009"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000009.jpg"; }
            if (sender.Name == "site_00010") { _id = "s_80"; this.control.content.findName("textForSite").Text = "#000010"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000010.jpg"; }
            if (sender.Name == "site_00011") { _id = "s_81"; this.control.content.findName("textForSite").Text = "#000011"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000011.jpg"; }
            if (sender.Name == "site_00012") { _id = "s_82"; this.control.content.findName("textForSite").Text = "#000012"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000012.jpg"; }
            if (sender.Name == "site_00013") { _id = "s_83"; this.control.content.findName("textForSite").Text = "#000013"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000013.jpg"; }
            if (sender.Name == "site_00014") { _id = "s_84"; this.control.content.findName("textForSite").Text = "#000014"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000014.jpg"; }
            if (sender.Name == "site_00015") { _id = "s_85"; this.control.content.findName("textForSite").Text = "#000015"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000015.jpg"; }
            if (sender.Name == "site_00016") { _id = "s_86"; this.control.content.findName("textForSite").Text = "#000016"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000016.jpg"; }
            if (sender.Name == "site_00017") { _id = "s_87"; this.control.content.findName("textForSite").Text = "#000017"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000017.jpg"; }
            if (sender.Name == "site_00018") { _id = "s_88"; this.control.content.findName("textForSite").Text = "#000018"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000018.jpg"; }
            if (sender.Name == "site_00019") { _id = "s_89"; this.control.content.findName("textForSite").Text = "#000019"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000019.jpg"; }
            if (sender.Name == "site_00020") { _id = "s_90"; this.control.content.findName("textForSite").Text = "#000020"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000020.jpg"; }
            if (sender.Name == "site_00021") { _id = "s_91"; this.control.content.findName("textForSite").Text = "#000021"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000021.jpg"; }
            if (sender.Name == "site_00022") { _id = "s_92"; this.control.content.findName("textForSite").Text = "#000022"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000022.jpg"; }
            if (sender.Name == "site_00023") { _id = "s_93"; this.control.content.findName("textForSite").Text = "#000023"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000023.jpg"; }
            if (sender.Name == "site_00024") { _id = "s_94"; this.control.content.findName("textForSite").Text = "#000024"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000024.jpg"; }
            if (sender.Name == "site_00025") { _id = "s_120"; this.control.content.findName("textForSite").Text = "#000025"; this.control.content.findName("imageForSite").Source = "Images/Sites/0000000025.jpg"; }

            if (sender.Name == "project_00001") { _id = "p_33"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000001.jpg"; }
            if (sender.Name == "project_00002") { _id = "p_34"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000002a.jpg"; }
            if (sender.Name == "project_00003") { _id = "p_35"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000003a.jpg"; }
            if (sender.Name == "project_00005") { _id = "p_37"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000005.jpg"; }

	    if (sender.Name == "offer_1") { _id = "o_1"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000009b.jpg"; }
            if (sender.Name == "offer_2") { _id = "o_2"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "ImageData/Offers/of000000002.jpg"; }
	    if (sender.Name == "offer_4") { _id = "o_4"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000004a.jpg"; }
	    if (sender.Name == "offer_5") { _id = "o_5"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000008.jpg"; }
	    if (sender.Name == "offer_6") { _id = "o_6"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "Images/Projects/000000010b.jpg"; }
            if (sender.Name == "offer_9") { _id = "o_9"; this.control.content.findName("textForSite").Text = ""; this.control.content.findName("imageForSite").Source = "ImageData/Offers/of000000007.jpg"; }
	}

        this.control.content.findName("loading_Animation").Begin();
        this.control.content.findName("info_Show").Begin();
    },

    Completed_Hide: function(sender, eventArgs) {
        this.control.content.findName("imageForSite").Source = "ImageData/Map/000000000.png";
        objectFlag = 0;
    },

    handleMouseLeave: function(sender, eventArgs) {
        if (objectFlag == 1) {
            this.control.content.findName("info_Hide").Begin();
            objectFlag = 2;
        }
    },

    video_onMouseUp: function(sender, eventArgs) {
        if (sender.Name == "project_17_video") {
            var v17 = this.control.content.findName("project_17_video");
            if (p17v == 0)
            { v17.pause(); v17.Opacity = 0.3; p17v = 1; }
            else
            { v17.play(); v17.Opacity = 1; p17v = 0; }
        }

        if (sender.Name == "project_19_video") {
            var v19 = this.control.content.findName("project_19_video");
            if (p19v == 0)
            { v19.pause(); v19.Opacity = 0.3; p19v = 1; }
            else
            { v19.play(); v19.Opacity = 1; p19v = 0; }
        }
    },

    handleMouseUpVideo: function(sender, eventArgs) {

        this.control.content.findName("object_animation").Stop();

        var v17 = this.control.content.findName("project_17_video");
        var v17c = this.control.content.findName("project_17_video_Canvas");
        var v19 = this.control.content.findName("project_19_video");
        var v19c = this.control.content.findName("project_19_video_Canvas");

        if (objectVideoFlag == 0) {
            if (sender.Name == "project_00017") {
                var objan = this.control.content.findName("object_animation_target");
                objan["Storyboard.TargetName"] = sender.Name;
                this.control.content.findName("object_animation").Begin();

                v17c.Visibility = "Visible";
                v17.Source = "VideoData/Projects/CBD02w.wmv";
                v17.Cursor = "Hand";
                v17.Opacity = 1
            }
            if (sender.Name == "project_00019") {
                var objan = this.control.content.findName("object_animation_target");
                objan["Storyboard.TargetName"] = sender.Name;
                this.control.content.findName("object_animation").Begin();

                v19c.Visibility = "Visible";
                v19.Source = "VideoData/Projects/CBD01w.wmv";
                v19.Cursor = "Hand";
                v19.Opacity = 1
            }
            objectVideoFlag = 1;
        }
        else if (objectVideoFlag == 1) {
            v17c.Visibility = "Collapsed";
            v19c.Visibility = "Collapsed";
            objectVideoFlag = 0;
        }
    },

    fullscreen_handleMouseUp: function(sender, eventArgs) {
        var host = sender.getHost();
        host.content.fullScreen = !host.content.fullScreen;
    },

    fullscreen_handleMouseEnter: function(sender, eventArgs) {
        this.control.content.findName("FullScreen_Note").Visibility = "Visible";
    },

    fullscreen_handleMouseLeave: function(sender, eventArgs) {
        this.control.content.findName("FullScreen_Note").Visibility = "Collapsed";
    },

    site_Canvas_MouseEnter: function(sender, eventArgs) {
        this.control.content.findName("InvestmentSites_Note").Visibility = "Visible";
    },

    site_Canvas_MouseLeave: function(sender, eventArgs) {
        this.control.content.findName("InvestmentSites_Note").Visibility = "Collapsed";
    },

    project_Canvas_MouseEnter: function(sender, eventArgs) {
        this.control.content.findName("InvestmentProjects_Note").Visibility = "Visible";
    },

    project_Canvas_MouseLeave: function(sender, eventArgs) {
        this.control.content.findName("InvestmentProjects_Note").Visibility = "Collapsed";
    },

    handle_map_Canvas_Move: function(action) {
        var map_Canvas = this.control.content.findName("map_Canvas");

        var map_Canvas_MoveX_Start = this.control.content.findName("map_Canvas_MoveX_Start");
        var map_Canvas_MoveX_End = this.control.content.findName("map_Canvas_MoveX_End");

        var map_Canvas_MoveY_Start = this.control.content.findName("map_Canvas_MoveY_Start");
        var map_Canvas_MoveY_End = this.control.content.findName("map_Canvas_MoveY_End");

        map_Canvas_MoveX_Start["Value"] = map_Canvas["Canvas.Left"];
        map_Canvas_MoveY_Start["Value"] = map_Canvas["Canvas.Top"];

        map_Canvas_MoveX_End["Value"] = map_Canvas["Canvas.Left"];
        map_Canvas_MoveY_End["Value"] = map_Canvas["Canvas.Top"];

        if (action == "Right") { map_Canvas_MoveX_End["Value"] = map_Canvas["Canvas.Left"] - move_Step * zoom_Scale; }
        if (action == "Left") { map_Canvas_MoveX_End["Value"] = map_Canvas["Canvas.Left"] + move_Step * zoom_Scale; }
        if (action == "Up") { map_Canvas_MoveY_End["Value"] = map_Canvas["Canvas.Top"] + move_Step * zoom_Scale; }
        if (action == "Down") { map_Canvas_MoveY_End["Value"] = map_Canvas["Canvas.Top"] - move_Step * zoom_Scale; }
        if (action == "Start") { map_Canvas_MoveX_End["Value"] = 0; map_Canvas_MoveY_End["Value"] = 0; }

        this.control.content.findName("map_Canvas_Move").Begin();
    },

    move_right_Button_MouseLeftButtonUp: function(sender, eventArgs) {
        this.handle_map_Canvas_Move("Right");
    },

    move_left_Button_MouseLeftButtonUp: function(sender, eventArgs) {
        this.handle_map_Canvas_Move("Left");
    },

    move_up_Button_MouseLeftButtonUp: function(sender, eventArgs) {
        this.handle_map_Canvas_Move("Up");
    },

    move_down_Button_MouseLeftButtonUp: function(sender, eventArgs) {
        this.handle_map_Canvas_Move("Down");
    },

    move_original_Button_MouseLeftButtonUp: function(sender, eventArgs) {
        this.handle_map_Canvas_Move("Start");
        this.handle_map_Canvas_Zoom("Start");
    },

    zoom_in_Button_MouseLeftButtonUp: function(sender, eventArgs) {
        if (zoom_Scale != zoom_Scale_End) {
            this.handle_map_Canvas_Zoom("ZoomIn");
        }
    },

    zoom_out_Button_MouseLeftButtonUp: function(sender, eventArgs) {
        if (zoom_Scale != zoom_Scale_Start) {
            this.handle_map_Canvas_Zoom("ZoomOut");
        }
    },

    site_Canvas_MouseLeftButtonUp: function(sender, eventArgs) {
        if (siteToggle == 0) {
            siteToggle = 1;
            this.control.content.findName("site_Canvas_Down").Begin();
            this.control.content.findName("sites_Canvas_Hide").Begin();
            var sc = this.control.content.findName("sites_Canvas");
            sc["Visibility"] = "Collapsed";
        }
        else {
            siteToggle = 0;
            var sc = this.control.content.findName("sites_Canvas");
            sc["Visibility"] = "Visible";
            this.control.content.findName("site_Canvas_Up").Begin();
            this.control.content.findName("sites_Canvas_Show").Begin();
        }
    },

    project_Canvas_MouseLeftButtonUp: function(sender, eventArgs) {
        if (projectToggle == 0) {
            projectToggle = 1;
            this.control.content.findName("project_Canvas_Down").Begin();
            this.control.content.findName("projects_Canvas_Hide").Begin();
            var pc = this.control.content.findName("projects_Canvas");
            pc["Visibility"] = "Collapsed";
        }
        else {
            projectToggle = 0;
            var pc = this.control.content.findName("projects_Canvas");
            pc["Visibility"] = "Visible";
            this.control.content.findName("project_Canvas_Up").Begin();
            this.control.content.findName("projects_Canvas_Show").Begin();
        }
    },

    offer_Canvas_MouseLeftButtonUp: function() {
        if (offerToggle == 0) {
            offerToggle = 1;
            //this.control.content.findName("offers_Canvas_Down").Begin();
            this.control.content.findName("offers_Canvas_Hide").Begin();
            var oc = this.control.content.findName("offers_Canvas");
            oc["Visibility"] = "Collapsed";
        }
        else {
            offerToggle = 0;
            var oc = this.control.content.findName("offers_Canvas");
            oc["Visibility"] = "Visible";
            //this.control.content.findName("offers_Canvas_Up").Begin();
            this.control.content.findName("offers_Canvas_Show").Begin();
        }
    }

}
