

//////////////////////////////    
//////////////////////////////    SOME KICK ASS CODE FOLLOWS :-)
//////////////////////////////	  


//////////////////////////////
//////////////////////////////    1. BROWSER SNIFFER
//////////////////////////////

function Is() {
    agent		    = navigator.userAgent.toLowerCase();
    this.major		= parseInt(navigator.appVersion);
    this.minor		= parseFloat(navigator.appVersion);
    this.ns			= ((agent.indexOf('mozilla')   !=   -1) && ((agent.indexOf('spoofer')   ==   -1) && (agent.indexOf('compatible') ==   -1)));
    this.ns4		= (this.ns && (this.major      ==    4));
    this.ns6		= (this.ns && (this.major      >=    5));
    this.ie			= (agent.indexOf("msie")       !=   -1);
    this.ie3		= (this.ie && (this.major      < 4));
    this.ie4		= (this.ie && (this.major      ==    4) && (agent.indexOf("msie 5.0")   ==   -1));
    this.ie5		= (this.ie && (this.major      ==    4) && (agent.indexOf("msie 5.0")   !=   -1));
    this.ie55		= (this.ie && (this.major      ==    4) && (agent.indexOf("msie 5.5")   !=   -1));
    this.ie6		= (this.ie && (agent.indexOf("msie 6.0")!=-1) );
}

var is = new Is();

//////////////////////////////
//////////////////////////////    2. Global Timers
//////////////////////////////

var scrolltimer = null;
var speed 		= 12;
var opactimer	= null; 
mTimer          = null;
var jimWindow   = null;


//////////////////////////////
//////////////////////////////    3. OBJECT SETUP
//////////////////////////////

function objectSetup() {
  page              = new Object();
  pageWidth         = (is.ns6) ? innerWidth  : document.body.clientWidth;
  pageHeight        = (is.ns6) ? innerHeight : document.body.clientHeight;
  
  searchoptimise    = new layerSetup("searchLYR",-220,-220,200,200,1,"visible","absolute");
  
  content           = new layerSetup("contentLYR",30,18,pageWidth*.59,pageHeight*3.0,4,"visible","absolute");
  content.overflow  = "hidden"; 
   
  main              = [new menuSetup('m0'), new menuSetup('m1'), new menuSetup('m2'), new menuSetup('m3'), new menuSetup('m4')];
  subs              = [new menuSetup('sub0'), new menuSetup('sub1'), new menuSetup('sub2'), new menuSetup('sub3'), new menuSetup('sub4')];
  
	
  flowManager('menu');
}

//////////////////////////////
//////////////////////////////    4. Element Scaling Manager
//////////////////////////////


function scaleImages() {
	img = document.getElementsByTagName("IMG");
	for(i = 0; i < img.length; i++) {
	imgW = img[i].getAttribute("w"), imgH = img[i].getAttribute("h");
		if(img[i].className == "imgR") {
			img[i].style.width = (imgW > 2) ?imgW : pageWidth * eval(imgW);
			img[i].style.height = (imgH > 2) ?imgH : pageHeight * eval(imgH);
		}

}

}

//////////////////////////////
//////////////////////////////    5. SETUP FUNCTIONS
//////////////////////////////

function layerSetup(id,left,top,width,height,zindex,visibility,position) {
  this.obj           	= document.getElementById(id).style;
  this.obj.id        	= document.getElementById(id);
  this.obj.position  	= position;
  this.obj.left      	= left
  this.obj.top       	= top;
  this.obj.width     	= width;
  this.obj.height    	= height;
  this.obj.zIndex    	= zindex;
  this.obj.visibility	= visibility;
  return this.obj;
}

function menuSetup(obj) {
  this.lyr 		= document.getElementById(obj).style;
  this.lyr.id 	= document.getElementById(obj);
  return this.lyr;
}

function animationSetup(attribute1,attribute2,animator,command1,command2,command3,delay,cycle) {
  this.loop       	= 0;
  this.interval   	= null;
  this.attribute1 	= attribute1;
  this.attribute2 	= attribute2;
  this.animator   	= animator;
  this.command1   	= command1;
  this.command2   	= command2;
  this.command3   	= command3;
  this.start      	= startAnimation;
  this.stop       	= stopAnimation;
  this.delay      	= delay;
  this.cycle      	= cycle
  return this;
}

function pathAnimator() {
  if(this.animation.loop <= this.path.length-1) {
    this[this.animation.attribute1] = this.path[this.animation.loop].attribute1;
    this[this.animation.attribute2] = this.path[this.animation.loop].attribute2;
    if(this.animation.command1) eval(this.animation.command1);
    this.animation.loop++;
  } else {
    if(this.animation.cycle) {
      if(this.animation.command2) eval(this.animation.command2);
      this.animation.loop = 0;
    } else {
      clearInterval(this.animation.interval);
      if(this.animation.command3) eval(this.animation.command3);
      this.animation.loop = 0;
    }
  }
}

function startAnimation() {
  clearInterval(this.interval);
  this.interval = setInterval(this.animator,this.delay);
}

function stopAnimation() {
  clearInterval(this.interval);
}

function pathSetup(type,pos_1,pos_2,pos_3,pos_4,radius_1,radius_2,steps) {
  var dataArray = new Array();
  if(type == "linear") {
    var attr1 = pos_1;
    var attr2 = pos_3;
    for(var i = 0; i <= steps-1; i++) {
      attr1 += Math.round(pos_2/steps);
      attr2 += Math.round(pos_4/steps);
      dataArray[i] = {attribute1:attr1,attribute2:attr2};
    }
  }
  if(type == "circular") {
    var increment = (pos_2 - pos_1)/steps;
    for(var i = 0; i <= steps-1; i++) {
      pos_1 += increment;
      var attr1 = Math.round(pos_3 + radius_1 * Math.cos(pos_1*(Math.PI/180)));
      var attr2 = Math.round(pos_4 + radius_2 * Math.sin(pos_1*(Math.PI/180)));
      dataArray[i] = {attribute1:attr1,attribute2:attr2};
    }
  }
  return dataArray;
}

function scrollSetup() {
	page 	= eval("document.getElementById('contentLYR').style");
	scrl_bottom = (document.getElementById('contentLYR').offsetHeight - screen.availHeight/3);
}

function eventSetup(event,command) {
  var trigger  = (is.ns6) ? event : "on" + event;
  var listener = (is.ns6) ? document.body.addEventListener(trigger,command,false) :
                            document.body.attachEvent(trigger,command);
}


function textTransform(tag,attribute,value,size,color,weight,style) {
  var font_scaler         = parseInt((0.016*pageHeight+0.016*pageWidth)/2);
  var tag_collection      = document.getElementsByTagName(tag);
  for(var i = 0; i <= tag_collection.length-1; i++) {
    var attributeType = (attribute == "class") ?  tag_collection[i].className : tag_collection[i].getAttribute(attribute)
    if(attributeType == value) {
      this.obj            = document.getElementById(tag_collection[i].id).style;
      this.obj.fontSize   = size + font_scaler + "px";
      this.obj.color      = color;
      this.obj.fontWeight = weight;
      this.obj.fontStyle  = style;
    }
  }
}

function setLetterSpace(id,space) {
document.getElementById(id).style.letterSpacing = space;
}



//////////////////////////////
//////////////////////////////    6. ANIMATION MANAGER
//////////////////////////////


function animationManager(cmd) {
   switch(cmd) {
    case "scrollDown" :
    var y_pos 	= parseInt(page.top);
	if (y_pos > -eval(scrl_bottom)) {
	page.top 	= y_pos - speed;
	} else { 
	animationManager('stopScroll'); 
	}
	scrolltimer 	= setTimeout("animationManager('scrollDown')", 10);
	
	break;

    case "scrollUp" :
    var y_pos 	= parseInt(page.top);
	if (y_pos < 18) page.top = y_pos + speed;
	scrolltimer 	= setTimeout("animationManager('scrollUp')", 10);
		        
    break;
	
	case "stopScroll" :
      clearTimeout(scrolltimer);
		        
		        
    break;
	
  }
}

function makeMenu(l,t) {
    if(is.ns6) mTimer = setTimeout("makeMenu("+l+","+t+")", 100)
	a = (is.ns6) ?2 : 0;
	
	main[0].left = l; main[0].top = t;
	for(m = 1; m < main.length; m++) {
		main[m].left = main[m-1].id.offsetLeft + main[m].id.offsetWidth - a;
		main[m].top = t;
	}
	for(s = 0; s < subs.length; s++) {
		subs[s].left = main[s].id.offsetLeft - a; 
		subs[s].top = main[s].id.offsetTop + main[s].id.offsetHeight - 20;
		subs[s].animation = new animationSetup("visibility","clip","subs["+s+"].animator()",null,null,null,25,false);
		main[s].visibility = "visible";
	}
	setTimeout("clearTimeout(mTimer)", 10);
}

function show(s) {
	subs[s].animator = doShow;
	subs[s].animation.start();
	if(subs[s].animation.loop >= subs[s].id.offsetHeight+8) subs[s].animation.stop();
}

function doShow() {
	this[this.animation.attribute1] = "visible";
	this[this.animation.attribute2] = 'rect(0, 1000, '+this.animation.loop+', 0)';
	this.animation.loop += 10;
	if(this.animation.loop >= this.id.offsetHeight+8) this.animation.stop();
}

function hide(s) {
	subs[s].animator = doHide;
	subs[s].animation.start();
	if(subs[s].animation.loop <= 0) subs[s].animation.stop();
}

function doHide() {
	this[this.animation.attribute1] = "visible";
	this[this.animation.attribute2] = 'rect(0, 1000, '+this.animation.loop+', 0)';
	this.animation.loop -= 10;
	if(this.animation.loop <= 0) {
		this.animation.stop();
		this[this.animation.attribute1] = "hidden";
	}
}



//////////////////////////////
//////////////////////////////    7. CONTENT DISPLAY FUNCTIONS
//////////////////////////////

function displayLanguage(languageName) {
  var tag_collection = document.getElementsByTagName("div");
  for(var i = 0; i <= tag_collection.length-1; i++) {
    if(tag_collection[i].getAttribute("lang")) {
      document.getElementById(tag_collection[i].id).style.display = "none";
    }
    if(tag_collection[i].getAttribute("lang") == languageName) {
      document.getElementById(tag_collection[i].id).style.display = "block";
    }
  }
}

function loadPage(url) {
  	parent.rbottom.location.href=url}

function displayPage() {
	content.id.innerHTML =  window.frames.contentFRM.document.getElementById("bodyHTML").innerHTML;
}
                                                                                                                        
function displayInfo(name, message) {
        document.getElementById(name).innerHTML = message;
}

function openJim() {
  if(screen.height <= 600) {
    var window_width = screen.width-12;
    var window_height = screen.height-12;
  } else {
    var window_width = 800;
    var window_height = 600;
  }
  if(is.ie5 || is.ie55 || is.ie6) {
    var window_left = (screen.width - 800) / 2;
    var window_top = (screen.height - 600) / 2;
    jimWindow = window.open('http://dhtmlnirvana.com/jim/jim_stage.htm','JIM','resizable=yes,status=yes,width=' + window_width + ',height=' + window_height
    + ',top=' + window_top + ',left=' + window_left + '');
  } else {
    alert('Note: Attempts to make the site compatible with Netscape 4.x ran into a stumbling block due to the fact that this browser doesn\'t support the transparent overlay of plugins with DHTML layers which is essential for the two to work together in this design.  So for now, it is restricted to Explorer 4/5, Flash 4 plus the Media Player Plugin.');
  }
}


//////////////////////////////
//////////////////////////////    8. GLOBAL EVENT HANDLER MANAGER
//////////////////////////////

function eventManager(e) {
  var target    = (is.ns6) ? e.target : e.srcElement;
  var parent    = (is.ns6) ? target.parentNode.parentNode : target.parentNode;
  var child     = (is.ns6) ? target.parentNode : target;
  switch(e.type) {
    case "mouseover" :
      if(target.nodeName == "#text" && child.className == "item" || child.className == "menu")
		child.style.backgroundColor = "#004600";
	  if(target.className == "item" || target.className == "menu") 
	  target.style.backgroundColor = "#004600";
	  
	  if(target.className == "scrollup") {
	    animationManager('scrollUp'); 
	    animationManager('showEyes'); 
	    pink1.animation.stop();
	    pink2.animation.stop(); 
	    clearTimeout(opactimer); 
	  }
	  if(target.className == "scrolldown") {
	    animationManager('scrollDown'); 
	    animationManager('showEyes'); 
	    pink1.animation.stop();
	    pink2.animation.stop(); 
	    clearTimeout(opactimer); 
	  }
	break;

    case "mouseout" :
      if(target.nodeName == "#text" && child.className == "item" || child.className == "menu") {
		child.style.backgroundColor = "#000000";
		}
	  if(target.className == "item" || target.className == "menu") {
		target.style.backgroundColor = "#000000";
	  }
	  if(target.className == "scrollup" || target.className == "scrolldown" ) {
	    animationManager('hideEyes'); 
 	    animationManager('randomOpacity'); 
	    animationManager('stopScroll');
	  }
    break;
	
	case "click" :
	  if(target.nodeName == "#text" && child.className == "item") 
	  loadPage(child.getAttribute("url")) ;
	  if(target.className == "item")
	  loadPage(target.getAttribute("url"));
    break;
  }
}



//////////////////////////////
//////////////////////////////    9. SMART PAGE MANAGER
//////////////////////////////

function flowManager(action) {
  switch(action) {
    case "menu" :
      
  //    displayLanguage("english");   Placeholder for Dynamic Langauge Switching
      makeMenu(0,0);
  	  flowManager('events');
  
    break;
    case "events" :
      eventSetup("mouseover",eventManager);
      eventSetup("mouseout",eventManager);
	  eventSetup("click",eventManager);
	  
	  flowManager('start');
      
	 break;
	 
	  case "start" :
	  
	  scrollSetup();
	  setTimeout('scaleImages()', 1000);

  
   
    break;
		
  }
}