var postsarray = [];
var currenthash = 'start';
var userhashname = '';
var sortbytype = 0;
var sortbyrel = 0;
var sortby = 'Popularity';
var sortbyt = 'All';
var filtertext = '';
var writeusername = null;
var defaultwin = 0;

var uniknotionstitle = 'Uniknotions | Easiest Way to Share';
var uniknotionsmeta = 'Uniknotions serves as an open source information sharing platform - made for creative people to discover and share content from the Internet.';

var pagenum = 1;
var maxpage = 1;
var posthashpage = null;

var initialhashcheck = document.location.hash;
var postidtrue = null;
var postitemid = '';

var firsttimechk = 0;

var thisusername = null;
var thisuserid = null;
var minchatchk = 3000;
var maxchatchk = 40000;
var chatchktime = minchatchk;
var periodicchk = null;
var chatwinpos = 0;
var periodichighlight = [];
var chattimearray = [];
var streamholder = [];

var image_path = 'users/';

var UI = {};

var smileyreplace = function(text) {
	var path = "images/smileys/";
	var smileyTranslator = {
		":)" : "smile",
		":p" : "tongue",
		":(" : "sad",
		":'(" : "cry",
		";)" : "wink",
		":D" : "laugh",
		"x(" : "angry",
		":o" : "wow",
		":|" : "confused"
	};

	var smileyRegex = /:\)|:p|:\(|:\'\(|;\)|:D|x\(|:o|:\|/g;
	var converted = text.replace(
		smileyRegex,
		function (s) {
			if (s in smileyTranslator) {
			//alert(s);
				return '<img alt="'+s+'" src="'+path+''+ smileyTranslator[s] +'.png"/>';
			}
		return s;
		}
	);
return converted;
};

var escapeRegex = function(text){
	if (!arguments.callee.sRE) {
		var specials = ['/', '.', '*', '+', '&', '$', '^', '?', '|','(', ')', '[', ']', '{', '}', '\\'];
		arguments.callee.sRE = new RegExp(
		'(\\' + specials.join('|\\') + ')', 'gi'
		);
	}
	return text.replace(arguments.callee.sRE, '\\$1');
};

var replaceurl = function(text){

	//var text = text;
	var regex = /\[code\](.*?)\[\/code\]/gi;
	
	var matches = [];
	matches = text.match(regex);
	var match;
	
	//--- replace code start
	var totalcodematches = 0;
	var tempcodehld = [];
	if (matches){
		matches.each(function(matches){
			var newmatches = '<pre>'+matches+'</pre>';
			var escapedmatch = escapeRegex(matches);

			var re = new RegExp(escapedmatch,"gi");
			
			text = text.replace(re, '{#codearea#:'+totalcodematches+'}');
			tempcodehld[totalcodematches] = newmatches;
			totalcodematches++;
		});
	}
	
	//--- replace code end
	var input = text;
	
	//--- replace url start
	regex = /\b((?:((?:https?|ftp):\/\/)|www.)[a-z0-9]+(?:[\-.][a-z0-9]+)*\.[a-z]{2,5}(?:(?::\d{1,5})?\/\S*)?)/gi;
	var totalurlmatches = 0;
	var tempurlhld = [];
	
	var output = '';
	if (input.match(regex)){
	var regex1 = /(http:\/\/)/gi;
	var matchtemp = '';
	var matchvar = '';
		if(regex.test(input)){
			var matchesurl = input.match(regex);
			totalurlmatches = matchesurl.length;
			for(var i = 0; i < totalurlmatches; i++) {
				var removebr = matchesurl[i].replace(regex1, '');
				removebr = removebr.replace(/<br[^>]*>/gi,"");
				output = input.replace(matchesurl[i], '{#url#:'+i+'}');
				tempurlhld[i] = removebr;
				input = output;
			}
		} else {
				output = input;
		}
	}else{
		output = input;
	}
	//--- replace url end
	
	output = smileyreplace(output);
	
	for (var k = 0; k < totalurlmatches; k++){
		output = output.replace('{#url#:'+k+'}',' <a href="http://'+tempurlhld[k]+'" target="_blank">'+tempurlhld[k]+'</a> ');
	}
	for (var j = 0; j < totalcodematches; j++){
		output = output.replace('{#codearea#:'+j+'}', tempcodehld[j]);
	}
	
	output = output.replace(/\[code\]|\[\/code\]/gi,"");
	return output;
};


function htmlspecialchars_decode (string, quote_style) {

    var optTemp = 0, i = 0, noquotes= false;
    if (typeof quote_style === 'undefined') {
        quote_style = 2;
    }
    string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE' : 1,
        'ENT_HTML_QUOTE_DOUBLE' : 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE' : 4
    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i=0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            }
            else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
        // string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
    }
    if (!noquotes) {
        string = string.replace(/&quot;/g, '"');
    }
    // Put this in last place to avoid escape being double-decoded
    string = string.replace(/&amp;/g, '&');

    return string;
}

function wordwrap (str, int_width) {
	var textOut = str;
	var reMatch = /(?:(?!\])\S){25,}(?=[^\[\]]*(?:\[|$))/g;
	var sliceLength = int_width;
	var parts = [];
	for (var matches = reMatch.exec(textOut); matches !== null; matches = reMatch.exec(textOut)) {
	    parts=Array();
		    for (var i=0; i < matches[0].length; i=i+sliceLength) {
		       parts.push(matches[0].slice(i,i+sliceLength));
		    }
	    textOut = textOut.replace(matches[0], parts.join("<br/>"));
	}
	return textOut;
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength"), 10) : "";
	if (obj.getAttribute && obj.value.length>mlength){
		obj.value=obj.value.substring(0,mlength);
	}
}

var faviconchange = function (var1){
    var link = document.createElement('link');
    link.type = 'image/gif';
    link.rel = 'shortcut icon';
    link.href = ''+var1+'';
    document.getElementsByTagName('head')[0].appendChild(link);
};

var adduserhash = function(hashvalue){
	var hashnow = document.location.hash;
	var newhash;
	
	var username = hashvalue;
		if (hashnow.match(/user:/)){
			newhash = hashnow.replace(/user:([a-zA-Z0-9_.,\-]{1,})/gi, 'user:'+username);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'user:'+username;
			}else{
			newhash = hashnow+'&user:'+username;
			}
		}

		hashnow = newhash;
		pagenum = 1;
		if (hashnow.match(/filt3\=/)){
			newhash = hashnow.replace(/filt3=(.\d{0,})/gi, 'filt3='+pagenum);
			//alert(pagenum);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'filt3='+pagenum;
			}else{
			newhash = hashnow+'&filt3='+pagenum;
			}
		}

	document.location.hash = newhash;
};

var removeuserhash = function(){
	var hashnow = document.location.hash;
	var newhash;
	
		if (hashnow.match(/user:/)){
			newhash = hashnow.replace(/&?user:([a-zA-Z0-9_.,\-]{1,})/gi, '');
		}else{
			hashnow = newhash;
		}

		hashnow = newhash;
		pagenum = 1;
		if (hashnow.match(/filt3\=/)){
			newhash = hashnow.replace(/filt3=(.\d{0,})/gi, 'filt3='+pagenum);
			//alert(pagenum);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'filt3='+pagenum;
			}else{
			newhash = hashnow+'&filt3='+pagenum;
			}
		}

	document.location.hash = newhash;
};

var addqueryhash = function(hashvalue){
	var hashnow = document.location.hash;
	var filtervalue = hashvalue;
	var newhash;
	
	filtertext = filtervalue;
		if (hashnow.match(/query:/)){
			newhash = hashnow.replace(/(query)([^\&]{1,})/gi, 'query:'+filtervalue);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'query:'+filtervalue;
			}else{
			newhash = hashnow+'&query:'+filtervalue;
			}
		}

		hashnow = newhash;
		pagenum = 1;
		if (hashnow.match(/filt3\=/)){
			newhash = hashnow.replace(/filt3=(.\d{0,})/gi, 'filt3='+pagenum);
			//alert(pagenum);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'filt3='+pagenum;
			}else{
			newhash = hashnow+'&filt3='+pagenum;
			}
		}

	document.location.hash = newhash;
};

var removequeryhash = function(){
	filtertext = '';
	var newhash;
	
	var hashnow = document.location.hash;
		if (hashnow.match(/query:/)){
			newhash = hashnow.replace(/(&?query)([^\&]{1,})/gi, '');
		}else{
			newhash = hashnow;
		}

		hashnow = newhash;
		pagenum = 1;
		if (hashnow.match(/filt3\=/)){
			newhash = hashnow.replace(/filt3=(.\d{0,})/gi, 'filt3='+pagenum);
			//alert(pagenum);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'filt3='+pagenum;
			}else{
			newhash = hashnow+'&filt3='+pagenum;
			}
		}

	document.location.hash = newhash;
};

var trimsentence = function(str,n){ 
  if(str === null){str='...';}
  if(str.length > n){  
	str = str.replace(/<(.*)>/g, " ");
	str = str.replace(/^\s+|\s+|\n+|\r+/g,' ');
	//alert(str);
    var s = str.substr(0, n);
    var words = s.split(' '); 
    words[words.length-1] = '';
    str = words.join(' ') + '...';
  }
return str;
};

var addposthash = function(hashvalue){
	var hashnow = document.location.hash;
	var postid = hashvalue;
	var newhash;
	
		if (hashnow.match(/postID:/)){
			newhash = hashnow.replace(/postID:(.\d{0,})/gi, 'postID:'+postid);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'postID:'+postid;
			}else{
			newhash = hashnow+'&postID:'+postid;
			}
		}

		hashnow = newhash;
		pagenum = 1;
		if (hashnow.match(/filt3\=/)){
			var matches = hashnow.match(/filt3=(.\d{0,})/gi);
			matches = matches[0].replace('filt3=','');
			posthashpage = matches;
			newhash = hashnow.replace(/filt3=(.\d{0,})/gi, 'filt3='+pagenum);
			//alert(pagenum);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'filt3='+pagenum;
			}else{
			newhash = hashnow+'&filt3='+pagenum;
			}
		}

	document.location.hash = newhash;
};

var removeposthash = function(var1){
	var hashnow = document.location.hash;
	var newhash;
	
		if (hashnow.match(/postID:/)){
			newhash = hashnow.replace(/&?postID:(.\d{0,})/gi, '');
		}else{
			newhash = hashnow;
		}

		hashnow = newhash;
		if (!posthashpage){
			pagenum = 1;
		}else{
			if (var1 == 1){
				pagenum = posthashpage;
			}else{
				pagenum = 1;
			}
		}
		if (hashnow.match(/filt3\=/)){
			newhash = hashnow.replace(/filt3=(.\d{0,})/gi, 'filt3='+pagenum);
			//alert(pagenum);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'filt3='+pagenum;
			}else{
			newhash = hashnow+'&filt3='+pagenum;
			}
		}

	document.location.hash = newhash;
};

var addhash = function(hashvalue){
	var hashnow = document.location.hash;
	var newhash;


	if (hashvalue == 'older' || hashvalue == 'newer'){
		if (hashvalue == 'older'){
			pagenum = pagenum + 1;
		}
		if (hashvalue == 'newer'){
			pagenum = pagenum - 1;
		}

		if (pagenum > maxpage){
			pagenum = maxpage;
		}
		
		if (pagenum < 1){
			pagenum = 1;
		}

		if (hashnow.match(/filt3\=/)){
			newhash = hashnow.replace(/filt3=(.\d{0,})/gi, 'filt3='+pagenum);
			//alert(pagenum);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'filt3='+pagenum;
			}else{
			newhash = hashnow+'&filt3='+pagenum;
			}
		}
	}

	var popvalue = 0;
	if (hashvalue == 'new'){
		popvalue = 1;
	}
	if (hashvalue == 'pop'){
		popvalue = 0;
	}
	if(hashvalue == 'pop' || hashvalue == 'new'){
		if (hashnow.match(/filt1\=/)){
			newhash = hashnow.replace(/filt1\=\d/gi, 'filt1='+popvalue);
		}else{
			if (hashnow == ''){
				newhash = hashnow+'filt1='+popvalue;
			}else{
				newhash = hashnow+'&filt1='+popvalue;
			}
		}
	
		hashnow = newhash;
		pagenum = 1;
		if (hashnow.match(/filt3\=/)){
			newhash = hashnow.replace(/filt3=(.\d{0,})/gi, 'filt3='+pagenum);
			//alert(pagenum);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'filt3='+pagenum;
			}else{
			newhash = hashnow+'&filt3='+pagenum;
			}
		}

	}

	if (hashvalue == 'link'){
		popvalue = 1;
	}else if (hashvalue == 'vid'){
		popvalue = 2;
	}else if (hashvalue == 'pic'){
		popvalue = 3;
	}else{
		popvalue = 0;
	}
	if(hashvalue == 'link' || hashvalue == 'vid' || hashvalue == 'pic' || hashvalue == 'all'){
		if (hashnow.match(/filt2\=/)){
			newhash = hashnow.replace(/filt2\=\d/gi, 'filt2='+popvalue);
		}else{
			if (hashnow == ''){
				newhash = hashnow+'filt2='+popvalue;
			}else{
				newhash = hashnow+'&filt2='+popvalue;
			}
		}

		hashnow = newhash;
		pagenum = 1;
		if (hashnow.match(/filt3\=/)){
			newhash = hashnow.replace(/filt3=(.\d{0,})/gi, 'filt3='+pagenum);
			//alert(pagenum);
		}else{
			if (hashnow == ''){
			newhash = hashnow+'filt3='+pagenum;
			}else{
			newhash = hashnow+'&filt3='+pagenum;
			}
		}
	}

	document.location.hash = newhash;
};

var disablebuttons = function(){
	$('filterall').fade(0.3);
	$('filterlinks').fade(0.3);
	$('filtervid').fade(0.3);
	$('filterpic').fade(0.3);

	$('filterpop').fade(0.3);
	$('filternew').fade(0.3);

};
var enablebuttons = function(){
	$('filterall').fade('in');
	$('filterlinks').fade('in');
	$('filtervid').fade('in');
	$('filterpic').fade('in');

	$('filterpop').fade('in');
	$('filternew').fade('in');

};

var divdisplaytoggle = function(divid, dowhat){

	var myVerticalSlide;
	if (dowhat == 1){
		//show
		myVerticalSlide = new Fx.Slide(divid);
		myVerticalSlide.slideIn();
	}else if(dowhat == 2){
		myVerticalSlide = new Fx.Slide(divid);
		myVerticalSlide.hide();
		$('writecomment').value = '';
	}else{
		myVerticalSlide = new Fx.Slide(divid);
		myVerticalSlide.slideOut();
		$('writecomment').value = '';
	}
};

var groupupdate = function (updatewhat){
	//var updatewhat = updatewhat;

	var recoid = '';
	if(document.location.hash.match(/postID:/gi)){
		postidchk = document.location.hash.match(/postID:(.\d{0,})/gi);
		recoid = postidchk[0].replace('postID:','');
	}

	if (!updatewhat){
		//update all

			MochaUI.updateContent({
			'element':  $('mainPanel')
			});

			MochaUI.updateContent({
			'element':  $('help-panel')
			});

			MochaUI.updateContent({
			'element':  $('followers-panel'),
			'title': 'Followers'
			});

			MochaUI.updateContent({
			'element':  $('following-panel'),
			'title': 'You\'re following'
			});

			MochaUI.updateContent({
			'element':  $('chatPanel')
			});

	}else{
		if ((updatewhat == 'reco-panel') || (updatewhat == 'recommended')){

			if (updatewhat == 'reco-panel'){
				new Request.JSON({url: "getdata/getupdates.php", onComplete: function (dataset){
					stream(dataset.updates);
				}}).send();
			}
			
			if (updatewhat == 'recommended'){
				new Request.JSON({url: "getdata/getreco.php?recoid="+recoid, onComplete: function (dataset){
					recommend(dataset.posts);
				}}).send();
			}

		}else{
			MochaUI.updateContent({
			'element':  $(''+updatewhat+'')
			});
		}
	}
};

var mod_quicklist = function (itemid, dowhat){
	new Request.JSON({url: "writedata/write_quicklist.php?itemid="+itemid+"&do="+dowhat, onComplete: function (dataset){
			groupupdate('help-panel');
		}}).send();
};

var mod_rating = function (itemid){
	new Request.JSON({url: "writedata/write_rating.php?itemid="+itemid, onComplete: function (dataset){
			if (dataset.rate_item == 1){
				$('item_likes_val_'+itemid).firstChild.data = parseInt($('item_likes_val_'+itemid).firstChild.data, 10) + 1;
				//$('rate_sign_'+itemid).removeClass('likestext');
				$('item_likes_'+itemid).addClass('likedbtn');
			}
		}}).send();
};

var mod_follows = function (followingid, dowhat){
	new Request.JSON({url: "writedata/write_follows.php?following="+followingid+"&dowhat="+dowhat, onComplete: function (dataset){
			if (dataset.follow_mod == 1){
				groupupdate('mainPanel');
				groupupdate('following-panel');
				groupupdate('reco-panel');
			}
		}}).send();
};

var invitationstatus = function(){
		new Request.JSON({url: "getdata/getinvitations.php", onComplete: function (dataset){
			invitations(dataset.invites);
		}}).send();
};

var mod_buddy = function (buddyid, dowhat, invupdate, buddyemail){
	new Request.JSON({url: "writedata/write_addusr2chat.php?buddyid="+buddyid+"&dowhat="+dowhat+"&buddyemail="+buddyemail, onComplete: function (dataset){
			if (dataset.add_usr.status == 1){
				groupupdate('chatPanel');
				if (invupdate == 1){
					invitationstatus();
				}
				
				if (invupdate == 2){
					MochaUI.closeWindow($('invitefrnd'));
					MochaUI.notification('Invitation Sent');
				}
					
			}else{
				if (invupdate == 2){
					MochaUI.closeWindow($('invitefrnd'));
					MochaUI.notification('Invitation Sent');
				}
			}
		}}).send();
};

var checksession = function (testvar, var1, var2, var3, var4){
	new Request.JSON({url: "login/loginchk.php", onComplete: function (dataset){
			var sessionexists = dataset.status.login_status;
			thisusername = dataset.status.login_username;
			thisuserid = dataset.status.login_userid;

				if (sessionexists == 1){
					$('usernotlogged_reg').fade('hide');
					$('usernotlogged_log').fade('hide');

					$('userlogged').setStyle('display', 'inline');	
					$('usernametop').set('html', 'Welcome <a onclick="removeposthash(); $(\'filterinput\').value = \'\'; adduserhash(\''+thisusername+'\');">'+thisusername+'</a>');
					$('userlogged_logout').setStyle('display', 'inline');	

					uniknotionstitle = thisusername+' - uniknotions.com';

					if (testvar == 'quicklist'){
						mod_quicklist(var1, var2);
					}

					if (testvar == 'likes'){
						mod_rating(var1);
					}

					if (testvar == 'follow'){
						mod_follows(var1, var2);
					}
					
					if (testvar == 'add2chat'){
						mod_buddy(var1, var2, var3);
						if (var4 == 'show'){
							MochaUI.notification('Invitation sent');
						}
					}

					if (testvar == 'share'){
						MochaUI.shareWindow(var1);
					}

					if (testvar == 'comment'){
						divdisplaytoggle(var1,var2);
					}

					if (testvar == 'settings'){
						MochaUI.accordiantestWindow();
					}

				}else{
					$('usernotlogged_reg').fade('in');
					$('usernotlogged_log').fade('in');
					$('userlogged').setStyle('display', 'none');	
					$('usernametop').set('html', '');
					$('userlogged_logout').setStyle('display', 'none');
					if (testvar != 'nologinbox'){
						MochaUI.loginWindow();
					}

					thisusername = null;
					thisuserid = null;
				}
		}}).send();
};

var chkhash = function(){

	var documenthash = document.location.hash;
	//alert(documenthash);
	if (currenthash !== documenthash && $chk('filternew')){
	//alert(documenthash);
		currenthash = documenthash;
		if (currenthash.match(/filt2\=/)){
			var sortbytype0 = (currenthash.match(/filt2\=(\d)/gi));
			if (sortbytype0 !== null){
				sortbytype = sortbytype0[0].replace('filt2=','');
			}else{
				sortbytype = 0;
			}
		}else{
			sortbytype = 0;
		}

		if (currenthash.match(/filt1\=/)){
			var sortbyrel0 = (currenthash.match(/filt1\=(\d)/gi));
			if(sortbyrel0 !== null){
				sortbyrel = sortbyrel0[0].replace('filt1=','');
			}else{
				sortbyrel = 0;
			}
		}else{
			sortbyrel = 0;
		}

		var pagechk = 1;
		if (currenthash.match(/filt3\=/)){
			var pagechk0 = (currenthash.match(/filt3=(.\d{0,})/gi));
			if (pagechk0 !== null){
				pagechk = pagechk0[0].replace('filt3=','');
				pagechk = parseInt(pagechk, 10);
			}else{
				pagechk = 1;
			}
		}

		if (pagechk === null){
		pagenum = 1;
		}else{
		pagenum = pagechk;
		}

		if (currenthash.match(/query:/)){
			if (currenthash.match(/query:([^\&]{1,})/gi)){
				var filterquery = (currenthash.match(/query:([^\&]{1,})/gi));
				filtertext = filterquery[0].replace('query:','');
				if($chk('filterinput')){
					$('filterinput').value = filtertext;
				}
			}else{
				//alert('empty');
				filtertext = '';
			}
		}else{
				//alert('nothing');
			filtertext = '';
		}

		if (currenthash.match(/user:/)){
			var userhashname0 = (currenthash.match(/user:([a-zA-Z0-9_.,\-]{1,})/gi));
			userhashname = userhashname0[0].replace('user:','');
			writeusername = ' | '+userhashname+'<span class="crossuser" onclick="removeuserhash();">x</span>';
		}else{
			writeusername = '';
			userhashname = '';
		}

		//alert(postitemtitle);
		if (currenthash.match(/postID:/)){
			postidtrue = 'getpost';
			var postidchk = (currenthash.match(/postID:(.\d{0,})/gi));
			postidchk = postidchk[0].replace('postID:','');
			postidchk = parseInt(postidchk, 10);
			postitemid = postidchk; //important
		}else{
			postidtrue = 'posts';
			//enablebuttons();
		}

		firsttimechk = 1;
		groupupdate('mainPanel');

	}
};

	// universal addposts function
	var addPosts = function(images) {
		$('mainPanel').empty();
		enablebuttons();
		
		postsarray = images.items;
		maxpage = images.pages;
		var searchquery = trimsentence(images.searchquery,20);
		var reflex = 0;
		var floatside;
		errorpostdis = '';

		if(writeusername != ''){
			if (images.user_details.username){
				var itemholderx = new Element('div', {'class': 'itemholder'});
				
				var showbirthday = '';
				if (images.user_details.birthday >= 150){
					showbirthday = '';
				}else{
					showbirthday = ''+images.user_details.birthday+' yrs old, ';
				}
				
				var templikes = [];
				var k;
				for (k = 1; k <= 5; k++){
					if (k <= images.user_details.likecalc){
						templikes[k] = 'likeshq';
					}else{
						templikes[k] = 'likes';
					}
				}

				var followtext;
				if(images.user_details.userfollowing == 1){
					followtext = '- unfollow';
				}else{
					followtext = '+ follow';
				}

				var elx = new Element('div', {'class': 'unikpost_user', 'html': '<div class="name">'+images.user_details.username+'<div class="subname">'+images.user_details.fullname+'<div class="subname">'+showbirthday+images.user_details.gender+'</div></div></div>     <div class="name name_margin">'+images.user_details.followers+'<div class="subname">followers</div></div>          <div class="name name_margin">'+images.user_details.following+'<div class="subname">following</div></div>     <div class="name name_margin"><div class="subname">Popularity</div> <div class="'+templikes[1]+'"></div><div class="'+templikes[2]+'"></div><div class="'+templikes[3]+'"></div><div class="'+templikes[4]+'"></div><div class="'+templikes[5]+'"></div> </div>     <div class="name name_margin"><div class="subname fn" onclick="checksession(\'follow\','+images.user_details.id+','+images.user_details.userfollowing+')">'+followtext+'</div><div class="subname fn" onclick="checksession(\'add2chat\','+images.user_details.id+',0, 0,\'show\');">+ Add to chat</div></div>'}).inject(itemholderx);
				
				var postimagex = new Element('div', {'class':'image'}).inject(elx, 'top');
				var postimagefilex;
				if (images.user_details.image != ''){
					postimagefilex = new Element('img', {'src': image_path+images.user_details.username+'/thumb_'+images.user_details.image+'','onclick':'adduserhash(\''+images.user_details.username+'\')'}).inject(postimagex);
				}else{
					postimagefilex = new Element('img', {'src': 'images/default.gif','onclick':'adduserhash(\''+images.user_details.username+'\')'}).inject(postimagex);
				}
				
				if (images.user_details.about != ''){
					var aboutmedesc = replaceurl(images.user_details.about);
				}else{
					var aboutmedesc = 'Yet to be updated!';
				}
					var aboutuser = new Element ('div', {'class':'aboutuser', 'html': '<span class="title">About '+images.user_details.username+':</span> '+aboutmedesc+''}).inject(elx);
				
				itemholderx.inject($('mainPanel'));
			}else{
				errorpostdis = 'nouser';
			}
		}

		var sortpopmsg = '<img width="12" height="12" src="images/fatcow/exclamation.png"/> <span id="alertmsgpop"></span>';
		var hashnow = document.location.hash;
		//alert(maxpage);
		if (pagenum >= maxpage){
			if (hashnow.match(/filt1\=0/) || hashnow.match(/filt1/) === null){
				if (!searchquery){
					sortpopmsg = '<img width="12" height="12" src="images/fatcow/exclamation.png"/> <span id="alertmsgpop"></span>Sorting by <b><i>date (new)</i></b> could give you more results.';
					var itemholderx1 = new Element('div', {'id':'changetopop', 'class': 'itemholder'});
					var elx1 = new Element('div', {'class': 'unikpost_empty', 'html': sortpopmsg}).inject(itemholderx1);
					itemholderx1.inject($('mainPanel'));
				}
			}else{
				if (!images.items){
					if (!searchquery){
						var itemholderx2 = new Element('div', {'id':'changetopop', 'class': 'itemholder'});
						var elx2 = new Element('div', {'class': 'unikpost_empty', 'html': sortpopmsg}).inject(itemholderx2);
						itemholderx2.inject($('mainPanel'));
					}
				}
			}
		}
		
		if (searchquery){
			var nposts = images.nposts;
			sortpopmsg = '<img width="12" height="12" src="images/fatcow/magnifier.png"/> '+nposts+' search result(s) retrieved for the query: "<i>'+images.searchquery+'</i>"<span id="alertmsgpop"></span>';
			var itemholderx3 = new Element('div', {'id':'changetopop', 'class': 'itemholder'});
			var elx3 = new Element('div', {'class': 'unikpost_empty', 'html': sortpopmsg}).inject(itemholderx3);
			itemholderx3.inject($('mainPanel'));
		}
		
		var countvar = 0;
		if (!images.items){
			//$('alertmsgpop').empty();
			if (!searchquery){
				var emptymessage = new Element('span', {'html': '0 posts here. '}).inject($('alertmsgpop'));
			}
		}else{
		
		/*	if (images.items.length >= 10 && writeusername == ''){
				var AdBrite_Title_Color = '66B5FF';
				var AdBrite_Text_Color = '808080';
				var AdBrite_Background_Color = 'FFFFFF';
				var AdBrite_Border_Color = 'CCCCCC';
				var AdBrite_URL_Color = '78B749';
				try{var AdBrite_Iframe=window.top!=window.self?2:1;var AdBrite_Referrer=document.referrer==''?document.location:document.referrer;AdBrite_Referrer=encodeURIComponent(AdBrite_Referrer);}catch(e){var AdBrite_Iframe='';var AdBrite_Referrer='';}
				//try{var AdBrite_Iframe=window.top!=window.self?2:1;var AdBrite_Referrer=document.referrer==''?document.location:document.referrer;AdBrite_Referrer=encodeURIComponent(AdBrite_Referrer);}catch(e){var AdBrite_Iframe='';var AdBrite_Referrer='';}
			}*/
			
			images.items.each(function(image) {
			
			/*	if (images.items.length >= 10 && writeusername == ''){
					if (countvar == 5){
						var itemholderad = new Element('div', {'class': 'itemholder'});
						var elad = new Element('div', {'class': 'adspace', 'html': '<iframe frameborder=0 src="ads/ad.php"></iframe><a target="_top" href="http://www.adbrite.com/mb/commerce/purchase_form.php?opid=1547962&afsid=1"><img src="http://files.adbrite.com/mb/images/adbrite-your-ad-here-banner.gif" style="background-color:#CCCCCC;border:none;padding:0;margin:0;" alt="Your Ad Here" width="11" height="60" border="0" /></a>'}).inject(itemholderad);
						elad.inject($('mainPanel'));
					}
				}*/
			
				//alert(image);
				var itemholder = new Element('div', {'class': 'itemholder'});
				var el = new Element('div', {'class': 'unikpost'});
				var likes_01_btn = new Element('div', {'id':'item_likes_'+image.item.id+'', 'class':'likesbtn', 'onclick':'checksession(\'likes\',\''+image.item.id+'\');'}).inject(el);
				var likes_01_val = new Element('div', {'id':'item_likes_val_'+image.item.id+'', 'class':'likestext', 'html':image.likes.likes}).inject(likes_01_btn);
				
				if (image.likes.liked == 1){
					likes_01_btn.addClass('likedbtn');
				}
			
				var postimage;
				var postimagefile;
				if (image.user.image != ''){
				postimage = new Element('div', {'class':'userimage'}).inject(el);
				postimagefile = new Element('img', {'src': image_path+image.user.username+'/thumb_'+image.user.image+'','onclick':'adduserhash(\''+image.user.username+'\')'}).inject(postimage);
				}else{
				postimage = new Element('div', {'class':'userimage'}).inject(el);
				postimagefile = new Element('img', {'src': 'images/default.gif','onclick':'adduserhash(\''+image.user.username+'\')'}).inject(postimage);
				}

				var postlikes;
				if (image.user.following != 1){
					postlikes = new Element('div', {'class':'follow', 'onclick': 'checksession("follow",'+image.user.id+',0);', 'html': 'Follow'}).inject(postimage);
				}else{
					postlikes = new Element('div', {'class':'unfollow', 'onclick': 'checksession("follow",'+image.user.id+',1);', 'html': 'Unfollow'}).inject(postimage);
				}

				var postusername = new Element('span', {'class':'username', 'html': image.user.username+' &rsaquo; ','onclick':'adduserhash(\''+image.user.username+'\')'}).inject(el);
			
				var share = image.item.share;
				if (share != ''){share = '<img class="quoteimg" src="images/str_quote.png"/>'+share+'<img class="quoteimg" src="images/end_quote.png"/>';}
				var postshare = new Element('span', {'class':'share', 'html': share}).inject(el);
				var postdate = new Element('div', {'class':'date', 'html': ' ('+image.item.date+')'}).inject(el);
		
				if (image.item_att.type !== '0'){

				var domainonly = image.item_att.url.match(/^(http:\/\/)?([^\/]+)/i);
				var postnum_comments = new Element('span', {'class':'num_comments', 'html': ' . '+domainonly[2]}).inject(postdate);

					var attachlink = new Element('div', {'class':'attachment'}).inject(el);
					if (image.item_att.type == 2 || image.item_att.type == 3){
						if ((image.item_att.thumb).length >= '5'){
						
						var attachimage;
						var postimg1;
						var postimg;
							if (image.item_att.type == 2){
								temptitle = 'Uniknotions Video';
								attachimage = new Element('div', {'class':'attachimage', 'onclick':'MochaUI.uniktvWindow(\''+image.item_att.url+'\',\''+image.item.id+'\',"'+temptitle+'");'}).inject(attachlink);
								postimg1 = new Element('img', {'src': 'images/fatcow/control_play_blue.png', 'class':'floatthumb'}).inject(attachimage);
								postimg = new Element('img', {'src': image.item_att.thumb}).inject(attachimage);
							}else{
								attachimage = new Element('div', {'class':'attachimage', 'onclick':'MochaUI.browserWindow(\''+image.item_att.url+'\',\''+image.item.id+'\');'}).inject(attachlink);
								postimg1 = new Element('img', {'src': 'images/fatcow/image.png', 'class':'floatthumb'}).inject(attachimage);
								postimg = new Element('img', {'src': 'users/'+image.item_att.thumb}).inject(attachimage);
							}
						}
					}

					var attachsub = new Element('div', {'class':'attachment_sub'}).inject(attachlink);

					var posttitle = new Element('span', {'class':'title', 'html': image.item_att.title, 'onclick':'addposthash(\''+image.item.id+'\');'}).inject(attachsub);

					var postdesc = new Element('div', {'class':'desc', 'html': image.item_att.description}).inject(attachsub);

				}
				el.inject(itemholder);

				if(reflex === 0){
					floatside = '_leftside';
				}else{
					floatside = '_leftside';
				}
				
				/*
				if (image.likes.liked == 0){
					var haveornotrated = 'likestext';
				}

				if (image.likes.liked == 1){
					var haveornotrated = 'likedtext';
				}*/

				var itemfooter = new Element('div', {'class': 'itemfooter'+floatside, 'html': '<div class="floattextsec" onclick="checksession(\'quicklist\', \''+image.item.id+'\', \'1\');"> + Quicklist</div><div class="floattextsec"> . </div>'});
				var postlikestext = new Element('span', {'class':'likestext', 'html': '<div onclick="addposthash(\''+image.item.id+'\');" class="floattextsec">('+image.item.comments+') comments</div><div class="floattextsec"> . </div><div onclick="addposthash(\''+image.item.id+'\');" class="floattextsec"> View </div>'}).inject(itemfooter);

				itemfooter.inject(itemholder);

				itemholder.inject($('mainPanel'));

				if(reflex === 0){
					reflex = 1;
				}else{
					reflex = 0;
				}
				countvar++;
			});

		}
				
			temptitle = 'Posts | Sorted by ' + sortby + ' | Browsing ' +sortbyt+writeusername;
			if (searchquery != ''){
				temptitle = temptitle+' | <img class="quoteimg" src="images/str_quote.png"/>'+searchquery+'<img class="quoteimg" src="images/end_quote.png"/><span class="crossuser" onclick="removequeryhash(); $(\'filterinput\').value=\'search ...\'">x</span>';
				$('filterpop').fade(0.3);
				$('filternew').fade(0.3);
			}else{
				$('filterpop').fade('in');
				$('filternew').fade('in');
			}

			temptitle = new Element('span', {'html':temptitle});
			$('mainPanel_title').empty();
			temptitle.inject($('mainPanel_title'));

			if (writeusername != ''){
				document.title = userhashname+' - uniknotions.com';
			}else{
				document.title = uniknotionstitle;
			}

			var myFx = new Fx.Scroll('mainPanel');
			myFx.toTop();
	};


	// universal addposts function
	var quickList = function(images) {
		$('help-panel').empty();
		
			if (!images.items){
			
			if (images.logged != 1){
			
				temptitle = new Element('span', {'html':'Why you\'ll <span class="heartshape">&hearts;</span> Uniknotions'});
				$('help-panel_title').empty();
				temptitle.inject($('help-panel_title'));
						
					var itemholder = new Element('div', {'class': 'itemholder'});
					var el = new Element('div', {'class': 'unikpost'});
					var share = '<b>Uniknotions</b> helps you connect with users that can provide you with exactly the information you need.<div class="join_now" onclick="MochaUI.registerWindow();"><img name="joinnowbtn" onmouseover=\'joinnowbtn.src="images/joinnow_hover.jpg"\'; onmouseout=\'joinnowbtn.src="images/joinnow.jpg"\'; src="images/joinnow.jpg"/></div>';
					var postshare = new Element('span', {'class':'sharedefaulttxt', 'html': share}).inject(el);
					el.inject(itemholder);
					
					var el1 = new Element('div', {'class': 'anothermsg'});
					var share1 = 'Please <b onclick="MochaUI.registerWindow();" class="cursorlink">register</b> if you\'re not a member yet. We promise you, it won\'t take long.';
					var postshare1 = new Element('div', {'class':'', 'html': share1}).inject(el1);
					el1.inject(itemholder);
					
				itemholder.inject($('help-panel'));
				
			}else{
			
				temptitle = new Element('span', {'html':'<img style="width: 12px; height: 12px;" src="images/fatcow/add.png"/> Quick List'});
				$('help-panel_title').empty();
				temptitle.inject($('help-panel_title'));
			
					var itemholder2 = new Element('div', {'class': 'itemholder'});
					var el2 = new Element('div', {'class': 'recoholder'});
					var share2 = 'You can add posts to this quicklist for quick access.';
					if (share2 != ''){share2 = '<img class="quoteimg" src="images/fatcow/disk.png"/><img class="quoteimg" src="images/str_quote.png"/>'+share2+'<img class="quoteimg" src="images/end_quote.png"/>';}
					var postshare2 = new Element('div', {'class':'reco', 'html': share2}).inject(el2);

					el2.inject(itemholder2);
				itemholder2.inject($('help-panel'));

			}
			
		}else{
		
			temptitle = new Element('span', {'html':'<img style="width: 12px; height: 12px;" src="images/fatcow/add.png"/> Quick List'});
			$('help-panel_title').empty();
			temptitle.inject($('help-panel_title'));
				
		images.items.each(function(image) {
			//alert(image);
			var itemholder = new Element('div', {'class': 'itemholder'});
			var el = new Element('div', {'class': 'unikpost'});

			var postusername = new Element('span', {'class':'username', 'html': image.user.username+' &rsaquo; ','onclick':'adduserhash(\''+image.user.username+'\'); removeposthash();'}).inject(el);
			
			var share = image.item.share;
			if (share != ''){share = '<img class="quoteimg" src="images/str_quote.png"/>'+share+'<img class="quoteimg" src="images/end_quote.png"/>';}
			var postshare = new Element('span', {'class':'share', 'html': share}).inject(el);

			if (image.item_att.type !== '0'){
				var attachlink = new Element('div', {'class':'attachment_quicklist'}).inject(el);
				if (image.item_att.type == 2 || image.item_att.type == 3){
					if ((image.item_att.thumb).length >= '5'){
					var attachimage;
					var postimg;
						if (image.item_att.type == 2){
							attachimage = new Element('div', {'class':'attachimage', 'onclick':'MochaUI.uniktvWindow(\''+image.item_att.url+'\',\''+image.item.id+'\');'}).inject(attachlink);
							postimg = new Element('img', {'src': image.item_att.thumb}).inject(attachimage);
						}else{
							attachimage = new Element('div', {'class':'attachimage', 'onclick':'MochaUI.browserWindow(\''+image.item_att.url+'\',\''+image.item.id+'\');'}).inject(attachlink);
							postimg = new Element('img', {'src': 'users/'+image.item_att.thumb}).inject(attachimage);
						}
					}
				}
				var attachsub = new Element('div', {'class':'attachment_sub'}).inject(attachlink);

				var posttitle = new Element('span', {'title':image.item_att.title, 'class':'title_quicklist', 'html': trimsentence(image.item_att.title, 50), 'onclick':'addposthash(\''+image.item.id+'\');'}).inject(attachsub);

				var postdesc = new Element('div', {'class':'desc_quicklist', 'html': trimsentence(image.item_att.description, 70)}).inject(attachsub);
			}
			el.inject(itemholder);
			var itemfooter = new Element('div', {'class': 'itemfooter_leftside_q', 'html': '<div class="floattextsec" onclick="addposthash(\''+image.item.id+'\');"> View</div><div class="floattextsec"> | </div><div class="floattextsec" onclick="checksession(\'quicklist\', \''+image.item.id+'\', \'2\');">Remove (-)</div>'}).inject(itemholder);

			itemholder.inject($('help-panel'));

		});
		
		}

			var myFx = new Fx.Scroll('help-panel');
			myFx.toTop();

	};


	var addPOST = function(images) {
		$('mainPanel').empty();
		disablebuttons();
		
		var temptitle = '';
		//alert(images.item);
		if (!images.item){
			var itemholderx = new Element('div', {'class': 'itemholder'});
			var elx = new Element('div', {'class': 'unikpost_empty', 'html': '<img width="12" height="12" src="images/fatcow/exclamation.png"/> 0 posts here.'}).inject(itemholderx);
			itemholderx.inject($('mainPanel'));
			
			temptitle = new Element('span', {'html':'404 : Unable to find item <span class="crossuser" onclick="removeposthash(1);">x</span>'});
			$('mainPanel_title').empty();
			temptitle.inject($('mainPanel_title'));
			
		}else{
		
		postsarray = images;
		var image = images;
		maxpage = images.pages;
		
			var itemholder = new Element('div', {'class': 'itemholder'});
			var el = new Element('div', {'class': 'unikpost'});
				var likes_01_btn = new Element('div', {'id':'item_likes_'+image.item.id+'', 'class':'likesbtn', 'onclick':'checksession(\'likes\',\''+image.item.id+'\');'}).inject(el);
				var likes_01_val = new Element('div', {'id':'item_likes_val_'+image.item.id+'', 'class':'likestext', 'html':image.likes.likes}).inject(likes_01_btn);
				
				if (image.likes.liked == 1){
					likes_01_btn.addClass('likedbtn');
				}
			
			var share = replaceurl(image.item.share);
			if (share != ''){
				var postshare = new Element('div', {'class':'sharein', 'html': share}).inject(el);
			}

			if (image.item_att.type !== '0'){

				var attachlink = new Element('div', {'class':'attachment_det'}).inject(el);
				if (image.item_att.type == 2 || image.item_att.type == 3){
					if ((image.item_att.thumb).length >= '5'){
						attachlink.addClass('att_heightadjust');
						
						var attachimage;
						var postimg1;
						var postimg;
						
						if (image.item_att.type == 2){
							attachimage = new Element('div', {'class':'attachimage', 'onclick':'MochaUI.uniktvWindow(\''+image.item_att.url+'\',\''+image.item.id+'\');'}).inject(attachlink);
							postimg1 = new Element('img', {'src': 'images/fatcow/control_play_blue.png', 'class':'floatthumb'}).inject(attachimage);
							postimg = new Element('img', {'src': image.item_att.thumb}).inject(attachimage);
						}else{
							attachimage = new Element('div', {'class':'attachimage', 'onclick':'MochaUI.browserWindow(\''+image.item_att.url+'\',\''+image.item.id+'\');'}).inject(attachlink);
							postimg1 = new Element('img', {'src': 'images/fatcow/image.png', 'class':'floatthumb'}).inject(attachimage);
							postimg = new Element('img', {'src': 'users/'+image.item_att.thumb}).inject(attachimage);
						}
					}
				}
				var attachsub = new Element('div', {'class':'attachment_sub'}).inject(attachlink);

				var posttitle;
				if ((image.item_att.thumb).length >= '5' && image.item_att.type == 2){
					posttitle = new Element('span', {'class':'title', 'html': image.item_att.title, 'onclick':'MochaUI.uniktvWindow(\''+image.item_att.url+'\',\''+image.item.id+'\');'}).inject(attachsub);
				}else if ((image.item_att.thumb).length >= '5' && image.item_att.type == 3){
					posttitle = new Element('span', {'class':'title', 'html': image.item_att.title, 'onclick':'MochaUI.browserWindow(\''+image.item_att.url+'\',\''+image.item.id+'\');'}).inject(attachsub);
				}else{
					posttitle = new Element('span', {'class':'title', 'html': '<a target="_blank" href="'+image.item_att.url+'">'+image.item_att.title+'</a>'}).inject(attachsub);
				}

				var postdesc = new Element('div', {'class':'desc', 'html': image.item_att.description}).inject(attachsub);
				var domainonly = image.item_att.url.match(/^(http:\/\/)?([^\/]+)/i);
				var postdomainonly = new Element('span', {'class':'domainonly', 'html': ' (source: '+domainonly[2]+')'}).inject(postdesc);
			}


			var userdetails = new Element('div', {'class':'postedbydetails'});
		
			var postimage;
			var postimagefile;
			if (image.user.image != ''){
				postimage = new Element('div', {'class':'userimage_rightside'}).inject(userdetails);
				postimagefile = new Element('img', {'src': image_path+image.user.username+'/thumb_'+image.user.image+'', 'onclick':'adduserhash(\''+image.user.username+'\');  removeposthash();'}).inject(postimage);
			}else{
				postimage = new Element('div', {'class':'userimage_rightside'}).inject(userdetails);
				postimagefile = new Element('img', {'src': 'images/default.gif', 'onclick':'adduserhash(\''+image.user.username+'\');  removeposthash();'}).inject(postimage);
			}
			
			var postusername = new Element('span', {'class':'userdetails', 'html': 'posted by: '});
			var postusername1 = new Element('span', {'class':'username', 'html': image.user.username,'onclick':'adduserhash(\''+image.user.username+'\');  removeposthash();'}).inject(postusername);
			var postdate = new Element('div', {'class':'date', 'html': image.item.date}).inject(postusername);
			postusername.inject(userdetails);
			
			userdetails.inject(el);
			
			if (image.item_att.type !== '0'){
				var relatedbox = new Element('div', {'html':'<div class="showrecotitle" onclick="if ($(\'recoholderdiv\').hasClass(\'displaynone\')){$(\'recoholderdiv\').removeClass(\'displaynone\');}else{$(\'recoholderdiv\').addClass(\'displaynone\');}"> <span class="showtitle">What\'s Next? (show / hide recommendations)</span></div>'});
				var recoholder = new Element('div', {'id':'recoholderdiv', 'class':'relatedbox'}).inject(relatedbox);
				var recoholderdiv = new Element('div', {'class':'related'}).inject(recoholder);
				relatedbox.inject(el);
			}
			
			el.inject(itemholder);


			var haveornotrated;
			if (image.likes.liked === 0){
				haveornotrated = 'likestext';
			}

			if (image.likes.liked === 1){
				haveornotrated = 'likedtext';
			}
			
			var titleforbookmark = trimsentence(image.item_att.title, 97);

			var itemfooter = new Element('div', {'class': 'itemfooter_leftside', 'html': '<div class="floattextsec"> <a href="http://twitter.com/home?status='+titleforbookmark+' http://uniknotions.com/url/?id='+image.item.id+'" target="_blank"><img src="images/icondock/twitter.png"/></a></div><div class="floattextsec"> <a href="http://www.facebook.com/sharer.php?u=http://uniknotions.com/url/?id='+image.item.id+'&t='+titleforbookmark+'" target="_blank"><img src="images/icondock/facebook.png"/></a></div><div class="floattextsec"> <a href="http://delicious.com/post?url=http://uniknotions.com/url/?id='+image.item.id+'&title='+titleforbookmark+'" target="_blank"><img src="images/icondock/delicious.png"/></a></div><div class="floattextsec"> <a href="http://digg.com/submit?url=http://uniknotions.com/url/?id='+image.item.id+'" target="_blank"><img src="images/icondock/digg.png"/></a></div><div class="floattextsec"> <a href="http://www.stumbleupon.com/submit?url=http://uniknotions.com/url/?id='+image.item.id+'&title='+titleforbookmark+'" target="_blank"><img src="images/icondock/stumbleupon.png"/></a></div><div class="floattextsec"> <img src="images/arrow-right.gif"/> </div><div class="floattextsec" onclick="checksession(\'quicklist\', \''+image.item.id+'\', \'1\');"> + Quicklist</div><div class="floattextsec"> . </div>'});
			var postlikestext = new Element('span', {'class':'likestext', 'html': '<div onclick="checksession(\'comment\',\'commentbox\',1);" class="floattextsec">('+image.item.total_comments+') comments [+add]</div>'}).inject(itemfooter);
			
			itemfooter.addClass('itemfooter_leftside_newwidth');
			itemfooter.inject(itemholder);

			var commentbox = new Element('div', {'id':'commentbox', 'html': '<textarea id="writecomment"></textarea><br/><button id="writecommentbtn" onclick="add_comment('+image.item.id+'); this.addClass(\'displaynone\'); $(\'writecommentbtncross\').addClass(\'displaynone\'); $(\'writecommentspinner\').removeClass(\'displaynone\');">Submit</button><button id="writecommentbtncross" onclick="divdisplaytoggle(\'commentbox\',0);">x</button><button id="writecommentspinner" class="displaynone"><img src="images/spinner.gif"/></button>'}).inject(itemholder);			
			itemholder.inject($('mainPanel'));

			divdisplaytoggle('commentbox',2);
			
			temptitle = trimsentence(image.item_att.title, 70);
			if (temptitle == ''){
				temptitle = trimsentence(image.item.share, 70);
			}
			var thisposttitle = htmlspecialchars_decode(temptitle,3);
			temptitle = temptitle + '<span class="crossuser" onclick="removeposthash(1);">x</span>';

			temptitle = new Element('span', {'html':temptitle});
			$('mainPanel_title').empty();
			temptitle.inject($('mainPanel_title'));

			document.title = thisposttitle;
			
			if (image.item.total_comments > 0){

			var commentsle = new Element('div',{'class':'commentsle'}).inject($('mainPanel'));

			image.comments.each(function(comm) {
				var le = new Element('div', {'class': 'postcomment'});
				
				var commimage;
				var commimagefile;
				if (comm.comment.user.image != ''){
					commimage = new Element('div', {'class':'userimage','onclick':'adduserhash(\''+comm.comment.user.username+'\'); removeposthash();'}).inject(le);
					commimagefile = new Element('img', {'src': image_path+comm.comment.user.username+'/thumb_'+comm.comment.user.image+''}).inject(commimage);
				}else{
					commimage = new Element('div', {'class':'userimage','onclick':'adduserhash(\''+comm.comment.user.username+'\'); removeposthash();'}).inject(le);
					commimagefile = new Element('img', {'src': 'images/default.gif'}).inject(commimage);
				}

				var commuser = new Element('div', {'class':'userdate'}).inject(le);
				var commusername = new Element('span',{'class': 'username','onclick':'adduserhash(\''+comm.comment.user.username+'\'); removeposthash();', 'html': comm.comment.user.username+' &rsaquo;'}).inject(commuser);
				var commuser1 = new Element('div', {'class':'date','html': comm.comment.date}).inject(commuser);

				var thiscomment = wordwrap(comm.comment.value, 50);
				var comment_value = replaceurl(thiscomment);
				var commtext = new Element('div', {'class':'value','html': comment_value}).inject(le);

				le.inject(commentsle);
			});
			}

			groupupdate('recommended');
		}
			var myFx = new Fx.Scroll('mainPanel');
			myFx.toTop();

	};


	// recently active function
	var recentlyactivefn = function(images, var01) {
		$(''+var01+'').empty();
		var itemholder = new Element('div', {'class': 'followholder'});
		
		if (images){
			images.each(function(image) {
				//alert(image);
				var el = new Element('div', {'title':image.user.username, 'class': 'followers', 'onclick':'adduserhash(\''+image.user.username+'\'); removeposthash();'});

				var imagepath;
				if (image.user.image != ''){
					imagepath = '<img src="'+image_path+image.user.username+'/thumb_'+image.user.image+'"/>';
				}else{
					imagepath = '<img src="images/default.gif"/>';
				}
				var postimage = new Element('div', {'class':'image', 'html': imagepath}).inject(el);
				el.inject(itemholder);
			});
		}
			itemholder.inject($(''+var01+''));
	};
	
	var activaterecentlyactivefn = function(var01){
			var request = new Request.JSON({
				url: 'getdata/getrecentlyactive.php',
				onComplete: function(jsonObj){
					recentlyactivefn(jsonObj.recently_active, var01);
				}
			}).send();
	};

	// followers function
	var followersfn = function(images) {
		$('followers-panel').empty();
		var itemholder = new Element('div', {'class': 'followholder'});
		
		if (!images.follows){
			var tempuser = 'uniknotions';
			var el = new Element('div', {'title':tempuser, 'class': 'followers', 'onclick':'adduserhash(\''+tempuser+'\'); removeposthash();'});
			var imagepath = '<img src="images/default.gif"/>';
			var postimage = new Element('div', {'class':'image', 'html': imagepath}).inject(el);
			el.inject(itemholder);
		}else{
		images.follows.each(function(image) {
			//alert(image);
			var el = new Element('div', {'title':image.user.username, 'class': 'followers', 'onclick':'adduserhash(\''+image.user.username+'\'); removeposthash();'});

			var imagepath;
			if (image.user.image != ''){
				imagepath = '<img src="'+image_path+image.user.username+'/thumb_'+image.user.image+'"/>';
			}else{
				imagepath = '<img src="images/default.gif"/>';
			}
			var postimage = new Element('div', {'class':'image', 'html': imagepath}).inject(el);
			el.inject(itemholder);
		});
		
					temptitle = new Element('span', {'html':'Followers ('+images.follows.length+')'});
					$('followers-panel_title').empty();
					temptitle.inject($('followers-panel_title'));
			
		}
			itemholder.inject($('followers-panel'));

	};

	// following function
	var followingfn = function(images) {
		$('following-panel').empty();
		var itemholder = new Element('div', {'class': 'followholder'});
		
		if (!images.follows){
		
			var tempuser = 'uniknotions';
			var el = new Element('div', {'title':tempuser, 'class': 'following', 'onclick':'adduserhash(\''+tempuser+'\'); removeposthash();'});
			var imagepath = '<img src="images/default.gif"/>';
			var postimage = new Element('div', {'class':'image', 'html': imagepath}).inject(el);
			el.inject(itemholder);
			
		}else{
		images.follows.each(function(image) {
			var el = new Element('div', {'id': 'following_hld_'+image.user.id, 'title':image.user.username, 'class': 'following', 'onclick':'adduserhash(\''+image.user.username+'\'); removeposthash();'});

			var imagepath;
			if (image.user.image != ''){
				imagepath = '<img src="'+image_path+image.user.username+'/thumb_'+image.user.image+'"/>';
			}else{
				imagepath = '<img src="images/default.gif"/>';
			}
			var postimage = new Element('div', {'class':'image', 'html': imagepath}).inject(el);
			el.inject(itemholder);

		});
		
				temptitle = new Element('span', {'html':'Following ('+images.follows.length+')'});
				$('following-panel_title').empty();
				temptitle.inject($('following-panel_title'));
			
		}
			itemholder.inject($('following-panel'));

	};


	// reco
	var recommend = function(images) {
		$('recoholderdiv').empty();
		
		if (!images.item){
		
				var el = new Element('div', {'class': 'relatedhld'});

				var posttitle = new Element('span', {'class':'title', 'html': '0 recommendations found.'}).inject(el);
				el.inject($('recoholderdiv'));

				var myFx = new Fx.Scroll('recoholderdiv');
				myFx.toTop();
				
		}else{
			images.item.each(function(image) {
				var el = new Element('div', {'class': 'relatedhld'});
				var posttitle = new Element('span', {'title':image.title,'class':'title', 'html': '+ '+trimsentence(image.title, 70), 'onclick':'addposthash(\''+image.id+'\');'}).inject(el);
				el.inject($('recoholderdiv'));

				var myFx = new Fx.Scroll('recoholderdiv');
				myFx.toTop();

			});
		}

	};


	// stream
	var streamvar = 0;
	var streamvartot = 0;
	var periodicadd;
	
	var periodicstream = function(){
	
		if (streamvartot >= 10){
			if (streamvar < streamvartot){
				streamvar = streamvar + 1;
			}else{
				streamvar = 0;
			}
			streamholder[streamvar].fade('hide');
			streamholder[streamvar].inject($('reco-panel'), 'top');
			streamholder[streamvar].fade('in');
			var subtractorval;
			
			if (streamvar >= 10){
				subtractorval = streamvar - 10;
			}else{
				var tempsub = streamvar - 10;
				subtractorval = streamvartot + tempsub;
			}
			streamholder[subtractorval].dispose();
		}
	};
	
	var stream = function(images) {
		$('reco-panel').empty();
		streamholder.empty();
		
		if (!images){
		
				var itemholder = new Element('div', {'class': 'streamhld'});
				var el = new Element('div', {'class': 'stream'});
				
				var postitle;
				if(thisusername){
					posttitle = new Element('div', {'html': 'Oops, no new updates in your circle! Why not get hold of these recently active users?'}).inject(el);
				
					temptitle = new Element('span', {'html':'Friends Updates'});
					$('reco-panel_title').empty();
					temptitle.inject($('reco-panel_title'));
			
				}else{
					posttitle = new Element('div', {'html': 'Oops, no new updates in your circle! Why not get hold of these recently active users?'}).inject(el);
				}
				
				el.inject(itemholder);
				itemholder.inject($('reco-panel'));
				
				var itemholder2 = new Element('div', {'id':'recently_active'});
				itemholder2.inject($('reco-panel'));
				activaterecentlyactivefn('recently_active');

				var myFx = new Fx.Scroll('reco-panel');
				myFx.toTop();
				
		}else{
			var countstream = 0;
			streamvar = 0;
			streamvartot = 0;
			
			images.each(function(image) {
				//alert(image);
				streamholder[countstream] = new Element('div', {'class': 'streamhld'});
				var el = new Element('div', {'class': 'stream'});

				var imagepath;
				if (image.userimage != ''){
					imagepath = '<div class="image" onclick="removeposthash(); adduserhash(\''+image.username+'\');"><img src="'+image_path+image.username+'/thumb_'+image.userimage+'"/></div>';
				}else{
					imagepath = '<div class="image" onclick="removeposthash(); adduserhash(\''+image.username+'\');"><img src="images/default.gif"/></div>';
				}
			
				var posttitle;
				if (image.dowhat === 0){
					posttitle = new Element('span', {'html': imagepath+'<div class="streamdet"><span onclick="removeposthash(); adduserhash(\''+image.username+'\');" class="username">'+image.username+'</span>' +' posted <span class="title" onclick="addposthash(\''+image.itemid+'\');">'+image.itemtitle+'</span> <small>('+image.date+')</small></div>'}).inject(el);
				}else if(image.dowhat === 1){
					posttitle = new Element('span', {'html': imagepath+'<div class="streamdet"><span onclick="removeposthash(); adduserhash(\''+image.username+'\');" class="username">'+image.username+'</span>' +' commented on <span class="title" onclick="addposthash(\''+image.itemid+'\');">'+image.itemtitle+'</span> <small>('+image.date+')</small></div>'}).inject(el);
				}else if(image.dowhat === 2){
					posttitle = new Element('span', {'html': imagepath+'<div class="streamdet"><span onclick="removeposthash(); adduserhash(\''+image.username+'\');" class="username">'+image.username+'</span>' +' <span class="heartshape">&hearts;</span>\'d <span class="title" onclick="addposthash(\''+image.itemid+'\');">'+image.itemtitle+'</span> <small>('+image.date+')</small></div>'}).inject(el);
				}else if(image.dowhat === 3){
					posttitle = new Element('span', {'html': imagepath+'<div class="streamdet"><span onclick="removeposthash(); adduserhash(\''+image.username+'\');" class="username">'+image.username+'</span>' +' is following <span onclick="removeposthash(); adduserhash(\''+image.follow_username+'\');" class="username2">'+image.follow_username+'</span></div>'}).inject(el);
				}else{
				}
				
				el.inject(streamholder[countstream]);
				if (countstream <= 9){
					streamholder[countstream].inject($('reco-panel'), 'top');
					streamvar = countstream;
				}
				countstream++;
			});
			
			streamvartot = countstream - 1;
			$clear(periodicadd);
			periodicadd = periodicstream.periodical(7000);
			
				if(thisusername){
					temptitle = new Element('span', {'html':'Friends Updates'});
					$('reco-panel_title').empty();
					temptitle.inject($('reco-panel_title'));
			
				}else{
					temptitle = new Element('span', {'html':'Uniknotions Stream'});
					$('reco-panel_title').empty();
					temptitle.inject($('reco-panel_title'));
				}
		}

	};
	
	// invitations
	var invitations = function(images) {
		if (images.buddies){
			MochaUI.invitationWindow();			
			images.buddies.each(function(image) {
			
				//alert(image);
				var itemholder = new Element('div', {'class': 'invitation'});
				var el1 = new Element('div', {'class': 'decline', 'html': 'Decline', 'onclick': 'checksession(\'add2chat\','+image.user.id+', 2, 1);'}).inject(itemholder);
				var el2 = new Element('div', {'class': 'accept', 'html': 'Accept', 'onclick': 'checksession(\'add2chat\','+image.user.id+', 0, 1);'}).inject(itemholder);
				
				var imagepath;
				if (image.user.image != ''){
					imagepath = '<img src="'+image_path+image.user.username+'/thumb_'+image.user.image+'"/>';
				}else{
					imagepath = '<img src="images/default.gif"/>';
				}
				
				var el3 = new Element('div', {'class': 'image', 'html': imagepath, 'onclick':'adduserhash(\''+image.user.username+'\'); removeposthash();'}).inject(itemholder);
				
				var el4 = new Element('div', {'class': 'username', 'html': image.user.username, 'onclick':'adduserhash(\''+image.user.username+'\'); removeposthash();'}).inject(itemholder);
				var el5 = new Element('div', {'class': 'name', 'html': ''+image.user.firstname+' '+image.user.lastname+'', 'onclick':'adduserhash(\''+image.user.username+'\'); removeposthash();'}).inject(itemholder);
				
				itemholder.inject($('chatinvitations'));
				
				var myFx = new Fx.Scroll('invitation_content');
				myFx.toTop();

			});
		}else{
			MochaUI.closeWindow($('invitation'));
		}

	};

	// buddy list
	var buddylistfn = function(images) {
		$('chatPanel').empty();
		var altrdiv = 1;
		var totalonline = 0;
		
		var mystatus = 'off';
		if (images.mystatus == 1){
			mystatus = 'on';
		}

		var setstatus = null;
		if (images.mystatus != 1){
			setstatus = 2;
		}else{
			setstatus = 1;
		}

		if (!images.buddies){
				temptitle = new Element('span', {'html':'Chat'});
				$('chatPanel_title').empty();
				temptitle.inject($('chatPanel_title'));
				
				if (thisuserid){
					var itemholder = new Element('div', {'onclick':'MochaUI.invitefrndWindow();'});
					var el = new Element('div', {'class': 'invitefrndbtn','html':'Invite friends [+email]'});
					el.addClass('cursorlinkhover');
					el.inject(itemholder);
					itemholder.inject($('chatPanel'));
					
					if (setstatus == 1){
						tempstatus = new Element('span', {'html':'<button class="statusbtn statusbtn_bck1" title="click to go offline" onclick="chatstatus('+setstatus+')">Online</button>'});
					}else{
						tempstatus = new Element('span', {'html':'<button class="statusbtn statusbtn_bck2" title="click to go online" onclick="chatstatus('+setstatus+')">Offline</button>'});
					}
					
					$('onlineofflinestat').removeClass('displaynone');
					$('onlineofflinestat').empty();
					tempstatus.inject($('onlineofflinestat'));
					

					temptitle = new Element('span', {'html':'<div title="Click to toggle status" onclick="chatstatus('+setstatus+')" class="thisuserstatus_'+mystatus+'"/></div> Chat: '});
					temptitle1 = new Element('span', {'class':'chatbox_online', 'html':totalonline+' contact(s) online'}).inject(temptitle);
					$('chatPanel_title').empty();
					temptitle.inject($('chatPanel_title'));
					
				
				}else{
					var itemholder2 = new Element('div', {'id':'recently_active_off'});
					itemholder2.inject($('chatPanel'));
					activaterecentlyactivefn('recently_active_off');
					temptitle = new Element('span', {'html':'Recently Active Users'});
					$('chatPanel_title').empty();
					temptitle.inject($('chatPanel_title'));
					
					$('onlineofflinestat').addClass('displaynone');
					$('onlineofflinestat').empty();
				}
				
		}else{

					var itemholderemail = new Element('div', {'onclick':'MochaUI.invitefrndWindow();'});
					var elemail = new Element('div', {'class': 'invitefrndbtn','html':'Invite friends [+email]'});
					elemail.addClass('cursorlinkhover');
					elemail.inject(itemholderemail);
					itemholderemail.inject($('chatPanel'));
				
			images.buddies.each(function(image) {
	//			alert(image.user.id);
				
				var statusimage;
				if (image.status == 'offline'){
					newaltr = '_off';
					statusimage = 'bullet_white.png';
				}else{
					newaltr = '';
					statusimage = 'bullet_green.png';
				}

				var userimage;
				if (image.user.image != ''){
					userimage = image_path+'/'+image.user.username+'/thumb_'+image.user.image;
				}else{
					userimage = 'images/default.gif';
				}

				var itemholder = new Element('div', {'class': 'chathldr'});
				var el = new Element('div', {'id':'chathldr_'+image.user.id, 'class': 'chatuser', 'onclick':'MochaUI.chatWindow('+image.user.id+', \''+image.user.username+'\', \''+userimage+'\');'});
				el.addClass ('chatuser'+newaltr+altrdiv);

				if (image.value == 'NaN'){
					el.addClass ('userblocked');
				}

				el.addClass('chatusersel');
				var postusername = new Element('div', {'class':'username', 'html': image.user.username}).inject(el);
				el.inject(itemholder);
				itemholder.inject($('chatPanel'));

				if (altrdiv == 1){
					altrdiv = 2;
				}else{
					altrdiv = 1;
				}

				if(image.status == 'online'){
					totalonline++;
				}

		         var rightclkmenu   = new UI.Menu( 'chathldr_'+image.user.id, { event : 'rightClick' }, { position : [ 'top', 'right' ] } );

		         rightclkmenu.addItem( { id : 'button0_'+image.user.id, label :''+image.user.username+'', icon : 'images/fatcow/'+statusimage+'', styles : { 'font-weight' : 'bold' } } );
				 rightclkmenu.addSeparator();
		         rightclkmenu.addItem( { id : 'button1_'+image.user.id, label :'Chat', icon : 'images/fatcow/comments_add.png', onclick : function() { MochaUI.chatWindow(image.user.id, image.user.username, userimage); } } );

				if (image.value == 'NaN'){
                    rightclkmenu.addItem( { id : 'button2_'+image.user.id, label :'Unblock', icon : 'images/fatcow/lock_open.png', onclick : function() { mod_buddy(image.user.id, 0); } } );
				} else {
                    rightclkmenu.addItem( { id : 'button2_'+image.user.id, label :'Block', icon : 'images/fatcow/lock.png', onclick : function() { mod_buddy(image.user.id, 1); } } );
				}
                    rightclkmenu.addItem( { id : 'button3_'+image.user.id, label :'View posts', icon : 'images/fatcow/page_white_get.png', onclick : function() { adduserhash(image.user.username); } } );



			});
				
				if (setstatus == 1){
					tempstatus = new Element('span', {'html':'<button class="statusbtn statusbtn_bck1" title="click to go offline" onclick="chatstatus('+setstatus+')">Online</button>'});
				}else{
					tempstatus = new Element('span', {'html':'<button class="statusbtn statusbtn_bck2" title="click to go online" onclick="chatstatus('+setstatus+')">Offline</button>'});
				}
				
				$('onlineofflinestat').removeClass('displaynone');
				$('onlineofflinestat').empty();
				tempstatus.inject($('onlineofflinestat'));
				

				temptitle = new Element('span', {'html':'<div title="Click to toggle status" onclick="chatstatus('+setstatus+')" class="thisuserstatus_'+mystatus+'"/></div> Chat: '});
				temptitle1 = new Element('span', {'class':'chatbox_online', 'html':totalonline+' contact(s) online'}).inject(temptitle);
				$('chatPanel_title').empty();
				temptitle.inject($('chatPanel_title'));

		}
		
		
		if (images.myid != thisuserid){
			checksession('nologinbox');
			groupupdate();
			groupupdate('reco-panel');
		}

	};

var chatsession = function(){
	if (thisusername !== null && thisuserid !== null){
		// get buddylist
			groupupdate('chatPanel');
		// get data

		new Request.JSON({url: "getdata/getchat.php", onComplete: function (jsonObj){
			addChat(jsonObj.chatdata);
		}}).send();

	}
};

	// chat values
	var addChat = function(images) {
		if (!images.data){
			chatchktime = chatchktime * 1.1;

			if (chatchktime > maxchatchk){
				chatchktime = maxchatchk;
			}

			$clear(periodicchk);
			periodicchk = chatsession.periodical(chatchktime);
			
		}else{

			chatchktime = minchatchk;

			$clear(periodicchk);
			periodicchk = chatsession.periodical(chatchktime);

			var ncountchat = 1;
			images.data.each(function(image) {
			
				var userimage;
				if (image.user.image != ''){
					userimage = image_path+'/'+image.user.username+'/thumb_'+image.user.image;
				}else{
					userimage = 'images/default.gif';
				}

				if ( !$('chat_'+image.user.id)){
					MochaUI.chatWindow(image.user.id, image.user.username, userimage);
				}

				var itemholder = new Element('div', {'class':'chatdisplay'});

				var thismsg = wordwrap(image.chatvalue.text, 40);
				var el = new Element('div', {'html': '<b>'+image.user.username+'</b> says: '+ replaceurl(thismsg)}).inject(itemholder);
				itemholder.inject($('chat_'+image.user.id+'_content'));
				
				if (ncountchat == images.data.length){
						// correct time ------
						var lasttime = new Date().format('db');
						var temptime2 = new Date().parse(image.chatvalue.date);
						var timezoneoff = -1*temptime2.getTimezoneOffset();
						temptime2 = temptime2.increment('minute', timezoneoff);

						var timetodisplay = temptime2.format('%Y-%m-%d %I:%M%p');
						var temptime1 = new Date().parse(lasttime);
						var timediff = temptime2.diff(temptime1, 'minute');

						if (timediff > 3){
							var eldate = new Element('div', {'class':'lastmessage', 'html': 'Sent at '+timetodisplay}).inject($('chat_'+image.user.id+'_content'));
						}
						//----------
				
				}
				
					var myFx = new Fx.Scroll('chat_'+image.user.id+'_contentWrapper');
					myFx.toBottom();

					$clear(periodichighlight[image.user.id]);
					periodichighlight[image.user.id] = (function(){$('chat_'+image.user.id+'_dockTabText').highlight('#877d6a', '#474032');}).periodical(1000);

				ncountchat++;
			});

		}
	};


var add_comment = function (itemid){
	$('writecomment').readOnly = true;
	$('writecomment').addClass('freezetext');
	var comment_txt = encodeURIComponent($('writecomment').value);
	new Request.JSON({url: "writedata/write_comment.php?itemid="+itemid+"&comment_txt="+comment_txt, onComplete: function (dataset){
		groupupdate('mainPanel');
	}}).send();
};

var add_share_att = function (sharemsg, shareurl, sharetitle, sharedesc){
	var share_txt = encodeURIComponent(sharemsg);
	var share_url = encodeURIComponent(shareurl);
	var share_title = encodeURIComponent(sharetitle);
	var share_desc = encodeURIComponent(sharedesc);

				new Request.JSON({url: "writedata/write_share.php?share_txt="+share_txt+"&att=1&url="+share_url+"&url_title="+share_title+"&url_desc="+share_desc, onComplete: function (dataset){
					if (dataset.add_share == 1){
						MochaUI.closeWindow($('share'));
						if (document.location.hash.match(/user:/)){
							removeuserhash();
						}
						adduserhash(thisusername);
						addhash('new');
						removeposthash();
						$('shareinfo_missingbtn').fade('in');
					}else{
						$('shareinfo_missingbtn').fade('in');
						MochaUI.notification('Invalid Input.');
					}
				}}).send();
};

var add_share = function (dowhat, sharemsg, shareurl){
	var share_txt = encodeURIComponent(sharemsg);
	var share_url = encodeURIComponent(shareurl);

	if (dowhat === 0){
		new Request.JSON({url: "writedata/write_share.php?share_txt="+share_txt, onComplete: function (dataset){

		if (dataset.add_share == 1){
			MochaUI.closeWindow($('share'));
			if (document.location.hash.match(/user:/)){
				removeuserhash();
			}
			adduserhash(thisusername);
			addhash('new');
			removeposthash();
		}else{
			MochaUI.notification('Invalid Input.');
			$('share_main_btns').fade(1);
		}
		}}).send();
	}

	if (dowhat == 1){
		new Request.JSON({url: "getdata/geturl.php?url="+share_url, onComplete: function (dataset){
		
			if (dataset.att_url.error == 'none'){
				MochaUI.notification('Still Working...');

				add_share_att(sharemsg, shareurl);

			}else if(dataset.att_url.error == 'invalid_title_desc' || dataset.att_url.error == 'invalid_title' || dataset.att_url.error == 'invalid_desc'){
				MochaUI.notification('Information Missing');
				$('share_missing_btns').removeClass('displaynone');
				
				if (dataset.att_url.error == 'invalid_title_desc' || dataset.att_url.error == 'invalid_title'){
					$('shareurlinput_missing').removeClass('displaynone');
				}
				
				if (dataset.att_url.error == 'invalid_title_desc' || dataset.att_url.error == 'invalid_desc'){
					$('sharetextarea_missing').removeClass('displaynone');
				}
				
				$('share_main_btns').addClass('displaynone');
				$('shareurlinput').readOnly = true;
				$('shareurlinput').fade(0.5);
			}else{
				MochaUI.notification('Invalid Url');
				$('share_main_btns').fade(1);
			}
		}}).send();
	}
};

var sendmsg = function (receiverid, msg){

	chatchktime = minchatchk;
		$clear(periodicchk);
		periodicchk = chatsession.periodical(chatchktime);

	msg = encodeURIComponent(msg);
	new Request.JSON({url: "writedata/write_chat.php?chatto="+receiverid+"&msg="+msg, onComplete: function (dataset){
		
		var thismsg;
		var myFx;
		if (dataset.sentmsg.sent_ok == 1 || dataset.sentmsg.sent_ok == 2){

			thismsg = wordwrap(dataset.sentmsg.chatmsg, 40);

			var itemholder = new Element('div', {'class':'chatdisplay'});
			var el = new Element('div', {'html': '<b>me</b>: '+ replaceurl(thismsg)}).inject(itemholder);
			itemholder.inject($('chat_'+receiverid+'_content'));

				myFx = new Fx.Scroll('chat_'+receiverid+'_contentWrapper');
				myFx.toBottom();
		}else if(dataset.sentmsg.sent_ok == 3){

			thismsg = wordwrap(dataset.sentmsg.chatmsg, 40);

			var itemholder1 = new Element('div', {'class':'chatdisplay'});
			var el1 = new Element('div', {'html': '<b>me</b>: '+ replaceurl(thismsg)}).inject(itemholder1);
			var unblk = new Element('div', {'class':'lastmessage', 'html': 'Message not sent. You must <b><span class="userunblock" onclick="mod_buddy('+receiverid+',0)">unblock</span></b> the user first.'}).inject(itemholder1);
			itemholder1.inject($('chat_'+receiverid+'_content'));

				myFx = new Fx.Scroll('chat_'+receiverid+'_contentWrapper');
				myFx.toBottom();
		}

	}}).send();
};

var chatstatus = function(var1){
		chatchktime = minchatchk;
		new Request.JSON({url: "writedata/write_status.php?dowhat="+var1, onComplete: function (dataset){
			groupupdate('chatPanel');
		}}).send();
};

var changeprofile = function(var01, var02, var03, var04, var05){
	var var1 = encodeURIComponent(var01);
	var var2 = encodeURIComponent(var02);
	var var3 = encodeURIComponent(var03);
	var var4 = encodeURIComponent(var04);
	var var5 = encodeURIComponent(var05);
	
		new Request.JSON({url: "writedata/write_profile.php?name="+var1+"&birthday="+var2+"&gender="+var3+"&hometown="+var4+"&aboutme="+var5, onComplete: function (dataset){
			if (dataset.profile_change.status == 1){
				$('prochangedone').removeClass('displaynone');
				$('profile_name').removeClass('wrongpass');
				$('datepickertxt').removeClass('wrongpass');
			}else{
				$('prochangedone').addClass('displaynone');
				$('profile_name').removeClass('wrongpass');
				$('datepickertxt').removeClass('wrongpass');
				
				if (dataset.profile_change.error.name){
					$('profile_name').addClass('wrongpass');
				}
				
				if (dataset.profile_change.error.bday){
					$('datepickertxt').addClass('wrongpass');
				}
				
				var myFx = new Fx.Scroll('settingsWindow_contentWrapper');
				myFx.toTop();
			}
		}}).send();
};

var registeruser = function(var01, var02, var03, var04, var05, var06, var07){
	var var1 = encodeURIComponent(var01);
	var var2 = encodeURIComponent(var02);
	var var3 = encodeURIComponent(var03);
	var var4 = encodeURIComponent(var04);
	var var5 = encodeURIComponent(var05);
	var var6 = encodeURIComponent(var06);
	var var7 = encodeURIComponent(var07);
	$('register_submit').fade('out');
	
		new Request.JSON({url: "writedata/write_register.php?username="+var1+"&name="+var2+"&email="+var3+"&password="+var4+"&cpassword="+var5+"&gender="+var6+"&captcha="+var7, onComplete: function (dataset){

				$('register_username').removeClass('wrongpass');
				$('register_fullname').removeClass('wrongpass');
				$('register_email').removeClass('wrongpass');
				$('register_password').removeClass('wrongpass');
				$('register_password_c').removeClass('wrongpass');
				$('captcha_input').removeClass('wrongpass');
				$('register_submit').fade('in');
				
			if (dataset.profile_change.status == 1){
				MochaUI.closeWindow($('register'));
				MochaUI.notification('please login now');
				MochaUI.loginWindow();
			}else{
			
				document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date();
			
				if (dataset.profile_change.error.username){
					$('register_username').addClass('wrongpass');
				}
				
				if (dataset.profile_change.error.name){
					$('register_fullname').addClass('wrongpass');
				}
				
				if (dataset.profile_change.error.email){
					$('register_email').addClass('wrongpass');
				}
				
				if (dataset.profile_change.error.password){
					$('register_password').addClass('wrongpass');
				}
				
				if (dataset.profile_change.error.cpassword){
					$('register_password_c').addClass('wrongpass');
				}
				
				if (dataset.profile_change.error.captcha){
					$('captcha_input').addClass('wrongpass');
				}
			}
			
		}}).send();
};

var changepass = function(oldpass, newpass, newpass1){
		new Request.JSON({url: "writedata/write_newpass.php?oldpass="+oldpass+"&newpass="+newpass+"&newpass1="+newpass1+"", onComplete: function (dataset){
			if(dataset.pass_mod == 1){
				$('passchangedone').removeClass('displaynone');
				$('newpassvalue1').removeClass('wrongpass');
				$('oldpassvalue').removeClass('wrongpass');
				
			}else if(dataset.pass_mod == 2){
			
				$('passchangedone').addClass('displaynone');
				$('newpassvalue1').addClass('wrongpass');
				$('oldpassvalue').removeClass('wrongpass');
				
			}else if(dataset.pass_mod == 3){
			
				$('passchangedone').addClass('displaynone');
				
				$('newpassvalue1').removeClass('wrongpass');
				$('oldpassvalue').addClass('wrongpass');
				
			}else{
				$('passchangedone').addClass('displaynone');
				$('newpassvalue1').removeClass('wrongpass');
				$('oldpassvalue').removeClass('wrongpass');
			}
			
		}}).send();
};

var logoutfn = function (){
		new Request.JSON({url: "login/logout.php", onComplete: function (dataset){
			checksession('nologinbox');
			groupupdate();
			groupupdate('reco-panel');
			uniknotionstitle = 'Uniknotions | Easiest Way to Share';
			MochaUI.closeAll();
		}}).send();
};

if (top !== self){top.location.href = self.location.href;}
//addhash('pop');

