 // JavaScript Document

var _DOMAIN = 'businesscatalystsites.com.au';

function initRollovers() {
	var all_links;
	var link;
	var idx;
	var tmp_image;
	var section_id = getSectionId();
	
	if (!document.getElementsByTagName) {
		return;   
	}
	
	all_links = document.getElementsByTagName("a");
	
	for (idx = 0; idx < all_links.length; idx++) {
		link = all_links[idx];
		
		if (link.className && (' ' + link.className + ' ').indexOf(' rollover ') != -1) {
			if (link.childNodes && link.childNodes.length == 1 && link.childNodes[0].nodeName.toLowerCase() == 'img') {
				// Pre-load state 2 images
				tmp_image = new Image();
				tmp_image.src = link.childNodes[0].src.replace(/(\.[^.]+)$/, "_f2$1");

				if (link.childNodes[0].id && link.childNodes[0].id == section_id) {
					// Don't attach a listener. Instead, set rollover state permanently
					link.childNodes[0].src = link.childNodes[0].src.replace(/(\.[^.]+)$/, "_f2$1");
				} else {	
					// Attach listeners
					link.onmouseover = mouseover;
					link.onmouseout = mouseout;
					link.onfocus = mouseover;
					link.onblur = mouseout;
				}
			}
		}
	}
}

function findTarget(e) {
   var target;
   
   if (window.event && window.event.srcElement) {
      target = window.event.srcElement;
   }
   else if (e && e.target) {
      target = e.target;	   
   }
   
   if (!target) return null;
   
   while (target != document.body && target.nodeName.toLowerCase() != "a") {
      target = target.parentNode;   
   }
   
   if (target.nodeName.toLowerCase() != "a") return null;
   
   return target;
}

function mouseover(e) {
   var target = findTarget(e);
   var img_tag;
   
   if (!target) return;
   
   img_tag = target.childNodes[0];
   
   if (img_tag.src.indexOf("_f2.") < 0) img_tag.src = img_tag.src.replace(/(\.[^.]+)$/, "_f2$1"); 
}

function mouseout(e) {
   var target = findTarget(e);
   var img_tag;
   
   if (!target) return;
   
   img_tag = target.childNodes[0];
   img_tag.src = img_tag.src.replace(/_f2(\.[^.]+)$/, "$1");   
}

function getSectionId() {
	var current_url = location.href;
	var pattern = new RegExp("^http:\\/\\/" + _DOMAIN + "\\/(\\w+)");
	var regexp_results = pattern.exec(current_url);
	
	if (RegExp.$1) {
		return RegExp.$1;
	} else {
		return '';
	}
}

window.onload = initRollovers;

function wopen(url, name, w, h)
{
// Fudge factors for window decoration space.
 // In my tests these work well on all platforms & browsers.
w += 32;
h += 96;
 var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=yes, resizable=no');
 win.resizeTo(w, h);
 win.focus();
}


function popup1(URL) { 
 day = new Date(); 
 id = day.getTime(); 
 params = 'scrollbars,resizable,width=990,height=600,left=0,top=0'; 
 var win = window.open(URL,id,params); 
 return false;
 }  
 
 function popup2(URL) { 
 day = new Date(); 
 id = day.getTime(); 
 params = 'scrollbars,resizable,width=1024,height=768,left=0,top=0'; 
 var win = window.open(URL,id,params); 
 return false; 
} 

 function popup3(URL) { 
 day = new Date(); 
 id = day.getTime(); 
 params = 'scrollbars,resizable,width=600,height=660,left=0,top=0'; 
 var win = window.open(URL,id,params); 
 return false; 
} 

 function popup4(URL) { 
 day = new Date(); 
 id = day.getTime(); 
 params = 'scrollbars,resizable,width=580,height=450,left=0,top=0'; 
 var win = window.open(URL,id,params); 
 return false; 
} 
