;(function(window){
	jee_fw={
		caches:{subContextMax:false},
		confs:{currentMainMenu:null,currentSubMenu:null,scroll:true,dialog:null},
		init:function(){
			jee_fw.caches.container=$("#global_container");
			jee_fw.caches.header=$("#header");
			jee_fw.caches.mainMenu=$("#mainBav");
			jee_fw.caches.subMenu=$("#sidebar");
			jee_fw.caches.mainContent=$(".main-content");
			jee_fw.caches.footer=$("#footer");
			jee_fw.caches.messageCount=$("#msg_count");
			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});
			
			$('.ui-has-sub-menu').mouseenter(function(){
				$('.ui-sub-menu').hide();
				var t=$(this);
				var sm=$('#'+t.attr('id')+'_sub');
				var offset=t.offset();
				sm.css({'left':offset.left,'top':(offset.top+t.height())});
				sm.show();
			}).mouseleave(function(){var t=$(this);var sm=$('#'+t.attr('id')+'_sub');setTimeout(function(){if(!sm.data('show')){sm.hide();}},300);});
			$('.ui-sub-menu').mouseleave(function(){var t=$(this);t.data('show',false);t.hide();}).mouseenter(function(){$(this).data('show',true);});
		},
		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.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.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");
						}
						*/
					}
				/*}*/
			}
			var ubar=$("#online_user_bar");
			if(ubar&&ubar.length>0){
				ubar.css("top",w.height()-ubar.height());
			}
		},
		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){close=function(){$("iframe",$(this)).attr("src","/styles/default/images/loading.gif");};}
			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:true,show:showeffect,hide:hideeffect,title:title,width:width,height:height,modal:modal,buttons:buttons,close: close,resizeStop:function(event,ui){var t=$(this);var f=$("iframe",t);f.width(t.width());f.height(t.height()-16);}});
			}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(type,src,title,modal,w,h,buttons,close){
			if(!w){width=300;}
			if(!h){height=250;}
			if(!close){colose=function(){};}
			if(jee_fw.caches.dialog==null){
				jee_fw.caches.dialog=$("<div></div>");
				jee_fw.caches.dialog.dialog({autoOpen:true,resizable:true,title:title,width:w,height:h,modal:modal,buttons:buttons,close: close});
			}else{
				jee_fw.caches.dialog.dialog("option",{title:title,width:w,height:h,model:modal,buttons:buttons,close:close});
				jee_fw.caches.dialog.dialog("open");
			}
			if(type=="ajax"){
				jee_fw.caches.dialog.load(src);
			}else{
				jee_fw.caches.dialog.html(src);
			}
		},
		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);
		},
		GetWindowSize:function(){
			var w=$(window);
			return {width:w.width(),height:w.height()};
		},
		GetMessageCount:function(path){
			if(!jee_fw.caches.messageCount){
				jee_fw.caches.messageCount=$("#msg_count");
			}
			jee_fw.caches.messageCount.load(path+"/app/home/social/message/count");
		}
	};
	window.jee_fw=jee_fw;
})(window);
