argos.check("effects");


// AUTO SCROLLING...
argos.effects.autoscroll = (new function() {
	var t = this;

	this.init = function() {
		var fi = self.document.location.hash;

		// 1). If the page URL has fragment identifier (and not just "#").
		if(fi.length > 1) {
			// remove any "..." from URLs.
			fi = fi.replace(/#([\w-_]+)\.{3}/, "#$1");
			t.activate(fi, 2000); // pause and scroll.
		}

		// 2). Set up links for use with autoscroll.
		_setUpLinks();
	}

	this.activate = function(target, pause, jump) {
		// target = (string) element id with hash e.g. #top.
		// pause = (int) value that delays start of scroll.

		// IE6+7 passing full blah#blah href on some where other browsers just have #blah, so using a replace on target to clean.
		var cleanTarget = target ? target.replace(/.*(#.*)/,"$1") : "";
		var id = (cleanTarget != "#") ? cleanTarget : "top";
		var t = ($(id).length > 0) ? $(id) : $("[name='" + id.slice(1) + "']");
       	var targetOffset = (target && t.length > 0) ? t.offset().top : 0;
		if(jump) {
			$('html').scrollTop(targetOffset);
			if(target) { 
				window.location.hash = (id != "#logo") ? id : "#top";
			}
		}
		else {
			window.setTimeout(
				function() {
					$('html').animate(
						{scrollTop: targetOffset}, 
						1000,
						function() {
							// Append the fragment identifier unless it's for top/logo.
							if(target) { 
								window.location.hash = (id != "#logo") ? id : "#top";
							}
						}
					);
				}, 
				(pause || 10)
			);
		}
	}

	function _setUpLinks() {
		$('a[href*=#]').each(function() {
			var a = $(this);
			var href = a.attr("href");
			var hrefWithoutFragment = href.replace(/(.*)#.*/, "$1");
			var locationWithoutFragment = String(document.location.href).replace(/(.*)#.*/, "$1");
			var internal = (href.indexOf("#") >= 0 && href != "#" && (hrefWithoutFragment.length > 0) ? (locationWithoutFragment == hrefWithoutFragment) : true);
			var http = "http[s]?:\/\/";
			var host = "(.*?)[\/|\?|#].*";
			var reHttp = new RegExp(http, "gi");
			var reHttpHost = new RegExp(http + host, "gi");
			var reHost = new RegExp(host, "gi");
			var sameHost = (window.location.hostname == ((href.search(reHttp) >= 0) ? href.replace(reHttpHost, "$1") : href.replace(reHost, "$1")));

			if(internal) a.click(_autoScroll);
			if(!internal && sameHost) a.attr("href", href.replace(/#([\w-_]+)/, "#$1..."));
		});
	}

	function _autoScroll() {
		t.activate($(this).attr("href")); 
		return false;
 	}		
});

