/*Button initialization*/
btn_loop = new Image();
btn_loop.src = 'images/button/btn_loop.png';
btn_loop_on = new Image();
btn_loop_on.src = 'images/button/btn_loop_on.png';
left_btn = new Image();
left_btn.src = 'images/button/left_btn.png';
left_btn_on = new Image();
left_btn_on.src = 'images/button/left_btn_on.png';
right_btn = new Image();
right_btn.src = 'images/button/right_btn.png';
right_btn_on = new Image();
right_btn_on.src = 'images/button/right_btn_on.png';

/*menu initialization*/
menu_mouseover = new Image();
menu_mouseover.src = 'images/menu_mouseover.jpg';
submenu_mouseover = new Image();
submenu_mouseover.src = 'images/submenu_mouseover.png';

function openChatRoom(){
	FRchatRoom = window.open('','FRchatRoom','left=0,top=0,screenX=0,screenY=0,width=1038,height=855,scrollbars=yes,resizable=yes,status=yes,directories=no,menubar=no');
	if (document.chatroomForm!=null){
		document.chatroomForm.submit();
	}
	return false;
}

function closeChatroom(){
  if (typeof(FRchatRoom)!='undefined' && FRchatRoom && FRchatRoom.open && !FRchatRoom.closed){
	  FRchatRoom.close();
  }
}

function toPage(url){
	//if(navigator.appName != "Microsoft Internet Explorer"){
//		op -= 0.1;
//		document.body.style.opacity = op;
		//xmlhttp=new XMLHttpRequest()
		//xmlhttp.onreadystatechange=xmlhttpChange
		//xmlhttp.open("GET",url,true)
		//xmlhttp.send(null)
//		trans(url);
//	}else{
		window.location.href = url;
//	}
}
function trans(url){
	destination = url;
	op -= 0.1;
	document.body.style.opacity = op;
	if(op < 0.2){
		window.clearTimeout(timerId);
		timerId=0;
		//document.body.style.opacity=1;
		//document.open();
		//document.write(xmlhttp.responseText);
		//document.close();
		//window.location.href = destination;
		window.location.replace(destination);
		//window.location.reload(true);
		return;
	}
	timerId = window.setTimeout("trans('"+url+"');",20);
}
function transBack(){
	op += 0.1;
	document.body.style.opacity = op;
	if(op > 0.9){
		document.body.style.opacity=1;
		return;
	}
	setTimeout("transBack()",40);
}
function setBackground(){
  var trial = 0;
  var expiry_date = new Date("June 16, 3000");
  var the_cookie = "screenWidth="+ screen.width;
  var the_cookie = the_cookie + ";expires=" + expiry_date.toGMTString();
  document.cookie=the_cookie
}
function hideEffect(cell){
  cell.style.backgroundImage='';
}
function menuEffect(cell){
	cell.style.backgroundImage = 'url(' + menu_mouseover.src + ')';
}
function submenuEffect(cell){
	cell.style.backgroundImage = 'url(' + submenu_mouseover.src + ')';
}
function trim(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

//for input fields to have different border
sfFocus = function() {
	var sfEls = document.getElementsByTagName("INPUT");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
	var sfEls = document.getElementsByTagName("TEXTAREA");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfFocus);

function btn(cell,image,repeat){
	cell = document.getElementById(cell);
	if (repeat==1){
		cell.style.backgroundRepeat= 'repeat';
	}else if (repeat == 0){
		cell.style.backgroundRepeat= 'no-repeat';
	}
	cell.style.backgroundImage='url('+image.src+')';
}

function btnEffect(left,loop,right,action){
	if (action == 1){
		btn(left,left_btn_on,0);
		btn(loop,btn_loop_on,1);
		btn(right,right_btn_on,0);
	}else{
		btn(left,left_btn,0);
		btn(loop,btn_loop,1);
		btn(right,right_btn,0);
	}
}
function shareBtnEffect(element, direction){
	$(element).set('tween', {duration: '1'});
	if (direction == '1'){
		$(element).tween('margin-bottom', '2px');
	}else{
		$(element).tween('margin-bottom', '0px');
	}
}
