window.onload = init;

// Initialize
function init() {
  var temp = "";
  var lang = getLanguage();

  var swfinstall = false;
  var flashvars = {};
  var params = {};
  var attributes = {};
	swfobject.embedSWF(temp+"/common/swf/mastheads.swf", "header", "733", "211", "8.0.0", swfinstall, flashvars, params, attributes);
  
	//writeFlash(6, temp+"/common/swf/mastheads", 733, 211, "576421", "header", "jpg", "Bugsmart.ca", "_link_", "_target_");
	//randomHeader();
  //selectOnChange();
	
  if (document.getElementsByTagName('body')[0].id &&
    document.getElementsByTagName('body')[0].id != 'search')
    googleSearchHighlight();
}

// Get element
function getElem(id) {
  var obj = (typeof id == 'string') ? document.getElementById(id) : id;
  return obj;
}

// Set event attribute
function setAttr(obj, handler, theFunction) {
  if (document.all) {
    obj[handler] = new Function(theFunction);
  } else {
    obj.setAttribute(handler, theFunction);
  }
}

// Events onchange
function selectOnChange() {
  var oSelect;

  if (document.getElementById("redirect")) {
    oSelect = document.getElementById("redirect");
  }
  if (oSelect) {
    setAttr(oSelect, 'onchange', "goPage(this)");
  }
}

// Open window
function openWin(filename, width, height, show) {
	var attr = '';

	// close window if already open
	if (popWin && !popWin.closed) popWin.close();

	// open window
	attr += 'width=' + width + ',';
	attr += 'height=' + height + ',';
	attr += (show) ?
		'resizable=yes,location=yes,menubar=yes,scrollbars=yes' :
		'resizable=no,location=no,menubar=no,scrollbars=no';
	popWin = window.open(filename, 'popWin', attr);
	popWin.focus();
}

// Redirect
function goPage(obj) {
	oValue = obj[obj.selectedIndex].value;
	if (oValue) location.href = oValue;
}

// Radomize header image
function randomHeader() {
  var r = Math.floor(Math.random() * 3 + 1);
  getElem('header').className = 'header' + r;
}

function getLanguage() {
  var htmlElement = document.getElementsByTagName('html')[0];
  return htmlElement.getAttribute('xml:lang');
}
  