var site_index = '';
//var base_site = '192.168.1.3';
var base_site = 'craft-candy.org';
//var site = 'http://'+base_site+'/crafty/public_html/'+site_index; 
var site = 'http://www.'+base_site+'/'+site_index;
var page = window.location.href;
if(page.substr(-1,1) != '/') page = page+'/';

function logger(text)
{
	if(window.console) console.log(text);
}

function window_dims()
{
	ww = (window.getWidth() == 0) ? window.getScrollWidth()-22 : window.getWidth();
	wh = (window.getHeight() == 0) ? window.getScrollHeight() : window.getHeight();
	st = document.body.scrollTop  || document.documentElement.scrollTop;
	topp = st + (wh / 10);
}

function event_stop(evt)
{	
	new Event(evt).stop();
}

window.addEvent('domready', get_externals)

var external_links = new Array();

function get_externals()
{
	// Fetch all the a elements in the document.
	var links = $$('a');
	
	var append_text = '(opens in new window/tab)';
	
	// traverse the links
	
	links.each(function(link)
	{
		// If the element doesn't have an href, skip it.
		if(link.href && !link.hasEvent('click'))
		{
			// if link is 'external' attach the onclick handler. 
			if ((link.href.indexOf('http:\/\/') != -1 && link.href.indexOf(base_site) == -1 && !link.hasClass('same_window')) || link.hasClass('new_window'))
			{
				link.addEvent('click',function(evt) { return new_win(evt,link.href) } );
				link.set('title',link.get('title')+' '+append_text); 
			}
		}
	});
	
}
	
function new_win(evt,href) 
{
	// Open a new window with the link's href.
	var newwin = window.open(href);
	
	// return the inverse (if it didn't work will return true so that link opens)
	return !newwin;
}

// adds element.hasEvent('click') to element.Event
Native.implement([Element, Window, Document], {
	hasEvent: function(type){
		var events = this.retrieve('events', {});
		if (events && events[type]) return true;
		else return false;
	}
});

logger(site);