//-- init

initializeWindows = function(){

	// Examples
	MochaUI.ajaxpageWindow = function(){
		new MochaUI.Window({
			id: 'ajaxpage',
			loadMethod: 'xhr',
			contentURL: 'pages/lipsum.html',
			width: 340,
			height: 150
		});
	}	
	if ($('ajaxpageLinkCheck')){ 
		$('ajaxpageLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.ajaxpageWindow();
		});
	}	
	
	MochaUI.jsonWindows = function(){
		var url = 'data/json-windows-data.js';
		var request = new Request.JSON({
			url: url,
			method: 'get',
			onComplete: function(properties) {
				MochaUI.newWindowsFromJSON(properties.windows);
			}
		}).send();
	}	
	if ($('jsonLink')){
		$('jsonLink').addEvent('click', function(e) {
			new Event(e).stop();
			MochaUI.jsonWindows();
		});
	}

	MochaUI.uniktvWindow = function(geturl, newwin, wintitle){
		if (typeof(geturl) == 'undefined'){
			url = '';
		}else{
			url = encodeURIComponent(geturl);
		}
		if (newwin != 'default'){
			var addwinid = newwin;
		}else{
			defaultwin++;
			var addwinid = '_'+newwin+defaultwin;
		}
		
		if (wintitle == null){
			wintitle = 'Uniknotions Video';
		}else{
			wintitle = wintitle;
		}
		new MochaUI.Window({
			id: 'uniktv' + addwinid,
			title: wintitle,
			loadMethod: 'iframe',
			contentURL: 'pages/videoshow.php',
			width: 340,
			height: 280,
			resizeLimit: {'x': [330, 2500], 'y': [250, 2000]},
			toolbar: true,
			toolbarURL: 'pages/videobox.php?v='+url+'&winid='+addwinid,
			contentBgColor: '#000',
			onMinimize: function(){
				$('uniktv'+addwinid+'_spinner').addClass('displaynone');
			},
			onRestore: function(){
				$('uniktv'+addwinid+'_spinner').removeClass('displaynone');
			}
		});
	}
	if ($('videobrowse')) {
		$('videobrowse').addEvent('click', function(e){
		new Event(e).stop();
		var temp = '';
		var newwin = 'default';
			MochaUI.uniktvWindow(temp,newwin);
		});
	}

	MochaUI.slideshareWindow = function(){
		new MochaUI.Window({
			id: 'slideshare',
			title: 'Slideshare in Iframe',
			loadMethod: 'iframe',
			contentURL: 'pages/slideshare.html',
			width: 415,
			height: 355,
			resizeLimit:  {'x': [330, 2500], 'y': [250, 2000]},
			contentBgColor: '#000'
		});
	}
	if ($('slideshareLinkCheck')) {
		$('slideshareLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.slideshareWindow();
		});
	}
	
	MochaUI.parametricsWindow = function(){	
		new MochaUI.Window({
			id: 'parametrics',
			title: 'Window Parametrics',
			loadMethod: 'xhr',
			contentURL: 'plugins/parametrics/index.html',
			onContentLoaded: function(){
				if ( !MochaUI.parametricsScript == true ){
					new Request({
						url: 'plugins/parametrics/scripts/parametrics.js',
						method: 'get',
						onSuccess: function() {
							MochaUI.addRadiusSlider.delay(10); // Delay is for IE6
							MochaUI.addShadowSlider.delay(10); // Delay is for IE6
							MochaUI.parametricsScript = true;
						}.bind(this)
					}).send();
				}
				else {
					MochaUI.addRadiusSlider.delay(10); // Delay is for IE6
					MochaUI.addShadowSlider.delay(10); // Delay is for IE6
				}
			},
			width: 305,
			height: 110,
			x: 570,
			y: 160,
			padding: { top: 12, right: 12, bottom: 10, left: 12 },
			resizable: false,
			maximizable: false,
			contentBgColor: '#fff'
		});
	}
	if ($('parametricsLinkCheck')){
		$('parametricsLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.parametricsWindow();
		});
	}	

	MochaUI.clockWindow = function(){
		new MochaUI.Window({
			id: 'clock',
			title: 'Canvas Clock',
			addClass: 'transparent',
			loadMethod: 'xhr',
			contentURL: 'plugins/coolclock/index.html?t=' + new Date().getTime(),
			onContentLoaded: function(){
				if ( !MochaUI.clockScript == true ){
					new Request({
						url: 'plugins/coolclock/scripts/coolclock.js?t=' + new Date().getTime(),
						method: 'get',
						onSuccess: function() {
							if (Browser.Engine.trident) {
								myClockInit = function(){
									CoolClock.findAndCreateClocks();
								};
								window.addEvent('domready', function(){
									myClockInit.delay(10); // Delay is for IE
								});
								MochaUI.clockScript = true;
							}
							else {
								CoolClock.findAndCreateClocks();
							}
						}.bind(this)
					}).send();
				}
				else {
					if (Browser.Engine.trident) {
						myClockInit = function(){
							CoolClock.findAndCreateClocks();
						};
						window.addEvent('domready', function(){
							myClockInit.delay(10); // Delay is for IE
						});
						MochaUI.clockScript = true;
					}
					else {
						CoolClock.findAndCreateClocks();
					}
				}
			},
			shape: 'gauge',
			headerHeight: 30,
			width: 160,
			height: 160,
			x: 570,
			y: 140,
			padding: { top: 0, right: 0, bottom: 0, left: 0 },
			bodyBgColor: [250,250,250]
		});	
	}
	if ($('clockLinkCheck')){
		$('clockLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.clockWindow();
		});
	}

	// Examples > Tests
	MochaUI.eventsWindow = function(){
		new MochaUI.Window({
			id: 'windowevents',
			title: 'Window Events',
			loadMethod: 'xhr',
			contentURL: 'pages/events.html',
			onContentLoaded: function(windowEl){
				MochaUI.notification('Window content was loaded.');
			},
			onCloseComplete: function(){
				MochaUI.notification('The window is closed.');
			},
			onMinimize: function(windowEl){
				MochaUI.notification('Window was minimized.');
			},
			onMaximize: function(windowEl){
				MochaUI.notification('Window was maximized.');
			},
			onRestore: function(windowEl){
				MochaUI.notification('Window was restored.');
			},
			onResize: function(windowEl){
				MochaUI.notification('Window was resized.');
			},
			onFocus: function(windowEl){
				MochaUI.notification('Window was focused.');
			},
			onBlur: function(windowEl){
				MochaUI.notification('Window lost focus.');
			},
			width: 340,
			height: 250
		});
	}	
	if ($('windoweventsLinkCheck')){
		$('windoweventsLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.eventsWindow();
		});
	}
	
	MochaUI.containertestWindow = function(){ 
		new MochaUI.Window({
			id: 'containertest',
			title: 'Container Test',
			loadMethod: 'xhr',
			contentURL: 'pages/lipsum.html',
			container: 'pageWrapper',
			width: 340,
			height: 150,
			x: 100,
			y: 100
		});
	}
	if ($('containertestLinkCheck')){ 
		$('containertestLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.containertestWindow();
		});
	}
	
	MochaUI.iframetestWindow = function(){
		new MochaUI.Window({
			id: 'iframetest',
			title: 'Iframe Tests',
			loadMethod: 'iframe',
			contentURL: 'pages/iframetest.html'
		});
	}
	if ($('iframetestLinkCheck')) {
		$('iframetestLinkCheck').addEvent('click', function(e){
		new Event(e).stop();
			MochaUI.iframetestWindow();
		});
	}

	MochaUI.accordiantestWindow = function(){
		var id = 'settingsWindow';
		new MochaUI.Window({
			id: id,
			title: 'Settings',
			loadMethod: 'xhr',
			contentURL: 'pages/settings.php',
			width: 470,
			height: 300,
			resizable: false,
			maximizable: false,				
			padding: { top: 10, right: 10, bottom: 10, left: 10 }
		});
	}	

/*	if ($('accordiantestLinkCheck')){ 
		$('accordiantestLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.accordiantestWindow();
		});
	}
*/
	MochaUI.noCanvasWindow = function(){
		new MochaUI.Window({
			id: 'nocanvas',
			title: 'No Canvas',
			loadMethod: 'xhr',
			contentURL: 'pages/lipsum.html',
			addClass: 'no-canvas',
			width: 305,
			height: 175,
			shadowBlur: 0,
			resizeLimit: {'x': [275, 2500], 'y': [125, 2000]},
			useCanvas: false
		});
	}
	if ($('noCanvasLinkCheck')){
		$('noCanvasLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.noCanvasWindow();
		});
	}

	// View
	if ($('sidebarLinkCheck')){
		$('sidebarLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.Desktop.sidebarToggle();
		});
	}

	if ($('cascadeLink')){
		$('cascadeLink').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.arrangeCascade();
		});
	}

	if ($('tileLink')){
		$('tileLink').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.arrangeTile();
		});
	}

	if ($('closeLink')){
		$('closeLink').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.closeAll();
		});
	}

	if ($('minimizeLink')){
		$('minimizeLink').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.minimizeAll();
		});
	}	

	// Tools
	MochaUI.builderWindow = function(){	
		new MochaUI.Window({
			id: 'builder',
			title: 'Window Builder',
			icon: 'images/icons/page.gif',
			loadMethod: 'xhr',
			contentURL: 'plugins/windowform/',
			onContentLoaded: function(){
				if ( !MochaUI.windowformScript == true ){
					new Request({
						url: 'plugins/windowform/scripts/Window-from-form.js',
						method: 'get',
						onSuccess: function() {
							$('newWindowSubmit').addEvent('click', function(e){
								new Event(e).stop();
								new MochaUI.WindowForm();
							});
							MochaUI.windowformScript = true;
						}.bind(this)
					}).send();
				}
			},
			width: 370,
			height: 410,
			maximizable: false,
			resizable: false,
			scrollbars: false
		});
	}
	if ($('builderLinkCheck')){
		$('builderLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.builderWindow();
		});
	}
	
	// Todo: Add menu check mark functionality for workspaces.
	
	// Workspaces
	
	if ($('saveWorkspaceLink')){
		$('saveWorkspaceLink').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.saveWorkspace();
		});
	}

	if ($('loadWorkspaceLink')){
		$('loadWorkspaceLink').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.loadWorkspace();
		});
	}

	// Help	
	MochaUI.featuresWindow = function(){
		new MochaUI.Window({
			id: 'features',
			title: 'Help Content',
			loadMethod: 'xhr',
			contentURL: 'pages/features-layout.php',
			width: 305,
			height: 175,
			resizeLimit: {'x': [275, 2500], 'y': [125, 2000]},
			toolbar: true,
			toolbarURL: 'pages/features-tabs.php'
		});
	}
	if ($('featuresLinkCheck')){
		$('featuresLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.featuresWindow();
		});
	}

	MochaUI.faqWindow = function(){
			new MochaUI.Window({
				id: 'faq',
				title: 'FAQ',
				loadMethod: 'xhr',
				contentURL: 'pages/faq.html',
				width: 750,
				height: 350
			});
	}
	if ($('faqLinkCheck')){
		$('faqLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.faqWindow();
		});
	}

	MochaUI.docsWindow = function(){
			new MochaUI.Window({
				id: 'docs',
				title: 'Documentation',
				loadMethod: 'xhr',
				contentURL: 'pages/docs.html',
				width: 750,
				height: 350,
				padding: [10,10,10,10,10]
			});
	}
	if ($('docsLinkCheck')){
		$('docsLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.docsWindow();
		});
	}

	MochaUI.resourcesWindow = function(){
			new MochaUI.Window({
				id: 'resources',
				title: 'Resources',
				loadMethod: 'xhr',
				contentURL: 'pages/resources.html',
				width: 300,
				height: 275,
				x: 20,
				y: 90 
			});
	}
	if ($('resourcesLinkCheck')){
		$('resourcesLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.resourcesWindow();
		});
	}

	MochaUI.helpWindow = function(){
			new MochaUI.Window({
				id: 'help',
				title: 'Support',
				loadMethod: 'xhr',
				contentURL: 'pages/support.html',
				width: 320,
				height: 320,
				x: 20,
				y: 90 
			});
	}
	if ($('helpLinkCheck')){
		$('helpLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.helpWindow();
		});
	}	

	MochaUI.contributeWindow = function(){
		new MochaUI.Window({
			id: 'contribute',
			title: 'Contribute',
			loadMethod: 'xhr',
			contentURL: 'pages/contribute.html',
			width: 320,
			height: 320,
			x: 20,
			y: 90 
		});
	}
	if ($('contributeLinkCheck')){
		$('contributeLinkCheck').addEvent('click', function(e){	
			new Event(e).stop();
			MochaUI.contributeWindow();
		});
	}

	MochaUI.aboutWindow = function(){
		new MochaUI.Window({
			id: 'about',
			title: 'About',
			loadMethod: 'xhr',
			contentURL: 'pages/about.php',
			type: 'modal2',
			width: 350,
			height: 195,
			contentBgColor: '#e5e5e5',
			padding: { top: 30, right: 12, bottom: 10, left: 12 },
			scrollbars:  false
		});
	}
	if ($('aboutLink')){
		$('aboutLink').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.aboutWindow();
		});
	}

	MochaUI.loginWindow = function(){
		new MochaUI.Window({
			id: 'login',
			title: 'Login',
			loadMethod: 'xhr',
			contentURL: 'login/login.php',
			type: 'modal2',
			width: 300,
			height: 225,
			contentBgColor: '#f5f5f5',
			padding: { top: 12, right: 12, bottom: 12, left: 12 },
			scrollbars:  false
		});
	}
	
	MochaUI.invitefrndWindow = function(){
		new MochaUI.Window({
			id: 'invitefrnd',
			title: 'invitefrnd',
			//loadMethod: 'xhr',
			content: '<div class="invitefrnd"><b>Invite Friend:</b> Enter your friend\'s email address: <br/><input id="invitefriendinput" class="loginvarsinput"/><button onclick="mod_buddy(\'\', 0, 2, $(\'invitefriendinput\').value);" class="loginvarssubmit">Invite</button></div>',
			type: 'modal2',
			width: 220,
			height: 200,
			contentBgColor: '#f5f5f5',
			padding: { top: 20, right: 12, bottom: 12, left: 12 },
			scrollbars:  false
		});
	}
	
	//MochaUI.invitefrndWindow();
	
	MochaUI.registerWindow = function(){
		new MochaUI.Window({
			id: 'register',
			title: 'register',
			loadMethod: 'xhr',
			contentURL: 'writedata/register.php',
			type: 'modal2',
			width: 300,
			height: 410,
			contentBgColor: '#f5f5f5',
			padding: { top: 12, right: 12, bottom: 12, left: 12 },
			scrollbars:  false
		});
	}

	MochaUI.shareWindow = function(url){
		new MochaUI.Window({
			id: 'share',
			title: 'Share',
			//loadMethod: 'xhr',
			//contentURL: 'login/login.php',
			content: '<div id="sharebox"><textarea id="sharetextarea" maxlength="2000" onKeyUp="return ismaxlength(this);"></textarea><div id="attachalink">Url: </div><input id="shareurlinput" value="'+url+'"/><br/><div id="share_main_btns"><button onclick="add_share(1,$(\'sharetextarea\').value, $(\'shareurlinput\').value); $(\'share_main_btns\').fade(0);">Share (with link)</button><button onclick="add_share(0,$(\'sharetextarea\').value); $(\'share_main_btns\').fade(0);">Share (no link)</button></div><div id="share_missing_btns" class="displaynone"><input id="shareurlinput_missing" value="Please add a title here." onClick="if(this.value == \'Please add a title here.\'){this.value = \'\';}" class="displaynone" maxlength="75"/><br/><textarea class="displaynone" id="sharetextarea_missing" onClick="if(this.value == \'We were not able to retrieve description for your url. Please add some description here.\'){this.value = \'\';}" maxlength="200" onKeyUp="return ismaxlength(this);">We were not able to retrieve description for your url. Please add some description here.</textarea><button id="shareinfo_missingbtn" onclick="add_share_att($(\'sharetextarea\').value, $(\'shareurlinput\').value, $(\'shareurlinput_missing\').value, $(\'sharetextarea_missing\').value); this.fade(0);">Share</button></div></div>',
			width: 315,
			height: 225,
			resizable: false,
			maximizable: false
		});
	}

	if ($('filemenushare')){
		$('filemenushare').addEvent('click', function(e){
			new Event(e).stop();
			checksession('share','http://');
		});
	}

	MochaUI.chatWindow = function(buddyid, buddyusername, buddyimage){

		posx = 250;
		posy = 150;

		chatwinpos = Math.floor(Math.random()*101);

		new MochaUI.Window({
			id: 'chat_'+buddyid,
			title: buddyusername,
			//loadMethod: 'xhr',
			//contentURL: 'login/login.php',
			content: '<div id="chat_maincontent'+buddyid+'"></div>',
			width: 300,
			height: 225,
			x: posx + chatwinpos,
			y: posy + chatwinpos,
			toolbar: true,
//			toolbarURL: 'pages/features-tabs.html',
			toolbarHeight: 70,
			toolbarContent: '<div onClick="$clear(periodichighlight['+buddyid+']);" class="typechat" id="typechat_'+buddyid+'"><textarea maxlength="1000" wrap="SOFT" onKeyUp="$clear(periodichighlight['+buddyid+']); if(event.keyCode == 13){sendmsg('+buddyid+',this.value); this.value = \'\';} return ismaxlength(this);" name="chattypetext_'+buddyid+'" id="chattypearea"></textarea><div class="chatsendimg"><img src="'+buddyimage+'"/></div></div>',
			toolbarPosition: 'bottom',
			resizable: false,
			maximizable: false,
			onFocus: function(){
				$clear(periodichighlight[buddyid]);
			}
		});
		chatwinpos = chatwinpos+30;
	}

	//MochaUI.chatWindow(19, 'harkedai');

	MochaUI.browserWindow = function(url, id){

		if (id != 'default'){
			id = id;
		}else{
			defaultwin++;
			id = '_'+id+defaultwin;
		}
		new MochaUI.Window({
			id: 'browser'+id,
			title: 'Uniknotions',
			loadMethod: 'iframe',
			contentURL: 'pages/browsepageinit.php',
			width: 500,
			height: 350,
			toolbar: true,
			toolbarURL : 'pages/browsepage.php?winid='+id+'&page='+encodeURIComponent(url),
			resizeLimit: {'x': [300, 2500], 'y': [300, 2000]},
			onMinimize: function(){
				$('browser'+id+'_spinner').addClass('displaynone');
			},
			onRestore: function(){
				$('browser'+id+'_spinner').removeClass('displaynone');
			}
		});
	}
	if ($('pagebrowse')){
		$('pagebrowse').addEvent('click', function(e){
			new Event(e).stop();
			MochaUI.browserWindow('','default');
		});
	}


	MochaUI.invitationWindow = function(){
		new MochaUI.Window({
			id: 'invitation',
			title: 'Invitations',
			//loadMethod: 'xhr',
			content: 'Following user(s) want to add you to their chat list. You can accept or decline the request(s). If you wish to decline, the user will NOT be informed. <div id="chatinvitations" class="chat_invitations">    <div class="invitation"> <div class="decline">Decline</div> <div class="accept">Accept</div> <div class="username">kurbsdude</div> <div class="name">Kurbs Dude</div> </div>      <div class="invitation"> <div class="decline">Decline</div> <div class="accept">Accept</div> <div class="username">kurbsdude</div> <div class="name">Kurbs Dude</div> </div>   </div>',
			//type: 'modal2',
			width: 350,
			height: 195,
			//contentBgColor: '#e5e5e5 url(images/logo2.gif) left 3px no-repeat',
			//padding: { top: 43, right: 12, bottom: 10, left: 12 },
			//scrollbars:  false,
			onContentLoaded: function(){

			}
		});
		$('chatinvitations').empty();
	}
	
	//MochaUI.invitationWindow();

	shortcut.add("Ctrl+N",function() {
			MochaUI.browserWindow('','default');
	});
	shortcut.add("Ctrl+T",function() {
			MochaUI.uniktvWindow('','default');
	});


	// Deactivate menu header links
	$$('a.returnFalse').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop();
		});
	});
	
	// Build windows onDomReady
	//MochaUI.parametricsWindow();
}

// Initialize MochaUI when the DOM is ready
window.addEvent('domready', function(){
document.oncontextmenu  = function() { return false; };
	MochaUI.Desktop = new MochaUI.Desktop();
	MochaUI.Dock = new MochaUI.Dock();

	/* Create Columns
	 
	If you are not using panels then these columns are not required.
	If you do use panels, the main column is required. The side columns are optional.
	Create your columns from left to right. Then create your panels from top to bottom,
	left to right. New Panels are inserted at the bottom of their column.

	*/	 
	new MochaUI.Column({
		id: 'sideColumn1',
		placement: 'left',
		width: 185,
		resizeLimit: [185, 185]
	});

	new MochaUI.Column({
		id: 'mainColumn',
		placement: 'main',	
		width: null,
		resizeLimit: [100, 300]
	});

	new MochaUI.Column({
		id: 'sideColumn2',
		placement: 'right',	
		width: 225,		
		resizeLimit: [225, 225]
	});

	// Add panels to first side column
	new MochaUI.Panel({
		id: 'following-panel',
		title: 'You\'re following',
		content: '<img src="images/loading.gif">',
		column: 'sideColumn1',
		panelBackground: '#f8f8f8 url(images/unikchar1.png) bottom left no-repeat',
		//height: 80,
		onContentLoaded: function(){
			$('spinner').setStyle('visibility','visible');
			var request = new Request.JSON({
				url: 'getdata/following.php',
				onComplete: function(jsonObj){
					followingfn(jsonObj.followers);
					$('spinner').setStyle('visibility','hidden');
				}
			}).send();
		}
	});


	new MochaUI.Panel({
		id: 'chatPanel',
		title: 'Chat',
		//loadMethod: 'xhr',
		//contentURL: 'pages/overview.html',
		content: '<img src="images/loading.gif">',
		column: 'sideColumn1',
		height: 180,
		onContentLoaded: function(){
			//$('spinner').setStyle('visibility','visible');
			var request = new Request.JSON({
				url: 'getdata/getchatlist.php',
				onComplete: function(jsonObj){
					buddylistfn(jsonObj.chatlist);
			//		$('spinner').setStyle('visibility','hidden');
				}
			}).send();
		}
	});


	// Add panels to main column	
	new MochaUI.Panel({
		id: 'mainPanel',
		title: 'Posts | Sorted by Popularity | Browsing All',
		//loadMethod: 'xhr',
		//contentURL: 'getdata/posts.php',
		content: '<img src="images/loading.gif">',
		collapseExpandPanel: false,
		column: 'mainColumn',
		onContentLoaded: function(){
		if (firsttimechk == 1){
			$('spinner').setStyle('visibility','visible');
			var request = new Request.JSON({
				url: 'getdata/'+postidtrue+'.php?type='+sortbytype+'&pagenumber='+pagenum+'&rel='+sortbyrel+'&user='+userhashname+'&itemid='+postitemid+'&filter='+encodeURIComponent(filtertext),
				onComplete: function(jsonObj){
				
							if (sortbyrel == 1){
								sortby = 'Date';
								$('filternew').addClass('filterbtnactive');
								$('filterpop').removeClass('filterbtnactive');
							}else{
								sortby = 'Popularity';
								$('filterpop').addClass('filterbtnactive');
								$('filternew').removeClass('filterbtnactive');
							}

							if (sortbytype == 1){
								sortbyt = 'Links';
								$('filterlinks').addClass('filterbtnactive');
								$('filtervid').removeClass('filterbtnactive');
								$('filterpic').removeClass('filterbtnactive');
								$('filterall').removeClass('filterbtnactive');

							} else if (sortbytype == 2){
								sortbyt = 'Videos';
								$('filtervid').addClass('filterbtnactive');
								$('filterlinks').removeClass('filterbtnactive');
								$('filterpic').removeClass('filterbtnactive');
								$('filterall').removeClass('filterbtnactive');
							} else if (sortbytype == 3){
								sortbyt = 'Photos';
								$('filterpic').addClass('filterbtnactive');
								$('filtervid').removeClass('filterbtnactive');
								$('filterlinks').removeClass('filterbtnactive');
								$('filterall').removeClass('filterbtnactive');
							} else {
								sortbyt = 'All';
								$('filterall').addClass('filterbtnactive');
								$('filtervid').removeClass('filterbtnactive');
								$('filterpic').removeClass('filterbtnactive');
								$('filterlinks').removeClass('filterbtnactive');
							}
							
							
					if (postidtrue == 'getpost'){
						addPOST(jsonObj.posts);
					}else{
						addPosts(jsonObj.posts);
					}
					$('spinner').setStyle('visibility','hidden');
				}
			}).send();
		}
		}
		//height: 200,
		//panelBackground: '#fff'
	});


	new MochaUI.Panel({
		id: 'panel1',
		title: '<button id="filterpop" class="filterpostsbtn" onclick="addhash(\'pop\');">Popular</button><button id="filternew" class="filterpostsbtn morepostsbtn1" onclick="addhash(\'new\');">New</button><button id="filterall" class="filterpostsbtn morepostsbtn5" onclick="addhash(\'all\');">All</button><button id="filterlinks" class="filterpostsbtn morepostsbtn1" onclick="addhash(\'link\');">Links</button><button id="filtervid" class="filterpostsbtn morepostsbtn1" onclick="addhash(\'vid\');">Videos</button><button id="filterpic" class="filterpostsbtn morepostsbtn1" onclick="addhash(\'pic\');">Photos</button><button class="filterpostsbtn morepostsbtn40" onclick="addhash(\'newer\');">&laquo;</button><button class="filterpostsbtn morepostsbtn1" onclick="addhash(\'older\');">&raquo;</button>',
		//loadMethod: 'xhr',
		//contentURL: '',
		content: '',
		column: 'mainColumn',
		collapseExpandPanel: false,
		height: 0
	});

	// Add panels to second side column
	
	new MochaUI.Panel({
		id: 'help-panel',
		title: '<img style="width: 12px; height: 12px;" src="images/fatcow/add.png"/> Quick List',
		//loadMethod: 'xhr',
		//contentURL: 'pages/overview.html',
		content: '<img src="images/loading.gif">',
		column: 'sideColumn2',
		//tabsURL: 'pages/panel-tabs.php',
		onContentLoaded: function(){
			$('spinner').setStyle('visibility','visible');
			var request = new Request.JSON({
				url: 'getdata/quicklist.php',
				onComplete: function(jsonObj){
					quickList(jsonObj.quicklist);
					$('spinner').setStyle('visibility','hidden');
				}
			}).send();
		}
	});

	new MochaUI.Panel({
		id: 'reco-panel',
		title: 'Uniknotions Stream',
		//loadMethod: 'xhr',
		//contentURL: 'pages/overview.html',
		content: '<img src="images/loading.gif">',
		column: 'sideColumn2',
		//tabsURL: 'pages/panel-tabs.php',
		height: 180
	});
	groupupdate('reco-panel');
	var updatestream = function(){
		groupupdate('reco-panel');
	}
			var streamupdate;
			$clear(streamupdate);
			streamupdate = updatestream.periodical(480000);

	new MochaUI.Panel({
		id: 'followers-panel',
		title: 'Followers',
		content: '<img src="images/loading.gif">',
		column: 'sideColumn2',
		height: 50,
		//footer: true,
		//footerURL: 'pages/toolbox-demo.html',
		onContentLoaded: function(){
			$('spinner').setStyle('visibility','visible');
			var request = new Request.JSON({
				url: 'getdata/followers.php',
				onComplete: function(jsonObj){
					followersfn(jsonObj.followers);
					$('spinner').setStyle('visibility','hidden');
				}
			}).send();
		}
	});

	MochaUI.Modal = new MochaUI.Modal();
	
	MochaUI.Desktop.desktop.setStyles({
		'background': '#fff',
		'visibility': 'visible'
	});
	initializeWindows();

});

//check query at start
//$('filterinput').value = '';

checksession('nologinbox');
chkhash.periodical(300);

//chatsession();
periodicchk = chatsession.periodical(chatchktime);

/*
window.onbeforeunload = function() {
	return "This will close all events including the chat dialogue boxes. Please check before you proceed.";
}
*/

// This runs when a person leaves your page.
window.addEvent('unload', function(){
	if (MochaUI) MochaUI.garbageCleanUp();
});
