initializeWindows = function(){

	MochaUI.neonewsWindow = function(){	
		new MochaUI.Window({
			id: 'neonews',
			title: 'Neo News Feed',
			loadMethod: 'iframe',
			contentURL: 'pages/neonews.php',
			width: 500,
			height: 200,
            padding: {top:0,right:0,bottom:0,left:0},
			x: window.size().width-600,
			y: 70,
			contentBgColor: '#fff'
		});
	}
    MochaUI.neoWindow = function (url,title) {
		  new MochaUI.Window({
			  id: 'neo_'+url+'_window',
			  title: $chk(title)?title:'Neopets',
			  loadMethod: 'iframe',
			  contentURL: url,
			  width: window.size().width>1200?1026:window.size().width-200,
			  height: window.size().height-100,
              padding: {top:0,right:0,bottom:0,left:0},
			  contentBgColor: '#fff'
		  });
    }
    MochaUI.portalWindow = function (url,title,iframe) {
            MochaUI.uniWindow({
                'url':'/pages/'+url,
                'title':title,
                'loadMethod':typeof iframe=='undefined'?'xhr':'iframe'
            });
        /*new MochaUI.Window({
            id: 'portal_'+url+'_window',
            title: $chk(title)?title:'neoPortal',
            loadMethod: typeof iframe=='undefined'?'xhr':'iframe',
			contentURL: 'pages/'+url,
			width: 500,
			height: 300,
            padding: {top:5,right:10,bottom:5,left:10},
			contentBgColor: '#fff'
        });*/
    }
    MochaUI.shoutboxWindow = function () {
        new MochaUI.Window({
            id: 'shoutboxWindow',
            contentURL:"pages/shoutbox.html",
            title:"Shoutbox",
            loadMethod:"iframe",
            width:300,
            height:210
        })
    }
    MochaUI.uniWindow = function (op) {
        new MochaUI.Window({
            id: 'uni_'+op.url+'_window',
            title: $chk(op.title)?op.title:'neoPortal',
            loadMethod: op.loadMethod?op.loadMethod:'xhr',
			contentURL: op.url,
			width: op.width?op.width:500,
			height: op.height?op.height:300,
            padding: {top:5,right:10,bottom:5,left:10},
			contentBgColor: '#fff'
        });
    }
    MochaUI.welcomeWindow = function () {
        new MochaUI.Window({
            id: 'welcome_window',
            title: 'Welcome!',
            loadMethod: 'iframe',
			contentURL: 'pages/welcome.html',
			width: 400,
			height: 300,
			x: 150,
			y: window.size().height-400,
            padding: {top:5,right:10,bottom:5,left:10},
			contentBgColor: '#fff'
        });
    }
    //for reference:
	/*MochaUI.ajaxpageWindow = function(){ 
		new MochaUI.Window({
			id: 'ajaxpage',
			loadMethod: 'xhr',
			contentURL: 'pages/lipsum.html',
			width: 340,
			height: 150
		});
	}*/
    
    MochaUI.twitterWindow = function(){ //port this to widgets when widgets can handle it
        new MochaUI.Window({
            id: 'twitterWindow',
            title: 'Update Feed',
            //addClass: 'transparent',
            loadMethod: 'xhr',
            contentURL: '/pages/twitter.html',
            width: 290,
            height: 350,
            padding: {top:0,right:0,bottom:0,left:0},
            resizable: false,
            maximizable: false
        });
    }
    MochaUI.clockWindowOnContentLoaded = 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();
			}
		}
	};
	MochaUI.clockWindow = function(){	
	    return;
		new MochaUI.Window({
			id: 'clock',
			title: 'Canvas Clock',
			addClass: 'transparent',
			loadMethod: 'xhr',
			contentURL: 'plugins/coolclock/index.html',//?t=' + new Date().getTime(),
			onContentLoaded: function () {MochaUI.clockWindowOnContentLoaded()},
			shape: 'gauge',
			headerHeight: 30,
			width: 160,
			height: 160,
			x: window.size().width-250,
			y: window.size().height-200,
			padding: { top: 0, right: 0, bottom: 0, left: 0 },
			bodyBgColor: [250,250,250],
            closable: false
		});	
	}
	MochaUI.siteWidgetsWindow = function(){
	//javascript:MochaUI.siteWidgetsWindow();void(0)
		var id = 'sitewidgets';
		new MochaUI.Window({
			id: id,
			title: 'Site Widgets',
			loadMethod: 'xhr',
			contentURL: '/pages/site_widgets.php',
			width: 300,
			height: 200,
			//scrollbars: false,
			resizable: false,
			maximizable: false,				
			padding: { top: 0, right: 0, bottom: 0, left: 0 },
			onContentLoaded: function(windowEl){
				this.windowEl = windowEl;
				var accordianDelay = function(){
					new Accordion('#' + id + ' h3.accordianToggler', "#" + id + ' div.accordianElement',{
						start: 'all-closed',
						opacity: false,
						alwaysHide: true,
						onActive: function(toggler, element){
							toggler.addClass('open');
						  if(!$(element).getElement("form")) return;
					    var inputs = $(element).getElement("form").getElements("input");
					    $each(inputs,function (el) {
					      el = $(el);
					      el.setProperty("default",el.getProperty("value"));
					    });
						},
						onBackground: function(toggler, element){
						    if(toggler.hasClass('open') && $(element).getElement("form")) {
						      var form = $(element).getElement("form");
						      var inputs = form.getElements("input");
						      var changed = false;
						      $each(inputs,function (el) {
						        el = $(el);
						        if(el.getProperty("default")!=el.getProperty("value") && el.getProperty("value").length){
						          changed = true;
						          return false;
						        }
						      });
						      if(changed && confirm("Would you like to save your changes?")) {
						        site_widgets_save(form);
						      } else {
  					        $each(inputs,function (el) {
  					          el = $(el);
  					          el.setProperty("value",el.getProperty("default"));
  					        });
						      }
						    }
								toggler.removeClass('open');
						},							
						onStart: function(toggler, element){
							this.windowEl.accordianResize = function(){
								MochaUI.dynamicResize($(id));
							}
							this.windowEl.accordianTimer = this.windowEl.accordianResize.periodical(10);
						}.bind(this),
						onComplete: function(){
							this.windowEl.accordianTimer = $clear(this.windowEl.accordianTimer);
							MochaUI.dynamicResize($(id)) // once more for good measure
						}.bind(this)
					}, $(id));
				}.bind(this)
				accordianDelay.delay(10, this); // Delay is a fix for IE
			}
		});
	}	
	
	MochaUI.registerWindow = function(){
	    MochaUI.portalWindow('register.php','Register now!',1);
	}
	
    MochaUI.ieWarningWindow = function(){
        new MochaUI.Window({
            id: 'ieWarningWindow',
            title: 'Internet Explorer',
            type: 'modal',
            loadMethod: 'html',
            content: "<center><img src='portal-images/ie.png' alt='Internet Explorer' /><h1>Internet Explorer</h1><p>Hi! Welcome to neoPortal!</p><p>We noticed you're using Internet Explorer. That's nice and all, but since IE is so quirky - just ask any web developer - we figured we'd warn you that fancy features, such as dragging icons, may not work as smoothly as expected.</p><p>We recommend using Firefox, a browser famous for its speed, stability, and cutting-edge technology. All your settings and bookmarks from Internet Explorer will be imported, so why not upgrade today?</p><p><a href='http://www.mozilla.com/firefox?from=sfx&uid=255988&t=309'><img border='0' alt='Spreadfirefox Affiliate Button' src='http://sfx-images.mozilla.org/affiliates/Buttons/firefox3/468x60.png' /></a></p><p><a href='#' onclick='MochaUI.ieWarningWindow_close(0)'>No Thanks</a></p><p><a href='#' onclick='MochaUI.ieWarningWindow_close(1)'>No Thanks, and don't bug me for a week!</a></p></center>",
            width: 500,
            height: 500
        });
    }
    MochaUI.ieWarningWindow_close = function (c) {
        MochaUI.closeWindow($("ieWarningWindow"));
        if(c) Cookie.write("ieWarningWindow_ignore","1",{duration:7});
    }
		/*
		 
		 APRIL FOOLS! ^_^
		 
		*/
		MochaUI.aprilFoolsWindow = function(){
        new MochaUI.Window({
            id: 'aprilFoolsWindow',
            title: 'Internet Explorer',
            type: 'modal',
            loadMethod: 'html',
            content: "<center><img src='portal-images/ie.png' alt='Internet Explorer' /><h1>Internet Explorer</h1><p>Hi! Welcome to neoPortal!</p><p>We noticed you're not using Internet Explorer. Though I'm sure your browser is nice and all, unless it's IE, it is not fully supported. Why is this?</p><p>As everyone knows, IE is the industry standard. Microsoft's Internet Explorer is always racing to adopt the latest technologies before anyone else, and is the safest option: IE has a 100% track record of preventing virus attacks, after all!</p><p>As the web continues to evolve, so does IE. Microsoft is always first to adopt these fresh, new technologies and, as neoPortal grows to make use of the latest HTML5 and CSS3 web development techniques, use of IE is vital so as not to fall behind. Who knows what those renegade browser makers are up to down in their basements, after all? Surely not quality coding.</p><p>So, what are you waiting for? <a href='#' onclick='MochaUI.aprilFoolsWindow_close()'>Upgrade today!</a></p><p><a href='#' onclick='MochaUI.aprilFoolsWindow_close()'>No Thanks</a></p><p><a href='#' onclick='MochaUI.aprilFoolsWindow_close()'>No Thanks, and don't bug me for a week!</a></p></center>",
            width: 500,
            height: 500,
						onClose: function () {
							MochaUI.notification("IE fails! Happy April Fools'!");
						}
        });
    }
    MochaUI.aprilFoolsWindow_close = function (c) {
        MochaUI.closeWindow($("aprilFoolsWindow"));
				//MochaUI.notification("IE fails! Happy April Fools'!");
    }
		/*
		 
		 /APRIL FOOLS! ^_^
		 
		*/
    
    MochaUI.announcementWindow = function (html) {
        new MochaUI.Window({
            id: 'announcementWindow',
            title: 'Announcement!',
            type: 'modal',
            loadMethod: 'html',
            content: html,
            width: 500,
            height: 500
        });
    };
	// Deactivate menu header links
	$$('a.returnFalse').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop();
		});
	});

	// Build windows onDomReady
	// (Removed in favor of widgets)
	// MochaUI.neonewsWindow();
	// MochaUI.welcomeWindow();
	if (!Browser.Engine.trident) {
		MochaUI.clockWindow();
		/*
		 
		 APRIL FOOLS! ^_^
		 
		*/
		var d = new Date();
		if(d.getMonth()==3 && d.getDate()==1)MochaUI.aprilFoolsWindow();
		/*
		 /APRIL FOOLS! ^_^
		*/
	}
	else {
    	if(!Cookie.read("ieWarningWindow_ignore")) MochaUI.ieWarningWindow();
		MochaUI.clockWindow.delay(500);	
	}
	
}

/*function clipDesktopIcons() {
    var ct,elCoords,ctCoords;
    $$(".desktopIcon").each(function (el) {
        ct = el.getElement(".clippedTitle");
        elCoords = el.getCoordinates();
        ctCoords = ct.getCoordinates();
        alert("bottom: "+elCoords.bottom+"<"+ctCoords.bottom+"\nright:"+elCoords.right+"<"+ctCoords.right);
        for(i=0;(elCoords.bottom<ctCoords.bottom || elCoords.right<ctCoords.right) && i<20;i++) {
            //if(ct.innerHTML.substr(ct.innerHTML.length-3,3)!="...") ct.innerHTML+="...";
            if(ct.innerHTML.length==3) {MochaUI.notification("Fatal error compressing: die.");return false;}
            ct.innerHTML = ct.innerHTML.substr(0,ct.innerHTML.length-(ct.innerHTML.substr(ct.innerHTML.length-3,3)=="..."?4:0))+"...";
        }
        MochaUI.notification("Clipped.");
    });
}*/

var dragStart=new Array(),dragEl=false,dragParam="",dragTarget=false,dragMode=0,dragOnSuccess=$empty; //0=none,1=waiting for mousemove,2=dragging

function dragMouseDown(el,param,onSuccess) {
    if($(el).hasClass('noDrag')) return false;
    dragEl = el;
    dragTarget = false;
    dragParam = param;
    dragMode = 1;
    dragOnSuccess = typeof onSuccess == 'function'?onSuccess:$empty;
}

function clearContextMenu() {
	if($('iconContextMenu')) $('iconContextMenu').destroy();
}

function updateDesktopIcons(html) {
    $("page").innerHTML=html;
    new Asset.css("/themes/"+$("desktopTheme").innerHTML+".css");
    $$(".desktopIcon").addEvents({
        "mousedown": function (e) {
            if (!e) var e = window.event;
            if (e.rightClick) return false;
            dragMouseDown(this,"from="+encodeURIComponent(this.getProperty("iconslot")));
            e.preventDefault().stopPropogation;
            return false;
        },
        "contextmenu": function (e) {
            var el = $('iconContextMenu');
            var actions = new Array();
            var icon = this;
            var toParam = "from="+encodeURIComponent(icon.getProperty("iconslot"));
            var el = $(e.target).hasClass('desktopIcon')?e.target:e.target.getParent('a');
            if($(el).hasClass('isCreator')) {
                actions[actions.length] = new Array('Edit',function () {MochaUI.portalWindow('icon_create.php?edit='+el.getAttribute('iconid'),'Edit Icon')});
                actions[actions.length] = false;
            }
            actions[actions.length] = new Array('Move',function () {dragMouseDown(icon,toParam);dragMouseMove()});
            actions[actions.length] = new Array('Trash',function () {moveIcon(-1,toParam)});
            clearContextMenu();
            var pagePos = $("pageWrapper").getPosition();
            contextMenu = new Element('div',{
                'id': 'iconContextMenu',
                'styles': {
                    'position': 'absolute',
                    'left': trueX,
                    'top': trueY,
                    'zIndex': 9001, //it's over 9000
                    'opacity': 0,
                    'border': '1px solid #ddd',
                    'borderWidth': '1px 1px 0 1px',
                    'backgroundColor': '#fff',
                    'width': 100
                }
            });
            $(document.body).appendChild(contextMenu);
            var divider = new Element('div',{
                'styles': {
                    'height': 2,
                    'padding': 0,
                    'backgroundColor': '#ddd'
                }
            });
            for(var i=0;i<actions.length;i++) {
                if(actions[i]) {
                    contextMenu.appendChild(new Element('a',{
                        'href': '#',
                        'html': actions[i][0],
                        'contextOption': i,
                        'styles': {
                            'display': 'block',
                            'padding': '2px',
                            'borderBottom': '1px solid #ddd'
                        },
                        'events': {
                            'mouseup': function () {
                                clearContextMenu();
                                actions[$(this).getProperty('contextOption')][1]();
                                return false;
                            },
                            'mouseover': function () {
                                $(this).setStyle('backgroundColor','#eee');
                            },
                            'mouseout': function () {
                                $(this).setStyle('backgroundColor','#fff');
                            }
                        }
                    }));
                } else {
                    contextMenu.appendChild(divider);
                }
            }
            var contextMenuCoords = $(contextMenu).getCoordinates();
            var windowSize = window.size();
            if(contextMenuCoords.right>windowSize.width) {
                contextMenu.setStyle('top',windowSize.width-contextMenuCoords.width);
            }
            if(contextMenuCoords.bottom>windowSize.height) {
                contextMenu.setStyle('top',windowSize.height-contextMenuCoords.height-5);
            }
            contextMenu.set('tween',{duration:100}).fade('in');
            //actions[prompt(actions+'\n\nWhich will you choose? Type 1-'+(actions.length),'1')-1][1]();
            e.preventDefault().stopPropogation;
            return false;	
        }
    });
    fitDesktopIcons();
}

function fetchDesktopIcons() {
    AJAX('components/desktop.php','',function (h) {
        updateDesktopIcons(h.responseText);
    });
}
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0,tempY = 0,trueX = 0, trueY = 0;
function getMouseXY(e) {
//lifted from CodeLifter.com :)
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}
//mod here because we're acting in the pageWrapper
trueY = tempY;
tempY -= $("pageWrapper").getPosition().y;
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}
if (trueY < 0){trueY = 0;}
trueX = tempX; 
//document.title = trueX+","+trueY;
return true;
}

function dragMouseMove() {
	var iconDrag = $("iconDrag");
	if(dragMode==1) {
		var pagePos = $("pageWrapper").getPosition();
		$$(".desktopIcon","#trash").addClass("desktopIconDragMode").each(function (el) {
			if($(el).hasClass('iconPlaceholder') && !dragParam.match('id=')) return false;
			var elCoords = el.getCoordinates();
			var newEl = new Element("a",{
				"class": "dragTarget",
				"href": "#",
				"html": "&nbsp;",
				"styles": {
					"top": elCoords.top-pagePos.y,
					"left": elCoords.left-pagePos.x,
					"height": elCoords.height,
					"width": elCoords.width
				},
				"iconslot": el.getProperty("iconslot"),
				"events": {
					"mouseover": function () {dragTarget=this;},
					"mouseout": function () {dragTarget=false;}
				}
			});
			$("pageWrapper").appendChild(newEl);
		});
		iconDrag.innerHTML=dragEl.innerHTML;
		dragMode=2;
	}
	if(dragMode==2) {
		//document.title='dragging: ';
		//document.title += tempX+"/"+tempY;
		idSize = iconDrag.getSize();
		iconDrag.setStyles({left:tempX-idSize.x/2,top:tempY-idSize.y/2});
	}
}

window.addEvent("load", function () {
    $('desktop').addEvents({
        "mousemove": dragMouseMove,
        "mouseup": function () {
            if(dragMode==2) {
                if(dragTarget) {
                    //MochaUI.notification("target selected: "+dragTarget.getProperty("iconslot"));
                    var to = dragTarget.getProperty("iconslot");
                    //if(to==dragEl.getProperty("iconslot")) return false;
                    moveIcon(to,dragParam,dragOnSuccess);
                } //else MochaUI.notification("no target");
                dragTarget = false;
                dragEl = false;
                $$(".dragTarget").destroy();
                $("iconDrag").setStyles({left:-1000,top:-1000});
                $$(".desktopIcon").removeClass("desktopIconDragMode");
            }
            dragMode=0;
            //MochaUI.notification("window mouseup");
			clearContextMenu();
            return true;
        }
    });
    $('pageWrapper').addEvent('contextmenu',function (e) {
        e.preventDefault().stopPropogation;
        return false;
    });
});

function moveIcon(to,param,oncomplete) {
    //MochaUI.notification("Moving icon...");
    runAJAX("components/icon_move.php","to="+encodeURIComponent(to)+"&"+param,function () {
		$$(".moveIconDependent").each(function (el) {
			if(typeof el.moveIconDependency == 'function') el.moveIconDependency();
		});
		if(typeof oncomplete == 'function') oncomplete();
	});
}

function moveIconDependency(el,f) {
    $(el).addClass("moveIconDependent").moveIconDependency = f;
}

function fitDesktopIcons() {
    var pageY = $("pageWrapper").getCoordinates().bottom,pageH=$("pageWrapper").getSize().y,iconX = 15,iconY = 15;
    //document.title=pageH;
    $$(".iconShadow").destroy();
    $$(".desktopIcon").each(function (el) {
        if(el.id=='iconDrag') return false;
        var elH = el.getSize().y;
        if(elH>pageH) {MochaUI.notification("Your window is far too small... try a resize?");return false;}
        if(iconY+elH>=pageH) {
            iconX += 65; //width=50, margin of 15
            iconY = 15;
        }
        el.setStyles({left:iconX,top:iconY});
        iconY += elH+15;
        var cel = el.clone().removeClass("desktopIcon").addClass("iconShadow");
        var s = el.getStyles('left','top');
        cel.setStyles({left:s.left.toInt()+1,top:s.top.toInt()+1}).injectAfter(el);
    });
}

var iconTrashedTimeout = 0;

function iconTrashed() {
    var trashFull;
    if(!(trashFull=$('trashFull'))) {
        trashFull = new Element('img',{
            'id': 'trashFull',
            'src': 'http://matchu.is-a-geek.com/portal-images/trash_full.png',
            'styles': {
                'opacity': 0
            }
        });
        $('pageWrapper').appendChild(trashFull);
    }
    new Fx.Tween(trashFull,{duration:500,property:'opacity'}).start(0,1);
    clearTimeout(iconTrashedTimeout);
    iconTrashedTimeout = setTimeout(function () {new Fx.Tween(trashFull,{duration:1000,property:'opacity'}).start(1,0);},1000);
}

window.addEvent('resize',function () {setTimeout(fitDesktopIcons,0)});

var login = new Object();
login.logged_in = false;

login.refresh = function () {
    AJAX("components/login_header_module.php","",function (h) {
        var r = h.responseText;
        login.logged_in = r.match("<!--logged_in:1-->");
        $$(".menu-right")[0].innerHTML=r;
    });
    widgets.load();
    fetchDesktopIcons();
    AJAX("components/header_menu.php","",function (h) {
        $("desktopNavbar").innerHTML = h.responseText;
    })
};

login.login_as = function (n,p) {
    AJAX("components/login_login.php","name="+encodeURIComponent(n)+"&password="+encodeURIComponent(p),function (h) {
        if(h.responseText=='1') {
            login.refresh();
        } else if(h.responseText=='0') {
            MochaUI.notification("Login failed! Try again!");
        } else if(h.responseText=='-1') {
            MochaUI.notification("Too many login attempts! Wait 5 minutes or so.");
        } else {
            MochaUI.notification("Unexpected error!");
        }
    });
}

login.logout = function () {
    AJAX("components/login_logout.php","",function (h) {
        login.refresh();
    });
}



var widgets = {
    load: function (windows) {
        var data = typeof windows!='undefined'?'windows='+windows:'';
        widgets.json(data,function(json,text) {
	        if(!json) {
	            MochaUI.notification("Error loading widgets! Uh oh!");
	        } else {
		        $each(json.windows,function (w) {
		            var isX = typeof w.x == 'number',isY = typeof w.y == 'number';
		            w = widgets.cornerSnap(w);
	                var windowEl = $(w.id);
		            if(windowEl && isX && isY) {
		    	        var moveMorph = new Fx.Morph(windowEl, {
		    	            'duration': 550
	                    });
		    		    moveMorph.start({
			    		    'top': w.y,
						    'left': w.x
					    });
		            } else {
		                //alert(w.onContentLoaded);
		                if(typeof w.onContentLoaded=='string') w.onContentLoaded = new Function(w.onContentLoaded);
		                //alert(w.onContentLoaded);
		                new MochaUI.Window(w);
		            }
		        })
		    }
	    });
    },
    json: function(windows,complete) {
        var request = new Request.JSON({
		    url: '/pages/widget_json.php',
		    method: 'get',
		    onComplete: complete
	    }).send(windows);
    },
    cornerSnap: function(w) {
        /****************\
        *1              2*
        *   Attachment   *
        *    Corners!    *
        *                *
        *3              4*
        \****************/
        //remember, -50 height due to top and bottom bars
        var size = window.size(),extraHeight = (w.headerHeight?w.headerHeight:50)+(w.footerHeight?w.footerHeight:50);
        if(w.corner==2 || w.corner==4) w.x = size.width-w.x-w.width;
        if(w.x<0) w.x = 0; else if(w.x+w.width>size.width) w.x = size.width-w.width;
        if(w.corner==3 || w.corner==4) w.y = size.height-w.y-w.height-50;
        if(w.y<0) w.y = 0; else if(w.y+w.height>size.height) w.y = size.height-w.height-50;
        return w;
    }
}
//:checked pseudo-selector for finding checked widgets in prefs_widget
Selectors.Pseudo.checked = function(){
	return ('input' == this.get('tag') && ('radio' == this.get('type') || 'checkbox' == this.get('type')) && this.checked);
};



// Initialize MochaUI when the DOM is ready
window.addEvent('domready', function(){
	MochaUI.Desktop = new MochaUI.Desktop();
	MochaUI.Dock = new MochaUI.Dock({
		dockPosition: 'bottom'
	});
	MochaUI.Modal = new MochaUI.Modal();
    
	MochaUI.Desktop.desktop.setStyles({
		'background': '#fff',
		'visibility': 'visible'
	});
	
	initializeWindows();
    login.refresh();
    $("affiliatesFooter").addEvent("click", function (e) {
        $("affiliatesContent").setStyle("height",$("affiliatesContent").getSize().y?"0":"auto");
        e.preventDefault().stopPropogation;
        return false;
    });
});

window.addEvent('load', function(){
	$$(".returnFalse").addEvent("click", function () {
        return false;
    });
});

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

