﻿// JScript File

var curContentOffsetLeft = 0;
var animateNow = false;

$(document).ready(function() {

	if ((window.location + "").indexOf("#") > 0 )
	{
		var tempArr = (window.location + "").split("#");
		$("#url_ref").val(tempArr[1]);
		window.location.hash = ""
	}
	else
	{
		if ((document.referrer + "") == "")
		{
			$("#url_ref").val("url was typed directly");
		}
		else
		{
			$("#url_ref").val(document.referrer + "");
		}
	}

    $('#photo-thumbs a').click(function(e) {
        $('#large-photo').attr({src: $(this).attr('href')});
        e.preventDefault();
    });
    
    containerWidth = 550;
    contentWidth = $('#photo-thumbs').find('li').length * 104;
    if (contentWidth > containerWidth) {
        $('#photo-thumbs').mousemove(function(e) {
            contentWidth = $(this).find('li').length * 104;
            containerWidth = 550;
            cursorX = e.clientX - document.getElementById('photo-thumbs-container').offsetLeft;  //e.clientX - obj.pageLeft + obj.offsetLeft;
            progress = cursorX / containerWidth;
            maxLeft = contentWidth - containerWidth;
            contentOffsetLeft = Math.round(-progress*maxLeft);
            delta = Math.abs(contentOffsetLeft - curContentOffsetLeft);
            if (delta > 150) {
                animateNow = true;
                $(this).stop().animate({left: contentOffsetLeft+'px'}, delta, 'linear', function() { animateNow = false; })
                curContentOffsetLeft = contentOffsetLeft;
            }
            else if (!animateNow) {
                $(this).css({left: contentOffsetLeft+'px'});
                curContentOffsetLeft = contentOffsetLeft;
            }
        });
    };
    $("a").click(function(){
    	if (!($(this).attr("href") == "http://www.recapinvestments.ca"))
	{
		$(this).attr("href", $(this).attr("href") + "#" + $("#url_ref").val());
	}
    });
});