MUI.path['plugins'] = StylePath + '/plugins/';

MUI.path['themes'] = StylePath + '/themes/';

initializeWindows = function(){

	MUI.ChatWindow = function(){	
		
		new MUI.Window({
			id: 'chat',
			title: '即时聊天',
			loadMethod: 'iframe',
			contentURL: '/Chat/index.php',
			width: 400,
			height: 282,
			x: 620,
			y: 152,
			require: {
				css: [MUI.path.plugins + 'windowform/css/style.css']
			}			
		});
	}
	// Workspaces

	if ($('saveWorkspaceLink')){
		$('saveWorkspaceLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.saveWorkspace();
		});
	}
	
	if ($('loadWorkspaceLink')){
		$('loadWorkspaceLink').addEvent('click', function(e){
			new Event(e).stop();
			MUI.loadWorkspace();
		});
	}
	
	if ($('toggleEffectsLinkCheck')){
		$('toggleEffectsLinkCheck').addEvent('click', function(e){
			new Event(e).stop();
			MUI.toggleEffects($('toggleEffectsLinkCheck'));			
		});
		if (MUI.options.useEffects == true) {
			MUI.toggleEffectsLink = new Element('div', {
				'class': 'check',
				'id': 'toggleEffects_check'
			}).inject($('toggleEffectsLinkCheck'));
		}
	}	

	// Deactivate menu header links
	$$('a.returnFalse').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop();
		});
	});
	// Build windows onLoad
	MUI.ChatWindow();
	
	MUI.myChain.callChain();
	
}

// Initialize MochaUI when the DOM is ready
window.addEvent('load', function(){

	MUI.myChain = new Chain();
	MUI.myChain.chain(
		function(){MUI.Desktop.initialize();},
		function(){MUI.Dock.initialize();},
		function(){initializeWindows();}		
	).callChain();
	
	// This is just for the demo. Running it onload gives pngFix time to replace the pngs in IE6.
	$$('.desktopIcon').addEvent('click', function(){
		//MUI.notification('Do Something');
	});	

	//MUI.minimizeAll();
	CallView();
});

window.addEvent('unload', function(){
	// This runs when a user leaves your page.	
});


var CallHttp = {
	httpmode:null,
	goApiList:function (apiclassid){
		var url  = BaseUrl + '/index.php?do=api&act=list&apiclassid='+apiclassid;
	
		jQuery.get(url, function(data){
			jQuery("#page").html(data);
});
			jQuery("#pageWrapper").css({background:"#E1E1E1"});
	},
	goDeskTop : function(){
		var url  = BaseUrl + '/index.php?do=index&act=desk';
	
		jQuery.get(url, function(data){
			jQuery("#pageWrapper").css({background:"#777777"});
			jQuery("#page").html(data);
})
},
	goAllApilist:function (){
			jQuery("#pageWrapper").css({background:"#E1E1E1"});
		var url  = BaseUrl + '/index.php?do=api&act=allapi';
	
		jQuery.get(url, function(data){
			jQuery("#page").html(data);
})
	},
	
	ApiParam:function(interfaceid,name){

		if(jQuery(".form form").html())
		{
			jQuery(".form form input[id=autopost]").click();
		}

		var idname = 'apiInfo' + interfaceid + '_panel1';
		var url  = BaseUrl + '/index.php?do=api&act='+name+'&interfaceid='+interfaceid;
		
		MUI.updateContent({			
					element: $(idname),
					url: url,
					require: {
						onload: function(){
						}	
					}
				});

	},
	phpSdk : function(){
		new MUI.Window({
			id: 'builder',
			title: 'TaoapiPHPSDK示例',
			contentURL: BaseUrl + '/index.php?do=api&act=sdk',
			width: 600,
			height: 320,
			require: {
				css: [MUI.path.plugins + 'windowform/css/style.css']
			}			
		});
	},
	autoPostForm : function (interfaceid,formid){
		var idname = 'apiInfo' + interfaceid + '_panel1';
		$(formid).addEvent('submit', function(e){
						e.stop();

				this.set('send', {
					async:false,
					onComplete: function(response) {  
					},
					onSuccess: function(){
						if (MUI.options.standardEffects == true) {
							//$('postContent').setStyle('opacity', 0).get('morph').start({'opacity': 1});
						}
					}
				});
				this.send();
			});	
	},
	postForm:function(interfaceid,formid){
		var idname = 'apiInfo' + interfaceid + '_panel1';

		$(formid).addEvent('submit', function(e){

						e.stop();

				this.set('send', {
					onComplete: function(response) { 
	 						MUI.updateContent({
							'element': $(idname),
							'content': response,
							'title': 'Ajax Response',
							'padding': { top: 8, right: 8, bottom: 8, left: 8 }
						});			
					},
					onSuccess: function(){
						if (MUI.options.standardEffects == true) {
							//$('postContent').setStyle('opacity', 0).get('morph').start({'opacity': 1});
						}
					}
				});
				this.send();
			});	
	},
	goApiInfo:function(interfaceid,title){

		var idname = 'apiInfo'+interfaceid;

		new MUI.Window({
					id: idname,
					title: title,
					width: 820,
					height: 360,
					resizeLimit: {'x': [450, 2500], 'y': [300, 2000]},
					scrollbars: false, // Could make this automatic if a 'panel' method were created
					onContentLoaded: function(){	
				
						new MUI.Column({
							container:idname + '_contentWrapper',
							id: idname + '_mainColumn',
							placement: 'main',
							width: null,
							resizeLimit: [100, 300]
						});
					
						new MUI.Column({
							container: idname + '_contentWrapper',
							id: idname + '_sideColumn',
							placement: 'right',
							width: 120,
							resizeLimit: [100, 120]
						});
					
						new MUI.Panel({
							header: false,
							id: idname + '_panel1',					
							contentURL: BaseUrl + '/index.php?do=api&act=param&interfaceid='+interfaceid,
							column: idname + '_mainColumn',
							panelBackground: '#fff',
							require: {
								css: [MUI.path.plugins + 'windowform/css/style.css'],
								onload: function(){
								}			
							}			
						});
					
						new MUI.Panel({
							header: false,
							id: idname + '_panel2',
							addClass: 'panelAlt',					
							contentURL: BaseUrl + '/index.php?do=api&act=menu&interfaceid='+interfaceid,
							column: idname + '_sideColumn',
							require: {
								onload: function(){
									//jQuery(".mymenu #MenuButton_3").click();
									ClickMenu(3);

								}			
							}			
						});
					}			
				});
	},		
	tableInfo : function (tableid){
		var idname = 'tableInfo_panel1';
		var url  = BaseUrl + '/index.php?do=index&act=tableinfo&tableid='+tableid;
		
		MUI.updateContent({			
					element: $(idname),
					url: url,
					require: {
						onload: function(){
						}	
					}
				});

	},
	tableList:function(){

		var idname = 'tableInfo';

		new MUI.Window({
					id: idname,
					title: '淘宝TOP数据结构',
					width: 820,
					height: 360,
					resizeLimit: {'x': [450, 2500], 'y': [300, 2000]},
					scrollbars: false, // Could make this automatic if a 'panel' method were created
					onContentLoaded: function(){	
				
						new MUI.Column({
							container:idname + '_contentWrapper',
							id: idname + '_sideColumn',
							placement: 'left',
							width: 200,
							resizeLimit: [100, 200]
						});
					
						new MUI.Column({
							container: idname + '_contentWrapper',
							id: idname + '_mainColumn',
							placement: 'main',
							width: null,
							resizeLimit: [100, 220]
						});
					
						new MUI.Panel({
							header: false,
							id: idname + '_panel1',					
							contentURL: BaseUrl + '/index.php?do=index&act=tableinfo&tableid=2',
							column: idname + '_mainColumn',
							panelBackground: '#fff',
							require: {
								css: [MUI.path.plugins + 'windowform/css/style.css'],
								onload: function(){
								}			
							}			
						});
					
						new MUI.Panel({
							header: false,
							id: idname + '_panel2',
							addClass: 'panelAlt',					
							contentURL: BaseUrl + '/index.php?do=index&act=tablelist',
							column: idname + '_sideColumn',
							require: {
								onload: function(){
								}			
							}			
						});
					}			
				});
	},
	UserLogin:function(){
		var id = 'userlogin';
		new MUI.Window({
			id: id,
			title: '用户登录',
			loadMethod: 'xhr',
			contentURL: BaseUrl + '/index.php?do=user&act=login',
			width: 300,
			height: 200,
			scrollbars: false,
			resizable: false,
			maximizable: false,
			padding: { top: 0, right: 0, bottom: 0, left: 0 },
			require: {
				css: [MUI.path.plugins + 'accordian/css/style.css'],
				onload: function(){
					this.windowEl = $(id);				
					new Accordion('#' + id + ' h3.accordianToggler', "#" + id + ' div.accordianElement',{
						opacity: false,
						alwaysHide: true,
						onActive: function(toggler, element){
							toggler.addClass('open');
						},
						onBackground: function(toggler, element){
							toggler.removeClass('open');
						},							
						onStart: function(toggler, element){
							this.windowEl.accordianResize = function(){
								MUI.dynamicResize($(id));
							}
							this.windowEl.accordianTimer = this.windowEl.accordianResize.periodical(10);
						}.bind(this),
						onComplete: function(){
							this.windowEl.accordianTimer = $clear(this.windowEl.accordianTimer);
							MUI.dynamicResize($(id)) // once more for good measure
						}.bind(this)
					}, $(id));
				}	
			}
		});
	}	
}