;(function(window){
	jee_fw={
		caches:{subContextMax:false},
		confs:{currentMainMenu:null,currentSubMenu:null,scroll:true},
		init:function(){
			jee_fw.caches.container=$("#my_space_container");
			jee_fw.caches.header=$("#my_space_header",jee_fw.caches.container);
			jee_fw.caches.mainMenu=$("#my_space_menu_bar",jee_fw.caches.container);
			jee_fw.caches.subMenu=$("#my_space_left_menu",jee_fw.caches.container);
			jee_fw.caches.mainContent=$("#my_space_main_content",jee_fw.caches.container);
			jee_fw.caches.footer=$("#my_space_home_footer",jee_fw.caches.container);
			if(jee_fw.confs.currentMainMenu!=null){
				$("li.selected",jee_fw.caches.mainMenu).each(function(){
					$(this).removeClass("selected");
				});
				$("li."+jee_fw.confs.currentMainMenu,jee_fw.caches.mainMenu).addClass("selected");
			}
			jee_fw.updateSubMenuStatus();
			$("body").append("<button onclick='jee_fw.toggleMax()' id='resize_btn' class='resize-icon-normal'></button>");
			jee_fw.caches.resizeBtn=$("#resize_btn");
			jee_fw.resetLayout();
			$(window).resize(function(){jee_fw.resetLayout()});
			$.ajaxSetup({cache: false});
		},
		updateSubMenuStatus:function(){
			if(jee_fw.confs.currentSubMenu!=null){
				$("li.selected",jee_fw.caches.subMenu).each(function(){
					$(this).removeClass("selected");
				});
				$("li."+jee_fw.confs.currentSubMenu,jee_fw.caches.subMenu).addClass("selected");
			}
		},
		toggleMax:function(){
			jee_fw.caches.subContextMax=!jee_fw.caches.subContextMax;
			jee_fw.resetLayout();
		},
		resetLayout:function(){
			var mc=jee_fw.caches.mainContent;
			var c=jee_fw.caches.container;
			var sm=jee_fw.caches.subMenu;
			var w=$(window);
			if(!jee_fw.confs.scroll){
				var wh=w.height();
				/*if(wh>500){*/
					var iframe=$("iframe",mc);
					var mode=(jee_fw.caches.subContextMax?2:1);
					if(mode==1){
						var tmpH;
						tmpH=wh-jee_fw.caches.header.height()-jee_fw.caches.mainMenu.height()-jee_fw.caches.footer.height();
						if(tmpH>sm.outerHeight()){
							if(iframe&&iframe.length>0){
								iframe.css({"top":0,"left":0,"width":"100%","position":"static"});
								iframe.height(tmpH-10)
								mc.outerHeight(tmpH-5);
							}else{
								tmpH=wh-jee_fw.caches.header.height()-jee_fw.caches.mainMenu.height()-jee_fw.caches.footer.height();
								mc.css("over-flow","auto");
								mc.height(tmpH-5);
							}
							c.outerHeight(wh);
							var offset=mc.offset();
							var resizeBtn=jee_fw.caches.resizeBtn;
							resizeBtn.css({"left":(offset.left),"top":(offset.top)});
							if(resizeBtn.hasClass("resize-icon-normal")){
								resizeBtn.removeClass("resize-icon-normal");
								resizeBtn.addClass("resize-icon-max");
							}
						}
					}else{
						var coff=c.offset();
						iframe.css({"top":(coff.top),"left":(coff.left),"position":"absolute"});
						iframe.width(c.width());
						iframe.height($(document).height());
						var resizeBtn=jee_fw.caches.resizeBtn;
						resizeBtn.css({"left":(coff.left),"top":(coff.top)});
						if(resizeBtn.hasClass("resize-icon-max")){
							resizeBtn.removeClass("resize-icon-max");
							resizeBtn.addClass("resize-icon-normal");
						}
					}
				/*}*/
			}
		},
		iframeDialogClose:function(){
			var iDialog=jee_fw.caches.iframeDialog;
			if(iDialog!=null){iDialog.dialog("close");}
		},
		iframeDialog:function(src,title,modal,width,height,buttons,close,showeffect,hideeffect){
			if(!width){width=300;}
			if(!height){height=250;}
			if(!close){colose=function(){};}
			if(!showeffect){showeffect="";}
			if(!hideeffect){hideeffect="";}
			var iDialog=jee_fw.caches.iframeDialog;
			if(!iDialog){
				iDialog=$('<div id="dialog_iframe"><iframe frameborder="0"></iframe></div>');
				jee_fw.caches.iframeDialog=iDialog;
				iDialog.dialog({autoOpen:true,resizable:false,show:showeffect,hide:hideeffect,title:title,width:width,height:height,modal:modal,buttons:buttons,close: close});
			}else{
				iDialog.dialog("option",{title:title,width:width,show:showeffect,hide:hideeffect,height:height,model:modal,buttons:buttons,close:close});
				iDialog.dialog("open");
			}
			var iframe=$("iframe",iDialog);
			iframe.width(iDialog.width()-6);
			iframe.height(iDialog.height()-6);
			iframe.attr("src",src);
		},
		dialog:function(ctx,title,modal,width,height){
		},
		ResetIFrameHeight:function(h){
			if(jee_fw.confs.scroll){
				var iframe=$("iframe",jee_fw.caches.mainContent);
				if(iframe.length>0){
					iframe.height(h+10);
				}
			}
		},
		OpenMessage:function(path,title){
			jee_fw.iframeDialog(path+"/app/home/social/message/index",title,false,600,420);
		}
	};
	window.jee_fw=jee_fw;
})(window);