var loadmap = 1;
window.onload = function() {
	navi = $A($(document.body).getElementsByClassName('link'));
	$(navi).each(function(s) {
		$(s).onclick = function() {
			relname = this.readAttribute('rel');
			//$A($('nav').immediateDescendants()).each(function(k) {$(k).removeClassName('active')});
			//$('link_' + relname).up('LI').addClassName('active');
			new Effect.ScrollTo($(relname), {duration:0.5, afterFinish:function() {window.location.hash = relname;}});
			
			return false;
		}
		$(s).onfocus = function() {this.blur();}
	});
	
	loadimg = new Image();
	loadimg.src = '/common/images/aload.gif';
	$('contactform').onsubmit = function() {
		$('contactcon').update('<img src="/common/images/aload.gif?rev=2" alt="Loading..." />');
		new Ajax.Request('/?', {method: 'post', asynchronous: true, evalScripts: true, parameters: this.serialize(),
			onComplete: function(t) {
			},
			onSuccess: function(t) {
				$('contactcon').update(t.responseText);
			}
		});
		
		return false;
	}
	
	if(loadmap == 1) {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("gmap"));
			map.setCenter(new GLatLng(3.193688,101.711078), 15);
			map.setUIToDefault();
			latlng = new GLatLng(3.193688,101.711078);
			map.addOverlay(new GMarker(latlng));
		}
	}
	
	startSlide();
}

var imgArr = new Array();
var imgCurrent = 0;
var imgLoop = 0;
var imgTotal = 0;
function startSlide() {
	children = $('slideshow').immediateDescendants();
	if(imgTotal == 0) imgTotal = children.length;
	
	if(imgArr == '') {
		cimg = new Image();
		for(i=0; i < children.length; i++) {
			current = $(children[i]);
			
			currentimg = $(current).down('IMG');
			currentlink = $(current).down('A');
			
			cimg.src = currentimg.readAttribute('src');
			
			imgdata = new Array();
			imgdata['data'] = $(current).innerHTML;
			
			imgArr.push(imgdata);
			
			if(i != 0) {
				current.remove();
			}
		}
	}
	
	imgCurrent++;
	if(imgCurrent >= imgTotal) {
		imgCurrent = 0;
		imgLoop++;
	}
	imgId = 'currentimg' + imgCurrent + imgLoop;
	newhtml = '<li id="' + imgId + '" style="display:none">' + imgArr[imgCurrent]['data'] + '</li>';
	new Insertion.Bottom('slideshow', newhtml);
	new Effect.Appear($(imgId));
	if($(imgId).down('A')) $(imgId).down('A').setAttribute('target', '_blank');
	if($($(imgId).previous(1))) $(imgId).previous(1).remove();
	
	setTimeout('startSlide()', 5000);
}

