// EXTERNAL LINK
function externalLinks() {
	if (!document.getElementsByTagName) {
		return;
	}

	var anchors = document.getElementsByTagName("a");

	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("class") == "newwin") {
			anchor.target = "_blank";
		}
	}
}

// SMOOTH SCROLL
function smoothScroll() {
	$$('a[href^=#]:not([href=#])').each(function(element) {
		element.observe('click', function(event) {
			new Effect.ScrollTo(this.hash.substr(1));
			Event.stop(event);
		}.bindAsEventListener(element))
	})
}

// CURRENT PAGE
function currentPage() {
	$$('#aside .section .menu ul').each(function(element) {
		if ( document.location.href.indexOf("#examples") > 0 ) {
			var location    = encodeURI(document.location.href);
		} else {
			var location    = encodeURI(document.location.href).replace(/#.*/,'');
		}
		var descendants = element.descendants();

		descendants = descendants.map(function (descendant) {
			return $(descendant);
		});

		for (var i = 0, length = descendants.length;length > i;i++) {
			var elem = descendants[i];

			if (elem.tagName.match('A')) {
				if (location == elem.href) {
					Element.addClassName(elem, 'current');
//					elem.href = 'javascript:void(0);';
					break;
				}
			}
		}
	})
}
conf = {
       className : 'btn',
       postfix : '_on'
};
function setMouseOverImages() {
       $A(document.getElementsByClassName(conf.className)).each(function (node){
               node.onmouseout = changeSrcFunction(node.src);
               node.onmouseover =
			    changeSrcFunction(node.src.replace(/(\.gif|\.jpg|\.png)/, conf.postfix+"$1"));
       });
}
function changeSrcFunction(data){
       return function(){ this.src = data; }
}
Event.observe(window, 'load', setMouseOverImages, false);


Event.observe(window, 'load', externalLinks, false);
Event.observe(window, 'load', smoothScroll, false);
Event.observe(window, 'load', currentPage, false)

