﻿// JScript File
document.oncontextmenu=disableit;
    function disableit()
    {
    //alert("done")
    return false;
    }
    
var map = null;
    var geocoder = null;
    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        geocoder = new GClientGeocoder();   
        launchMap('');
      }
      
       var imgs = document.getElementsByName("get-images");
       var len=imgs.length;
		for(i=0;i<len;i++)
		{
			imgs[i].src=imgs[i].id;
		}
    }
     
   
    function launchMap(id) {
    if (id == '')
    {
        address = MapLoc;
    }
    else
    {
    
    var imgs = document.getElementsByName("img-" + id);
    var len=imgs.length;
		for(i=0;i<len;i++)
		{
			imgs[i].src=imgs[i].id;
		}


    document.getElementById("info").style.display="block";
    document.getElementById("details").style.display="block";
     document.getElementById("info").innerHTML = document.getElementById(id).innerHTML;
      document.getElementById("near").style.display="none";   
        //document.getElementById("info").innerHTML += "<a href=\"javascript:viewnearby();\">View neighborhood</a>" ;
       document.getElementById("map").focus();
       address = document.getElementById(id).title;
     } 
       if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              //alert(address + " not found");
            } else {
              document.getElementById("map").style.display="block";  
              map.setCenter(point, 16, G_HYBRID_MAP);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
      
    }
    
    function clearIt(what)
    {
	    if(what.value == '(e.g. L5M)' || what.value == '(e.g. open concept)') what.value = '';
    }
    
    
    function onEnter( evt, frm ) {
    var keyCode = null;

    if( evt.which ) {
    keyCode = evt.which;
    } else if( evt.keyCode ) {
    keyCode = evt.keyCode;
    }
    if( 13 == keyCode ) {
    document.getElementById(frm.id).click();
    return false;
    }
    return true;
}

 function nextPage(ID)
    {
       try
       {
          document.getElementById(pager).value = ID; 
          document.getElementById(btnSearch).click();
       }
       catch(ex)
       {} 
    }
    
    var address = "";
    
    function viewnearby()
    {
        
        //alert(address);
        document.getElementById("nearby").src = "NearBy.aspx?id=" + address;
        document.getElementById("near").style.display="block"; 
        
    }

    function hidedetails()
    {
        document.getElementById("info").style.display="none"; 
        //document.getElementById("map").style.display="none"; 
        document.getElementById("near").style.display="none";   
         document.getElementById("details").style.display="none";   
    }

function ImageExpander(oThumb, sImgSrc)
{
	// store thumbnail image and overwrite its onclick handler.
	this.oThumb = oThumb;
	this.oThumb.expander = this;
	this.oThumb.onclick = function() { this.expander.expand(); }
	
	// record original size
	this.smallWidth = oThumb.offsetWidth;
	this.smallHeight = oThumb.offsetHeight;	

	this.bExpand = true;
	this.bTicks = false;
	
	// self organized list
	if ( !window.aImageExpanders )
	{
		window.aImageExpanders = new Array();
	}
	window.aImageExpanders.push(this);

	// create the full sized image.
	this.oImg = new Image();
	this.oImg.expander = this;
	this.oImg.onload = function(){this.expander.onload();}
	this.oImg.src = sImgSrc;
}

ImageExpander.prototype.onload = function()
{
	this.oDiv = document.createElement("div");
	document.body.appendChild(this.oDiv);
	this.oDiv.appendChild(this.oImg);
	this.oDiv.style.position = "absolute";
	this.oDiv.expander = this;
	this.oDiv.onclick = function() {this.expander.toggle();};
	this.oImg.title = "Click to reduce.";
	this.bigWidth = this.oImg.width;
	this.bigHeight = this.oImg.height;
	
	if ( this.bExpand )
	{
		this.expand();
	}
	else
	{
		this.oDiv.style.visibility = "hidden";
		this.oImg.style.visibility = "hidden";
	}
}
ImageExpander.prototype.toggle = function()
{
	this.bExpand = !this.bExpand;
	if ( this.bExpand )
	{
		for ( var i in window.aImageExpanders )
			if ( window.aImageExpanders[i] !== this )
				window.aImageExpanders[i].reduce();
	}
}
ImageExpander.prototype.expand = function()
{
	// set direction of expansion.
	this.bExpand = true;

	// set all other images to reduce
	for ( var i in window.aImageExpanders )
		if ( window.aImageExpanders[i] !== this )
			window.aImageExpanders[i].reduce();

	// if not loaded, don't continue just yet
	if ( !this.oDiv ) return;
	
	// hide the thumbnail
	this.oThumb.style.visibility = "hidden";
	
	// calculate initial dimensions
	this.x = this.oThumb.offsetLeft; //+ 300;
	this.y = this.oThumb.offsetTop; //+ 300;
	this.w = this.oThumb.clientWidth;
	this.h = this.oThumb.clientHeight;
	
	this.oDiv.style.left = this.x + 300 + "px";
	this.oDiv.style.top = this.y + 300 + "px";
	this.oImg.style.width = this.w + "px";
	this.oImg.style.height = this.h + "px";
	this.oDiv.style.visibility = "visible";
	this.oImg.style.visibility = "visible";
	
	// start the animation engine.
	if ( !this.bTicks )
	{
		this.bTicks = true;
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},25);	
	}
}
ImageExpander.prototype.reduce = function()
{
	// set direction of expansion.
	this.bExpand = false;
}
ImageExpander.prototype.tick = function()
{
	// calculate screen dimensions
	var cw = document.body.clientWidth;
	var ch = document.body.clientHeight;
	var cx = document.body.scrollLeft + cw / 4;
	var cy = document.body.scrollTop + ch / 5;

	// calculate target
	var tw,th,tx,ty;
	if ( this.bExpand )
	{
		tw = this.bigWidth;
		th = this.bigHeight;
		if ( tw > cw )
		{
			th *= cw / tw;
			tw = cw;
		}	
		if ( th > ch )
		{
			tw *= ch / th;
			th = ch;
		}
		tx = cx - tw / 2;
		ty = cy - th / 2; 
	}
	else
	{
		tw = this.smallWidth;
		th = this.smallHeight;
		tx = this.oThumb.offsetLeft;
		ty = this.oThumb.offsetTop;
	}	
	// move 5% closer to target
	var nHit = 0;
	var fMove = function(n,tn) 
	{
		var dn = tn - n;
		if ( Math.abs(dn) < 3 )
		{
			nHit++;
			return tn;
		}
		else
		{
			return n + dn / 10;
		}
	}
	this.x = fMove(this.x, tx);
	this.y = fMove(this.y, ty);
	this.w = fMove(this.w, tw);
	this.h = fMove(this.h, th);
	
	this.oDiv.style.left = this.x + 300 + "px";
	this.oDiv.style.top = this.y + 300 + "px";
	this.oImg.style.width = this.w + "px";
	this.oImg.style.height = this.h + "px";

	// if reducing and size/position is a match, stop the tick	
	if ( !this.bExpand && (nHit == 4) )
	{
		this.oImg.style.visibility = "hidden";
		this.oDiv.style.visibility = "hidden";
		this.oThumb.style.visibility = "visible";

		this.bTicks = false;
	}
	
	if ( this.bTicks )
	{
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},25);
	}
}

