
	$(document).ready(function(){
		$('ul#buttons li, ul.buttons li').each(function(){$(this).hover(function() { $(this).addClass("hover") },function(){ $(this).removeClass("hover") })});
		


   var path = location.pathname.substring(0); 
   
   if ( path )
   {
     $('.buttons a').each(function(index, element){
     	var hRef=$(element).attr('href');
     	if(hRef == path)
     	{$(element).parents('li:eq(0)').addClass('selected');}
     	
     	});
  	}
		function NiceButtons(w,pad)
		{
			var butCount = $('.full-width li');
			
			var wSumm = 0;
			for (var i = 0; i<butCount.length; i++)
			{
				wSumm += $(butCount.get(i)).width() + pad;
			}
			var kk = Math.floor((w - wSumm) / (butCount.length - 1));
			for (var i = 0; i<butCount.length-1; i++) $(butCount.get(i)).css({'margin-right': kk});
			$('.full-width li:last-child').css({'margin-right':0});
		}
		
		NiceButtons(732,10);
		
	}); //DOM_Ready
	
function fswitcher(targ, hold, tag)
{
	if(document.getElementById(targ) && document.getElementById(hold))
	{
		var switcher = document.getElementById(targ);
		if (tag)
		{
			var switchers = switcher.getElementsByTagName(tag);
		}
		else
		{
			var switchers = switcher.getElementsByTagName('li');
		}
		var floorplan = document.getElementById(hold);
		if(switchers)
		{
			for (var i = 0; i < switchers.length; i++)
			{
				switchers[i].onclick = function()
				{
					floorplan.className = this.className;
					switcher.className = this.className;
					return false;
				}
			}
			var floorplansBlock = document.getElementById("floorplan");
			if(floorplansBlock)
			{
				var plans = document.getElementById("floorplan").getElementsByTagName('img');
				if(plans)
				{
					for (var i = 0; i < plans.length; i++)
					{
						plans[i].className += " hide";
					 }
				}
			}
			switcher.className=switchers[0].className;
			floorplan.className=switchers[0].className;
		}
	}
}

function swapPic(sPath){
  document.getElementById("imgGallery").src = sPath;
}

var m_sSectionLayerID = 'type-0';

function showHideSectionLayers(sLayerID)
{
  document.getElementById(m_sSectionLayerID).style.display='none';
	m_sSectionLayerID = sLayerID;
  
  if(document.getElementById(m_sSectionLayerID).style.display='none')
	{
		document.getElementById(m_sSectionLayerID).style.display='';
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function Locate(e, targ){
var posx=0,posy=0;
if(e==null) e=window.event;
if(e.pageX || e.pageY){
    posx=e.pageX; posy=e.pageY;
    }
else if(e.clientX || e.clientY){
    if(document.documentElement.scrollTop){
        posx=e.clientX+document.documentElement.scrollLeft;
        posy=e.clientY+document.documentElement.scrollTop;
        }
    else{
        posx=e.clientX+document.body.scrollLeft;
        posy=e.clientY+document.body.scrollTop;
        }
    }
		
		Move(targ, posx, posy);    
}

function Move (targ, pox, poy){
				 if(document.getElementById(targ)){
					var coors = findPos(document.getElementById('floorplans'));
					document.getElementById(targ).style.top=(poy+10-coors[1])+"px";
					document.getElementById(targ).style.left=(pox+20-coors[0])+"px";
					}
}

function reLocate(e){
var posx=0,posy=0;
var coors = findPos(document.getElementById("floorplans"));
if(e==null) e=window.event;
if(e.pageX || e.pageY){
    posx=e.pageX; posy=e.pageY;
	
    }
else if(e.clientX || e.clientY){
    var doc = document.documentElement, body = document.body;
			posx = e.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || body.clientLeft || 0);
			posy = e.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || body.clientLeft || 0);
			}								
						
	document.getElementById("tooltip").style.top=(posy+10)+"px";
	document.getElementById("tooltip").style.left=(posx+20)+"px";				
										
  
}




function setOpacity(el){
el.style.filter="alpha(opacity:85)";
el.style.KHTMLOpacity="0.85";
el.style.MozOpacity="0.85";
el.style.opacity="0.85";
}




function showKey(sKeyID) {	
	if(keySelected != null) {
		hideKey(keySelected);
	}
	
	if(document.getElementById(sKeyID)){
  document.getElementById(sKeyID).style.display='';
//  createCookie('keySelected', sKeyID, 7);
	return true;
	}
	else {
	return false;
	}
}  
function hideKey(sKeyID) {
if(document.getElementById(sKeyID)){
  document.getElementById(sKeyID).style.display='none';
//	eraseCookie('keySelected');
	return true;
	}
else {
		 return false;
}
}

function BlockSelect(nBlock, sKeyID){
document.getElementById("siteplan").src = "/images/siteplan/" + nBlock + ".png";

	if (nBlock != 'siteplan'){
		createCookie('siteplanSelected', nBlock, 7);
		createCookie('keySelected', sKeyID, 7);
		}
}



/*Cookie stuff*/
	
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setCookie(pid){
				 eraseCookie('high');
				 createCookie('high', pid);
}


/* /Cookie stuff */




/* Siteplan */

function getChecked(eid){
    if (document.getElementById(eid))
    	 return document.getElementById(eid)
    else
       return null
}

function siteplanLoad(targ){

var siteplanHolder = targ ? targ : 'siteplan-block'; 


/*Tooltip placeholder*/

    h=document.createElement("span");
    h.id="tooltip";
    h.setAttribute("id","tooltip");
    h.style.position="absolute";
    document.body.appendChild(h);

/*Imagemap areas*/

    processAreas(plotData, siteplanHolder);
    
    
}

function processAreas(data, siteplanHolder){
    for (var i in data) {
		    if(data[i].area && data[i].area.parentNode.parentNode == document.getElementById(siteplanHolder)){
				    
				    /*Tooltips*/
	 			    
	 			    var classN = 'ttips';  
				    
						ttip = createEl('span', classN);
				    
				    var pname = createEl("strong", "pname");
				    pname.appendChild(document.createTextNode(data[i].plotStyleName));

						
						var pnumber = createEl("strong", "pnumber");
						if (i.charAt(0) == 'p'){
							pnumber.appendChild(document.createTextNode("Plot " + i.substring(1,i.length).replace(/-P/,' - Car Park')));
						}
				    else {
//						pnumber.appendChild(document.createTextNode(""));
						}
				    
				    var pavail = createEl("strong", "pavail");
				    pavail.appendChild(document.createTextNode(data[i].availability));
				    
				    var pprice = createEl("strong", "pprice");
//    		    pprice.appendChild(document.createTextNode("\u00A3"));
				    pprice.appendChild(document.createTextNode(data[i].price));
				    
				    t = [pnumber, pname, pavail, pprice];
						for (var y in t) 
						    ttip.appendChild(t[y]);
						    
				    setOpacity(ttip);
				    data[i].area.ttip = ttip;
				    data[i].area.removeAttribute("title");
				    data[i].area.removeAttribute("alt");

				    /*Links*/
				    
				    
				    
				    
				    if(data[i].availability == 'Sold' || data[i].availability == ''){
								data[i].area.removeAttribute("href");
								data[i].area.style.cursor = 'default';
						}
				    
				    
				    
				    /*sitePlan spans*/
				    
				    var imageSpan = document.createElement('span');
				    imageSpan.id=data[i].area.id + '-span';
				    if(data[i].availability == 'Sold'){
								imageSpan.style.background = 'url(/images/siteplan/sold-plots/'+ data[i].area.id +'-sold.png)';
				    }
				    else {
								imageSpan.style.backgroundImage = 'url(/images/siteplan/hover-plots/'+ data[i].area.id +'.png)';
								imageSpan.style.visibility = 'hidden';				    		 
						}
				    document.getElementById(siteplanHolder).appendChild(imageSpan);
				    
				    
				    
				    /*Events*/
				    
				    if(data[i].availability == 'Sold'){
								data[i].area.onmouseover=onHighSold;
            		data[i].area.onmouseout=offHighSold;
						}
						
						else{
								data[i].area.onmouseover=onHigh;
            		data[i].area.onmouseout=offHigh;						
						}
						
    				data[i].area.onmousemove=reLocate;
				}
		}
}

function createEl(t,c){
    var x=document.createElement(t);
    x.className=c;
    return(x);
}

function onHighSold(e){
    document.getElementById("tooltip").appendChild(this.ttip);
    reLocate(e);
}

function offHighSold(e){
    var d=document.getElementById("tooltip");
    if(d.childNodes.length>0) d.removeChild(d.firstChild);
    d.style.left = '-200px';
    d.style.top = '0';
    
}


function onHigh(e){
    document.getElementById("tooltip").appendChild(this.ttip);
    reLocate(e);
    document.getElementById(this.id + '-span').style.visibility = 'visible';
}

function offHigh(e){
    var d=document.getElementById("tooltip");
    if(d.childNodes.length>0) d.removeChild(d.firstChild);
    if(window.high === undefined){
			 window.high = 'foo';
		}
    if(window.high !== this.id.toString()){
    document.getElementById(this.id + '-span').style.visibility = 'hidden';
    }
    d.style.left = '-200px';
    d.style.top = '0';
    
}



function section(k) {

for (i=1; i<30; i++)
    {
        if (i==k)
            {
                if(document.getElementById('text'+i)){
					if(document.getElementById('text'+i).style.display=='block')
						document.getElementById('text'+i).style.display='none';
					else
						document.getElementById('text'+i).style.display='block';
				}
            }
        else 
            {
                if(document.getElementById('text'+i)) document.getElementById('text'+i).style.display='none';
            }
    }
}

function section2(k) {
	for (i=1; i<8; i++)
    {
        if (i==k)
        {
        	$('#text' + i).show();
        	$('#img' + i).show();
        	$('#link' + i).parents('li:eq(0)').addClass('selected');
        }
        else 
        {
        	$('#text' + i).hide();
        	$('#img' + i).hide();
        	$('#link' + i).parents('li:eq(0)').removeClass('selected');
        }
    }
}



