
var com = {
	userspace : {
		widgets : {

			websitesmenu : {

	MouseOver : function(parCode,oEvent)
	{
		var jMouseEvent = ct.mouse.GetEvent(oEvent);
		
		// Open submenu
		com.userspace.widgets.websitesmenu.OpenSubmenu(jMouseEvent.Target);
		
	},
	
	MouseOut : function(parCode,oEvent)
	{
	},
	
	OpenSubmenu : function(oMenuItem)
	{
		// --------------------------------------------------------------------------------------
		// Declare variables
		var oUL,oLI,oSpan,oLabel,oCur,oSubMenus,oSubMenu;
		
		// --------------------------------------------------------------------------------------
		// Find the LI and UL
		oLI = oDiv = oWidget  = null;
		oUL = oCur = oClicked = oMenuItem;
		while(oCur != document)
		{
			if (oCur.tagName == 'LI')	oLI = oCur;
			if (oCur.tagName == 'UL')	oUL = oCur;
			if (oCur.tagName == 'DIV' && /cw_widget/.test(oCur.className)){oWidget = oCur;break;}
			oCur = oCur.parentNode;
		}
		if (oUL == null || oLI == null || oWidget == null)
			return;
		
		// --------------------------------------------------------------------------------------
		// Get menus, then submenu
		oCTMenu		= $('div.ct_menu');
		if (!oCTMenu) return;
		oCTMenu[0].setAttribute('id',oWidget.getAttribute('id'));
		
		oSubMenus	= $('#' + oWidget.getAttribute('id') + ' ul.submenu.i' + oLI.getAttribute('x-index'));
		if (!oSubMenus) return
		if (oSubMenus.length == 0) return;
		
		// --------------------------------------------------------------------------------------
		// Display the menu
		ct.menu.ShowXY(oLI,{"X":0,"Y":0},oSubMenus[0],true);
	},
	
	effects:
	{
		
		chenillard : 
		{
			_jMenus : [],
			
			Start : function(parCode)
			{
				if (!this._jMenus[parCode])
					this._jMenus[parCode] = {oTimer:null,oMenu:null,iCurIndex:0};
				
				// --------------------------------------------------------------------------------------
				// Stop current animation
				this.Stop(parCode);
				
				// --------------------------------------------------------------------------------------
				// Create new one
				this._jMenus[parCode].oMenu		= $('#' + parCode + ' ul.menu')[0];
				this._jMenus[parCode].oTimer 	= setInterval("com.userspace.widgets.websitesmenu.effects.chenillard.Next('" + parCode + "');", 2000);
				this._jMenus[parCode].iCurIndex = 0;
			},
			
			Stop : function(parCode)
			{
				if (!this._jMenus[parCode])
					return;
				
				// --------------------------------------------------------------------------------------
				// Remove hilights and add hilight to the correct
				var jMenuData 	= this._jMenus[parCode];
				if (jMenuData.oMenu)
				{
					var tMenuItems	= $('li.item',jMenuData.oMenu);
					ct.style.klass.Remove(tMenuItems,'hilight');
				}
				
				// --------------------------------------------------------------------------------------
				// Clear interval
				clearInterval(this._jMenus[parCode].oTimer);
				this._jMenus[parCode] = {oTimer:null,oMenu:null,iCurIndex:0};
			},
	
			Next : function(parCode)
			{
				// --------------------------------------------------------------------------------------
				// Get ojects
				var jMenuData 	= this._jMenus[parCode];
				var tMenuItems	= $('li.item',jMenuData.oMenu);
				var oCTMenu		= $('div.ct_menu')[0];
				
				// --------------------------------------------------------------------------------------
				// Remove hilights and add hilight to the correct
				ct.style.klass.Remove(tMenuItems,'hilight');
				
				// --------------------------------------------------------------------------------------
				// Verify if the menu is already opened, then do not display animation
				if (!oCTMenu) return;
				if (oCTMenu.style.display == 'block' && oCTMenu.getAttribute('id') == parCode) return;
				
				// --------------------------------------------------------------------------------------
				// Hilight the current index
				ct.style.klass.Add(tMenuItems[jMenuData.iCurIndex],'hilight');
				jMenuData.iCurIndex = (jMenuData.iCurIndex < tMenuItems.length - 1 ? jMenuData.iCurIndex + 1 : jMenuData.iCurIndex = 0);
			}
		}
	}

			},
			websitesmenu : {

	MouseOver : function(parCode,oEvent)
	{
		var jMouseEvent = ct.mouse.GetEvent(oEvent);
		
		// Open submenu
		com.userspace.widgets.websitesmenu.OpenSubmenu(jMouseEvent.Target);
		
	},
	
	MouseOut : function(parCode,oEvent)
	{
	},
	
	OpenSubmenu : function(oMenuItem)
	{
		// --------------------------------------------------------------------------------------
		// Declare variables
		var oUL,oLI,oSpan,oLabel,oCur,oSubMenus,oSubMenu;
		
		// --------------------------------------------------------------------------------------
		// Find the LI and UL
		oLI = oDiv = oWidget  = null;
		oUL = oCur = oClicked = oMenuItem;
		while(oCur != document)
		{
			if (oCur.tagName == 'LI')	oLI = oCur;
			if (oCur.tagName == 'UL')	oUL = oCur;
			if (oCur.tagName == 'DIV' && /cw_widget/.test(oCur.className)){oWidget = oCur;break;}
			oCur = oCur.parentNode;
		}
		if (oUL == null || oLI == null || oWidget == null)
			return;
		
		// --------------------------------------------------------------------------------------
		// Get menus, then submenu
		oCTMenu		= $('div.ct_menu');
		if (!oCTMenu) return;
		oCTMenu[0].setAttribute('id',oWidget.getAttribute('id'));
		
		oSubMenus	= $('#' + oWidget.getAttribute('id') + ' ul.submenu.i' + oLI.getAttribute('x-index'));
		if (!oSubMenus) return
		if (oSubMenus.length == 0) return;
		
		// --------------------------------------------------------------------------------------
		// Display the menu
		ct.menu.ShowXY(oLI,{"X":0,"Y":0},oSubMenus[0],true);
	},
	
	effects:
	{
		
		chenillard : 
		{
			_jMenus : [],
			
			Start : function(parCode)
			{
				if (!this._jMenus[parCode])
					this._jMenus[parCode] = {oTimer:null,oMenu:null,iCurIndex:0};
				
				// --------------------------------------------------------------------------------------
				// Stop current animation
				this.Stop(parCode);
				
				// --------------------------------------------------------------------------------------
				// Create new one
				this._jMenus[parCode].oMenu		= $('#' + parCode + ' ul.menu')[0];
				this._jMenus[parCode].oTimer 	= setInterval("com.userspace.widgets.websitesmenu.effects.chenillard.Next('" + parCode + "');", 2000);
				this._jMenus[parCode].iCurIndex = 0;
			},
			
			Stop : function(parCode)
			{
				if (!this._jMenus[parCode])
					return;
				
				// --------------------------------------------------------------------------------------
				// Remove hilights and add hilight to the correct
				var jMenuData 	= this._jMenus[parCode];
				if (jMenuData.oMenu)
				{
					var tMenuItems	= $('li.item',jMenuData.oMenu);
					ct.style.klass.Remove(tMenuItems,'hilight');
				}
				
				// --------------------------------------------------------------------------------------
				// Clear interval
				clearInterval(this._jMenus[parCode].oTimer);
				this._jMenus[parCode] = {oTimer:null,oMenu:null,iCurIndex:0};
			},
	
			Next : function(parCode)
			{
				// --------------------------------------------------------------------------------------
				// Get ojects
				var jMenuData 	= this._jMenus[parCode];
				var tMenuItems	= $('li.item',jMenuData.oMenu);
				var oCTMenu		= $('div.ct_menu')[0];
				
				// --------------------------------------------------------------------------------------
				// Remove hilights and add hilight to the correct
				ct.style.klass.Remove(tMenuItems,'hilight');
				
				// --------------------------------------------------------------------------------------
				// Verify if the menu is already opened, then do not display animation
				if (!oCTMenu) return;
				if (oCTMenu.style.display == 'block' && oCTMenu.getAttribute('id') == parCode) return;
				
				// --------------------------------------------------------------------------------------
				// Hilight the current index
				ct.style.klass.Add(tMenuItems[jMenuData.iCurIndex],'hilight');
				jMenuData.iCurIndex = (jMenuData.iCurIndex < tMenuItems.length - 1 ? jMenuData.iCurIndex + 1 : jMenuData.iCurIndex = 0);
			}
		}
	}

			},
			"end":"end"
		},
		apps : {

			"end":"end"
		}
	}
};

