// JavaScript Document


// Example: obj = findObj("image1");
// Example:
// simplePreload( '01.gif', '02.gif' ); 



function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


function hd_init(val){
	findObj(val).className = 'focus';
	var srcArray= findObj(val).firstChild.src.split('.gif')
	findObj(val).firstChild.src = srcArray[0]+ '_focus.gif';
	//alert(findObj(val).firstChild.src);
	return false;
}

//JQuery init. Load when the page is ready - Using jQuery to run events
$(document).ready(
	function(){
		
		//nav extend and focus init.
		$('li.extendable').hover(
		function() {
				$(this).addClass('extend');
				$('ul',this).show();
				return false;
			},
		function() {
				$(this).removeClass('extend');
				$('ul',this).hide();
				return false;
			}
		);
		
		$('li.extendable/ul').hide();
						
		//thickbox init.
		TB_init();
		
		$('a.goToTop').click(
			function(){
				jumpToPageTop();
				this.blur();
				return false;
			}
		);

	}
);
//pageTop init
var timerScroll;
var posX;
var posY;
var Ver = parseFloat(navigator.appVersion);
var frm = 5;
if(navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1) { fIE = true; } else { fIE = false; }
if(navigator.appVersion.indexOf('Mac',0) != -1) { fMac = true; } else { fMac = false; }
if(navigator.appName.indexOf("Netscape",0) != -1) { fNN = true; } else { fNN = false; }
if((fMac && navigator.appVersion.indexOf('MSIE 4.',0) != -1)) { fMacIE4 = true; } else { fMacIE4 = false; }
if((fMac && navigator.appVersion.indexOf('MSIE 3.',0) != -1)) { fMacIE3 = true; } else { fMacIE3 = false; }

function getPosY() {
	if (fIE) { return document.body.scrollLeft; }
	else if (window.pageXOffset) { return window.pageXOffset; }
	else { return 0; }
}

function getPosX() {
	if (fIE) { return document.body.scrollTop; }
	else if (window.pageYOffset) { return window.pageYOffset; }
	else { return 0; }
}

function scroll2Top(pos2X,pos2Y,pos3X,pos3Y) {
	if (timerScroll) { clearTimeout(timerScroll); }
	if (!pos2X || (pos2X < 0)) { pos2X = 0; }
	if (!pos2Y || (pos2Y < 0)) { pos2Y = 0; }
	if (!pos3X) { pos3X = 0 + getPosY() };
	if (!pos3Y) { pos3Y = 0 + getPosX() };

	if (pos2Y > pos3Y && pos2Y > (getAnchorPosObj2('end','enddiv').y) - getInnerSize().height) pos2Y = (getAnchorPosObj2('end','enddiv').y - getInnerSize().height) + 1;
	pos3X += (pos2X - getPosY()) / frm;
	if (pos3X < 0) pos3X = 0;
	pos3Y += (pos2Y - getPosX()) / frm;
	if (pos3Y < 0) pos3Y = 0;
	posX = Math.floor(pos3X);
	posY = Math.floor(pos3Y);
	window.scrollTo(posX, posY);

	if (posX != pos2X || posY != pos2Y) {
		timerScroll = setTimeout("scroll2Top("+pos2X+","+pos2Y+","+pos3X+","+pos3Y+")",10);
	}
}

function jumpToPageTop() {
	scroll2Top(0,0);
}