var Mac = navigator.appVersion.indexOf('Mac',0) != -1;
var Win = navigator.appVersion.indexOf('Win',0) != -1;
var IE = navigator.userAgent.indexOf("MSIE",0) != -1;
var IE4x = navigator.userAgent.indexOf("MSIE 4",0) != -1;
var NS  = navigator.userAgent.indexOf("Netscape",0) != -1;
var NS4x =!IE && navigator.userAgent.indexOf("Mozilla/4",0) != -1;
var Opera = navigator.userAgent.indexOf("Opera",0) != -1;
var FF = navigator.userAgent.indexOf("Firefox",0) != -1;
var Moz = navigator.userAgent.indexOf("Gecko") != -1;
var safari = navigator.userAgent.indexOf("Safari") != -1;

//popup window
function popupWindow (url, id, w, h, features, centering) {
	var s = (w ? ("width=" + w) : "") + (h ? (",height=" + h) : "");
	var ss = new Array ("menubar", "toolbar", "location", "scrollbars", "status", "resizable");
	if (features) for (i in ss) s += "," + ss [i] + "=" + features.charAt (i);
	if (centering) {
		var x = (screen.width / 2) - (w / 2 + 10);
		var y = (screen.height / 2) - (h / 2 + 10);
		s += ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y;
	}
	var o = window.open (url, id, s);
	o.focus ();
	return o;
}


//windo?J£Äheck
function windowClosed (o) {
	return(!window.opener||window.opener.closed);
}


//window close
function windowClose () {
	var a = arguments;
	var r = true;
	if (a.length) 
	for (var i = 0; i < a.length; i++) { 
	var o = a [i]; 
	if (o) o.close (); 
	else r = false;
	} 
	else top.close (); return r; 
}

function changeOpener (url) { 
	if (windowClosed (window.opener)) {
		popupWindow (url,"parent");
	}else{
		window.opener.location.href = url;
		window.opener.focus();
	}
}


function preloadImages() {
	var d=document; if(d.images){
		if(!d.p) d.p=new Array();
		var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}
	}
}


function swapImgRestore() {
	var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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

function swapImage() {
	var i,j=0,x,a=swapImage.arguments;
	document.sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=findObj(a[i]))!=null){
		document.sr[j++]=x;
		if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	}
}


//windowscroll
function getScrlX() {
 if (IE) return document.documentElement.scrollLeft;
 else if (window.pageXOffset) return window.pageXOffset;
 else return 0;
}

function getScrlY() {
 if (IE) return document.documentElement.scrollTop;
 else if (window.pageYOffset) return window.pageYOffset;
 else return 0;
}

function getInnerSize() {
 var obj = new Object();
 if (document.getElementById && IE) {
  obj.width = document.documentElement.clientWidth;
  obj.height = document.documentElement.clientHeight;
 } else if (document.layers || (document.getElementById && Moz)) {
  obj.width = window.innerWidth;
  obj.height = window.innerHeight;
 }else if(opera){
  obj.width = document.body.clientWidth;
  obj.height = document.body.clientHeight;
 }
 return obj;
}

var scrlTimer;
function pageScroll(toX,toY,frms,cuX,cuY) {
 if (scrlTimer) clearTimeout(scrlTimer);
 if (!toX || toX < 0) toX = 0;
 if (!toY || toY < 0) toY = 0;
 if (!cuX) cuX = 0 + getScrlX();
 if (!cuY) cuY = 0 + getScrlY(); 
 if (!frms) frms = 6;
 if (toY > cuY && toY > (getAncPos('end_div').y) - getInnerSize().height){
	 toY = (getAncPos('end_div').y - getInnerSize().height) + 1;
}
 cuX += (toX - getScrlX()) / frms; if (cuX < 0) cuX = 0;
 cuY += (toY - getScrlY()) / frms;  if (cuY < 0) cuY = 0;
 var posX = Math.floor(cuX);
 var posY = Math.floor(cuY);
 window.scrollTo(posX, posY);
 if (posX != toX || posY != toY) {
  scrlTimer = setTimeout("pageScroll("+toX+","+toY+","+frms+","+cuX+","+cuY+")",16);
 }
}

function getAncPos(elementid) {
 var obj = new Object();
 if (document.getElementById) {
  obj.x = document.getElementById(elementid).offsetLeft;
	if(elementid!="end_div"){
  obj.y = document.getElementById(elementid).offsetTop-20;
	}else{
		obj.y = document.getElementById(elementid).offsetTop;
	}
 } else {
  obj.x = 0;
  obj.y = 0;
 }
 return obj;
}

function scrlToAnc(elementname, elementid) {
 if (getAncPos(elementid).x != 0 || getAncPos(elementid).y != 0) {
  pageScroll(0,getAncPos(elementid).y,5);
 } else {
  location.hash = elementname;
 }
}

function scrlToTop() {
  pageScroll(0,0,5);
}
