var Mint = new Object();

if (false && (document.location.host == 'skatic.com' || document.location.host == 'www.skatic.com') && readCookie('MintIgnore') != 'true') {
	
createCookie('MintAcceptsCookies', 1, 999);
	
//adopted to javascript by bliss
Mint.generateKey = function() {
	// Get current time
	var key = time().toString();
	// Add random characters to the key
	var s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (var i = 0; i < 10; i++) {
		var r = '';
		var j = rand(0, 3);
		for (var k = 0; k < j; k++) {
			r += s.charAt(rand(0, s.length - 1));
		}
		var l = rand(0, key.length);
		key = key.substr(0, l) + r + key.substr(l, key.length);
	}
	// Reverse the key
	key = strrev(key);
	// Hex the key
	key = bin2hex(key);
	return key;
};

Mint.save = function()  {
	var now		= new Date();
	var debug	= false; // this is set by php 
	if (window.location.hash == '#Mint:Debug') {
		debug = true;
	}
	var path	= 'http://mint.skatic.com/?record&key='+Mint.generateKey();
	path 		= path.replace(/^https?:/, window.location.protocol);
	
	// Loop through the different plug-ins to assemble the query string
	for (var developer in this)  {
		for (var plugin in this[developer]) {
			if (this[developer][plugin] && this[developer][plugin].onsave) {
				path += this[developer][plugin].onsave();
			}
		}
	}
	// Slap the current time on there to prevent caching on subsequent page views in a few browsers
	path += '&'+now.getTime();
	
	// Redirect to the debug page
	if (debug) {
		window.open(path+'&debug&errors', 'MintLiveDebug'+now.getTime());
		return;
	}
	
	var ie = $.browser.msie;
	
	path += '&serveJs';
	
	if (!ie && document.getElementsByTagName && (document.createElementNS || document.createElement)) {
		var tag = (document.createElementNS) ? document.createElementNS('http://www.w3.org/1999/xhtml', 'script') : document.createElement('script');
		tag.type = 'text/javascript';
//		tag.src = path + '&serveJs';
		tag.src = path;
		document.getElementsByTagName('head')[0].appendChild(tag);
	} else if (document.write) {
//		document.write('<' + 'script type="text/javascript" src="' + path + '&amp;serveJs"><' + '/script>');
		document.write(unescape("%3Cscript%20type%3D%22text/javascript%22%20src%3D%22") + path + unescape("%22%3E%3C/script%3E"));
	}
	
//	alert(path);
	return true;
};
if (!Mint.SI) { Mint.SI = new Object(); }
Mint.SI.Referrer =  {
	'onsave' : function() {
//		var referer		= (window.decodeURI)?window.decodeURI(document.referrer):document.referrer;
		var referer = skatic.ajax.referer;
		if (referer === null) {
			referer	= (window.decodeURI)?window.decodeURI(document.referrer):document.referrer;
		}
//		var resource	= (window.decodeURI)?window.decodeURI(document.URL):document.URL;
//		var resource = historyStorage.get('loadedPage');
		var resource = skatic.ajax.current;
		
		var encoded = 0;
//		if (typeof Mint_SI_DocumentTitle == 'undefined') {
//			Mint_SI_DocumentTitle = document.title;
//		} else {
//			encoded = 1;
//		};
		Mint_SI_DocumentTitle = resource;

		referer = skatic.url.removeGetParams(referer);
		resource = skatic.url.removeGetParams(resource);

		return '&referer=' + escape(referer) + '&resource=' + escape(resource) + '&resourceTitle=' + escape(Mint_SI_DocumentTitle) + '&resourceTitleEncoded=' + encoded;
	}
};

//end if (document.location.host == 'skatic.com')
} else {
	Mint.save = function(){return false;};
}
