﻿// Version 0.0  Initial version 
// Version 0.1  10/10/2006 Added E_STYLE_7 
// Version 0.2  17/05/2007 Added .isHidden() and .supportsHide()
// Version 0.3  14/09/2007 added .zindex()
// Version 1.0  03/07/2008 RWN migrated from millerPX


var _toolTipScope = null;

/* -----------------------------------------------------------------
    Single development tooltip 
*/
var ExploreTooltip = Class.create();

ExploreTooltip.prototype = {

    _development: null,

    _exploreMapInstance: null,

    isIE6: function() {
        ///<summary>Is the current browser IE 6</summary>
        return (BrowserDetect.browser == "Explorer" && BrowserDetect.version == "6");
    },

    getHTML: function() { 
        ///<summary>Get the html for an Explorer map tooltip</summary>

        var html = new Array();
        html.push('<div id="mapToolTip">');
        html.push('<div class="exploreTooltipWrapper">');
        html.push('<div class="exploreTooltipInner">');

        html.push('<div class="closeButton">');
        html.push('<a href="#" onclick="return removeAll()">');
        html.push('<img src="../../images/icons/close.gif" class="closeImg" alt="close" />');
        html.push('</a>');
        html.push('</div>');

        html.push('<div class="left">');

        html.push('<div class="title">');
        html.push(this._development.Title);
        html.push('</div>');
        html.push('<div class="beds">');
        html.push(this._development.BedroomCount);
        html.push('</div>');
        html.push('<div class="summary">');
        html.push(this._development.PriceFrom);
        html.push('</div>');
        html.push('<div class="summary">');
        html.push(this._development.Postcode);
        html.push('</div>');

        if (this._development.HasSpecialOffer) {
            html.push('<div class="specialOfferLbl">');
            html.push('OFFERS AVAILABLE!');
            html.push('</div>');
        }

        html.push('<div class="summary">');
        html.push('<a href="' + this._development.DevelopmentUrl + '">View details</a>');
        html.push('</div>');

        html.push('</div>');

        // show image or coming soon text        
        if (this._development.ImageUrl.length > 0) {
            html.push('<div class="right">');
            html.push('<img src="' + this._development.ImageUrl + '" alt="" />');
            html.push('</div>');
        } else {
            html.push('<div class="right">');
            html.push('<img src="/Miller.HomesWeb/img/coming_soon_small.gif" alt="coming soon" />');
            html.push('</div>');
        }

        html.push('<div class="clearLeft"></div>');

        html.push('</div>');

        html.push('<div class="tail"></div>');

        html.push('</div>');
        html.push('<div>');
        html.push('<div class="tailLeft"></div>');
        html.push('<div class="tailGraphic"></div>');
        html.push('<div class="tailRight"></div>');
        html.push('<div class="clearLeft"></div>');
        html.push('</div>');
        html.push('</div>');


        return html.join('');
    },

    initialize: function(development, exploreMapInstance) {
        ///<summary>Initialise a new instance of the Explore map tooltip object</summary>
        ///<param name="developmet">The development to be identified by this tooltip</param>        
        this._development = development;
        this._exploreMapInstance = exploreMapInstance;
        _toolTipScope = this;
    }
};


/* -----------------------------------------------------------------
Single development tooltip 
*/
var ExploreMultiTooltip = Class.create();

ExploreMultiTooltip.prototype = {

    _development: null,

    _developmentArray: null,

    _exploreMapInstance: null,

    isIE6: function() {
        ///<summary>Is the current browser IE 6</summary>
        return (BrowserDetect.browser == "Explorer" && BrowserDetect.version == "6");
    },

    getHTML: function() {
        ///<summary>Get the html for an Explorer map tooltip</summary>

        var html = new Array();

        html.push('<div id="mapToolTip">');
        html.push('<div class="exploreTooltipWrapper">');
        html.push('<div class="exploreTooltipInner">');

        html.push('<div class="closeButton">');
        html.push('<a href="#" onclick="return removeAll()">');
        html.push('<img src="../../images/icons/close.gif" class="closeImg" alt="close" />');
        html.push('</a>');
        html.push('</div>');

        html.push('<div class="">');
        for (var i = 0; i < this._developmentArray.length; i++) {

            html.push('<div class="developmentItem">');

            // icon
            html.push('<div class="iconSide">');
            if (this._developmentArray[i].IsCurrent.toLowerCase() == 'true')
                html.push('<img src="/Miller.HomesWeb/img/GIcons/current_icon1.gif" alt="" />');
            else
                html.push('<img src="/Miller.HomesWeb/img/GIcons/future_icon1.gif" alt="" />');
            html.push('</div>');

            // details
            html.push('<div class="detailsSide">');
            html.push('<div class="title">');
            if (this._developmentArray[i].IsCurrent.toLowerCase() == 'true') {
                html.push('<span class="current">');
                html.push(this._developmentArray[i].Title);
                html.push('</span>');
            } else {
                html.push('<span class="future">');
                html.push(this._developmentArray[i].Title);
                html.push('</span>');
            }
            html.push('</div>');

            html.push('<div class="summary">');
            html.push(this._developmentArray[i].Locality);
            html.push('</div>');
            html.push('<div class="summary">');
            html.push('<a href="' + this._developmentArray[i].DevelopmentUrl + '">View details</a>');
            html.push('</div>');

            html.push('</div>');

            html.push('<div class="clearLeft"></div>');
            html.push('</div>');
        }
        html.push('</div>');

        html.push('</div>');

        html.push('<div class="tail"></div>');

        html.push('</div>');
        html.push('<div>'); // close #exploreTooltipInner
        html.push('<div class="tailLeft"></div>');
        html.push('<div class="tailGraphic"></div>');
        html.push('<div class="tailRight"></div>');
        html.push('<div class="clearLeft"></div>');
        html.push('</div>'); // close #exploreTooltipWrapper
        //html.push('</div>'); // close #mapToolTip


        return html.join('');
    },

    initialize: function(developmentArray, exploreMapInstance) {
        ///<summary>Initialise a new instance of the Explore map tooltip object</summary>
        ///<param name="developmet">The development to be identified by this tooltip</param>        
        this._developmentArray = developmentArray;
        this._exploreMapInstance = exploreMapInstance;
        _toolTipScope = this;
    }
};

/* -------------------------------------------------------------------- */
/* Browser sniff */
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
/* ---------------------------------------------------- */





// rwn : code taken from http://econym.googlepages.com/example_ewindowclose.htm


      function EStyle(stemImage, stemSize, boxClass, boxOffset) {
        this.stemImage = stemImage;
        this.stemSize = stemSize;
        this.boxClass = boxClass;
        this.boxOffset = boxOffset;
        //this.border = border;
        
        // Known fudge factors are:
        // Firefox (1.0.6 and 1.5)    5, -1
        // IE 6.0                     0, -1
        // Opera 8.54                 3, -1
        // Opera 9 prev               4, -1
        // Netscape (7.2, 8.0)        5, -1
        // Safari                     5, -1        
        
        var agent = navigator.userAgent.toLowerCase();
        
        var fudge = 5;  // assume Netscape if no match found
       
        if (agent.indexOf("opera") > -1) {
          fudge = 3;
        }   
        if (agent.indexOf("firefox") > -1) {
          fudge = 5;
        }   
        if (agent.indexOf("safari") > -1) {
          fudge = 5;
        }   
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){
          fudge = 0;
        }
        this.fudge = fudge;
      }
      
    // tooltip properties inc. stem graphic (unused), graphic size(unused), outer css class (unused) 
    // and tooltip offset - the only property still used!!!
    var E_STYLE = new EStyle("images/pins/stem.png", new GSize(24,24),  "estyle2", new GPoint(-200,-200)); // RWN : 27/08/08 OK in FF
    // IE style
    var E_STYLE2 = new EStyle("images/pins/stem.png", new GSize(24,24),  "estyle2", new GPoint(-145,-10)); // RWN : 11/08/08 OK in IE7
    // IE 6 style
    var E_STYLE2_IE6 = new EStyle("images/pins/stem.png", new GSize(24,24),  "estyle2", new GPoint(-145,-10)); // RWN : 27/08/08 not OK in IE6


    BrowserDetect.init();


      function EWindow(map, styleName) {
        // parameters
        this.map=map;
        if(styleName == '0')        
        {
            this.estyle = E_STYLE;
        }
        else
        {
            if(BrowserDetect.browser == "Explorer" && BrowserDetect.version != "7")
            {
                //!IE7
                this.estyle = E_STYLE2_IE6;
            }
            else
            {
                // IE7
                this.estyle = E_STYLE2;
            }                       
        }
        
        // internal variables
        this.visible = false;
        // browser - specific variables
        this.ie = false;
        var agent = navigator.userAgent.toLowerCase();
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){ this.ie = true} else {this.ie = false}
      } 
      
      EWindow.prototype = new GOverlay();

      EWindow.prototype.initialize = function(map) {
        var div1 = document.createElement("div");
        div1.style.position = "absolute";
        map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div1);
        
        var div2 = document.createElement("div");
        div2.style.position = "absolute";
        div2.style.width = this.estyle.stemSize.width+"px";
        map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div2);
        
        this.div1 = div1;
        this.div2 = div2;
      }

      EWindow.prototype.openOnMap = function(point, html, offset) {
        this.offset = offset||new GPoint(0,0);
        this.point = point;
        this.div1.innerHTML = '<div class="' + this.estyle.boxClass + '">' + html + '</div>';
        
        var z = GOverlay.getZIndex(this.point.lat());
        this.div1.style.zIndex = z;
        this.div2.style.zIndex = z+1;
        this.visible = true;
        this.show();
        this.redraw(true);
      }
      
      EWindow.prototype.openOnMarker = function(marker,html) {
        var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
        var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y;
        this.openOnMap(marker.getPoint(), html, new GPoint(vx,vy));
      }
      

      EWindow.prototype.redraw = function(force) {
        if (!this.visible) {return;}
        var p = this.map.fromLatLngToDivPixel(this.point);
        this.div2.style.left   = (p.x + this.offset.x) + "px";
        this.div2.style.bottom = (-p.y + this.offset.y -this.estyle.fudge) + "px";
        this.div1.style.left   = (p.x + this.offset.x + this.estyle.boxOffset.x) + "px";
        this.div1.style.bottom = (-p.y + this.offset.y + this.estyle.boxOffset.y) + "px";
      }

      EWindow.prototype.remove = function() {
        this.div1.parentNode.removeChild(this.div1);
        this.div2.parentNode.removeChild(this.div2);
        this.visible = false;
      }

      EWindow.prototype.copy = function() {
        return new EWindow(this.map, this.estyle);
      }

      EWindow.prototype.show = function() {
        this.div1.style.display="";
        // this.div2.style.display="";
        this.visible = true;
      }
      
      EWindow.prototype.hide = function() {
        this.div1.style.display="none";
        this.div2.style.display="none";
        this.visible = false;
      }
      
      EWindow.prototype.isHidden = function() {
        return !this.visible;
      }
      
      EWindow.prototype.supportsHide = function() {
        return true;
      }

      EWindow.prototype.zindex = function(zin) {
        var z = GOverlay.getZIndex(this.point.lat());
        this.div1.style.zIndex = z+zin;
        this.div2.style.zIndex = z+1+zin;
      }
