function buildGallery(){

	$(function(){
	
		var galleries = $('.ad-gallery').adGallery();
		$('#switch-effect').change(function(){
			galleries[0].settings.effect = $(this).val();
			return false;
		});
		$('#toggle-slideshow').click(function(){
			galleries[0].slideshow.toggle();
			return false;
		});
		galleries[0].addAnimation('wild', function(img_container, direction, desc){
			var current_left = parseInt(img_container.css('left'), 10);
			var current_top = parseInt(img_container.css('top'), 10);
			if (direction == 'left') {
				var old_image_left = '-' + this.image_wrapper_width + 'px';
				img_container.css('left', this.image_wrapper_width + 'px');
				var old_image_top = '-' + this.image_wrapper_height + 'px';
				img_container.css('top', this.image_wrapper_height + 'px');
			}
			else {
				var old_image_left = this.image_wrapper_width + 'px';
				img_container.css('left', '-' + this.image_wrapper_width + 'px');
				var old_image_top = this.image_wrapper_height + 'px';
				img_container.css('top', '-' + this.image_wrapper_height + 'px');
			};
			if (desc) {
				desc.css('bottom', '-' + desc[0].offsetHeight + 'px');
				desc.animate({
					bottom: 0
				}, this.settings.animation_speed * 2);
			};
			img_container.css('opacity', 0);
			return {
				old_image: {
					left: old_image_left,
					top: old_image_top,
					opacity: 0
				},
				new_image: {
					left: current_left,
					top: current_top,
					opacity: 1
				},
				easing: 'easeInBounce',
				speed: 2500
			};
		});
		
	});
};	
	$(function(){
		// Bind an event to window.onhashchange that, when the hash changes, gets the
		// hash and adds the class "selected" to any matching nav link.
		$(window).hashchange(function(){
			var hash = location.hash;
			// Iterate over all nav links, setting the "selected" class as-appropriate.
			$('.navigation a').each(function(){
				var that = $(this);
				that[that.attr('href') === hash ? 'addClass' : 'removeClass']('selected');
			});
			//remove "#" from hash string value 
			var curGallery = hash.replace(/#/i, "");
			
			// clear list with gallery images			
			$("#gallery").hide();
			if (curGallery != "") {
				$(".mainimagestable").hide();
				
				if (curGallery == "links") {
					$(".links").show();
					$(".contact").hide();
					
				}
				else 
					if (curGallery == "contact") {
						$(".contact").show();
						$(".links").hide();
					}
					else {
						$("#gallery li").remove();
						$("#gallery").show();
						$(".links").hide();
						$(".contact").hide();
						
						var galleryType = [{
							gallery: curGallery,
							inc: "1",
							imgClass: "0"
						}, {
							gallery: curGallery,
							inc: "2",
							imgClass: "1"
						}, {
							gallery: curGallery,
							inc: "3",
							imgClass: "2"
						}, {
							gallery: curGallery,
							inc: "4",
							imgClass: "3"
						}, {
							gallery: curGallery,
							inc: "5",
							imgClass: "4"
						}, {
							gallery: curGallery,
							inc: "6",
							imgClass: "5"
						}, {
							gallery: curGallery,
							inc: "7",
							imgClass: "6"
						}, {
							gallery: curGallery,
							inc: "8",
							imgClass: "7"
						}, {
							gallery: curGallery,
							inc: "9",
							imgClass: "8"
						}, {
							gallery: curGallery,
							inc: "10",
							imgClass: "9"
						}, {
							gallery: curGallery,
							inc: "11",
							imgClass: "10"
						}, {
							gallery: curGallery,
							inc: "12",
							imgClass: "11"
						}];
						
						// load new list of images from template
						$("#galleryTemplate").tmpl(galleryType).appendTo("#galleryThumbs");
						buildGallery();
					};
				
							};
		})
		
		// Since the event is only triggered when the hash changes, we need to trigger
		// the event now, to handle the hash the page may have loaded with.
		$(window).hashchange();
		
	})
$(document).ready(countDown);

        var pickArr = new Array();
        var countDownValue = 48;
        var countUpValue = 48;
        var counter = 0;

        function countDown() {
            if (countDownValue > 0) {
                countDownValue--;
                loadImage();
                setTimeout('countDown()', 100);
            }

            if (countDownValue == 36) {
                countIp();
            }
        }

        function countIp() {
            if (countUpValue > 0) {
                countUpValue--;
                loadDarkImage();
                setTimeout('countIp()', 100);
            }
        }

        function loadImage() {

            found = false;
            var currNum = Math.floor(Math.random() * 48) + 1;
            var i;

            for (i = 0; i < pickArr.length; i++) {
                if (currNum == pickArr[i]) {
                    found = true;
                    break;
                }
            }

            if (found) {
                var currNum = Math.floor(Math.random() * 48) + 1;
                loadImage();
            } else {
                pickArr[pickArr.length] = currNum;
                var img = document.images['Image' + (currNum)];
                img.src = "http://rbphotography.com.au/images/home_page_images/m-" + currNum + ".jpg";
            }
        }

        function loadDarkImage() {
            if (counter < 48) {
                currNum = pickArr[counter];
                var img = document.images['Image' + (currNum)];
                img.src = "http://rbphotography.com.au/images/home_page_images_opacity_50/m-" + currNum + ".jpg";
                counter++;
            }
        }

        function roll_over(img_name) {
            document["m-" + img_name].src = "http://rbphotography.com.au/images/home_page_images/m-" + img_name + ".jpg";
        }

        function roll_out(img_name) {
            document["m-" + img_name].src = "http://rbphotography.com.au/images/home_page_images_opacity_50/m-" + img_name + ".jpg";
        }	
		

