
// JScript source code
function HotelsResult(lState)
{
    var me = this;
    this.LocationState = lState;
    this.Hotels = new Array();
    this.MaxDistance =-1;
    this._map;
    this._minLat;
    this._maxLat;
    this._minLong;
    this._maxLong;
    this._list;
    this.ShowObject = function(f)
	{
	    var x = 0;
        var y = 0;
        var m = me._map.mapLayer;
        var vp = me._map.viewport;
        var left = parseInt( f.element.style.left ) + parseInt( m.style.left );
        var xBuffer = 15;
        var yBuffer = 15;
        if( left + f.element.offsetWidth + xBuffer > vp.offsetWidth ) {
            x = f.element.offsetWidth - vp.offsetWidth + left + xBuffer;
        }
        else if(left<0)
            x = left - xBuffer;
        var top = parseInt( f.element.style.top ) + parseInt( m.style.top );
        if( top + f.element.offsetHeight + yBuffer > vp.offsetHeight ) {
            y = f.element.offsetHeight - vp.offsetHeight + top + yBuffer;
        }
        else if(top<0)
            y=top - yBuffer;
        if( x != 0 || y != 0 )  {
			if(Math.abs(x)>(vp.offsetWidth*.45) || Math.abs(y)>(vp.offsetHeight*.45))
				me._map.centerOnPoint(f.point);
			else
            	me._map.slideBy( -x, -y );
        }
        f.element.style.visibility = "visible";
	}
	this.HideObject = function(f)
	{
        f.element.style.visibility = "hidden";
	}
    this.AddHotel = function(hotel)
    {
        me.Hotels[me.Hotels.length] = hotel;
		if(hotel.Distance > me.MaxDistance)
			me.MaxDistance=hotel.Distance;
    }
    this.AddList = function(list)
    {
        me._list = list
    }
    this.AddMap = function(map)
    {
        me._map = map;
    }
    this.DrawList = function()
    {
        if(me._list)
        {
            for(var i=0; i<me.Hotels.length; i++)
            {
                me._list.appendChild(me.Hotels[i].ListObject);
            }
        }
        if(me._list.offsetHeight>400)
            me._list.style.height='400px';
    }
    this.DrawMap = function()
    {
        var map = me._map;
        var locationPoint = new DSPoint(me.LocationState.Location.Latitude,me.LocationState.Location.Longitude);
        var marker = DSMap_CreateImage("http://images.myareaguide.com/maps/poi.png",null,null,null,null,20,26);
        var icon = new DSHotel( locationPoint, marker, 0,26);
        var objectid = map.addObject( icon );
        icon.ObjectID = objectid;
        
	    for(var i=0; i<me.Hotels.length; i++)
        {
            objectid = map.addObject(me.Hotels[i].MarkerObject);
            me.Hotels[i].MarkerObject.ObjectID = objectid;
		    objectid = map.addObject(me.Hotels[i].HoverObject);
		    me.Hotels[i].HoverObject.ObjectID = objectid;
		    objectid = map.addObject(me.Hotels[i].DetailObject);
		    me.Hotels[i].DetailObject.ObjectID = objectid;
        }
		map.bestFit();
    }
    this.HideAllDetails = function()
    {
        for(var i=0; i<me.Hotels.length; i++)
        {
            me.Hotels[i].CloseDetail();
        }
    }
    this.HideAllHovers = function()
    {
        for(var i=0; i<me.Hotels.length; i++)
        {
            me.Hotels[i].CloseHover();
        }
    }
    this.ShowLabel = function(marker)
    {
        if(marker.Hotel) marker.ShowInfo(marker.label);
    }
    this.HideLabel = function(marker)
    {
        if(marker.Hotel)
        {
            var label = document.getElementById(marker.label.id);
	        if (label != null) label.parentNode.removeChild(label);
	    }
    }
}
function LocationState(city,state,st,type)
{
    this.City = city;
    this.State = state;
    this.ST = st
    this.Type = type;
    this.Location = new Object();
}
function Hotel(hotels,row,id, name, street, city, state, postalCode, star, startRate,latLong, distance, propURL, availURL)
{
       var me = this
       var MarkerLabels = {'1':'A','2':'B','3':'C','4':'D','5':'E','6':'F','7':'G','8':'H','9':'I','10':'J'}
        this.Hotels = hotels;
        this.Row = row;
		this.ID = id
		this.Name = name;
		this.Street = street;
		this.City = city;
		this.State = state;
		this.PostalCode = postalCode;
		this.Stars = star;
		this.StartRate = startRate;
		this.LatLong = latLong;
		this.Distance = distance;
		this.PropURL = propURL;
		this.AvailURL = availURL;
		this.MarkerObject;
		this.HoverObject;
		this.DetailObject;
		this.ListObject;
		this.BuildList = function()
		{
	        var newelm = DSMap.createElement(null,"div");
	        newelm.className = "hotelmaplist";
	        newelm.innerHTML = '<table cellspacing="0" border="0" width="100%"><tr><td class="hmapnum" width="15" align="center" valign="top"><div style="position:relative">' + ((typeof newelm.style.filter != 'undefined')?'<img style="FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'http://images.myareaguide.com/hotels/marker.png\', sizingMethod=\'scale\');" height=25 src="http://images.myareaguide.com/blank.gif" width=30 galleryImg="no">':'<img src="http://images.myareaguide.com/hotels/marker.png" width="30" height="25">') + '<span class="markerText" style="position:absolute; left:7px; width:19px; text-align:center;">' + MarkerLabels[me.Row] + '</span></div></td><td class="hmapname"' + (row==1?' style="border-top:1px solid #d5d5d5"':'') + '>'+ me.Name + '</td></tr></table>';
	        newelm.onmouseover = function(e){
	            //debugger;
	            if(newelm.className != 'hotelmaplist-clicked') me.MarkerHover();
	           }
	        newelm.onmouseout = function(e){
	            //debugger;
	            if(!e)e=window.event; 
		        var relTarg;
	            if (e.relatedTarget) relTarg = e.relatedTarget;
	            else if (e.toElement) relTarg = e.toElement;
	            if(relTarg)
	            {
	                while (relTarg != newelm && relTarg.nodeName != 'BODY')
		                relTarg= relTarg.parentNode
	                if (relTarg==newelm) return;
	            }
	            me.CloseHover();
	        };
	        //newelm.onclick=me.HoverClick;
	        me.ListObject = newelm;
		}
		this.BuildMarker = function()
		{
	        var newelm = document.createElement('div');
		    var imgelm = DSMap_CreateImage("http://images.myareaguide.com/hotels/marker.png",newelm,null,null,null,30,25);
	        var numspan = DSMap.createElement(newelm,"span",MarkerLabels[me.Row],"style","position:absolute; left:7px; top:1px; width:19px; text-align:center;");
	        numspan.className = "markerText";
	        newelm.appendChild(numspan);
            var hotelicon =  new DSHotel(me.LatLong, newelm, 0, 0 );
	        newelm.onmouseover = function(e) { DSHotel_TriggerMouseOver.call(hotelicon,e); }
			hotelicon.addEventListener('mouseover',me.MarkerHover);
			me.MarkerObject = hotelicon;
		}
		this.BuildHover = function()
		{   
		    var full = DSMap.createElement(null,"div",null,"style","cursor:pointer; position:relative; visibility:hidden");
		    full.id = "Hover-"+me.ID;
		    document.body.appendChild(full);
            var totalheight =1;
            var totalwidth = 7;
            var mainbg = DSMap.createElement(null,'div',null,"style","position:absolute; left:7px;top:1px; background-image:url(http://images.myareaguide.com/hotels/markerbg.png); background-repeat:repeat-x; background-color:#DE9812");
            var elem = DSMap.createElement(null,'div',me.Name,"style","position:absolute; padding-left:8px; line-height:20px; padding-right:3px; left:7px;top:1px; font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; color:#FFFFFF;");
            full.appendChild(elem);
            var width = elem.offsetWidth;

            if (width>236) width=236;
            elem.style.width=width+'px'
            width+=5;
            totalwidth+=width + 4;
            mainbg.style.width=width + 'px';
            var textheight = elem.offsetHeight
            if (textheight<19) textheight=19;
            totalheight+=textheight+5;
            full.removeChild(elem);
            var top = DSMap.createElement(null,'div',null,"style","position:absolute; width:" + width + "px;left:7px;top:0px;");
            var topimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markertop.png',top,null,null,null,width,1);
            full.appendChild(top);
            var topr = DSMap.createElement(null,'div',null,"style","position:absolute; left:" + (width+7) + "px;top:0px;");
            var toprimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markertopright.png',topr,null,null,null,4,1);
            full.appendChild(topr);
            mainbg.style.height = textheight + 'px';
            full.appendChild(mainbg);
            var left = DSMap.createElement(null,'div',null,"style","position:absolute; left:0px;top:6px;");
            var leftimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerleft.png',left,null,null,null,7,textheight-4);
            full.appendChild(left);
            var right = DSMap.createElement(null,'div',null,"style","position:absolute; left:" + (width+7) + "px;top:1px;");
            var rightimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerright.png',right,null,null,null,3,textheight);
            full.appendChild(right);
            var bottom = DSMap.createElement(null,'div',null,"style","position:absolute; left:7px;");
            bottom.style.top= (textheight+1) + 'px';
            var bottomimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerbottom.png',bottom,null,null,null,width,4);
            full.appendChild(bottom);
            var bleft = DSMap.createElement(null,'div',null,"style","position:absolute; left:0px;top:" + (textheight+1) + "px;");
            var bleftimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerbleft.png',bleft,null,null,null,7,4);
            full.appendChild(bleft);
            var bright = DSMap.createElement(null,'div',null,"style","position:absolute; left:" + (width+7) + "px;top:" + (textheight+1) + "px;");
            var brightimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerbright.png',bright,null,null,null,4,4);
            full.appendChild(bright);
            var point = DSMap.createElement(null,'div',null,"style","position:absolute;left:0px;top:0px");
            var pointimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerpoint.png',point,null,null,null,7,6);
            full.appendChild(point);
            full.style.height = totalheight + 'px';
            full.style.width = totalwidth + 'px';
            full.appendChild(elem);
            document.body.removeChild(full);
            var hotelicon =  new DSHotel(me.LatLong, full, 0, 0,5 );
            me.HoverObject = hotelicon;
	        full.onmouseout = function(e) {DSHotel_TriggerMouseOut.call(hotelicon,e); }
	        full.onclick = function(e) {DSHotel_TriggerClick.call(hotelicon,e); }
			hotelicon.addEventListener('mouseout',me.HoverOut);
			hotelicon.addEventListener('click',me.HoverClick);
		}
		this.BuildDetail = function()
		{ 
		    var full = DSMap.createElement(null,"div",null,"style","position:relative; visibility:hidden");
		    full.id = "Detail-"+me.ID;
		    document.body.appendChild(full);
            var totalheight =1;
            var totalwidth = 7;
            var isOrbitz = me.AvailURL.indexOf("obz",1)>0;
            var isSuper8 = me.AvailURL.indexOf("super8",1)>0;
            var mainbg = DSMap.createElement(null,'div',null,"style","position:absolute; left:7px;top:1px; width:228px; line-height:20px; background-image:url(http://images.myareaguide.com/hotels/markerbg.png); background-repeat:repeat-x; background-color:#DE9812");
            var elem = DSMap.createElement(null,'div',null,"style","position:absolute; padding-left:8px; width:211px; line-height:20px; margin-right:1px; left:7px;top:1px; font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; color:#FFFFFF;");
			elem.innerHTML = me.Name;
            full.appendChild(elem);
            var width = elem.offsetWidth;
            totalwidth+=232;
            var textheight = elem.offsetHeight;
            if (textheight<21) textheight=21;
            var detail = DSMap.createElement(null,'div',null,"style","position:absolute; width:228px; margin-right:1px; left:7px;top:" + textheight + "px; font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#555555; background-color:#FFFFFF");
            var closeicon = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerclose.png',full,null,null,null,14,14);
            closeicon.onclick = me.CloseDetail;
            closeicon.style.top = '4px';
            closeicon.style.left = '218px';
            closeicon.style.cursor = "pointer"; 
            closeicon.style.zIndex = 100;
            detail.innerHTML = '<div style="margin:3px 2px 12px 5px"><table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td rowspan="2" valign="top"><div>' + me.Street + 
            '<br>' + me.City + ',' + me.State + " " + me.PostalCode + '</div></td><td align="right"><img src="http://images.myareaguide.com/blank.gif" class="star' + me.Stars + '" style="margin-bottom:10px"></td></tr><tr><td valign="bottom" align="right"><div style="margin-right:5px">' + (me.StartRate?'<span class="hRates">Starting at </span><br><span class="hPrice">$'+me.StartRate + '</span>':'') + '<div><a target="_blank" href="' + me.AvailURL + '" onClick="var s=s_gi(\'olwmarea\');s.linkTrackVars=\'eVar1,events,products\';s.linkTrackEvents=\'purchase\';s.events=\'purchase\';s.eVar1=\'' + (isSuper8?"Wyndam":(isOrbitz?"Orbitz":"IHG")) + '\';s.products=\'travel;hotel-' + (isSuper8?"wyndam":(isOrbitz?"orbitz":"ihg")) + ';1;0.' + (isSuper8?"75":"01") + '\';s.tl(this,\'o\',\'hotel_checkavail\');">Book It</a></div></div></td></tr></table></div>';
            full.appendChild(detail);
            var detailheight = detail.offsetHeight;
            var contentheight = textheight+detailheight;
            totalheight+=contentheight+5;
            full.removeChild(elem);
            full.removeChild(detail);
            var top = DSMap.createElement(null,'div',null,"style","position:absolute; width:228px;left:7px;top:0px;");
            var topimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markertop.png',top,null,null,null,228,1);
            full.appendChild(top);
            var topr = DSMap.createElement(null,'div',null,"style","position:absolute; left:235px;top:0px;");
            var toprimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markertopright.png',topr,null,null,null,4,1);
            full.appendChild(topr);
            mainbg.style.height = textheight + 'px';
            full.appendChild(mainbg);
            var left = DSMap.createElement(null,'div',null,"style","position:absolute; left:0px;top:6px;");
            var leftimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerleft.png',left,null,null,null,7,contentheight-4);
            full.appendChild(left);
            var right = DSMap.createElement(null,'div',null,"style","position:absolute; left:235px;top:1px;");
            var rightimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerright.png',right,null,null,null,3,contentheight);
            full.appendChild(right);
            var bottom = DSMap.createElement(null,'div',null,"style","position:absolute; left:7px;top:" + (contentheight) + "px;");
            var bottomimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerbottom.png',bottom,null,null,null,228,4);
            full.appendChild(bottom);
            var bleft = DSMap.createElement(null,'div',null,"style","position:absolute; left:0px;top:" + (contentheight) + "px;");
            var bleftimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerbleft.png',bleft,null,null,null,7,4);
            full.appendChild(bleft);
            var bright = DSMap.createElement(null,'div',null,"style","position:absolute; left:235px;top:" + (contentheight) + "px;");
            var brightimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerbright.png',bright,null,null,null,4,4);
            full.appendChild(bright);
            var point = DSMap.createElement(null,'div',null,"style","position:absolute;left:0px;top:0px");
            var pointimg = DSMap_CreateImage('http://images.myareaguide.com/hotels/markerpoint.png',point,null,null,null,7,6);
            full.appendChild(point);
            full.style.height = totalheight + 'px';
            full.style.width = totalwidth + 'px';
            full.appendChild(elem);
            full.appendChild(detail);
            document.body.removeChild(full);
            var hotelicon =  new DSHotel(me.LatLong, full, 0, 0,5 );
            me.DetailObject = hotelicon;
	       // full.onmouseout = function(e) {DSHotel_TriggerMouseOut.call(hotelicon,e); }
	        //full.onclick = function(e) {DSHotel_TriggerClick.call(hotelicon,e); }
			//hotelicon.addEventListener('mouseout',me.HoverOut);
			//hotelicon.addEventListener('click',me.DetailClick);
		}
		this.CloseDetail = function()
		{
		    if(me.DetailObject.element.style.visibility=='visible')
		    {
		        me.ListObject.className = "hotelmaplist";
		        me.Hotels.HideObject(me.DetailObject);
		        me.Hotels.ShowObject(me.MarkerObject);
		    }
		}
		this.CloseHover = function()
		{
		    if(me.HoverObject.element.style.visibility=='visible')
		    {
		        me.ListObject.className = "hotelmaplist";
		        me.Hotels.HideObject(me.HoverObject);
		        me.MarkerObject.element.style.visibility = "visible";
		    }
		}
		this.HoverOut = function(evt,obj)
		{
		    if(evt.Event)
		    {
		        if(obj.element.style.visibility=="visible")
		        {
		        var e=evt.Event;
		        var relTarg;
	            if (e.relatedTarget) relTarg = e.relatedTarget;
	            else if (e.toElement) relTarg = e.toElement;
	            //debugger;
	            if(relTarg)
	            {
	                while (relTarg != obj.element && relTarg.nodeName != 'BODY')
		                relTarg= relTarg.parentNode
	                if (relTarg==obj.element) return;
	                var markelm = me.MarkerObject.element;
	                markelm.style.visibility ="visible";
		            me.ListObject.className = "hotelmaplist";
	                var hoverelement = me.HoverObject.element
	                hoverelement.style.visibility ="hidden";
	            }
	            }
		    }
		    
		}
		this.MarkerHover = function()
		{
		    //debugger;
		    me.Hotels.HideAllHovers();
		    me.Hotels.HideObject(me.MarkerObject);
		    //me.Hotels.ShowObject(me.HoverObject);
        	me.HoverObject.element.style.visibility = "visible";
		    me.ListObject.className = "hotelmaplist-hover";
		}
		this.HoverClick = function()
		{
		    me.Hotels.HideAllDetails();
		    me.Hotels.HideObject(me.HoverObject);
		    me.Hotels.ShowObject(me.DetailObject);
		    me.ListObject.className = "hotelmaplist-clicked";
		}
		this.BuildList();
		this.BuildMarker();
		this.BuildHover();
		this.BuildDetail();
}
function DSHotel_GetIcon() {
    return this.element;
}
function DSHotel_Init( point, element, xOffset, yOffset, zOffset ) {
	var main = this;
    DOM2Event.initRegistration( element );
	main.events = new DSEvent();
	main.events.registerEvent('click');
	main.events.registerEvent('mouseover');
	main.events.registerEvent('mouseout');
	element.onclick = function(e) { DSHotel_TriggerClick.call(main,e); }
	element.onmouseover = function(e) { DSHotel_TriggerMouseOver.call(main,e); }
	element.onmouseout = function(e) { DSHotel_TriggerMouseOut.call(main,e); }
    DSHotel.superclass.init.call( this, point, element, xOffset, yOffset, zOffset );
}
function DSHotel_TriggerClick(e)
{
	if (!e) var e = window.event;
	var evt = new Object();
	evt.Event = e;
	this.events.triggerEvent('click', evt, this);
}
function DSHotel_TriggerMouseOver(e)
{
	if (!e) var e = window.event;
	var evt = new Object();
	evt.Event = e;
	this.events.triggerEvent('mouseover', evt, this);
}
function DSHotel_TriggerMouseOut(e)
{
	if (!e) var e = window.event;
	var evt = new Object();
	evt.Event = e;
	this.events.triggerEvent('mouseout', evt, this);
}
function DSHotel_AddEventListener(type, callback)
{
	this.events.addListener(type, callback);
}
function DSHotel( point, iconSrc, xOffset, yOffset, zOffset ) {
    if( arguments.length ) {
        this.init( point, iconSrc, xOffset, yOffset, zOffset );
    }
}
DSHotel.prototype = new DSMapObject();
DSHotel.superclass = DSMapObject.prototype;
DSHotel.prototype.init = DSHotel_Init;
DSHotel.prototype.getIcon = DSHotel_GetIcon;
DSHotel.prototype.addEventListener = DSHotel_AddEventListener;
DSHotel.prototype.triggerMouseOver = DSHotel_TriggerMouseOver;
DSHotel.prototype.triggerMouseOut = DSHotel_TriggerMouseOut;
DSHotel.prototype.triggerClick = DSHotel_TriggerClick;