// DOM ready Events
$(function () {
	// Remove default images from gallery
	// $('#galleryimages li').each(function (){
	// 	var defaultImg = "http://www.mirvacdevelopment.com/templates/mirvac_dev_chelseagardens/images/content/gallery_01.jpg";
	// 	if($('img', this).attr('src') == defaultImg) {
	// 		$(this).remove();
	// 	}
	// });
});

var Gallery = {
	
	current_img: 0,
	total_imgs: null,
	animating: false,
	
	setCurrentImageNumber: function() {
		$('h3#gallerycontrols span').empty().append((this.current_img + 1) + '/' + (this.total_imgs + 1));
	},
	
	scrollNext: function() {
		if(this.current_img < this.total_imgs && !this.animating) {
			this.animating = true;
			$('#galleryimages').animate({marginLeft: parseInt($('#galleryimages').css("margin-left")) - 700 }, "normal", function() { Gallery.animating = false; });
			this.current_img++;
			this.setCurrentImageNumber();
			if(this.current_img == this.total_imgs) {
				return "last";
			}
		}
	},
	
	scrollPrevious: function() {
		if(this.current_img > 0 && !this.animating) {
			this.animating = true;
			this.current_img--;
			this.setCurrentImageNumber();
			$('#galleryimages').animate({marginLeft: parseInt($('#galleryimages').css("margin-left")) + 700 }, "normal", function() { Gallery.animating = false; });
			if(this.current_img == 0) {
				return "first";
			}
		}
	}
}

// DOM ready Events
$(function () {
	// setup gallery
	Gallery.total_imgs = $('#galleryimages img').length - 1;
	$('a#back').css("opacity", "0.5");
	$('a#back').css("filter", "alpha(opacity=50)");
	Gallery.setCurrentImageNumber();
	// events
	$('a#forward').click(function() {
		if(Gallery.scrollNext() == "last") {
			$(this).css("opacity", "0.5");
			$(this).css("filter", "alpha(opacity=50)");
		} else {
			$('a#back').css("opacity", "1.0");
			$('a#back').css("filter", "alpha(opacity=100)");
		}
		return false;
	});
	$('a#back').click(function() {
		if(Gallery.scrollPrevious() == "first") {
			$(this).css("opacity", "0.5");
			$(this).css("filter", "alpha(opacity=50)");
		} else {
			$('a#forward').css("opacity", "1.0");
			$('a#forward').css("filter", "alpha(opacity=100)");
		}
		return false;
	});
});


