$(function() {
  
  	//Intelligent Back Link (a#backlink)
	/* WORKS LIKE A DREAM (and only within same domain) */
	$(document).ready(function() {
	if (document.referrer) {
    var reg = new RegExp("https?:\/\/([^/]+)"),
    domain = reg.exec(window.location.href),
    refdomain = reg.exec(document.referrer);
    if (domain[1] === refdomain[1]) {
      
	  if(document.referrer.match(/page\/(\d+)/)) { 
	  $("#backlink").attr('href', document.referrer);
	  }
      
    }
    
  	}
	});
	
	
	/*$(document).ready(function(){
	
			// Call stylesheet init so that all stylesheet changing functions 
			// will work.
			$.stylesheetInit();
			
			// This code loops through the stylesheets when you click the link with 
			// an ID of "toggler" below.
			$('#toggler').bind(
				'click',
				function(e)
				{
					$.stylesheetToggle();
					return false;
				}
			);
			
			// When one of the styleswitch links is clicked then switch the stylesheet to
			// the one matching the value of that links rel attribute.
			$('.styleswitch').bind(
				'click',
				function(e)
				{
					$.stylesheetSwitch(this.getAttribute('rel'));
					return false;
				}
			);
		}
	);*/
	
	
	
	//Intelligent Back to Results Link (a#back-to-results)
	/* WORKS LIKE A DREAM (and only within same domain) */
	$(document).ready(function() {
	if (document.referrer) {
    var reg = new RegExp("https?:\/\/([^/]+)"),
    domain = reg.exec(window.location.href),
    refdomain = reg.exec(document.referrer);
    if (domain[1] === refdomain[1]) {
      
	  if(document.referrer.match(/search/)) { 
	  //$("#back-to-results").attr('href', document.referrer);
	  $("#results-link").append('<a href="'+document.referrer+'">< Back to results</a>');
	  }
      
    }
    
  	}
	});
	
	
	
	
	$(document).ready(function() {
	if (document.referrer) {
    var reg = new RegExp("https?:\/\/([^/]+)"),
    domain = reg.exec(window.location.href),
    refdomain = reg.exec(document.referrer);
    if (domain[1] === refdomain[1]) {
      
	  $("#properties-link").append('<a href="'+document.referrer+'">< Back to results</a>');
	 
      
    }
    
  	}
	});
	
	
	
	
	
	
	
	/* WORKS LIKE A DREAM */
	/*$(document).ready(function() {
	if (document.referrer) {
		
	
	  if(document.referrer.match(/page\/(\d+)/)) { 
	  $("#backlink").attr('href', document.referrer);
	  }
	  
	}
    
  	});*/
  
	
	
	
	//GALLERY CAROUSEL
	$("#gallery-carousel-inner").jCarouselLite({
        btnNext: "#gallery-carousel-wrapper .next",
        btnPrev: "#gallery-carousel-wrapper .prev",
		easing: 'easeInOutCubic',
		speed: 1000,
		scroll: 1,
		visible: 1

	 });
	
	
	//GALLERY CAROUSEL
	$("#property-images-inner").jCarouselLite({
        btnNext: "#property-images-wrapper .next",
        btnPrev: "#property-images-wrapper .prev",
		easing: 'easeInOutCubic',
		scroll: 1,
		visible: 1,
		speed: 1000

	 });
	
	
	//PNG FIX
	$(document).ready(function(){ 
        $(document).pngFix(); 
    }); 
	
	
	
	
});


