var mainPanel = null;
var check = "0";
var check2 = "0";
var check3 = "0";
var executing = "0";
// Our initialization function which unobtrusively attaches
// click handlers on the product links within the page.
function InitProductPage()
{
	// Create an HTMLPanel for the element with the
	// id of "mainContent".
	  mainPanel   = new Spry.Widget.HTMLPanel("mainContent", { evalScripts: true });
	  
	  effectSlideOUT = new Spry.Effect.Slide('mainContent', {duration: 900, from: '100%', to: '0', toggle:false});
	  effectSlideIN   = new Spry.Effect.Slide('mainContent', {duration: 1800, from: '0%', to: '100%', toggle:false});
      effectSlideIN2 = new Spry.Effect.Slide('mainContent', {duration: 3000, from: '0%', to: '100%', toggle:false});
   
   function narrow(theURL){
	   check = "0";
	   if (executing == "0"){
		 executing = "1";
		 clean();
		  if  (document.getElementById('mainContent').style.display == "none"){
			 mainPanel.loadContent(theURL.href, { id: "mainContent"}, { evalScripts: true });
			 setTimeout("effectSlideIN2.start()", 500); setTimeout("checkID()", 200);		 
		 }
	else {
		 effectSlideOUT.start();
		 var effectObs3 = {onPostEffect:function (){mainPanel.loadContent(theURL.href, { id: "mainContent"}, { evalScripts: true });}};
		 var effectObs4 = {onPostEffect:function(){setTimeout("effectSlideIN.start()", 2500); setTimeout("checkID()", 1000); }}
		 effectSlideOUT.addObserver(effectObs3);
		 effectSlideOUT.addObserver(effectObs4);
	}
		
		  var observer2 = {onPostUpdate: function InitProductPage2(){			   
              Spry.$$("#Neighborhoods a").addEventListener("click", function(e)
				{       narrow(this);
            			 return false;            
				}, false);}}
			  mainPanel.addObserver(observer2);
	   }
   };
    
	// For every link on the page which points to a product page,
	// attach an onclick handler that will intercept clicks and
	// and fire off a request to load the URL via the HTMLPanel.
	//
	// For these links, we want to load the static product page
	// and extract out the content underneath the "mainContent"
	// node.
	Spry.$$("#featurednb a").addEventListener("click", function(e)
	{   narrow(this);
		return false;	 
	}, false); 
	
	Spry.$$("#BoiseMLS a").addEventListener("click", function(e)
	{   check2 = "1"; check3 = "1" 
	    narrow(this);
		return false;	 
	}, false);  
        
	Spry.$$("#BoiseHomesForSale a").addEventListener("click", function(e)
	{   narrow(this);
		return false;
	}, false);  
         
	Spry.$$("#HomeValueRequest a").addEventListener("click", function(e)
	{   narrow(this);
		return false;
	}, false); 
	
	/*Spry.$$("#BoiseNeighborhoods a").addEventListener("click", function(e)
	{   narrow(this);
		return false;
	}, false);    */
	Spry.$$("#BoiseRealEstateAgent a").addEventListener("click", function(e)
	{   narrow(this);       
		return false;
	}, false);
 
 
        Spry.$$("#BoiseInformation a").addEventListener("click", function(e)
	{    narrow(this);	
		return false;
	}, false);

        Spry.$$("#Boise a").addEventListener("click", function(e)
    {   narrow(this);
    	return false;
	}, false);

        Spry.$$("#Meridian a").addEventListener("click", function(e)
	{    narrow(this);   	
		return false;
	}, false);

        Spry.$$("#Eagle a").addEventListener("click", function(e)
	{      narrow(this); 
              return false;
	}, false);
       
        Spry.$$("#Kuna a").addEventListener("click", function(e)
	{     narrow(this);  	
		return false;
	}, false);
        
        Spry.$$("#Star a").addEventListener("click", function(e)
	{     narrow(this);  	
		return false;
	}, false);
		
        Spry.$$("#Neighborhoods a").addEventListener("click", function(e)
	{      	 	narrow(this);	
              return false;
	}, false);
		
    }

 Spry.$$("#nbHeaderLinksPrev a").addEventListener("click", function(e)
				{       narrow(this);
            			 return false;            
				}, false);
Spry.Utils.addLoadListener(InitProductPage);

function clean(){
	GUnload();
	if (document.getElementById("Iframecontainer").innerHTML != null){
	  document.getElementById("Iframecontainer").innerHTML = '';
    }
	document.getElementById("mainContent").style.zIndex = '14';
	document.getElementById("rightContent").style.zIndex = '14';
	check = '0';
}

function checkID() {
	  if (check2 == "0"){
		  if (check3 == "1"){setTimeout("changeState2()", 7800);}
		  else if (check3 == "0"){setTimeout("changeState()", 3500);}	
	  }
	  
	  if (check2 == "1"){
		  setTimeout("iframe()", 3500);
          setTimeout("visibility()", 5500);
		  setTimeout("changeState1()", 7800);
	  }
}

function checkIDNB() {
	  if (check2 == "0"){
		  if (check3 == "1"){setTimeout("changeState2()", 7000);}
		  else if (check3 == "0"){setTimeout("changeState()", 2400);}	
	  }
	  
	  if (check2 == "1"){
		  setTimeout("iframe()", 3500);
          setTimeout("visibility()", 5500);
		  setTimeout("changeState1()", 7000);
	  }
}

function iframe(){
	 if (document.getElementById("Iframecontainer")){
		document.getElementById("Iframecontainer").innerHTML = '<iframe id="Iframe" src="http://idx.diversesolutions.com/search/716/2"></iframe>';
		document.getElementById("Iframecontainer").style.visibility = "hidden";
		document.getElementById("Iframecontainer").style.zIndex = 25;
		document.getElementById("Iframe").style.zIndex = 100;
	}
}

function visibility(){
	 if (document.getElementById("Iframecontainer")){
		document.getElementById("Iframecontainer").style.opacity = "1.0";
		document.getElementById("Iframecontainer").style.zIndex = 25;
		document.getElementById("Iframecontainer").style.visibility = "visible";
	}
		document.getElementById("mainContent").style.zIndex = -1;
		document.getElementById("rightContent").style.zIndex = -1;
		document.getElementById("Iframe").style.zIndex = 100;	
}

function changeState(){
	executing = "0";
}

function changeState1(){
	executing = "0";
	check3 = "1";
	check2 = "0";
}

function changeState2(){
	executing = "0";
	check3 = "0";
}







function ListStreetView(lt, lg, pov, nbr) {
	document.getElementById("hldr").innerHTML = '<div id="pano2"><div id="panoTitle"><div id="panoNbTitle"></div><a title="Close Window" href="javascript: hide();">Close Window X</a></div></div>';
var lat = lt;
var lng = lg;
var stpov = pov;
var streetviewClient; 
var nb = nbr;
var pt = '10';
myPano = new GStreetviewPanorama(document.getElementById("pano2"));
fenwayPark = new GLatLng(lat,lng);
myPOV = {yaw:(stpov),pitch:(pt)};
myPano.setLocationAndPOV(fenwayPark, myPOV); 

document.getElementById("panoNbTitle").innerHTML = nbr+" Neighborhood Street View";

delete myPano;
delete fenwayPark;
delete myPOV;	
} 
function hide(){
document.getElementById("hldr").innerHTML = "";
}




function nbSearch(){

	var nbr = document.getElementById("productFilter").value;
	var nb = document.getElementById("productFilterLink").value;
	var nbcity = document.getElementById("productFilterCity").value + '/';
	var nblocation = document.getElementById("productFilterLocation").value;
	  if (nblocation){
		  nblocation += '/';
	  }
		  if (nb){
			  var nblink = 'http://www.idahohomeagent.com/Neighborhood/' + nbcity + nblocation + nb + '.php'; 
		  }
  
    if (nbr){
	  var checkDiv = document.getElementById(nbr);
	}
	  if (!checkDiv){
           var divCollection = document.getElementById('productMenuTable').getElementsByTagName("div"); // Establish array variable to get all divs on page
		   var str = '';
		   var divs = '';
		   var div = '';
		   var collected = '';
			  for (var i=0; i < divCollection.length; i++) { // Loop through all divs on page
			      if(divCollection[i].getAttribute("id")) { // If statement to verify that the div has an 'id' attribute  
			  		divs += divCollection[i].getAttribute("id") + '|';
					   } 	// End Code to run or a div found with an ID	
				 } // End FOR Loop to loop through all divs 
				       var divs = divs.split("|");
					   for (var l=0; l < divs.length; l++){
					   myRE = new RegExp(nbr, "i");
					   results = divs[l].match(myRE);						  
							if (results){ // if there is some sort of match made run this code							
									for(var j =0; j < results.length; j++) { // loop through the matched string
										  str += results[j];
										  collected += divs[l] + '|';
									   } // End for Loop						   
							} // End code to run if a match is found with the reg expression
					   }
			collected = collected.split("|");
			var arLength = collected.length-2;
			smallest = collected[0];
			if (arLength > 0){
			    	for (m = 1; m <= arLength; m++){
							    if (collected[m] < smallest){
									smallest = collected[m];
								}
						}
					}
			if (smallest){		
		   var checkDiv2 = document.getElementById(smallest);
		   var nb3 = smallest.replace(' ', "-");
		   var getDiv = checkDiv2.innerHTML;
		   var trm = getDiv.replace('||', "|");
		   var splt = trm.split("|");
		   if (splt.length == 3){
		   var nb2 = splt[2];
		   var nbcity2 = splt[1];
		   var nblocation2 = '';
		   }
		   if (splt.length == 4){
		   var nb2 = splt[3];
		   var nbcity2 = splt[1];
		   var nblocation2 = splt[2] + '/';
		   }	
		 /*  document.getElementById('mainContent').innerHTML = 'City = ' + nbcity2 + '<br /> Location = ' + nblocation2 + '<br /> Neighborhood = ' + nb2; */
		   var nblink = 'http://www.idahohomeagent.com/Neighborhood/'+nbcity2+'/'+nblocation2+nb3+'.php'; 
			}
			if (!smallest){ // No Neighborhood Found Give Send out a kind sticky note saying that the neighborhood cannot be found
			if(document.getElementById('fadeinboxcontent')){
				var getFadeBox = document.getElementById('fadeinboxcontent');
				fadeBox = getFadeBox.innerHTML = 'Sorry but it seems the Neighborhood you have entered cannot be found or is not in our database yet. <br /><br /> If you would like the Neighborhood added just send me an email and I will have the webmaster add it as soon as possible. <br /><br /> Thank you for using my website and if you would like to see any homes just let me know!<br /><br /><div style="text-align:center">Megan Schomer - RE/MAX Elite Properties <br />(208) 695-6300</div>';
				displayfadeinbox();
			}
			}
	  } // End checkDiv to see if the entered value matches an already established div
  
	  if (checkDiv && !nb){
	       var nb3 = nbr.replace(' ', "-");
		   var getDiv = checkDiv.innerHTML;
		   var trm = getDiv.replace('||', "|");
		   var splt = trm.split("|");
		   if (splt.length == 3){
		   var nb2 = splt[2];
		   var nbcity2 = splt[1];
		   var nblocation2 = '';
		   }
		   if (splt.length == 4){
		   var nb2 = splt[3];
		   var nbcity2 = splt[1];
		   var nblocation2 = splt[2] + '/';
		   }	
		 /*  document.getElementById('mainContent').innerHTML = 'City = ' + nbcity2 + '<br /> Location = ' + nblocation2 + '<br /> Neighborhood = ' + nb2; */
		 var nblink = 'http://www.idahohomeagent.com/Neighborhood/'+nbcity2+'/'+nblocation2+nb3+'.php'; 
	  } 
	  
	  
	  
	  	if (document.getElementById('mainContent').style.display == 'none'){
			if (nblink){
		document.getElementById('mainContent').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=1)';
		document.getElementById('mainContent').style.opacity = '1';
	   document.getElementById('mainContent').style.display = 'block';
	     opacity('mainContent', 1, 88, 250);
	   }
	}
		 return nblink;	   
}


function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 85); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    /*if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else*/ if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            {
			
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++;
			
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")";
	
	
	
}




function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


/***********************************************
* Sticky Note script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
* Go to http://www.dynamicdrive.com/ for full source code
***********************************************/

//Specify display mode. 3 possible values are:
//1) "always"- This makes the fade-in box load each time the page is displayed
//2) "oncepersession"- This uses cookies to display the fade-in box only once per browser session
//3) integer (ie: 5)- Finally, you can specify an integer to display the box randomly via a frequency of 1/integer...
// For example, 2 would display the box about (1/2) 50% of the time the page loads.

var displaymode="always"

var enablefade="yes" //("yes" to enable fade in effect, "no" to disable)
var autohidebox=["yes", 6] //Automatically hide box after x seconds? [yes/no, if_yes_hide_after_seconds]
var showonscroll="yes" //Should box remain visible even when user scrolls page? ("yes"/"no)
var IEfadelength=1.25 //fade in duration for IE, in seconds
var Mozfadedegree=0.05 //fade in degree for NS6+ (number between 0 and 1. Recommended max: 0.2)

////////No need to edit beyond here///////////

if (parseInt(displaymode)!=NaN)
var random_num=Math.floor(Math.random()*displaymode)

function displayfadeinbox(){
var ie=document.all && !window.opera
var dom=document.getElementById
iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
objref=(dom)? document.getElementById("fadeinbox") : document.all.fadeinbox
var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
var docwidth=(ie)? iebody.clientWidth : window.innerWidth
docheight=(ie)? iebody.clientHeight: window.innerHeight
var objwidth=objref.offsetWidth
objheight=objref.offsetHeight
objref.style.left=docwidth/2-objwidth/2+"px"
objref.style.top=scroll_top+docheight/4-objheight/4+"px"

if (showonscroll=="yes")
showonscrollvar=setInterval("staticfadebox()", 50)

if (enablefade=="yes" && objref.filters){
objref.filters[0].duration=IEfadelength
objref.filters[0].Apply()
objref.filters[0].Play()
}
objref.style.visibility="visible"
if (objref.style.MozOpacity){
if (enablefade=="yes")
mozfadevar=setInterval("mozfadefx()", 90)
else{
objref.style.MozOpacity=1
controlledhidebox()
}
}
else
controlledhidebox()
}

function mozfadefx(){
if (parseFloat(objref.style.MozOpacity)<1)
objref.style.MozOpacity=parseFloat(objref.style.MozOpacity)+Mozfadedegree
else{
clearInterval(mozfadevar)
controlledhidebox()
}
}

function staticfadebox(){
var ie=document.all && !window.opera
var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
objref.style.top=scroll_top+docheight/4-objheight/4+"px"
}

function hidefadebox(){
objref.style.visibility="hidden"
if (typeof showonscrollvar!="undefined")
clearInterval(showonscrollvar)
}

function controlledhidebox(){
if (autohidebox[0]=="yes"){
var delayvar=(enablefade=="yes" && objref.filters)? (autohidebox[1]+objref.filters[0].duration)*2000 : autohidebox[1]*4200
setTimeout("hidefadebox()", delayvar)
}
}

function initfunction(){
setTimeout("displayfadeinbox()", 100)
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = ""
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

