// JavaScript Document

function objLoading(fileList,funcAllComplete,funcItemComplete) {
	if (funcItemComplete == undefined) funcItemComplete = null;
	this.func2 = funcItemComplete;
	if (funcAllComplete == undefined) funcAllComplete = null;
	this.func1 = funcAllComplete;
	this.arr = fileList.split(",");
	this.allFile = new Array();
	this.nInc = 0;
	for (i = 0;i < this.arr.length;i++) {
		this.allFile[i] = new Image();
		this.allFile[i].parent = this;
		this.allFile[i].onload = function() {
			this.parent.nInc++;
			if (this.parent.func2 != null) this.aprent.func2();
			if (this.parent.nInc >= this.parent.arr.length) {
				if (this.parent.func1 != null) this.parent.func1();
			}
		}
		this.allFile[i].src = this.arr[i];
	}
}

function pageUnload() {
	
}

var _loadCheck = null;
var _imgMoveOut = null;
var _movementIMG1;
var _movementAll1;
var _mainScroll;
var _nSub = 0;
var _moveScroll;
var _moveSlide;
var _thumbs;
var _attri;
var _thumbsEleOld = null;

function effectLoad() {
	document.getElementById("btn_home").innerHTML = "<img src=\"mate/logo_home.png\" />";
	if (_contentt.last != undefined) {
		if (_contentt.last == 1) {
			_imgMoveOut = document.getElementById("movingIMG");
			_movementIMG1 = new objFree(_imgMoveOut,1);
			_movementIMG1.moveTo(0 - fullX,0,500,null,effectLoad2);
		}
		else if (_contentt.last == 2) {
			_imgMoveOut = document.getElementById("moveableBG");
			_movementIMG1 = new objFree(_imgMoveOut,2);
			_movementIMG1.moveTo(0 - fullX,0,500,null,effectLoad2);
		}
		else {
			_movement.moveTo(0 - fullX,0,500,null,adjPage);
		}
	}
	else {
		_movement.moveTo(0 - fullX,0,500,null,adjPage);
	}
}

function effectLoad2() {
	if (_contentt.last != undefined) {
		if (_contentt.last == 1) {
			_movement.moveTo(0,0 - fullY,500,null,adjPage);
			_movementIMG1 = null;
		}
	}
}

//callPage > callPage3 > pageLoaded > effectLoad

function callPage(page,nSub) {
	_dropMenu1.appear(false);
	if (_pageLoading == "c_service.php" || _pageLoading == "c_port_testimonial.php" || _pageLoading == "c_event.php") {
		if (_mainScroll != null) {
			_mainScroll.clearMe();
			_mainScroll = null;
		}
	}
	if (_pageLoading == "c_port_web.php" || _pageLoading == "c_port_testimonial.php" || _pageLoading == "c_event.php") {
		if (_moveSlide != null) {
			_moveSlide.destroy();
			_moveSlide = null;
		}
	}
	if (_pageLoading == "c_team.php" || _pageLoading == "c_awards.php") {
		clearTip();
	}
	if (nSub != undefined) _nSub = nSub;
	else _nSub = 0;
	_profileShow = 0;
	_menuLeft.pos = 1;
	_menuRight.pos = 1;
	menuSlide();
	menuSlide2();
	st = page.split('?');
	_pageLoading = st[0];
	_attri = st[1];
	callPage3(page);
}

function callPage2() {
}

function callPage3(page) {
	st = page.split('?');
	_pageLoading = st[0];
	_attri = st[1];
	_contentt.effect = 0;
	goAjax(page,pageLoaded,"",null);
}

function pageLoaded() {
	if (this.readyState == 4 && (this.status == 200 || this.status == 304)) {
		txt = this.responseText;
		n = txt.indexOf(':');
		files = txt.substr(0,n);
		arrFile = files.split(",");
		_txtNewPage = txt.substr(n + 1);
		document.getElementById("btn_home").innerHTML = "<img src=\"mate/loading.gif\" />";
		_loadCheck = new objLoading(files,effectLoad);
	}
}

function adjPage() {
	_contentt.last = _contentt.effect;
	_contentt.innerHTML = _txtNewPage;
	_myflash.style.zIndex = 0;
	_filter.style.left = "0px";
	_filter.style.top = "0px";
	_filter.style.width = fullX + "px";
	_filter.style.height = fullY + "px";
	_filter.style.zIndex = 1;
	
	if (_contentt.effect == 1) {
		_imgMoveOut = document.getElementById("movingIMG");
		_movement.setPosition(0,0 - fullY);
		_movement.moveToBreak(0,0,1000,null,adjPage2);
	}
	else {
		_movement.setPosition(0,0 - fullY);
		_movement.moveToBreak(0,0,1000,null,adjPage2);
	}
}

function adjPage2() {
	/*if (_pageLoading == "c_team.php") {
		imgs = _contentt.getElementsByTagName("img");
		ii = imgs.length;
		for (i = 0;i < ii;i++) {
			img = imgs[i];
			img.title = text[img.id];
			img.alt = text[img.id];
		}
	}
	if (_pageLoading == "c_awards.php") tooltip_initalize();*/
	if (_pageLoading == "c_service.php") {
		sb = document.getElementById("showbox");
		sb.style.height = (fullY - 200) + "px";
		document.getElementById("barscroll").style.height = (fullY - 275) + "px";
		_mainScroll = new scrollbar(document.getElementById("contbox"),0,0,0,2350,halfX + 455,140,halfX + 455,fullY - 140,"#666");
		_mainScroll.setPos(0,_nSub);
	}
	if (_pageLoading == "c_port_web.php" || _pageLoading == "c_port_printing.php" || _pageLoading == "c_port_product.php" || _pageLoading == "c_port_photo.php" || _pageLoading == "c_port_event.php" || _pageLoading == "c_event.php") {
		b2 = document.getElementById("box2");
		aW = parseInt(b2.style.width);
		aH = parseInt(b2.style.height);
		_moveSlide = new slideBox(document.getElementById("box1"),b2,aW,aH,714,476,714,476,714);
		tds = document.getElementsByTagName("td");
		_thumbs = new Array();
		if (_pageLoading == "c_port_web.php" || _pageLoading == "c_port_event.php") {
			for (i = 0;i < tds.length;i++) {
				if (tds[i].id == "thumb_td") {
					_thumbs.push(tds[i]);
					tds[i].nID = _thumbs.length - 1;
					tds[i].onmouseover = thumbOver;
					tds[i].onmouseout = thumbOut;
					tds[i].over = false;
				}
			}
		}
		
		//popup
		if (_pageLoading == "c_port_web.php") {
			goAjax("c_xml_port_web.php",xmlLoaded,"pcid=4&" + _attri,null);
		}
		else if (_pageLoading == "c_port_printing.php") {
			goAjax("c_xml_port_web.php",xmlLoaded,"pcid=6&" + _attri,null);
		}
		else if (_pageLoading == "c_port_photo.php") {
			goAjax("c_xml_port_web.php",xmlLoaded,"pcid=2&",null);
		}
		else if (_pageLoading == "c_port_event.php") {
			goAjax("c_xml_port_web.php",xmlLoaded,"pcid=3&" + _attri,null);
		}
		else if (_pageLoading == "c_event.php") {
			if (_attri != "" && _attri != undefined) goAjax("c_xml_event.php",xmlLoaded,_attri,null);
			else goAjax("c_xml_event.php",xmlLoaded,"",null);
		}
	}
	if (_pageLoading == "c_port_testimonial.php") {
		goAjax("c_xml_testimonial.php",parseTestimonial,"",null);
	}
	if (_pageLoading == "c_event.php") {
		b1 = document.getElementById("eventBox1");
		b2 = document.getElementById("eventBox2");
		w = parseInt(b2.style.height);
		//objTarget,defaultX,defaultY,maxX,maxY,scrollDX,scrollDY,scrollMX,scrollMY,color
		iY = parseInt(b2.style.height);
		iiY = 160 + 450;
		if (iY <= 480) {
			iY = 0;
		}
		else _mainScroll = new scrollbar(b2,0,0,0,iY,halfX + 510,180,halfX + 510,iiY,"#666666");
	}
	if (_pageLoading == "c_team.php") {
		imgs = _contentt.getElementsByTagName("img");
		l = imgs.length;
		for (var i = 0;i < l;i++) {
			img = imgs[i];
			img.id = arrText[i];
			img.onmouseover = showTip;
			img.onmouseout = hideTip;
		}
	}
	if (_pageLoading == "c_awards.php") {
		imgs = document.getElementById("txtbx").getElementsByTagName("img");
		l = imgs.length;
		for (var i = 0;i < l;i++) {
			img = imgs[i];
			img.id = i;
			img.onmouseover = showAward;
			img.onmouseout = hideAward;
		}
	}
}

function thumbOver() {
	this.over = true;
	//alert(this.toString());
	//return;
	div = this.getElementsByTagName("div");
	//this.div = div[1];
	//this.h = 0;
	//thumbOver2(this.nID);
	div[1].style.height = "40px";
	this.div = div[1];
	this.h = 0;
	thumbOver2(this.nID);
}

function thumbOver2(id) {
	td = _thumbs[id];
	td.h += 10;
	if (td.h >= 40) {
		if (!td.over) {
			td.div.style.height = "0px";
		}
		else {
			td.h = 40;
			td.div.style.height = td.h + "px";
		}
		return;
	}
	td.div.style.height = td.h + "px";
	setTimeout("thumbOver2(" + td.nID + ")",30);
}

function thumbOut() {
	this.over = false;
	this.div.style.height = "0px";
}

function parseTestimonial() {
	if (this.readyState == 4 && (this.status == 200 || this.status == 304)) {
		//this.parent.innerHTML = this.responseText;
		xml = this.responseXML.documentElement;
		persons = xml.getElementsByTagName("person");
		/*desc = persons[0].getElementsByTagName("desc");
		alert(desc[0].firstChild.nodeValue);
		document.body.getAt*/
		tt = document.getElementById("testThumb");
		areaName = document.getElementById("testName");
		areaDetail = document.getElementById("testDetails");
		mini = document.getElementById("testPicMini");
		imgFirst = null;
		nameFirst = null;
		descFirst = null;
		for (i = 0;i < persons.length;i++) {
			imgg = persons[i].getElementsByTagName("img")[0].getAttribute("src");
			descc = persons[i].getElementsByTagName("desc");
			desc = descc[0].firstChild.nodeValue;
			name = persons[i].getAttribute("name");
			div = document.createElement("div");
			img = new Image();
			if (imgFirst == null) {
				imgFirst = img;
				descFirst = desc;
				nameFirst = name;
			}
			img.title = name;
			img.alt = name;
			img.myDesc = desc;
			img.myName = name;
			img.myMini = mini;
			img.areaName = areaName;
			img.areaDetail = areaDetail;
			img.onmouseover = testOverThumb;
			div.className = "thumb_block_test";
			img.src = imgg;
			div.appendChild(img);
			tt.appendChild(div);
		}
		div = document.createElement("div");
		div.style.clear = "both";
		tt.appendChild(div);
		imgt = document.getElementById("testPic");
		areaName.innerHTML = nameFirst;
		areaDetail.innerHTML = descFirst;
		mini.src = imgFirst.src;
		_thumbsEleOld = imgFirst;
		imgFirst.parentNode.style.backgroundColor = "#9e8a2f";
		h = Math.ceil(persons.length / 2) * 121;
		e = h;
		if (h > 484) {
			e = h - 484;
		}
		_mainScroll = new scrollbar(document.getElementById("testThumb"),0,0,0,e,halfX + 335,177,halfX + 335,177 + 484 - 20,"#666");
	}
}

function testOverThumb() {
	this.areaName.innerHTML = this.myName;
	this.areaDetail.innerHTML = this.myDesc;
	this.myMini.src = this.src;
	this.parentNode.style.backgroundColor = "#9e8a2f";
	//if (_thumbsEleOld != null) {
		_thumbsEleOld.parentNode.style.backgroundColor = "#000";
		_thumbsEleOld = this;
	//}
}

var textx = new Array();
var arrText = new Array("0","2","3","4","5","6","7","8","9","10","11","12","14","15","18","19","21","22","23","24","25","26","27","28","29","30","32","33","34","35","36","37","39");
var thisTip;
var arrPicPop = null;
var arrTextPop = null;
var pPop;

textx[0] = "<b>John</b><br>Start the magazine 20 years ago, Happy to pass on to next generation.";
textx[1] = "<b>Ae</b><br>Programmer: I look like a computer geek, but the girls know better";
textx[2] = "<b>Tai</b><br>Sales Executive: The party girl of the office, loves people, brilliant at sales";
textx[3] = "<b>Cartoon</b><br>Accounts: Money collecting is a serious business, but I have my shitsu called Sushi that comes to work with me every day";
textx[4] = "<b>Oat</b><br>Photographer: While the low-slung hip hop look is awful, my photography is not";
textx[5] = "<b>Nut</b><br>Web Liasons: I try to make this programming stuff comprehensible to the outside world with my cute charm";
textx[6] = "<b>Kwan</b><br>Web Designer: I bring my ukelele to work every day, but still have time to pop out great web sites";
textx[7] = "<b>Sin</b><br>Head Gardener: All this eco-friendly stuff means a lot of raking, weeding, pruning then there\'s the heavy lifting for the parties!";
textx[8] = "<b>Tik</b><br>IT Manager: I control all the data in this company...mwah hahaha. I also know when people download things they shouldn\'t!";
textx[9] = "<b>Bet</b><br>CityNow! Editor: If you want to know what\'s going on in this city, then I'm da man";
textx[10] = "<b>James</b><br>Deputy Editor: I am a writer and editor, but annoy the entire company every day with my bad singing";
textx[11] = "<b>Pim</b><br>Editor/Director: Citylife\'s crazy boss; when she\'s good she\'s great, when she\'s awful, she\'s terrifying";
textx[12] = "<b>He</b><br>Photo Editor: I have a masters degree in Buddhism philosophy, but no one knows the ladies like I do";
textx[13] = "<b>Aor</b><br>Receptionist: You  have to get past me first, but I will always give you a smile";
textx[14] = "<b>Kao</b><br>Sales Executive: an odd little duck!";
textx[15] = "<b>Yong</b><br>Thai Deputy Editor: Finally someone in this company can write proper Thai!";
textx[16] = "<b>Darin</b><br>Office Manager: I make sure that things get done around here";
textx[17] = "<b>Jan</b><br>Marketing Manager: While I am a professional marketing manager, my singing sends everyone into ear surgery";
textx[18] = "<b>Pak</b><br>House Keeping: These creative types do leave a mess";
textx[19] = "<b>Tor</b><br>Search Engine Optimiser: I speak fluent English and can push your web sites right up the rankings";
textx[20] = "<b>Nui</b><br>Sales Execute: I am a good, sweet, adorable girl, but can sell ice to eskimos";
textx[21] = "<b>Win</b><br>Art Director: I direct this motley crew of designers and like wearing sexy tight t-shirts";
textx[22] = "<b>Tom</b><br>Programmer: I look like a rocker, but am secretly a computer geek";
textx[23] = "<b>Apple</b><br>Marketing Assistant: I am not a morning person, but I work late and love organising events...more details the better";
textx[24] = "<b>Yui</b><br>Assistant Production Manager: I have been here for over a decade and know EVERYTHING about this company";
textx[25] = "<b>Gai</b><br>Designer: I dress like I live on the street, I am always late, but no one draws like I do";
textx[26] = "<b>Tu</b><br>Desinger: Quiet, but as they say, still waters run deep, when I do occasionally speak, they all listen";
textx[27] = "<b>Tanoy</b><br>Accounts: I am the guardian of the company's treasure chest...";
textx[28] = "<b>Jack</b><br>Gardner: I rake leaves. All day.";
textx[29] = "<b>Ja</b><br>Production Manager: Been here for over a decade and am pretty much the mafia mother of the company";
textx[30] = "<b>Maping</b><br>Sales Executive: Epitomy of Thai lady, I am beautiful, polite and charming";
//textx[31] = "<b>Dean</b><br>Boss: I am the boss and my motto is we work as a team and do it my way";
textx[32] = "<b>Jay</b><br>Web Designer: Long hair, long nails, long limbs and long list of satisfied clients";
textx[33] = "<b>Kay</b><br>PA for Editor: I manage Pim's life...toughest job in the company";
textx[34] = "<b>Arm</b><br>Web Mistress: I am a programmer and love speaking in a language that no one else understands";
textx[35] = "<b>Steve</b>";
textx[36] = "<b>U</b><br>Sales Executive: Citylife's Casanova: new girl every lunch break";
textx[37] = "<b>Paew</b><br>Designer: I dress hot, I look hot, and my designs are hot too";
textx[38] = "<b>Ann</b><br>Sales Executive: In trend, independent and can talk anyone into anything";
textx[39] = "<b>Noi</b><br>Programmer: I smile all day and quietly and happily work away";
textx[40] = "<b>Kris</b><br>Sales Manager: I run my large team like a very tight ship, every man on deck must be at full attention";

var atext = new Array();

atext[0] = "<div style=\"width:250px; height:329px;\"><img src=\"images/aw1.jpg\" /></div><br /><br />Chiang Mai Creative City Goodwill Ambassador by M.L. Panadda Diskul, The Governor of Chiang Mai Province in July 2011";
atext[1] = "<div style=\"width:250px; height:395px;\"><img src=\"images/aw2.jpg\" /></div><br /><br />'Take the Next Step' grant in 2006 by the Leading Women Entrepreneurs of the World Organisation.";
atext[2] = "<div style=\"width:350px; height:246px;\"><img src=\"images/aw3.jpg\" /></div><br /><br />Winner of \"Homepage Design Contest for Division of Technical Services and Planning, Department of Provincial Administration in May 2007";
atext[3] = "<div style=\"width:350px; height:247px;\"><img src=\"images/aw4.jpg\" /></div><br /><br />APEC Women's e-Biz Training in Korea, 2005";
atext[4] = "<div style=\"width:350px; height:247px;\"><img src=\"images/aw5.jpg\" /></div><br /><br />Magazine Making and Publishing Training Course by PUM Netherland Senior Experts, 2008";
atext[5] = "<div style=\"width:350px; height:247px;\"><img src=\"images/aw6.jpg\" /></div><br /><br />The 4<sup>th</sup> Young BPW International Meeting  in Seoul, Korea, May 2007";
atext[6] = "<div style=\"width:350px; height:247px;\"><img src=\"images/aw7.jpg\" /></div><br /><br />BPW-SM Global Leadership Workshop in Korea, May 2007";
atext[7] = "<div style=\"width:350px; height:242px;\"><img src=\"images/aw8.jpg\" /></div><br /><br />3<sup>rd</sup> SMEs National Awards 2010 by the Ministry of Office of Small and Medium Enterprises Promotion (OSMEP)";

function showTip() {
	textBox(this.parentNode,textx[this.id],300,fullX);
	setAlpha(this,100);
	thisTip = this;
}

function showAward() {
	textBox(this.parentNode,atext[this.id],370,fullX);
	setAlpha(this,100);
	thisTip = this;
}

function hideTip() {
	setAlpha(this,60);
}

function hideAward() {
	//setAlpha(this,60);
	//this.box.close();
	_textBoxBox.style.top = "-10000px";
	_textBoxAr.style.top = "-10000px";
}

function hideTip2(obj) {
	_textBoxBox.style.top = "-10000px";
	_textBoxAr.style.top = "-10000px";
}

function picLoad(p) {
	setAlpha(p,60);
}

function clearTip() {
	_textBoxBox.style.top = "-10000px";
	_textBoxAr.style.top = "-10000px";
}

function xmlLoaded() {
	if (this.readyState == 4 && (this.status == 200 || this.status == 304)) {
		var x = this.responseXML.documentElement.getElementsByTagName("person");
		var xx;
		arrPicPop = new Array();
		arrTextPop = new Array();
		for (var i = 0;i < x.length;i++) {
			xx = x[i].getElementsByTagName("img");
			arrPicPop.push(xx[0].getAttribute("src"));
			dd = x[i].getElementsByTagName("desc");
			if (dd[0].hasChildNodes()) arrTextPop.push(dd[0].firstChild.nodeValue);
			else arrTextPop.push("");
		}
	}
}

function callPop(n) {
	if (_pageLoading == "c_port_web.php" || _pageLoading == "c_event.php") pPop = new picPopup(arrPicPop,n,500,500);
	else pPop = new picPopup(arrPicPop,n,500,500,arrTextPop);
}

