window.onload = function() {
	// Front page cycle	
	$('#cycle').cycle({
		before:  function(){
			var cap = this.alt;
			$('#cycle-container .image-caption-bottom span').fadeOut(400, function(){
				$(this).html(cap).fadeIn(500);
			});
		}
	});
}

$(function () {
		

	
	// Superfish
	$('ul#menu').superfish();
	
	var flashvars = {};
	var params = {};
	params.wmode = "transparent";
	var attributes = {};
	swfobject.embedSWF("swf/cycle-667x380.swf", "cycle", "667", "380", "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes);


	$('a.external').each(
		function() {
			$(this).attr('target', '_blank');
		}
	);

	$('#accordion').accordion({
		header: "h3",
		autoHeight: false,
		alwaysOpen: false,
		active: false
		
	});
		$('.prop-thumb').live('click', function () {
			/*var img_src = $(this).attr('href');
			$('#new-property-main-image').append('<img src="' + img_src
			+'" style="display: none;">');
			$('img:visible', '#new-property-main-image').fadeOut('slow');
			$('img:hidden', '#new-property-main-image').fadeIn('slow',
			function() {
				$('img:hidden', '#new-property-main-image').remove();
			});*/
			ii_n = parseInt($(this).attr('title')) + 1;
			var image = $('a', $(this)).attr('rel');
			$('img:visible', $('#photo-container'))
				.css('z-index', 150)
				.fadeOut('slow');
			$(image, $('#photo-container'))
				.css('z-index', 300)
				.fadeIn('slow');

			return false;
		});
		
		
	
	if(typeof(address) != 'undefined') {
		window.onload = function(){
			GMapLoad();
			showAddress(address);
		}
		window.onunload = GUnload;
		//<![CDATA[

		var map,geocoder;
		function GMapLoad() {
			if (GBrowserIsCompatible()) {
				map = new GMap2(document.getElementById("Gmap"));
				map.addControl(new GLargeMapControl());
				geocoder = new GClientGeocoder();
			}
		}

		function showAddress(address) {
			geocoder.getLatLng(
				address,
				function(point) {
					if (!point) {
						if (address.match(/^\d+/)) {
							streetOnly = address.replace(/^(\d|\s|\/)*/, '');
							showAddress(streetOnly);
							return;
						} else if (address.match(/,/g)) {
							suburbOnly = address.substring(address.indexOf(',')+1, address.length);
							showAddress(suburbOnly);
							return;
						} else {
							alert(address + " could not be found!");
							return;
						}
					} else {   
						map.setCenter(point, 16);
						var marker = new GMarker(point);
						map.addOverlay(marker);
						foundSuburbOnly = '';
						if (address.match(/^[^(,|\d)]+, Australia$/)) {
							foundSuburbOnly = '<br />(Found suburb location only!)';
						}
						marker.openInfoWindowHtml('<span style="color:black;font-family:Arial;font-size:11px;">' + address + '</span><br /><br /><img style="margin-left: 140px;" src="assets/images/gmap-logo.jpg" width=64 height=35>');
						panoOptions = { latlng:point, pov:{yaw:351.62006250915852,pitch:0} };
		/*
						var mappano = new GStreetviewPanorama(document.getElementById("pano"), panoOptions);

						GEvent.addListener(mappano, "error", handleNoFlash);

						svOverlay = new GStreetviewOverlay();
						map.addOverlay(svOverlay);       

						GEvent.addListener(map,"click", function(overlay,latlng) {
							mappano.setLocationAndPOV(latlng);
						});
		 */
					 }
				}
			);
		}

		function handleNoFlash(errorCode) {
			if (errorCode == FLASH_UNAVAILABLE) {
				alert("Error: Flash doesn't appear to be supported by your browser");
				return;
			}
		}
	}

	function validate_property_alert () {
		// Check to ensure that the text areas all have information.
		var name = $.trim($('#name').val());
		var email = $.trim($('#email').val());
		var phone = $.trim($('#phone').val());

		var message = 'PLEASE NOTE!\n\nThere is a vast amount of property sold that isn\'t advertised, please enter your best contact number so you don\'t miss out on the next property to be SOLD by the rweast team!';





		if(name == '') {
			alert(message);
			return false;
		} else if (email == '') {
			alert(message);
			return false;
		} else if (phone == '') {
			alert(message);
			return false;
		} else {
			// Congratulations, the user has successfully submitted the form.
			return true;
		}
	}

	$('#login').submit( function () {
		return validate_property_alert();		
	});

	var flashvars = {};
	flashvars.splash_location = "http://www.infochoice.com.au/modules/applets/flash9/Source/Applets/splash_icon.swf";
	flashvars.info_location = "http://www.infochoice.com.au/distributions/flash9/10397/info/";
	flashvars.xml_location = "http://www.infochoice.com.au/distributions/flash9/10397/";
	var params = {};
	params.wmode = "transparent";
	params.allowscriptaccess = "always";
	var attributes = {};
	attributes.id = "calc-container";
	swfobject.embedSWF("http://www.infochoice.com.au/modules/applets/flash9/Source/Applets/SplashLogo/LoanRepayments.swf", "loan-calc-container", "640", "330", "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes);

	var flashvars2 = {};
	flashvars2.splash_location = "http://www.infochoice.com.au/modules/applets/flash9/Source/Applets/splash_icon.swf";
	flashvars2.info_location = "http://www.infochoice.com.au/distributions/flash9/10397/info/";
	flashvars2.xml_location = "http://www.infochoice.com.au/distributions/flash9/10397/";
	var params2 = {};
	params2.wmode = "transparent";
	params2.allowscriptaccess = "always";
	var attributes2 = {};
	attributes2.id = "calc-container";
	swfobject.embedSWF("http://www.infochoice.com.au/modules/applets/flash9/Source/Applets/SplashLogo/StampDuty.swf", "stamp-calc-container", "640", "450", "9.0.0", "swf/expressInstall.swf", flashvars2, params2, attributes2);


	$('a.lightbox').lightBox();

	$('a.fp').lightBox();

	$('.lightbox-link').bind('click', function () {
		$('a.lightbox img:visible').parent().click();	
		return false;
	});
/*
	$('#slideshow').slideshow({

		timeout: 4000,
		type: 'sequence',
		pauselink: 'pause'
		
	});
*/
});

function new_window( url ) {
	var w = window.open(url, 'previewWindow', 'width=1024, height=800, status=1, menubar=0, toolbar=0, location=0, resizable=1, directories=0, scrollbars=1');
	w.focus();
	return false;
}
