window.addEvent('domready', function(){
	loadGoogleMap();
	
	if($('slidShowContainer')){
		initSlideShow();
	}
});


/* google map */
var map;
var geocoder;

function loadGoogleMap(){
	if(GBrowserIsCompatible()){
		if($('googleMapHome') != null){
			map = new GMap2($('googleMapHome'));
			map.setCenter(new GLatLng(-27.293689, 133.066406), 3);
			showAddress('220 Montague Rd, West End, QLD 4101');
			
		}else if($('googleMapWP') != null){
			map = new GMap2($('googleMapWP'));
			map.setCenter(new GLatLng(-27.293689, 133.066406), 3);
			showAddress('220 Montague Rd, West End, QLD 4101');
		}
	}
}

function showAddress(address){
	geocoder = new GClientGeocoder();
	geocoder.getLatLng(
		address,
		function(point){
			if(!point){
				alert('Address cannot be found!');
			}else{
				map.setCenter(point, 15);
				var marker = new GMarker(point);
				map.addOverlay(marker);
			}
		}
	);
}
/* end google map */


/* slide show */
var slideshow;
var featureBoxes;
var numFeatureBoxes;
var featureBoxWidth;
var currentFeatureBoxIndex;
var timer;

function initSlideShow(){
	slideshow = new Fx.Scroll('left', {
        wait: false,
        duration: 500,
        transition: Fx.Transitions.Quad.easeInOut
    });
	
	featureBoxes = $$('div#slidShowContainer div.imageBox');
	numFeatureBoxes = featureBoxes.length;
	featureBoxWidth = Number(featureBoxes[0].getStyle('width').replace(/px/, "")) + Number(featureBoxes[0].getStyle('margin-right').replace(/px/, ""));
	currentFeatureBoxIndex = 0;
	
	// add listener
	$('left').addEvent('mouseover', function(e){
		e.stop();
		
		stopSlideShow();
	});
	
	$('left').addEvent('mouseout', function(e){
		e.stop();
		
		startSlideShow();
	});
	
	startSlideShow();
}

function startSlideShow(){
	// timer every 15 seconds
	timer = window.setInterval('rotateSlideShow()', 15000);
}

function stopSlideShow(){
	timer = window.clearInterval(timer);
}

function rotateSlideShow(){
	currentFeatureBoxIndex++;

	if(currentFeatureBoxIndex > numFeatureBoxes - 1){
		currentFeatureBoxIndex = 0;
	}

	var nextPos = currentFeatureBoxIndex * featureBoxWidth;
	slideshow.start(nextPos, 0);
}
/* end slide show */