$(document).ready(function() {
	bindLinks();
	
});

function loadMainImage(theThumb) {
	imgSrc =  theThumb.id.replace("images/property_thumbs","images/property_images");
	
	var img = new Image();
  
	// wrap our new image in jQuery, then:
	$(img)
		// once the image has loaded, execute this code
		.load(function () {
		  // set the image hidden by default    
		  $(this).hide();
		
		  // with the holding div #loader, apply:
		  $('#loader')
		  	.empty()
			// remove the loading class (so no background spinner), 
			.removeClass('loading')
			// then insert our image
			.append(this);
		
		  // fade our image in to create a nice effect
		  $(this).fadeIn();
		})
		
		// if there was an error loading the image, react accordingly
		.error(function () {
		  // notify the user that the image could not be loaded
		})
		
		// *finally*, set the src attribute of the new image to our image
		.attr('src', imgSrc);
	//$("").attr("src",);
}

function bindLinks(){
	$("#prop_detail_new a.enquire").fancybox({
		hideOnContentClick: false									 
	});
	
	$("#prop_detail_new a.mapzoom").fancybox({
		'zoomSpeedIn'		:	500,
		'zoomSpeedOut'		:	500,
		'frameWidth'		: 600,
		'frameHeight'		: 600
	});

	$("a.zoom1").fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#FFF'
	});

	$("a.zoom2").fancybox({
		'zoomSpeedIn'		:	500,
		'zoomSpeedOut'		:	500
	});
	
	
	$("#prop_detail_new .thumb").each(function(){
		$(this).bind("click",function(){
			loadMainImage(this);
		});
	});
}

function preloadImages(){
	var theImageSrc = "";
	var preloadImages = new Array();
	var i = 0;
	$("#prop_detail_new .thumb").each(function(){
		theImageSrc = this.src.replace("_th","");
		preloadImages[i] = theImageSrc;
		alert(theImageSrc);
		i = i + 1;
		alert(i + " " + preloadImages[i]);
	});
}


(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

