 function findimg()
{

 var imgs,i,imgb;
imgb=document.getElementById('imgMain');
 imgs=document.getElementsByTagName('img');
 objImage = new Array();
 var x = 0;
 for(i=0;i<imgs.length;i++)
 {
  if(/thumbnail/.test(imgs[i].className))
  {

src = imgs[i].src;
objImage[x] = new Image();
 	  var pos = src.lastIndexOf("_");
	  var newsrc = src.substr(0,pos) + "_l.jpg";
objImage[x].src=newsrc;
   imgs[i].onclick=function(){swap(this,imgb);};

	  x=x+1;
  }
 }
      imgb.onload=function(){isLoaded();};
	  imgb.onclick=function(){
	  $('#zoom').attr('src', $(this).attr('src'));
	  
	  var offset = $(this).offset();
	  $('#zoom').css({'top': offset.top, 'left': offset.left, 'height': $('#imgMain').height()});
	  var left=$(window).width()/2-$(this).width()/$(this).height()*$(window).height()/2;
	  if (left<1){left=0;}
	  $('#zoom').animate({
	      top: $(window).scrollTop(),
	      left: left ,
    height: $(window).height()
	  });
	  // CenterFloat($('#zoom'),$('#zoom').height()/2+285,$('#zoom').width()+330);
	  
	  $('#zoom').show();
	  };
}

function isLoaded()
{
$('#imgMain').show();
$('#loader').hide();
imgLoaded=1;
}
function swap(o, target)
{
if(imgLoaded){
imgLoaded=0;
 var src,newsrc;
 src = o.src;
 $('#imgMain').hide(); $('#loader').show();
  tsrc = target.src;
 	  var pos = src.lastIndexOf("_");
	  var newsrc = src.substr(0,pos) + "_l.jpg";
 target.src=newsrc;
 
 	  pos = tsrc.lastIndexOf("_");
	  newsrc = tsrc.substr(0,pos) + "_th.jpg";
o.src=newsrc;
}
}
  var ModalVisible = 0;

  function CloseModal(){
	$('#mask').fadeOut("fast");
	$('#modal').fadeOut("fast");
	$('#zoom').hide();
	ModalVisible = 0;
  }
  $(window).resize(function(){
  if(ModalVisible){
  	  var left=$(window).width()/2-$('#zoom').width()/$('#zoom').height()*$(window).height()/2;
	  if (left<1){left=0;}
	  $('#zoom').css({'top': $(window).scrollTop(), 'left': left, 'height':  $(window).height()});

  $('#mask').css('width', $(document).width() + "px");
$('#mask').css('height', $(document).height() + "px");
CenterFloat($('#modal'), 600,900);
  }
  });
function CenterFloat(o,mHeight,mWidth){
  var wHeight = $(window).height();
  var wWidth = $(window).width();      
var top = (wHeight/2)-(mHeight/2) + $(window).scrollTop();
var left = (wWidth/2)-(mWidth/2);
if(top > 0) { o.css('top',  top);}else{o.css('top',  '0');}  
if(left > 0) { o.css('left',  left);}else{o.css('left',  '0');}  
}

function PreLoadModal(){
imgs=document.getElementsByTagName('img');
modalImage = new Array();
modalImage[0] = new Image();
modalImage[0].src='images/modalbox/modal-top-left.gif';
modalImage[1] = new Image();
modalImage[1].src='http://img1.keypropertyguide.net/images/modalbox/modal-top.gif';
modalImage[2] = new Image();
modalImage[2].src='images/modalbox/modal-button.gif';
modalImage[3] = new Image();
modalImage[3].src='http://img3.keypropertyguide.net/images/modalbox/modal-top-right.gif';
modalImage[4] = new Image();
modalImage[4].src='http://img2.keypropertyguide.net/images/modalbox/modal-left.gif';
modalImage[5] = new Image();
modalImage[5].src='images/modalbox/modal-gradient.gif';
modalImage[6] = new Image();
modalImage[6].src='http://img3.keypropertyguide.net/images/modalbox/modal-content-top.gif';
modalImage[7] = new Image();
modalImage[7].src='http://img1.keypropertyguide.net/images/modalbox/modal-content-border.gif';
modalImage[8] = new Image();
modalImage[8].src='http://img2.keypropertyguide.net/images/modalbox/modal-content-gradient.gif';
modalImage[9] = new Image();
modalImage[9].src='http://img3.keypropertyguide.net/images/modalbox/modal-content-bottom.gif';
modalImage[10] = new Image();
modalImage[10].src='images/modalbox/modal-right.gif';
modalImage[11] = new Image();
modalImage[11].src='http://img3.keypropertyguide.net/images/modalbox/modal-bottom-left.gif';
modalImage[12] = new Image();
modalImage[12].src='http://img1.keypropertyguide.net/images/modalbox/modal-bottom-right.gif';
modalImage[13] = new Image();
modalImage[13].src='http://img2.keypropertyguide.net/images/modalbox/modal-bottom.gif';
}

function link(link){	
var pos = link.lastIndexOf("#") + 1;
	 link = link.substr(pos,link.length);
	 $('#menu').html('');
	 $(".content-body").html("<div style=width:600px;height:300px;background-color:white;vertical-align:middle;text-align:center><img width=20 style=position:relative;top:120px; src=http://img3.keypropertyguide.net/loader.gif alt=\"loading..\"></div>");
 $.ajax({   
      url: link.toLowerCase() + ".php",  
      success: function(html) { $(".content-body").html(html); }
});
}


	$(function() {
	PreLoadModal();
		  $('#zoom').click(function(){
		  	  var offset = $("#imgMain").offset();
	

	  $('#zoom').animate({
	      top: offset.top,
	      left: offset.left ,
    height: $('#imgMain').height()
	  },function(){$(this).hide();});
	  
	  
	  });
	  
	  
	if(typeof(ie) == "undefined")
	{
	$('body').css('overflow-y','scroll');
	}

	if(location.href.lastIndexOf("#") != -1){
var link = location.href;
var pos = link.lastIndexOf("-");
if (pos > -1) link = link.substr(0,pos);
     pos = link.lastIndexOf("#") + 1;
	 link = link.substr(pos,link.length);
	 if(link.toLowerCase() == "main" || link.toLowerCase() == "agents" || link.toLowerCase() == "services" || link.toLowerCase() == "contact" || link.toLowerCase() == "listings")
	 {
	
	  $.ajax({   
      url: link.toLowerCase() + ".php",  
      success: function(html) { $(".content-body").html(html); }
	  });
	  }else{     
	  $.ajax({   
      url: "main.php",  
      success: function(html) {  
	  $(".content-body").html(html); }
});
	  }

}else{
 $.ajax({   
      url: "main.php",  
      success: function(html) { $(".content-body").html(html); }
});
}


	
	$('.link').click(function(){
var link = $(this).attr('href');
var pos = link.lastIndexOf("#") + 1;
	 link = link.substr(pos,link.length);
	 $('#menu').html('');
	 	 $(".content-body").html("<div style=width:600px;height:300px;background-color:white;vertical-align:middle;text-align:center><img width=20 style=position:relative;top:120px; src=http://img3.keypropertyguide.net/loader.gif alt=\"loading..\"></div>");
 $.ajax({   
      url: link.toLowerCase() + ".php",  
      success: function(html) { $(".content-body").html(html); }
});
	});
	
    var imgLoaded = 1;
  
 
	  $('#mask').click(function(){CloseModal();});
	  $('#close').click(function(){CloseModal();});
  });

