/* 
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷
  get data from iFrame page 
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ 
*/
function getMenuData(){
	var pageURLObj =  document.location;
	var pageURL = pageURLObj.toString();
	var QString = pageURL.substr(pageURL.lastIndexOf("?")+1);
	var QArr = QString.split(",");
	var vMap = document.getElementById('map').innerHTML;
	var vDirectory = document.getElementById(QArr[0]).innerHTML;
	var vItem = QArr[1];	

	var vPath = 'flash/';
	if (vItem == "index" ) {
		vPath = "site/"+vPath;
	} else {
  		vPath = "../"+vPath;
	}
	
	m="?vMap="+"ppochie";//vMap;
	w = 744;
	h = 140;
	//bgcolor="D90026";
	var bgcolor="FFFFFF";	
	window.parent.document.getElementById('header').innerHTML = ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'" id="menu" align="middle"><param name="allowscriptAccess" value="sameDomain" /><param name="movie" value="'+vPath+'menu.swf'+m+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /> <param name="bgcolor" value="#'+bgcolor+'" /><embed src="'+vPath+'menu.swf'+m+'" quality="high" wmode="transparent" bgcolor="#'+bgcolor+'" width="'+w+'" height="'+h+'" name="menu" align="middle" allowscriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}

function loadIframe(map){
	alert(map);
	//document.getElementById('sectionmap').src = "+M_student_living.htm";

}
/* 
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷
  load SWF menu  
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ 
*/
function loadMenus(vMap,vDirectory,vItem){

	vMap = "poo";///"+M_"+vMap+".htm";
	setTimeout('loadIframe(vMap)',2000);
	/*
	//alert(document.getElementById('sectionmap').src);
	//document.getElementById('sectionmap').src = "blank.htm";
	var vPath = 'flash/';
	if (vItem == "index" ) {
		vPath = "site/"+vPath;
	} else {
  		vPath = "../"+vPath;
	}
	m="?vMap="+vMap+"&vDirectory="+vDirectory+"&vItem="+vItem;
	w = 744;
	h = 140;
	//bgcolor="D90026";
	var bgcolor="FFFFFF";	
	//	document.getElementById('sectionmap').src = "+M_student_living.htm";

//	document.getElementById('header').innerHTML = ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'" id="menu" align="middle"><param name="allowscriptAccess" value="sameDomain" /><param name="movie" value="'+vPath+'menu.swf'+m+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /> <param name="bgcolor" value="#'+bgcolor+'" /><embed src="'+vPath+'menu.swf'+m+'" quality="high" wmode="transparent" bgcolor="#'+bgcolor+'" width="'+w+'" height="'+h+'" name="menu" align="middle" allowscriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
	//transparent windowless 
	//alert(document.getElementByID('sectionmap'));// = "fooo";//('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'" id="menu" align="middle"><param name="allowscriptAccess" value="sameDomain" /><param name="movie" value="'+vPath+'menu.swf'+m+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /> <param name="bgcolor" value="#'+bgcolor+'" /><embed src="'+vPath+'menu.swf'+m+'" quality="high" wmode="transparent" bgcolor="#'+bgcolor+'" width="'+w+'" height="'+h+'" name="menu" align="middle" allowscriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
	//solid bg
//document.getElementById('header').innerHTML = ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'" id="menu" align="middle"><param name="allowscriptAccess" value="sameDomain" /><param name="movie" value="'+vPath+'menu.swf'+m+'" /><param name="quality" value="high" /><param name="bgcolor" value="#'+bgcolor+'" /><embed src="'+vPath+'menu.swf'+m+'" quality="high"bgcolor="#'+bgcolor+'" width="'+w+'" height="'+h+'" name="menu" align="middle" allowscriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
	*/
	//alert("foo");
}


/*
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷
  pop up a window  
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ 
*/

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


/* 
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷
  select current page menu item  
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ 
*/

function setMenu(){
	var vPageURLObj =  document.location;
	var vPageURL = vPageURLObj.toString();
	var vPageFileName = vPageURL.substr(vPageURL.lastIndexOf("/")+1);
	var vMenu = document.getElementById('submenu');
	if(vMenu != null){
		var vListArr = vMenu.getElementsByTagName("li");
		for(var n=0; n < vListArr.length; n++){
			var vListItem = vListArr[n];
			var vAnchor = vListItem.getElementsByTagName("a")[0];
			var vHREF = vAnchor.getAttribute("href");
			//ie returns full path while moz / safari only return page. so... need to parse.
			var vLinkFileName = vHREF.substr(vHREF.lastIndexOf("/")+1);
			if(vLinkFileName == vPageFileName){	
				//vAnchor.style.backgroundColor = "#A0B604";
				vAnchor.style.color = "#A0C804";
			}
		}
	}
}

/* 
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷
  select current section menu items
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ 
*/

function setSectionMap(){
	var vPageURLObj =  document.location;
	var vPageURL = vPageURLObj.toString();
	var vPageFileName = vPageURL.substr(vPageURL.lastIndexOf("/")+1);
	var vMenu = document.getElementById('sectionmap');
	if(vMenu != null){
		var vListArr = vMenu.getElementsByTagName("li");
		for(var n=0; n < vListArr.length; n++){
			var vListItem = vListArr[n];
			var vAnchor = vListItem.getElementsByTagName("a")[0];
			var vHREF = vAnchor.getAttribute("href");
			//ie returns full path while moz / safari only return page. so... need to parse.
			var vLinkFileName = vHREF.substr(vHREF.lastIndexOf("/")+1);
			if(vLinkFileName == vPageFileName){	
			var vList = vListItem.parentElement;
			//does this page exist in a 'sublist' 
			// ul - li - ul - li

			var vAncestor = vList.parentElement
			alert(vList);
			alert(vAncestor);
			//if(vAncestor.TagName != 'div'){
				
			//	}
				//vAnchor.style.backgroundColor = "#A0B604";
				vAnchor.style.color = "#A0C804";
			}
		}
	}
}


/* 
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷
snippet styler
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ 
*/
function StyleSnippet(sDiv){

	var aSnippets = sDiv.getElementsByTagName('p');
		for(s=0;s<aSnippets.length;s+=2){
			
			aSnippets[s].style.backgroundColor = '#f0f0f0';
			
			}
	for(s=1;s<aSnippets.length;s+=2){
			
			aSnippets[s].style.backgroundColor = '#eaeaea';
			
			}

}
/* 
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷
  random .bImage div background image selector.   
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ 
*/
function LoadRandomImage(iDiv){
//use php to pull the imagelist from here.....
var vImageList = ["apple_bite.jpg","book.jpg","chopping_board_pot.jpg","table_chairs.jpg","guy_girl_study.jpg","highlight.jpg","mint_01.jpg","guy_smile.jpg","guy_girl_pc.jpg","girl_smile_02.jpg","girl_ponder.jpg","coffee_and_cup.jpg"];
var vRandom = Math.floor(Math.random() * vImageList.length);
var vPath = 'url(site/images/backgrounds/'+ vImageList[vRandom]+')';
iDiv.style.backgroundImage = vPath;
iDiv.style.backgroundPosition = "bottom";
iDiv.style.backgroundRepeat = "no-repeat";
}
/* 
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷
  balance divs  
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ 
*/

function balanceDivs(aRow){
	//aRow contains 1 -4 column elements
	//parse each column for b Div boxes
var aColH = [];
var aStretchDivs = [];
var vStretcher;
for(r=0;r<aRow.length;r++){
	
	var vCopyMarginAdjust = 0;
	vStretcher = null;
	var aBoxes = [];

	var aContent = aRow[r].getElementsByTagName('div');
	for(b=0;b<aContent.length;b++){
		if (aContent[b].className.substring(0,1) == "b"){
			aBoxes.push(aContent[b]);
			
			if (aContent[b].className == "bImage"){
				//save element
				 vStretcher =  aContent[b];
				 LoadRandomImage(vStretcher);		 
			}	
			else if (aContent[b].className == "bSpacer"){
				//save element
				 vStretcher =  aContent[b];
			}
			
			else if (aContent[b].className == "bSnippet"){
				StyleSnippet(aContent[b]);	 
			}
			
			else if (aContent[b].className == "bCopy"){
				vCopyMarginAdjust = 20;
			}
		}	
	}
	//now check if vImage was detected in order to choose vImage or last div box as the one to stretch
	 if(vStretcher == null){
	   vStretcher = aBoxes[aBoxes.length-1];
	 }
	//finally add element to be stretched to array.
	aStretchDivs.push(vStretcher);		
	//the copy div has a bottom margin of 20px for better readability.
	//this amount must be added to all other divs in this col...
	//the count will be.. 20px * total divs  - copycount...

	//aBoxes now contains all b elements for this column
	//use the last item to determine column height.
	vColH = aBoxes[aBoxes.length-1].offsetHeight+aBoxes[aBoxes.length-1].offsetTop+vCopyMarginAdjust;
	aColH.push(vColH);
}	
//now we know the col heights in aColH and the elements to stretch, in aStretchDivs.
//find the tallest col by sorting 
aSortH = aColH.slice(0);
aSortH.sort();
var vMaxH = aSortH[aSortH.length-1];
for(h=0;h<aStretchDivs.length;h++){
	var vColOffset = vMaxH - aColH[h];
	
	var vBoxHeight = aStretchDivs[h].offsetHeight+vColOffset;
	aStretchDivs[h].style.height = vBoxHeight + 'px';
}
}


function getDivs(){

var aContent = document.getElementById('content').getElementsByTagName('div');
var aColumns = [];
//separate into columns
for(i=0; i< aContent.length;i++){
	var vPrefix = aContent[i].className.substring(0,1);
	if (vPrefix == "c"){
		aColumns.push(aContent[i]);
	}
}
///return here...

//keep count 
var vWidthCount = 0;
var vCol = 0;
var aGrid = [];
//separate into rows
while(vCol < aColumns.length){ 
	var aRow = [];
	while(vWidthCount < 4){
		var vSuffix = parseInt(aColumns[vCol].className.substring(1));
		aRow.push(aColumns[vCol]);
		vWidthCount +=vSuffix;
		vCol +=1;
	 }
	 vWidthCount = 0;
	 balanceDivs(aRow);
	 
}
}
/*
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷
  switch element on and off
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ 
*/
	function switchElm(elmName)
	{
		document.getElementById(elmName).style.display = "block"
	//	document.getElementById(div_id).style.display = "block"
		currentDiv = div_id;
	}

/*
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷
  run page layout functions   
÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ 
*/
function runJS(){
//selectBGImage();
//selectTestimonial();
//balanceDivs();
getDivs();
setMenu();
//switchElm(sectionRef);
}



/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com

To get all a elements in the document with a “info-links” class.
getElementsByClassName(document, "a", "info-links");
To get all div elements within the element named “container”, with a “col” class.
getElementsByClassName(document.getElementById("container"), "div", "col");
To get all elements within in the document with a “click-me” class.
getElementsByClassName(document, "*", "click-me");



function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}
*/