var hc = new HumanConnection();
hc.init();

function HumanConnection() {
	
	this.initialised = false;
	
	this.init = function() {
		if(!hc.initialised) {
			hc.initialised = true;
		}
		this.navSlider.init();
		if($('#slider-wrapper').size() > 0) {
			var imageWidth = 1000;
			var width = $('#slider-wrapper .hero').size() * imageWidth;
			$('#slider-wrapper').width(width)
			this.rotator.init('#slider-wrapper', imageWidth);
		}
		if($('#content-slider-wrapper').size() > 0) {
			var imageWidth = 160;
			var width = $('#content-slider-wrapper .hero').size() * imageWidth;
			$('#content-slider-wrapper').width(width)
			this.rotator.init('#content-slider-wrapper', imageWidth);
		}
	}
	
	this.domFixes = function() {
		
	}
	
	this.navSlider = {
		
		speed: 450,
		
		enabled: true,
		
		init: function() {
			if(hc.navSlider.enabled) {
				hc.navSlider.enabled = false;
				$('#nav-plus').click(function() {
					if($('#nav-contents').css('marginLeft') == '0px') {
						$('#nav-contents').animate({
							marginLeft: '-1000px'
						}, hc.navSlider.speed, 'easeInOutExpo', function() {
							hc.navSlider.enabled = true;
						});
					}
					else {
						$('#nav-contents').animate({
							marginLeft: '0px'
						}, hc.navSlider.speed, 'easeInOutExpo', function() {
							hc.navSlider.enabled = true;
						});
					}
				});
			}
		}
	}
	
	/*this.fauxColumns = {
		
		sizes: [],
		
		init: function() {
			$('#sitemap-wrapper .sitemap-column').each(function() {
				hc.fauxColumns.sizes.push(parseInt($(this).height()));
			});
			hc.fauxColumns.sizes.sort(function(a,b){return a - b});
			$('#sitemap-wrapper .sitemap-column').each(function() {
				$(this).height(hc.fauxColumns.sizes[hc.fauxColumns.sizes.length - 1]);
			});
		}
	}*/
	
	/**
     * Rotator
     */
	this.rotator = {
		timer: null,
		current: 1,
		total: $('.hero').size() - 1,
		delay: 8000,
        width: null,
        speed: 600,
		wait: false,
		enabled: true,
		element: null,
		init: function(element, width) {
			this.element = element;
            this.width = width;
            if($('.hero').size() > 1) {
               this.timer = setInterval('hc.rotator.rotate()', hc.rotator.delay);
               $('#prev-hero').click(function() {
                  if(hc.rotator.enabled) {
                     hc.rotator.enabled = false;
                     hc.rotator.wait = true;
                     hc.rotator.previous();
                  }
                  return false;
               });
               $('#next-hero').click(function() {
                  if(hc.rotator.enabled) {
                     hc.rotator.enabled = false;
                     hc.rotator.wait = true;
                     hc.rotator.next();
                  }
                  return false;
               });
            }
		},
		rotate: function() {
			if(this.wait) {
				this.wait = false;
				return;
			}
            if(hc.rotator.enabled) {
               hc.rotator.enabled = false;
               var positionOffset = hc.rotator.total * hc.rotator.width;
               if($(hc.rotator.element).position().left >= '-' + (positionOffset + 5) && $(hc.rotator.element).position().left <= '-' + (positionOffset - 5)) {
                  var offset = '+=' + (hc.rotator.total * 100) + '%';
                  hc.rotator.current = 1;
               }
               else {
                  var offset = '-=' + (100) + '%';
                  hc.rotator.current++;
               }
               
               hc.rotator.animate(offset);
            }
		},
		previous: function() {
			if($(hc.rotator.element).position().left == 0) {
				var offset = '-=' + (hc.rotator.total * 100) + '%';
			}
			else {
				var offset = '+=' + (100) + '%';
			}
			hc.rotator.animate(offset);
		},
		next: function() {
            var positionOffset = hc.rotator.total * hc.rotator.width;
			if($(hc.rotator.element).position().left >= '-' + (positionOffset + 5) && $(hc.rotator.element).position().left <= '-' + (positionOffset - 5)) {
				var offset = '+=' + (hc.rotator.total * 100) + '%';
			}
			else {
				var offset = '-=' + (100) + '%';
			}
			hc.rotator.animate(offset);
		},
		gotoSlide: function(n) {
			var offset = (n - 1) * (hc.rotator.width * -1);
			var pixelOffset = offset.toString() + 'px';
            hc.rotator.current = n;
			hc.rotator.animate(pixelOffset);
		},
		animate: function(offset) {
            $(hc.rotator.element).animate({
               left: offset
            }, hc.rotator.speed, 'easeInOutExpo', function() {
               hc.rotator.enabled = true;
            });
		}
	}
}

/*$(function() {
	hc.fauxColumns.init();
});*/

$(function () {
    $('.TextBoxField, .TextAreaField').each(function () {
        var temp = $(this).val();
        $(this).focus(function () {
            var val = $.trim($(this).val());
            if (val == temp || val == '') {
                $(this).val('');
            }
        });
        $(this).blur(function () {
            var val = $.trim($(this).val());
            if (val == temp || val == '') {
                $(this).val(temp);
            }
        });
    });
});
