/****************************************************************************

   Copyright (c) Crusader Ltd
   
   webmaster[at]crusaderltd.com

   File:          cl.js
   Author:        Stephen Last
   Creation Date: 01/08/2008

****************************************************************************/

/////////////////////////////////////////////////////////
// Add load events
/////////////////////////////////////////////////////////
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function () {
			oldonload();
			func();
		}
	}
}

/////////////////////////////////////////////////////////
// Q and A - Show/Hide
// -------------------
// Loop through all anchors's looking for a class that 
// starts with 'answer_cat_'. Then grab the class name
// and use it to find the div in question. Then we 
// swap the display property between 'none' and 'block'
/////////////////////////////////////////////////////////
function cl_showHide() {
	var a = document.getElementsByTagName("a");
	for(var i=0;i<a.length;i++) {
		var a_class = a[i].className
		if ((a_class.indexOf('answer_cat_')!=-1) || (a_class.indexOf('answer_pro_')!=-1)) {
			a[i].a_class = a_class;
			a[i].onclick = function() {
				var div = document.getElementById(this.a_class);
				if (div.style.display=='none') { div.style.display='block'; } else { div.style.display='none'; }
				return false;
			}
		}
	}
}
addLoadEvent(cl_showHide);

/////////////////////////////////////////////////////////
// Blogs Hover
// -----------
// Set the hover for the blogs section, would normally
// use CSS for this stuff but I don't want to change the 
// h3 and p to spans (no nesting block within inline!).
/////////////////////////////////////////////////////////
function cl_blogs() {
	var div = document.getElementsByTagName("div");
	for(var i=0;i<div.length;i++) {
		var div_class = div[i].className
		if (div_class.indexOf('highlight')!=-1) {
			div[i].thediv = div[i];
			div[i].a = div[i].getElementsByTagName("a")[0];
			div[i].href = div[i].getElementsByTagName("a")[0].getAttribute('href');
			// On click
			div[i].onclick = function() {
				document.location=""+this.href+"";
			}
			// On mouse over
			div[i].onmouseover = function() {
				this.thediv.style.backgroundColor='#f2f2f2';
				this.thediv.style.cursor='pointer';
				this.a.style.color='#444';
			}
			// On mouse out
			div[i].onmouseout = function() {
				this.thediv.style.backgroundColor='#fff';
				this.a.style.color='#888';
			}
		}
	}
}
addLoadEvent(cl_blogs);

/////////////////////////////////////////////////////////
// Clickable boxes
// ---------------
// make the entire box clickable where the class is
// either 'class_box' or 'feat_box'
/////////////////////////////////////////////////////////
function cl_clickableBox() {
	var div = document.getElementsByTagName("div");
	for(var i=0;i<div.length;i++) {
		var div_class = div[i].className
		if ((div_class.indexOf('class_box')!=-1) || (div_class.indexOf('feat_box')!=-1)) {
			var div_id = div[i].getAttribute("id");
			var a = document.getElementById(div_id.replace("box","boxlink"));
			div[i].href = a;
			div[i].onclick = function() {
				document.location=""+this.href+"";
			}
		}
	}
}
addLoadEvent(cl_clickableBox);

/////////////////////////////////////////////////////////
// Popup window
// ------------
// Simply add class="popup" to any anchor tag
/////////////////////////////////////////////////////////
function cl_popup() {
	var a = document.getElementsByTagName("a");
	for(var i=0;i<a.length;i++) {
		var a_class = a[i].className
		if (a_class.indexOf('popup')!=-1) {
			a[i].href = a[i].getAttribute('href');
			a[i].onclick = function() {
				window.open(this.href,"","scrollbars=yes,width=600,height=400,resizable=yes,status=yes");
				return false;
			}
		}
	}
}
addLoadEvent(cl_popup);
















