

/******************************************	Vars define		******************************************/

var siteUrl = document.location.protocol+'//'+document.location.host+document.location.pathname.substr(0,document.location.pathname.lastIndexOf('/'));

/******************************************	browser Object		******************************************/

var userBrowser = {

	navName:   		navigator.appName.toLowerCase(),
	userAgent: 		navigator.userAgent.toLowerCase(),
	isDom: 			($),
	isDAll: 		(document.all),
	isDlayers: 		(document.layers),
	
	version: {
				_int: parseInt(navigator.appVersion),
				_float: parseFloat(navigator.appVersion)
			},
	
	isIe: 				function() { return (this.userAgent.indexOf("msie") != -1); },
	isIeSup:			function() { return (this.isIe() && (this.version._int >= 4)); },
	isNtscp:			function() { return (this.navName.indexOf('netscape') != -1); },
	isNtscp4:			function() { return (this.isNtscp() && (this.version._int == 4)); },
	isMac:				function() { return (this.userAgent.indexOf("mac") != -1); },
	isGecko:			function() { return (this.userAgent.indexOf("gecko") != -1); },
	isFirefox:			function() { return (this.userAgent.indexOf("firefox") != -1); },
	isKonqueror:		function() { return (this.userAgent.indexOf("konqueror") > -1); },
	isOpera: 			function() { return (window.opera); },
	isOpera5:			function() { return (this.userAgent.indexOf("opera 5") > -1 || this.userAgent.indexOf("opera/5") > -1 || this.userAgent.indexOf("opera 6") > -1 || this.userAgent.indexOf("opera/6") > -1); },
	revision:			function() { return (this.isGecko()) ? parseFloat(this.userAgent.split("rv:")[1]) : 0; },
	firefoxVersion:		function() { return (this.isFirefox()) ? this.userAgent.substring(this.userAgent.indexOf("firefox")).split("/")[1] : 0;},
	firefoxExtraHeight:	function() { return (this.isFirefox()) ? ((parseFloat(this.firefoxVersion()) >=1) ? 16 : 0) : 0; }
};


	/******************************************	Tools Functions		******************************************/


var histogram = {};
histogram['34'] = 'quot';
histogram['38'] = 'amp';
histogram['60'] = 'lt';
histogram['62'] = 'gt';
histogram['160'] = 'nbsp';
histogram['161'] = 'iexcl';
histogram['162'] = 'cent';
histogram['163'] = 'pound';
histogram['164'] = 'curren';
histogram['165'] = 'yen';
histogram['166'] = 'brvbar';
histogram['167'] = 'sect';
histogram['168'] = 'uml';
histogram['169'] = 'copy';
histogram['170'] = 'ordf';
histogram['171'] = 'laquo';
histogram['172'] = 'not';
histogram['173'] = 'shy';
histogram['174'] = 'reg';
histogram['175'] = 'macr';
histogram['176'] = 'deg';
histogram['177'] = 'plusmn';
histogram['178'] = 'sup2';
histogram['179'] = 'sup3';
histogram['180'] = 'acute';
histogram['181'] = 'micro';
histogram['182'] = 'para';
histogram['183'] = 'middot';
histogram['184'] = 'cedil';
histogram['185'] = 'sup1';
histogram['186'] = 'ordm';
histogram['187'] = 'raquo';
histogram['188'] = 'frac14';
histogram['189'] = 'frac12';
histogram['190'] = 'frac34';
histogram['191'] = 'iquest';
histogram['192'] = 'Agrave';
histogram['193'] = 'Aacute';
histogram['194'] = 'Acirc';
histogram['195'] = 'Atilde';
histogram['196'] = 'Auml';
histogram['197'] = 'Aring';
histogram['198'] = 'AElig';
histogram['199'] = 'Ccedil';
histogram['200'] = 'Egrave';
histogram['201'] = 'Eacute';
histogram['202'] = 'Ecirc';
histogram['203'] = 'Euml';
histogram['204'] = 'Igrave';
histogram['205'] = 'Iacute';
histogram['206'] = 'Icirc';
histogram['207'] = 'Iuml';
histogram['208'] = 'ETH';
histogram['209'] = 'Ntilde';
histogram['210'] = 'Ograve';
histogram['211'] = 'Oacute';
histogram['212'] = 'Ocirc';
histogram['213'] = 'Otilde';
histogram['214'] = 'Ouml';
histogram['215'] = 'times';
histogram['216'] = 'Oslash';
histogram['217'] = 'Ugrave';
histogram['218'] = 'Uacute';
histogram['219'] = 'Ucirc';
histogram['220'] = 'Uuml';
histogram['221'] = 'Yacute';
histogram['222'] = 'THORN';
histogram['223'] = 'szlig';
histogram['224'] = 'agrave';
histogram['225'] = 'aacute';
histogram['226'] = 'acirc';
histogram['227'] = 'atilde';
histogram['228'] = 'auml';
histogram['229'] = 'aring';
histogram['230'] = 'aelig';
histogram['231'] = 'ccedil';
histogram['232'] = 'egrave';
histogram['233'] = 'eacute';
histogram['234'] = 'ecirc';
histogram['235'] = 'euml';
histogram['236'] = 'igrave';
histogram['237'] = 'iacute';
histogram['238'] = 'icirc';
histogram['239'] = 'iuml';
histogram['240'] = 'eth';
histogram['241'] = 'ntilde';
histogram['242'] = 'ograve';
histogram['243'] = 'oacute';
histogram['244'] = 'ocirc';
histogram['245'] = 'otilde';
histogram['246'] = 'ouml';
histogram['247'] = 'divide';
histogram['248'] = 'oslash';
histogram['249'] = 'ugrave';
histogram['250'] = 'uacute';
histogram['251'] = 'ucirc';
histogram['252'] = 'uuml';
histogram['253'] = 'yacute';
histogram['254'] = 'thorn';
histogram['255'] = 'yuml';
	
function empty( mixed_var ) 
{	
	if (mixed_var === "" 
	|| mixed_var === 0   
	|| mixed_var === "0"
	|| mixed_var === null  
	|| mixed_var === false
	|| mixed_var === undefined    
	|| ((typeof mixed_var == 'array' || typeof mixed_var == 'object') && mixed_var.length === 0) ){
	return true;
    }
   
    return false;
}

function isset() 
{
    var a=arguments; var l=a.length; var i=0;
    
    if (l == 0)
	throw new Error('Empty isset'); 
    else if(l == 1)
	{
		if (typeof(a[0]) == 'undefined' || a[0] === null)
	    return false; 
				else
					return true;
	}
	
    while (i!=l) 
	{
	if (typeof(a[i]) == 'undefined' || a[i] === null)
	    return false; 
				else
					i++;
    }
    return true;
}

function htmlentities(str) 
{
	str = str.toString();
    var code = 0, tmp_arr = [], i = 0;
	for (i = 0; i < str.length; ++i) 
	{
		code = str.charCodeAt(i);
		if (code in histogram)
			tmp_arr[i] = '&'+histogram[code]+';';
				else
					tmp_arr[i] = str.charAt(i);
	}
    
	return tmp_arr.join('');
}

function html_entity_decode( string ) 
{
    var entity = chr = '';
    
    for (code in histogram) 
	{
	entity = histogram[code];
	histogram_r[entity] = code; 
    }
    
    return string.replace(/(\&([a-zA-Z]+)\;)/g, function(full, m1, m2)
	{
	if (m2 in histogram_r)
	    return String.fromCharCode(histogram_r[m2]);
				else
					return m2;
    });    
}

function htmlspecialchars(string, quote_style) 
{
    string = string.toString();
    string = string.replace(/&/g, '&amp;');
    string = string.replace(/</g, '&lt;');
    string = string.replace(/>/g, '&gt;');
    
    if (quote_style == 'ENT_QUOTES') 
	{
	string = string.replace(/"/g, '&quot;');
	string = string.replace(/'/g, '&#039;');
    } 
	else if (quote_style != 'ENT_NOQUOTES')
	string = string.replace(/"/g, '&quot;');
    
    return string;
}

function htmlspecialchars_decode(string, quote_style) 
{
    string = string.toString();
    string = string.replace('/&amp;/g', '&');
    string = string.replace('/&lt;/g', '<');
    string = string.replace(/&gt;/g, '>');
    
    if (quote_style == 'ENT_QUOTES') 
	{
	string = string.replace('/&quot;/g', '"');
	string = string.replace('/&#039;/g', '\'');
    } 
	else if (quote_style != 'ENT_NOQUOTES')
	string = string.replace('/&quot;/g', '"');
    
    return string;
}


function serialize (txt) 
{
	switch(typeof(txt)){
	case 'string':
		return 's:'+txt.length+':"'+txt+'";';
	case 'number':
		if(txt>=0 && String(txt).indexOf('.') == -1 && txt < 65536) return 'i:'+txt+';';
		return 'd:'+txt+';';
	case 'boolean':
		return 'b:'+( (txt)?'1':'0' )+';';
	case 'object':
		var i=0,k,ret='';
		for(k in txt){
			//alert(isNaN(k));
			if(typeof(txt[k]) == 'function')
				continue;
			
			if(!isNaN(k)) k = Number(k);
			ret += serialize(k)+serialize(txt[k]);
			i++;
		}
		return 'a:'+i+':{'+ret+'}';
	default:
		return 'N;';
		alert('var undefined: '+typeof(txt));return undefined;
	}
}

function unserialize(data)
{
    var error = function (type, msg, filename, line){throw new window[type](msg, filename, line);};
    var read_until = function (data, offset, stopchr){
	var buf = [];
	var chr = data.slice(offset, offset + 1);
	var i = 2;
	while(chr != stopchr){
	    if((i+offset) > data.length){
		error('Error', 'Invalid');
	    }
	    buf.push(chr);
	    chr = data.slice(offset + (i - 1),offset + i);
	    i += 1;
	}
	return [buf.length, buf.join('')];
    };
    var read_chrs = function (data, offset, length){
	buf = [];
	for(var i = 0;i < length;i++){
	    var chr = data.slice(offset + (i - 1),offset + i);
	    buf.push(chr);
	}
	return [buf.length, buf.join('')];
    };
    var _unserialize = function (data, offset){
	if(!offset) offset = 0;
	var buf = [];
	var dtype = (data.slice(offset, offset + 1)).toLowerCase();
	
	var dataoffset = offset + 2;
	var typeconvert = new Function('x', 'return x');
	var chrs = 0;
	var datalength = 0;
	
	switch(dtype){
	    case "i":
		typeconvert = new Function('x', 'return parseInt(x)');
		var readData = read_until(data, dataoffset, ';');
		var chrs = readData[0];
		var readdata = readData[1];
		dataoffset += chrs + 1;
	    break;
	    case "b":
		typeconvert = new Function('x', 'return (parseInt(x) == 1)');
		var readData = read_until(data, dataoffset, ';');
		var chrs = readData[0];
		var readdata = readData[1];
		dataoffset += chrs + 1;
	    break;
	    case "d":
		typeconvert = new Function('x', 'return parseFloat(x)');
		var readData = read_until(data, dataoffset, ';');
		var chrs = readData[0];
		var readdata = readData[1];
		dataoffset += chrs + 1;
	    break;
	    case "n":
		readdata = null;
	    break;
	    case "s":
		var ccount = read_until(data, dataoffset, ':');
		var chrs = ccount[0];
		var stringlength = ccount[1];
		dataoffset += chrs + 2;
		
		var readData = read_chrs(data, dataoffset+1, parseInt(stringlength));
		var chrs = readData[0];
		var readdata = readData[1];
		dataoffset += chrs + 2;
		if(chrs != parseInt(stringlength) && chrs != readdata.length){
		    error('SyntaxError', 'String length mismatch');
		}
	    break;
	    case "a":
		var readdata = {};
		
		var keyandchrs = read_until(data, dataoffset, ':');
		var chrs = keyandchrs[0];
		var keys = keyandchrs[1];
		dataoffset += chrs + 2;
		
		for(var i = 0;i < parseInt(keys);i++){
		    var kprops = _unserialize(data, dataoffset);
		    var kchrs = kprops[1];
		    var key = kprops[2];
		    dataoffset += kchrs;
		    
		    var vprops = _unserialize(data, dataoffset);
		    var vchrs = vprops[1];
		    var value = vprops[2];
		    dataoffset += vchrs;
		    
		    readdata[key] = value;
		}
		
		dataoffset += 1;
	    break;
	    default:
		error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype);
	    break;
	}
	return [dtype, dataoffset - offset, typeconvert(readdata)];
    };
    return _unserialize(data, 0)[2];
}

function getType( inp ) 
{
	var type = typeof inp, match;
	if (type == 'object' && !inp)
	    return 'null';
	
	if (type == "object") 
	{
	    if (!inp.constructor)
			return 'object';
	    
	    var cons = inp.constructor.toString();
	    if (match = cons.match(/(\w+)\(/))
			cons = match[1].toLowerCase();
	    
	    var types = ["boolean", "number", "string", "array"];
	    for (key in types) 
		{
			if (cons == types[key]) 
			{
				type = types[key];
				break;
			}
	    }
	}
	return type;
}

function var_export(mixed_expression, bool_return) 
{
 
    var retstr = "";
    var iret = "";
    var cnt = 0;
    var x = [];
    if(typeof(bool_return) == 'undefined' || bool_return === null)
		bool_return = true;
	
    var type = getType(mixed_expression);
    
    if( type === null)
		retstr = "NULL";
	else if(type == 'array' || type == 'object') 
	{
		for(i in mixed_expression)
			x[cnt++] = var_export(i,true)+" => "+var_export(mixed_expression[i], true);
		
		iret = x.join(',\n  ');
		retstr = "array (\n  "+iret+"\n)";
    } 
	else retstr = (!isNaN( mixed_expression )) ? mixed_expression : "'" + mixed_expression/*.replace('/(["\'\])/g', "\\$1").replace('/\0/g', "\\0")*/ + "'";
    
    if(bool_return != true) 
	{
		document.write(retstr);
		return null;
    } 
	else return retstr;
}

var b64Table = new Array(
					'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
					'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
					'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
					'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
				);
 
function b64_inChar(d) 
{
	r = -1;
	for (var i = 0; i < b64Table.length; i++) 
	{
		if (d == b64Table[i]) 
		{
			r = i;
			break;
		}
	}
	
	return r;
}
 
function b64_Find(n) 
{
	while (n > 256) 
		n -= 256;
	
	return n
}
 
if(!window.btoa)
{
	window.btoa = function(n) 
	{
		var o1 = o2 = o3 =o4 = 0;
		var text = "";
		j = 0;
		
		for (var i = 0; i < n.length; i += 3) 
		{
			t = Math.min(3, n.length - i);
			
			if (t == 1) 
			{
				x = n.charCodeAt(i);
				text += b64Table[(x >> 2)];
				text += b64Table[((x & 0X00000003) << 4)];
				text += '==';
			} 
			else if (t == 2) 
			{
				x = n.charCodeAt(i);
				y = n.charCodeAt(i+1);
				text += b64Table[(x >> 2)];
				text += b64Table[((x & 0X00000003) << 4) | (y >> 4)];
				text += b64Table[((y & 0X0000000f) << 2)];
				text += '=';
			} 
			else 
			{
				x = n.charCodeAt(i);
				y = n.charCodeAt(i+1);
				z = n.charCodeAt(i+2);
				text += b64Table[x >> 2];
				text += b64Table[((x & 0x00000003) << 4) | (y >> 4)];
				text += b64Table[((y & 0X0000000f) << 2) | (z >> 6)];
				text += b64Table[z & 0X0000003f];
			}
		}
		
		return text;
	}
}

if(!window.atob)
{
	window.atob = function(n) 
	{
		var p;
		var o1 = o2 = o3 = 0;
		var text = "";
		
		if ((n.length % 4) != 0)
			return null;
		
		j = 0;
		for (var i = 0; i < n.length; i += 4) 
		{
			x1 = b64_inChar(n.charAt(i));
			x2 = b64_inChar(n.charAt(i+1));
			x3 = b64_inChar(n.charAt(i+2));
			x4 = b64_inChar(n.charAt(i+3));
			ol = 4;
			
			if (x4 == -1) 
			{ 
				ol--; 
				x4 = 0;
			}
			
			if (x3 == -1) 
			{ 
				ol--; 
				x3 = 0;
			}
			
			if (ol == 4) 
			{
				o1 = ((x1 << 2) | (x2 >> 4)); ((o1 > 256) ? p=b64_Find(o1) : p=o1) ; text += String.fromCharCode(p);
				o2 = ((x2 << 4) | (x3 >> 2)); ((o2 > 256) ? p=b64_Find(o2) : p=o2) ; text += String.fromCharCode(p);
				o3 = ((x3 << 6) | x4); ((o3 > 256) ? p=b64_Find(o3) : p=o3) ; text += String.fromCharCode(p);
			} 
			else if (ol == 3) 
			{
				o1 = ((x1 << 2) | (x2 >> 4)); ((o1 > 256) ? p=b64_Find(o1) : p=o1) ; text += String.fromCharCode(p);
				o2 = ((x2 << 4) | (x3 >> 2)); ((o2 > 256) ? p=b64_Find(o2) : p=o2); text += String.fromCharCode(p);
			} 
			else if (ol == 2) 
			{
				o1 = ((x1 << 2) | (x2 >> 4)); ((o1 > 256) ? p=b64_Find(o1) : p=o1) ; text += String.fromCharCode(p);
			}
		}
		
		return text;
	}
}

function base64_encode(str)
{
	return window.btoa(str);
}

function base64_decode(str)
{
	return window.atob(str);
}


	/******************************************	Basic objects extend		******************************************/


Object.extend(String.prototype, {	

	trim: function(str) 
	{
		if(!str)
			var escapedString = str;
				else
					var escapedString = this;
		
		escapedString = unescape(escapedString);
		return escapedString.replace(/(^\s*)|(\s*$)/g, "");
	},
	
	unserialize: function() { return unserialize(this); },
	htmlspecialchars: function(quote_style) { return htmlspecialchars(this, quote_style); },
	htmlspecialchars_decode: function(quote_style) { return htmlspecialchars_decode(this, quote_style); },
	htmlentities: function() {return htmlentities(this);},
	html_entity_decode: function() { return html_entity_decode(this); },
	nl2br: function() { return this.replace(/\n/g, '<br />'); },	
	base64_encode: function() { return window.btoa(this); },
	ucFirst: function() { return this.substr(0,1).toUpperCase() + this.substr(1,this.length); },
	base64_decode: function() { return window.atob(this); },
	empty: function() { return (this == ""); },
	is_array: function() { return false; },
	is_object: function() { return false; },
	is_string: function() { return true; },
	is_number: function() { return false; }
});

Object.extend(Object.prototype, {	
	empty: function() { return empty(this); },
	serialize: function() { return serialize(this); },
	is_array: function() { return false; },
	is_object: function() { return true; },
	is_string: function() { return false; },
	is_number: function() { return false; }
});

Object.extend(Number.prototype, {	
	empty: function() { return empty(this); },
	is_array: function() { return false; },
	is_object: function() { return false; },
	is_string: function() { return false; },
	is_number: function() { return true; }
});

Object.extend(Array.prototype, {	
	empty: function() { return empty(this); },
	serialize: function() { return serialize(this); },
	rand: function(newTab)
	{
		copy = this;
		copy.sort(function() {return 0.5 - Math.random();});
		return copy;
	},
	is_array: function() { return true; },
	is_object: function() { return false; },
	is_string: function() { return false; },
	is_number: function() { return false; }
});



	/******************************************	Misc Functions		******************************************/


function openPopup(url,name,width,height,centered,scrollable,resizable) 
{
	scrollable = (!scrollable) ? 'no' : 'yes';
	resizable = (!resizable) ? 'no' : 'yes';
	width = (!width) ? window.screen.width/2 : width;
	height = (!height) ? window.screen.height/2 : height;
	name = (!name) ? '' : name;
	
	if(centered)
	{
		var left = (window.screen.width-width)/2;
		var top = (window.screen.height-height)/2;
	}
	else
	{
		var left = 10;
		var top = 10;
	}
	
	var options = "top="+top+",left="+left+",width="+width+",height="+height+",scrollbars="+scrollable+",resizable="+resizable+",toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no";
	
	var new_window = window.open(url, name, options);
	new_window.focus();
	/*if(new_window)
		
	else if(new_window.window.focus)
		new_window.window.focus();
	*/
	return new_window;
}

function preloadImages() 
{
	if(!document.preloadedImg) 
		document.preloadedImg = new Array();
	
	var i, a = preloadImages.arguments; 
	
	for(i=0; i<a.length; i++)
	{
		if(!document.preloadedImg[IMG_URL+a[i]])
		{
			document.preloadedImg[IMG_URL+a[i]] = new Image;
			document.preloadedImg[IMG_URL+a[i]].src = IMG_URL+a[i];
		}
	}
}

function httpGetVars(striptags,base64) 
{
	var httpVars = new Array();
	
	if (location.search) 
	{
		var params = (base64) ? location.search.substring(1).base64_decode() : location.search.substring(1);
		
		if (params.indexOf("&") != -1) 
			var variables = params.split("&");
				else 
					var variables = params.split("%26");
		
		for (var i in variables) 
		{
			if(!variables[i].indexOf) continue;
			
			var pos = variables[i].indexOf("=");
			if (pos != -1)
				httpVars[trim(variables[i].substring(0, pos))] = (striptags) ? variables[i].strip_tags(variables[i].trim(variables[i].substring(pos+1))) : variables[i].trim(variables[i].substring(pos+1));
					else 
						httpVars[i] = (striptags) ? variables[i].strip_tags(variables[i].trim()) : variables[i].trim();
		}
	}
	
	return httpVars;
}

function getCookie(name)
{
	var nameEQ = name+"=";
	var ca = document.cookie.split(';');
	
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	
	return null;
}

function setCookie(name, value, days)
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	
	document.cookie = name+"="+value+expires+"; path=/";
}

function deleteCookie(name) { setCookie(name, "", -1); }


var lastSelectedBanner = '';
var lastSelectedBannerText = '';

function getBannerCode(banner,text)
{
	if(!text)
		text = 'Tribute to Kriktus';
	
	lastSelectedBanner = banner;
	lastSelectedBannerText = text;
	$('kriktusBannerCode').value = '';
	
	if($('bCodeTypeF').checked)
		$('kriktusBannerCode').value = '[url='+MAIN_URL+'][img]'+MAIN_URL+banner+'[/img][/url]';
			else if($('bCodeTypeL').checked)
				$('kriktusBannerCode').value = MAIN_URL+banner;
					else
						$('kriktusBannerCode').value = '<a href="'+MAIN_URL+'"><img style="border:none;" src="'+MAIN_URL+banner+'" alt="'+text+'" title="'+text+'" /></a>';
}

function changeBannerCode()
{
	if(!lastSelectedBanner)
		return;
	
	$('kriktusBannerCode').value = '';
	if($('bCodeTypeF').checked)
		$('kriktusBannerCode').value = '[url='+MAIN_URL+'][img]'+MAIN_URL+lastSelectedBanner+'[/img][/url]';
			else if($('bCodeTypeL').checked)
				$('kriktusBannerCode').value = MAIN_URL+lastSelectedBanner;
					else
						$('kriktusBannerCode').value = '<a href="'+MAIN_URL+'"><img style="border:none;" src="'+MAIN_URL+lastSelectedBanner+'" alt="'+lastSelectedBannerText+'" title="'+lastSelectedBannerText+'" /></a>';
}

function resetBannerCode()
{
	lastSelectedBanner = '';
	lastSelectedBannerText = '';
	$('kriktusBannerCode').value = '';
}
