/* <[!CDATA[ */

/*
 * This script depends on mootools
 */

// The configure data
urlRewrite = 'http://www.djingis.se/extras/common-old/urlRewrite.php?u=';	// the url to the script doing everything
stdHostName = 'www.djingis.se';										// The local hostname that does not need to be rewritten
stdLocalHost = '127.0.0.1';											// localhost
imgsToFix = '#ja-contentwrap img';
maxImgWidth = 630;

// Need this shit because of IE. IE does NOT follow standard and adds the port to the link.host-property.
IEPort = ':80';
IEHostName = stdHostName + IEPort;
IELocalHost = stdLocalHost + IEPort;

localHost = stdLocalHost;
hostName = stdHostName;
if ( navigator.appName == 'Microsoft Internet Explorer' ) {
	hostName = IEHostName;
	localHost = IELocalHost;
}
// End of fucking IE stuff


window.addEvent('load', initStuff);	// x-browser ok using mootools

function initStuff()
{
	fixImgWidth();
	fixLinks();
}

function fixLinks()
{
	ataggar = $$('a');	// get all a tags
	
	for ( i = 0; i < ataggar.length; i++ ) {
		ataggar[i].addEvent('click', atagClicked);  // x-browser ok using mootools
	}
}	


function fixImgWidth()	// depends on mootools
{
	imgs = $$(imgsToFix);

	for ( i = 0; i < imgs.length; i++ ) {
		if (imgs[i].width > maxImgWidth )
			imgs[i].width = maxImgWidth;
	}
}	

function atagClicked(e)
{
	l = $(this);
	if ( ( l.protocol != 'http:' && l.protocol != 'https:' ) || l.host == '' || l.host == hostName || l.host == localHost )
		return true;
	l.href = urlRewrite + encodeURIComponent(l.href);	
	return true;
}

/* ]]> */
