/**********************************************************************************
* author:		Christopher Sheldon, www.christophersheldon.ca															
* notes:		Copyright (c) Christopher Sheldon 2005. All Rights Reserved.						
*																									
*				The code contained within this file is not liscensed for public usage.  
*				Do not reproduce or alter this file complete or in part without the 
*				express written	permission of the author. 													
********/
 
 function classSite() {
 
 	this.domainMessage = 'You have reached this site from our old address.  Please updated your links and bookmarks to use our new address at www.gpremax.com.  You will now be redirected to our new address.';
 	
	var intPosition;
	var userAgent = navigator.userAgent.toLowerCase();

	/******************************************************************************
	*
	********/
		
	function searchAgent(strBrowser) {
		intPosition = userAgent.indexOf(strBrowser) + 1;
		return intPosition;
	}
 	
	/******************************************************************************
	*
	********/

 	this.browserName = searchAgent('konqueror') ? 'Konqueror' :	searchAgent('firefox') || searchAgent('firebird') ? 'FireFox' :	
		searchAgent('safari') ? 'Safari' : searchAgent('opera') ? 'Opera' :	searchAgent('webtv') ? 'WebTV' : searchAgent('msie') ? 'Internet Explorer' :
		searchAgent('netscape6') ? 'Netscape 6' : searchAgent('netscape') ? 'Netscape' : searchAgent('mozilla') ? 'Mozilla' : 'Unknown';	
	/******************************************************************************
	*
	********/

	this.openWindow = function(strUrl, strName, strFeatures, bReplace) {
		var bResult = true;
		var elWindow = window.open((strUrl ? strUrl : ''), (strName ? strName : ''), (strFeatures ? strFeatures : ''), (bReplace ? bReplace : false));
		if(!elWindow) {
			alert('A required popup window has been blocked by your system.  This may be the result of security or ad blocking software running on your machine.\n\nPlease allow popup windows from this site before attempting to use this function.');
			bResult = false;
		}
		return false;
	}
		
	
	/******************************************************************************
	*
	********/

	this.swapClass = function(elThis, strClassName) {
		elThis = elThis.toString().indexOf('[object') != -1 ? elThis : document.getElementById(elThis);
		if(elThis && strClassName) {
			if(elThis.className != strClassName) {
				elThis.className = strClassName;
			};
		};
	};


	/******************************************************************************
	*
	********/
	
	this.topButtonOver = function() {
		var elItem = site.browserName == 'Internet Explorer' ? event.srcElement : this;			
		elItem = (elItem.tagName == 'DIV' ? elItem : elItem.tagName == 'A' ? elItem.parentNode.parentNode : elItem.parentNode);		
		elItem.style.backgroundImage = elItem.style.backgroundImage.slice(0, elItem.style.backgroundImage.indexOf('_')) + '_over.gif)';
		elItem.style.cursor = 'pointer';

	};

	/******************************************************************************
	*
	********/
	
	this.topButtonOut = function() {
		var elItem = site.browserName == 'Internet Explorer' ? event.srcElement : this;			
		elItem = (elItem.tagName == 'DIV' ? elItem : elItem.tagName == 'A' ? elItem.parentNode.parentNode : elItem.parentNode);
		elItem.style.backgroundImage = elItem.style.backgroundImage.slice(0, elItem.style.backgroundImage.indexOf('_')) + '_out.gif)';
	};

	/******************************************************************************
	*
	********/
	 	
	this.getTopButtons = function() {
		for(var intCount = 1; intCount < 4; intCount++) {
			var elButton = document.getElementById('feature' + intCount);
			elButton.style.backgroundImage = 'url(images/feature' + intCount + '_out.gif)';

			elButton.onmouseover = site.topButtonOver;
			elButton.onmouseout = site.topButtonOut;
			elButton.onclick = site.buttonClick;
		};
	};
		
	/******************************************************************************
	*
	********/
	
	this.buttonOver = function() {
		var elItem = site.browserName == 'Internet Explorer' ? event.srcElement : this;			
		site.swapClass(elItem.tagName == 'LI' ? elItem : elItem.tagName == 'A' ? elItem.parentNode : elItem.parentNode.parentNode, 'menuButton_over');		
	};

	/******************************************************************************
	*
	********/
	
	this.buttonOut = function() {
		var elItem = site.browserName == 'Internet Explorer' ? event.srcElement : this;	
		site.swapClass(elItem.tagName == 'LI' ? elItem : elItem.tagName == 'A' ? elItem.parentNode : elItem.parentNode.parentNode, 'menuButton_out');
	};
	
	/******************************************************************************
	*
	********/
	
	this.buttonClick = function() {
		var elItem = site.browserName == 'Internet Explorer' ? event.srcElement : this;	
		elItem = elItem.tagName == 'DIV' ? elItem.childNodes[1].childNodes[0] : elItem.tagName == 'LI' ? elItem.childNodes[0] : elItem.tagName == 'A' ? elItem : elItem.parentNode;
		if(elItem.className == 'externalButton') {
			site.openWindow(elItem.href);
		} else {
			location.href = elItem.href;
		};
		return false;
	};

	/******************************************************************************
	*
	********/
	 	
 	this.getButtons = function() {
 		var elMenu = document.getElementById('menu');
		var elButtons = elMenu.getElementsByTagName('li');
		for(var intCount = 0; intCount < elButtons.length; intCount++) {
			elButtons[intCount].onmouseover = site.buttonOver;
			elButtons[intCount].onmouseout = site.buttonOut;
			
			elButtons[intCount].onclick = site.buttonClick;
		};
	};
		
	/******************************************************************************
	*
	********/
	 	
	this.getLinks = function() {
		var elLinks = document.getElementsByTagName('a');
		for(var intCount = 0; intCount < elLinks.length; intCount++) {
			if(elLinks[intCount].className == 'externalLink') {
				elLinks[intCount].onclick = function() {
					return site.openWindow(this.href);
				};
			};
		};
	};
 };
 
 var site = new classSite();
 
 window.onload = function() {
 	// redirect from old domain
 	if(location.href.indexOf('grandeprairieremaxab.com') > 0 || location.href.indexOf('remaxgrandeprairieab.com') > 0) {
 		alert(site.domainMessage);
	 	var strFile = location.href.slice(location.href.lastIndexOf('/') + 1).toLowerCase(); 	
	 	var strUrl = 'http://www.gpremax.com/';
 		
 		switch(strFile) {
 			case 'index.htm':
 				strFile = 'default.aspx';
 			break;
 			case 'findanagent.htm':
 				strFile = 'findanagent.aspx';
 			break;
 			case 'whychooseremax.htm':
 				strFile = 'whyremax.aspx';
 			break;
 			case 'citymap.htm':
 				strFile = 'mapgp.aspx';
 			break;
 			case 'links.htm':
 				strFile = 'links.aspx';
 			break;
 			default:
 				strFile = '';
 			break;
 		};
 		location.href = strUrl + strFile;
 	};
 	
 	site.getLinks();
 	site.getTopButtons();
 	site.getButtons();
 };
 