active = 'link_1';
function highlightLink(obj){
	if(oldElement = document.getElementById(active)){
		oldElement.className = '';
	}
	active = obj;
	element = document.getElementById(obj);
	element.className = 'current';
}

function getStyleClass (className) {
	for (var s = 0; s < document.styleSheets.length; s++){
		if(document.styleSheets[s].rules){
			for (var r = 0; r < document.styleSheets[s].rules.length; r++){
				if (document.styleSheets[s].rules[r].selectorText == className){
					return document.styleSheets[s].rules[r];
				}
			}
		}else if(document.styleSheets[s].cssRules){
			for (var r = 0; r < document.styleSheets[s].cssRules.length; r++){
				if (document.styleSheets[s].cssRules[r].selectorText == className){
                    return document.styleSheets[s].cssRules[r];
                }
			}
		}
	}
	
	return null;
}

function switchListStyles(which){
    var listClass = getStyleClass('#HomesList .text-view');
    var detailClass = getStyleClass('#HomesList .thumb-view');
    
    if(which == 'list'){
		listClass.style.display='block';
        detailClass.style.display='none';
    }else{
		listClass.style.display='none';
        detailClass.style.display='block';
    }
}

function switchHoods(mode) {
  var nid = document.getElementById("neighborhood_select").value;
  document.location = '/neighborhood/index.php?m='+mode+'&nid='+nid;
}

function sortIt(refPage,nid) {
  var by = document.getElementById("sorter").value;
  var target_location = '';
  if (refPage == 'all-homes')
    target_location = '/findahome/all-homes.php?by='+by;
  else if (refPage == 'custom-home')
    target_location = '/custom-home/home-site.php?m=homes&nid='+nid+'&by='+by;
  else if (refPage == 'best-buy')
    target_location = '/findahome/best-buy-homes.php?by='+by;
  else target_location = '/neighborhood/index.php?m=homes&nid='+nid+'&by='+by;
  document.location = target_location;
}

function changeImg (whichpic,whichsrc,count) {
	var target, source;
	
	if (document.images.large_img)
		target=document.images.large_img;
	if (document.all && document.getElementById("large_img"))
		target=document.getElementById("large_img");

  source=document.getElementById(whichsrc);

	target.src = whichpic;
	
  for (i=0;i<count;i++) {
    source=document.getElementById("t"+i);
    if ("t"+i == whichsrc) source.setAttribute("class","current");
    else source.setAttribute("class","");
  }

}

function clearField(target) {
  document.getElementById(target).value = "";
}


/**
 IMAGE MOVER AND SHAKER
**/
function moveImage(direction, nid, mcount  ){
	
	strCurrentImageValue = 'currentImage'+nid;
	cur = document.getElementById(strCurrentImageValue).value;
	
	
	if(direction == '+'){
		cur++;
		
		if(cur > mcount){
			cur = 1
			
		}
		
	}else{
		cur--;

		if(cur < 1){
			cur = mcount;
	
		}
	
	}
	
	document.getElementById(strCurrentImageValue).value = cur;
	document.getElementById(strCurrentImageValue).width = '208';
	document.getElementById(strCurrentImageValue).height = '156';
	
	imgoftext = "imgcount"+nid;
	
	
	document.getElementById(imgoftext).innerHTML = cur+" of "+mcount;
	
	
	strNew = 'img'+nid+cur;
	newSource=document.getElementById(strNew).src;
	
	strOld = "displayPhoto"+nid;
	document.getElementById(strOld).src= newSource;

	/*
		displayPhoto+nid
	*/
}