/*****************************************************
Style hacks
*****************************************************/

if (document.all) { // hack for IE 7 and under
	document.write("<style type='text/css'>hr {margin: 5px 0px 15px 0px;} .moveinText ul.firstList { padding-bottom:0px;	}</style>");
}

/*****************************************************
Page state functions
*****************************************************/
var strAnchorNameArray;
var boolPageInitialized = false;
var strPageTitle = document.title;

function DLHhtmlPageChanged(newHash)
{	
	//Handle the page change after the page is initialized
	if(boolPageInitialized){			
		if(newHash != "" && newHash != "#")
		{
			
		}
		else
		{
			newHash = strSelectedContentNavItemId;
		}

		document.title = strPageTitle;
		
		//get the first value in the comma delimited hash
		//this is the id of the bookmarked content nav
		strAnchorNameArray = newHash.split(",");
		if(strAnchorNameArray[0]){ 
			strSelectedContentNavItemId = strAnchorNameArray[0];		
		}
		if(strAnchorNameArray[1]){ 
			strSelectedContentItemId = 'ArticleDetailsContentCopy';		
		}
				
		SetSelectedContent();
		
	}else{		
		boolPageInitialized = true;
	}
	
}

function init()
//set the default state of the page on page load
{
	//if there is an anchor name in the url, override the default content nav item id.
	var strAnchorName = window.location.hash.replace('#', '');
	strAnchorNameArray = strAnchorName.split(",");
	if(strAnchorNameArray[0]){ 
		strSelectedContentNavItemId = strAnchorNameArray[0];
	}

	//load Flash banner
	var flashBanner = new SWFObject('/swfs/'+strSectionBanner+'_banner.swf','banner','100%','100%','8','#7f1c31');
		flashBanner.skipDetect = true;
		flashBanner.addParam('quality','high');
		flashBanner.write('flash_banner');
		
	//load Flash main nav 
	
	var flashMainNav = new SWFObject('/swfs/navigation_2.swf','mainMenu_flash','100%','20','8','#ffffff',true);
		flashMainNav.addParam('xiRedirectUrl',window.location.href);
		flashMainNav.addParam('quality','high');
		flashMainNav.addVariable('flashVar_sourceId',		'mainMenuHTML_div');
		flashMainNav.addVariable('flashVar_linkSelected',	'navMain_'+strSection);
		flashMainNav.addVariable('flashVar_fontSize',		'11');
		flashMainNav.addVariable('flashVar_pipeColor',	'0xA5A5A5');
		flashMainNav.addVariable('flashVar_linkColor',	'0x285c74');
		flashMainNav.addVariable('flashVar_hoverColor',	'0x000000');
		flashMainNav.addVariable('flashVar_location',		window.location.href);
		flashMainNav.write('mainMenuFlash_div');
	
	//load Flash left side
	var leftSideFlash = new SWFObject('/swfs/'+strSectionBanner+'.swf','LeftFlash','100%','100%','8','#ffffff');
		leftSideFlash.addParam('scale','noscale');
		leftSideFlash.addParam('salign','tl');
		leftSideFlash.addParam('quality','high');
		leftSideFlash.addParam('wmode','transparent');
		leftSideFlash.write('flashLeft');
	
	//load Flash right side
	var strOffset = '-602';
	if(typeof strRightSWFOffset != "undefined"){
		//this page has strRightSWFOffset set globally. Use this value as the right side swf offset
		strOffset = strRightSWFOffset;		
	}
	var rightSideFlash = new SWFObject('/swfs/rightSideHolder.swf','RightFlash','100%','100%','8','#ffffff');
		rightSideFlash.addParam('scale','noscale');
		rightSideFlash.addParam('salign','tl');
		rightSideFlash.addParam('quality','high');
		rightSideFlash.addParam('wmode','transparent');
		rightSideFlash.addVariable('x',strOffset);
		rightSideFlash.addVariable('y','0');
		rightSideFlash.addVariable('swf','swfs/'+strSectionBanner+'.swf')
		rightSideFlash.write('flashRight');

	//load Flash specific to loaded page
	loadAdditionalFlash();
	
	//show the flash player download link if it has not been removed
	try{
		document.getElementById('flashPlayerDownload').style.display = 'block';
	}catch(e){
	
	}
		
	//for pages with a content nav, show the selected content
	SetSelectedContent();
	
	//initialize DLH
	DLHINIT();
	
}

/*****************************************************
Content Nav functions
*****************************************************/

function SetSelectedContent(){
//Set the selected state of the content if strSelectedContentNavItemId is not emply or undefined
	if(typeof strSelectedContentNavItemId != 'undefined'){ //set the default nav item to selected if there is a default
		if(strSelectedContentNavItemId != ''){
			try
			{	
				//clear any selected nav item in the content Flash nav
				document.getElementById('contentNav_flash').clear()
				//hightlight the nav item to select in the given Flash nav
				document.getElementById('contentNav_flash').highlight(strSelectedContentNavItemId,true);
			}catch(err)	{
		
			}				
			//Hide all content items that maybe shown
			clearChildNodes("contentCopy");		
					
			//Show the given content item
			var strDivToShow = strSelectedContentNavItemId+'ContentCopy';			
			if(typeof strSelectedContentItemId != 'undefined'){		
				if(strSelectedContentItemId != ''){
					//this is a special case where the content item is not tied to the nav item, use the provided content item id								
					strDivToShow = strSelectedContentItemId;	
					//clear this variable
					strSelectedContentItemId = '';
					
				}
			}
						
			document.getElementById(strDivToShow).style.display = 'block';				
						
		}
	}
}

function clearChildNodes(parent_node)
//sets the style of all DIVs contained in the HTML container with the given id
{
	parent_node = document.getElementById(parent_node);	
	for(var count=0; count<parent_node.childNodes.length; count ++)
	{
		if(parent_node.childNodes[count].nodeName == "DIV")
		{
			parent_node.childNodes[count].style.display = "none";
		}
	}
}

/*****************************************************
Misc. functions
*****************************************************/

function fixPNG(objImage) 
// fix for PNG images in IE using the AlphaImageLoader filter
{
 var arVersion = navigator.appVersion.split("MSIE")
 var version = parseFloat(arVersion[1])
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
  var strImageSource = objImage.src;
	  if(strImageSource.indexOf('.png') > -1){
	   //only apply the filter if the current image is a png   
	   objImage.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+objImage.src+"', sizingMethod='scale')";
	   objImage.src = 'images/spacer.gif';
	  	} else if (strImageSource.indexOf('nav_bot.gif') > -1) {
		 // This example was when the PNG included solid dark area so needed an overlying transparent GIF 
		 // of the non-gradient portion. The PNG was put in the CSS file, the GIF was placed in the Web page.
		 // Of course, then IE6 needs to swap out the GIF for a PNG so it can use its filter   
	   objImage.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/nav_botIE.png', sizingMethod='scale')";
	   objImage.src = 'images/spacer.gif';
	   }
    } else if (!document.all) {
			// If certain PNGs have been added to style sheet, we don't want to also have it as the image
			// so need to remove them from the image source so only style sheet PNG is visible. 
			// This example is from a job where the PNGs are hardcoded below
		if (objImage.src.indexOf("midright.png") > -1 || objImage.src.indexOf("topmid2.png") > -1 || objImage.src.indexOf("botmid.png") > -1 || objImage.src.indexOf("midleft.png") > -1 || objImage.src.indexOf("home_right_sidebar") > -1 ) {
			objImage.height = 0;
		} 
	}
}

/*****************************************************/

var vtWin;
function openVirtualTour(community,name,mls,path,id) {
	var which = "/movein_ready/virtual_tours/index.htm?comm="+community+"&name="+name+"&mls="+mls+"&id="+id;
	if (!vtWin || vtWin.closed) {
	  xStr = "left=" + eval(screen.width - 502)/2 + ",top="+ eval(screen.height - 560)/2 +",width=502,height=560";
	  vtWin = window.open(which,"vtWin",xStr);
	} else {
	  vtWin.location = which;
	  vtWin.focus();
	}
}

/*****************************************************/

function request(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return "";
}

/*****************************************************/

function writeVTApplet(id) {
	var str = '<applet code="BeHereViewer" archive="BeHereViewer.jar" width="464" height="384" align="center">';
	str = str + '<param name="panImage" value="'+id+'.jpg">';
	str = str + '<param name="autoSpin" value="20">';
	str = str + '<param name="viewWidth" value="464">';
	str = str + '<param name="viewHeight" value="256">';
	str = str + '<param name="ShowPanView" value="true">';
	str = str + '<param Name ="Initialview" value="0.0, 180.0, 0.8">';
	str = str + '</applet>';
	//alert(str)
	document.write(str);
}
