// GC CLASS FOR WEB SITE CLASS
// MADE BY SHARJEEL BIN SALEEM Date:18th Feb, 2010 


var GC =Class.create();



// FOR DIV SECTIONS 
GC.prototype.menu = {
	
    /*
      LIST OF MENUES
      new Array ('ID MENU', 'TITLE', 'IMAGE', 'RollOVER IMAGE', 'LINK')
      Return Menu Array 
    */
	parentMenu:function(){

		// new Array(id, 'name', 'image', 'image-over', 'URL', 'Width')
		var menuList = new Array(new Array('0','home','nav_home.png','nav_home-da.png','/index.html','28.6em'),
						   	 //new Array('8','schedule','nav_schedule.png','nav_schedul-da.png','/schedule/schedule.pdf','22.6em'),
							 
							// new Array('1','submission','nav_papersubmission.png','nav_papersubmission-da.png','/call_papers.html','26.6em'),
							 new Array('1','callforpaper','nav_call.png','nav_call-da.png','/call_papers.html','26.6em'),
							/* new Array('2','submitpapers','submit_nav.png','','https://www.easychair.org/login.cgi?conf=igcc10','17.6em'),*/
							 //new Array('3','location','nav_loc.png','nav_loc-da.png','/location.html','16.6em'),
							 //new Array('4','registration','nav_reg.png','nav_reg-da.png','https://www.eiseverywhere.com/ereg/newreg.php?eventid=22870&','15.6em'),
							 new Array('4','registration','nav_reg.png','nav_reg-da.png','/fee.html','15.6em'),
							// new Array('5','sponsors','nav_sponsors.png','nav_sponsors.png','/sponsors.html','17.6em'),
							 new Array('6','workshop','nav_workshop.png','nav_workshop-da.png','/PMP2012.html','34.6em'),
							new Array('7','archievs','nav_arch.png','nav_arch-da.png','/','19.6em'),
new Array('8','contact','nav_contact.png','nav_contact-da.png','/contact_us.html','19.6em')

							//new Array('9','future','nav_future.png','nav_future-da.png','/2012','19.6em')
							);
		
			return 	menuList;				
	},
	
	/*
		subMenuList : LIST OF SUB MENUES
		new Array ('ID SUB MENU', 'TITLE', 'IMAGE', 'RollOVER IMAGE', 'LINK','PARENT MENU') 			
		Return Sub Menu Array 
	*/
	
	subMenu:function(){
		// new Array(id, 'name', 'image', 'target', 'URL', 'Parent', 'Width','margin')
		var subMenuList = new Array( 
								
								 
								 new Array('101','Main Conference Home','mainconferencehome.png','_self','/index.html','0','18.6em','0'),
								 new Array('104','WorkShop','topicsnew.png','_self','/index.html#topic','0','18.6em','0'),
								 //new Array('105','Main Conference Home','committee.png','_self','/index.html#committee','0','18.6em','0'),
								 new Array('106','Main Conference Home','chairsnew.png','_self','/index.html#committee','0','18.6em','0'),
								 
								 //new Array('102','chairs','chairs.png','_self','/index.html#committee','0','18.6em','0'),
 								 new Array('103','steeringcommittee','steeringcommittee.png','_self','/index.html#steering','0','18.6em','0'),
								 new Array('107','workshops','workshops.png','_self','/index.html#workshop','0','35.6em','0'),
								 new Array('111','awards2012','awards2012.png','_self','/index.html#awards','0','35.6em','0'),
								 new Array('112','Deadlines','Deadlines.png','_self','/index.html#dates','0','18.6em','0'),

								
									
								 
								
									//Call for papers menu
									
//								 new Array('111','Computing Conference','camerareadycopies.png','_self','/call_papers.html','1','18.6em','0'),
//								 new Array('112','Computing Conference','CameraReadyInstructionsinpd.png','_blank','docs/InstructionsFinal.pdf','1','18.6em','0'),			   
								 //new Array('111','Computing Conference','topicinterest.png','_self','call_papers.html#topics','1','20.6em','0'),
								 //new Array('112','Computing Conference','organization.png','_self','call_papers.html#organization','1','20.6em','0'),
								 //new Array('113','Computing Conference','mainconferencedates.png','_self','/call_papers.html#dates','1','20.6em','0'),
								 //new Array('114','Computing Conference','MainConferenceAwards.png','_self','call_papers.html#award','1','20.6em','0'),
								 
								 
								 //new Array('115','instructions','MainConferenceCFPinpdf.png','_blank','/igcc-cfp-2012.pdf','1','20.6em','0'),
								 
								 new Array('112','Computing Conference','linktosubmit.png','_blank','https://www.easychair.org/account/signin.cgi?conf=igcc12','1','18.6em','0'),			   
								 new Array('113','Computing Conference2','manuscripts.png','_self','/call_papers.html#menu','1','18.6em','0'),
 								 new Array('111','Computing Conference','ManuscriptsWorkshops.png','_self','/call_papers.html#workshop','1','18.6em','0'),
								 new Array('114','Computing Conference3','CameraReadyCopies2.png','_self','/call_papers.html#cameraready','1','18.6em','0'),
								 new Array('115','instructions','BestPaperAwards.png','_self','/call_papers.html#award','1','18.6em','0'),
								 new Array('116','callforapers','CallForPapers.png','_blank','/igcc-cfp-2012.pdf','1','18.6em','0'),
								 new Array('117','submitpaper','submitpaper.png','_blank','https://www.easychair.org/account/signin.cgi?conf=igcc12','2','18.6em','0'),
								 new Array('411','fee','feeimage.png','_self','/fee.html','4','18.6em','0'),
								 
								 new Array('611','pmp','pmp.png','_self','/PMP2012.html','6','34.6em','0'),
								 new Array('612','WorkingProcess','WorkinProgressinGreenComput.png','_self','/wipgc.html','6','34.6em','0'),
								 new Array('613','IGCCPhd','IGCCPhDForum.png','_self','/igccphd.html','6','34.6em','0'),
								 new Array('614','ECRSS','Ecss.png','_self','/erss.html','6','34.6em','0'),
								 new Array('615','PGFC','PowerGrid-FriendlyComputing.png','_self','/pgfc.html','6','34.6em','0'),
								 new Array('616','EFCC','EnergyEfficientCloudComputi.png','_self','/gcc.html','6','34.6em','0'),
								 
								 
																	 
/*								 new Array('112','Computing Conference','CameraReadyInstructionsinpd.png','_blank','/docs/InstructionsFinal.pdf','1','18.6em','0'),			   
								 new Array('113','Computing Conference2','mainconferencedates.png','_self','/#dates','1','18.6em','0'),
 								 new Array('111','Computing Conference','camerareadycopies.png','_self','/call_papers.html','1','18.6em','0'),
								 new Array('114','Computing Conference3','MainConferenceAwards.png','_self','/#awards','1','18.6em','0'),
								 new Array('115','instructions','MainConferenceCFPinpdf.png','_blank','/igcc-cfp-2012.pdf','1','18.6em','0'),
								
	*/							 
								 //new Array('103','Main Conference Home','mainconferencehome.png','','index.html','0','18.6em'),
													
								// new Array('112','Committee','soc.png','','https://www.easychair.org/login.cgi?conf=igcc10','1','17.6em'),
								 //contactUs Menu
								// new Array('121','subscribe','subscribe.png','_self','/contact_us.html#green','6','17.6em','0'),
								// new Array('122','green forum','greenforum.png','_self','/contact_us.html#greenforum','6','17.6em','0'),
								// new Array('123','more information','moreinformations.png','_self','/contact_us.html#information','6','17.6em','0'),
								  new Array('124','IGCC10','IGCC10.png','_self','/2010','7','14.6em','0'),
								  new Array('124','IGCC10','IGCC11.png','_self','/2011','7','14.6em','0')
								 // Registration
							// new Array('131','Information','informationandrates.png','_self','/registration.html','4','16.6em','0'),
	//							 new Array('132','singup','singup.png','_blank','http://www.regonline.com/greencomp','4','16.6em','0'),
								  // Schedule
								  
 //		 	 new Array('150','Schdule1','ScheduleonGoogle.png','_self','/schedule/googlecalendar.html','8','16.6em','0'),
/*
								 new Array('151','Schdule2','Scheduleonly.png','_self','/schedule.html','8','16.6em','0'),
				new Array('151','Schdule2','ScheduleGlance.png','_self','/schedule/schedule.pdf','8','16.6em','0'),
							   	// new Array('152','Schdule3','Accepted.png','_self','/schedule/acceptedpapers.pdf','8','16.6em','0'),
								 							   	 new Array('152','Schdule3','IGCConGoogleCalendar.png','_blank','http://www.google.com/calendar/embed?src=a79s7miubus40uvb6ff0mer248%40group.calendar.google.com&ctz=America/New_York&dates=20110725%2F20110728','8','16.6em','0'),
								  
//							     new Array('153','Schdule4','acceptedpapers.png','_self','/schedule/soc_accepted.html','8','16.6em','0'),
//								 new Array('154','Schdule5','acceptedpapersworkshop.png','_self','/schedule/wipg_accepted.html','8','16.6em','0'),
								 
								 //Location Menu
 								 new Array('141','topic interest','Location-Lodging.png','_self','/location.html','3','16.6em','0'),
						//		 new Array('142','Make Reservation','MakeReservation.png','_self','http://www.ichotelsgroup.com/h/d/cp/1/en/advancedsearch?whichtype=room&roomResult=none&hotelCode=chiav&quickRes=city&_GPC=WSU&_requestid=103672','3','16.6em','0'),
								 new Array('143','Directions','DirectionsfromAirport.png','_blank','http://maps.google.com/maps?saddr=Orlando+International+Airport,+Airport+Boulevard,+Orlando,+FL&daddr=1805+Hotel+Plaza+Blvd,+Orlando,+FL+32830&hl=en&ll=28.417674,-81.373329&spn=0.153996,0.220757&sll=28.375087,-81.50823&sspn=0.038514,0.055189&geocode=FVnesQEdblIn-yFg7nvGGmXZ2Q%3BFS_4sAEdekgk-ykbfla7JYDdiDFQ1oOiyq9ozA&mra=ls&z=12','3','16.6em','0'),
								 new Array('144','Social Events','SocialEvents.png','_self','/events.html','3','16.6em','0')
								 */
								 );
		return subMenuList;
	},
	
	subMenuSecondry:function (){
	},
		
	/*
		generateMenu : GENERATE MENUS 
		FUCNTION Get thelist of all parent menu and then for each parent 
		menu it finds the sub menus of each parent. 
		Set the inner html of DIV 
	*/	
	generateMenu:function(){
		
		menuList = GC.menu.parentMenu();
		menuHTML = "";
		$counter = 0;
		background ="#7B84BA";
		imagePath = "/images/";
		
		for(i =0; i < menuList.length; i++ ) {
			menu = menuList[i];

			parentName = menu[1];
			parentId = menu[1];
			parentImage = menu[2];
			parentImageOver = menu[3];
			parentLink = menu[4];
			
			subMenuList = GC.menu.getSubMenuById(menu[0]);
			
			if( subMenuList != null &&  subMenuList.length > 0 ) {
				
				
				// Creating Parent Menus 
				menuHTML += '<li><a class="MenuBarItemSubmenu" href="'+parentLink+'">'
							+ '<img name="'+parentId+'" src="'+imagePath+parentImage+'" border=0  onMouseover="this.src=\''+imagePath+parentImageOver+'\'" '
							+ 'onMouseOut="this.src=\''+imagePath+parentImage+'\'"  /></a>';
							
				menuHTML += '<ul style="padding-left:0px; display:table; width:'+menu[5]+'" onMouseover="document[\''+parentId+'\'].src=\''+imagePath+parentImageOver+'\'"'
									+ 'onMouseOut="document[\''+parentId+'\'].src=\''+imagePath+parentImage+'\'">';
				
				totalMainLoop = subMenuList.length;
				for( k=0; k < totalMainLoop; k++ ){
					
					//Creating Child menus
					subMenu = subMenuList[k];
					marginImage = subMenu[7];	
					
					if( subMenu[2] != ""  ) {
						menuHTML += '<li style="padding:1px;  text-align:left; width:'+menu[5]+'" >'
									+ '<a href="'+subMenu[4]+'" style="margin-left:-10px;" target="'+subMenu[3]+'">'
									+ '<img src="'+imagePath + 'menus/'+subMenu[2]+'" border="3" style="margin-left:'+marginImage+';" /></a>';
						if(subMenu[0] == 108){
							subMenuListSub = GC.menu.getSubMenuById(108);						
							if(subMenuListSub != null && subMenuListSub.length > 0){
											///////////////////////////
																		
									menuHTML += '<ul style="margin-left: 140px; margin-top: -5px;padding-left:0px; display:table; width:'+subMenu[6]+'" onMouseover="document[\''+subMenu[0]+'\'].src=\''+imagePath+subMenu[8]+'\'"'
									+ 'onMouseOut="document[\''+subMenu[0]+'\'].src=\''+imagePath+subMenu[2]+'\'">';
				
									totalMainLoop = subMenuListSub.length;
									for( k=0; k < totalMainLoop; k++ ){
											subMenu = subMenuListSub[k];
									marginImage = subMenu[7];	
									if ( subMenu[2] != ""  ) {
									menuHTML += '<li style="padding:1px;  text-align:left; width:500px" >'
									+ '<a href="'+subMenu[4]+'" style="margin-left:-10px;" target="'+subMenu[3]+'">'
									+ '<img src="'+imagePath +'menus/'+subMenu[2]+'" border="3" style="margin-left:'+marginImage+';" /></a>';
									var subMenuLiSize =  subMenu[6];
									menuHTML += '</li>';
								
									} else {
									menuHTML += '<li><a href="'+subMenu[4]+'"  target="'+subMenu[3]+'">'+subMenu[1]+'</a></li>';
									}
								//Creating Child menus
									}
									menuHTML += '</ul></li>';
											//////////////////////////////////
							}
						}
						
						var subMenuLiSize =  subMenu[6];
						menuHTML += '</li>';
						
					} else {
						menuHTML += '<li><a href="'+subMenu[4]+'"  target="'+subMenu[3]+'">'+subMenu[1]+'</a></li>';
					}

				}
				menuHTML += '</ul></li>';
				$counter++;
			
			} else {
				menuHTML += '<li><a class="MenuBarItemSubmenu"  href="'+parentLink+'"><img src="'+imagePath+parentImage+'" border=0 style="margin-left:'+marginImage+'" /></a></li>';
			}
			
		}
		
		$('MenuBar1').innerHTML = menuHTML;
	},
	
	getSubMenuById:function(parentId){
		var subMenuList = GC.menu.subMenu();
		var subList = new Array();
		var count = 0;
		for(k = 0; k < subMenuList.length; k++){
			var smenu = subMenuList[k];
			if( smenu[5] == parentId){
				subList[count] = smenu;
				count++;
			}
		}
		return subList;
	},
	
	getSubMenuByIdsecondary:function(parentId){
		
		var subMenuList = GC.menu.subMenuSecondry();
		/*
		var subList = new Array();
		var count = 0;
		
		for(l = 0; l < subMenuList.length; l++){
			var smenu = subMenuList[l];
			if( smenu[5] == parentId){
				subList[count] = smenu;
				count++;
			}
			
		}
		*/
		return subList;
		
	}
	
};

		
var Spry;
if(!Spry)
{
	Spry = {};
}
if(!Spry.Widget)
{
	Spry.Widget = {};
}

// Constructor for Menu Bar
// element should be an ID of an unordered list (<ul> tag)
// preloadImage1 and preloadImage2 are images for the rollover state of a menu
Spry.Widget.MenuBar = function(element, opts)
{
	this.init(element, opts);
};

Spry.Widget.MenuBar.prototype.init = function(element, opts)
{
	this.element = this.getElement(element);

	// represents the current (sub)menu we are operating on
	this.currMenu = null;

	var isie = (typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE');
	if(typeof document.getElementById == 'undefined' || (navigator.vendor == 'Apple Computer, Inc.' && typeof window.XMLHttpRequest == 'undefined') || (isie && typeof document.uniqueID == 'undefined'))
	{
		// bail on older unsupported browsers
		return;
	}

	// load hover images now
	if(opts)
	{
		for(var k in opts)
		{
			var rollover = new Image;
			rollover.src = opts[k];
		}
	}

	if(this.element)
	{
		this.currMenu = this.element;
		var items = this.element.getElementsByTagName('li');
		for(var i=0; i<items.length; i++)
		{
			this.initialize(items[i], element, isie);
			if(isie)
			{
				this.addClassName(items[i], "MenuBarItemIE");
				items[i].style.position = "static";
			}
		}
		if(isie)
		{
			if(this.hasClassName(this.element, "MenuBarVertical"))
			{
				this.element.style.position = "relative";
			}
			var linkitems = this.element.getElementsByTagName('a');
			for(var i=0; i<linkitems.length; i++)
			{
				linkitems[i].style.position = "relative";
			}
		}
	}
};

Spry.Widget.MenuBar.prototype.getElement = function(ele)
{
	if (ele && typeof ele == "string")
		return document.getElementById(ele);
	return ele;
};

Spry.Widget.MenuBar.prototype.hasClassName = function(ele, className)
{
	if (!ele || !className || !ele.className || ele.className.search(new RegExp("\\b" + className + "\\b")) == -1)
	{
		return false;
	}
	return true;
};

Spry.Widget.MenuBar.prototype.addClassName = function(ele, className)
{
	if (!ele || !className || this.hasClassName(ele, className))
		return;
	ele.className += (ele.className ? " " : "") + className;
};

Spry.Widget.MenuBar.prototype.removeClassName = function(ele, className)
{
	if (!ele || !className || !this.hasClassName(ele, className))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};

// addEventListener for Menu Bar
// attach an event to a tag without creating obtrusive HTML code
Spry.Widget.MenuBar.prototype.addEventListener = function(element, eventType, handler, capture)
{
	try
	{
		if (element.addEventListener)
		{
			element.addEventListener(eventType, handler, capture);
		}
		else if (element.attachEvent)
		{
			element.attachEvent('on' + eventType, handler);
		}
	}
	catch (e) {}
};

// createIframeLayer for Menu Bar
// creates an IFRAME underneath a menu so that it will show above form controls and ActiveX
Spry.Widget.MenuBar.prototype.createIframeLayer = function(menu)
{
	var layer = document.createElement('iframe');
	layer.tabIndex = '-1';
	layer.src = 'javascript:false;';
	menu.parentNode.appendChild(layer);
	
	layer.style.left = menu.offsetLeft + 'px';
	layer.style.top = menu.offsetTop + 'px';
	layer.style.width = menu.offsetWidth + 'px';
	layer.style.height = menu.offsetHeight + 'px';
};

// removeIframeLayer for Menu Bar
// removes an IFRAME underneath a menu to reveal any form controls and ActiveX
Spry.Widget.MenuBar.prototype.removeIframeLayer =  function(menu)
{
	var layers = menu.parentNode.getElementsByTagName('iframe');
	while(layers.length > 0)
	{
		layers[0].parentNode.removeChild(layers[0]);
	}
};

// clearMenus for Menu Bar
// root is the top level unordered list (<ul> tag)
Spry.Widget.MenuBar.prototype.clearMenus = function(root)
{
	var menus = root.getElementsByTagName('ul');
	for(var i=0; i<menus.length; i++)
	{
		this.hideSubmenu(menus[i]);
	}
	this.removeClassName(this.element, "MenuBarActive");
};

// bubbledTextEvent for Menu Bar
// identify bubbled up text events in Safari so we can ignore them
Spry.Widget.MenuBar.prototype.bubbledTextEvent = function()
{
	return (navigator.vendor == 'Apple Computer, Inc.' && (event.target == event.relatedTarget.parentNode || (event.eventPhase == 3 && event.target.parentNode == event.relatedTarget)));
};

// showSubmenu for Menu Bar
// set the proper CSS class on this menu to show it
Spry.Widget.MenuBar.prototype.showSubmenu = function(menu)
{
	if(this.currMenu)
	{
		this.clearMenus(this.currMenu);
		this.currMenu = null;
	}
	
	if(menu)
	{
		this.addClassName(menu, "MenuBarSubmenuVisible");
		if(typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE')
		{
			if(!this.hasClassName(this.element, "MenuBarHorizontal") || menu.parentNode.parentNode != this.element)
			{
				menu.style.top = menu.parentNode.offsetTop + 'px';
			}
		}
		if(typeof document.uniqueID != "undefined")
		{
			this.createIframeLayer(menu);
		}
	}
	this.addClassName(this.element, "MenuBarActive");
};

// hideSubmenu for Menu Bar
// remove the proper CSS class on this menu to hide it
Spry.Widget.MenuBar.prototype.hideSubmenu = function(menu)
{
	if(menu)
	{
		this.removeClassName(menu, "MenuBarSubmenuVisible");
		if(typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE')
		{
			menu.style.top = '';
			menu.style.left = '';
		}
		this.removeIframeLayer(menu);
	}
};

// initialize for Menu Bar
// create event listeners for the Menu Bar widget so we can properly
// show and hide submenus
Spry.Widget.MenuBar.prototype.initialize = function(listitem, element, isie)
{
	var opentime, closetime;
	var link = listitem.getElementsByTagName('a')[0];
	var submenus = listitem.getElementsByTagName('ul');
	var menu = (submenus.length > 0 ? submenus[0] : null);

	var hasSubMenu = false;
	if(menu)
	{
		this.addClassName(link, "MenuBarItemSubmenu");
		hasSubMenu = true;
	}

	if(!isie)
	{
		// define a simple function that comes standard in IE to determine
		// if a node is within another node
		listitem.contains = function(testNode)
		{
			// this refers to the list item
			if(testNode == null)
			{
				return false;
			}
			if(testNode == this)
			{
				return true;
			}
			else
			{
				return this.contains(testNode.parentNode);
			}
		};
	}
	
	// need to save this for scope further down
	var self = this;

	this.addEventListener(listitem, 'mouseover', function(e)
	{
		if(self.bubbledTextEvent())
		{
			// ignore bubbled text events
			return;
		}
		clearTimeout(closetime);
		if(self.currMenu == listitem)
		{
			self.currMenu = null;
		}
		// show menu highlighting
		self.addClassName(link, hasSubMenu ? "MenuBarItemSubmenuHover" : "MenuBarItemHover");
		if(menu && !self.hasClassName(menu, "MenuBarSubmenuVisible"))
		{
			opentime = window.setTimeout(function(){self.showSubmenu(menu);}, 100);
		}
	}, false);

	this.addEventListener(listitem, 'mouseout', function(e)
	{
		if(self.bubbledTextEvent())
		{
			// ignore bubbled text events
			return;
		}

		var related = (typeof e.relatedTarget != 'undefined' ? e.relatedTarget : e.toElement);
		if(!listitem.contains(related))
		{
			clearTimeout(opentime);
			self.currMenu = listitem;

			// remove menu highlighting
			self.removeClassName(link, hasSubMenu ? "MenuBarItemSubmenuHover" : "MenuBarItemHover");
			if(menu)
			{
				closetime = window.setTimeout(function(){self.hideSubmenu(menu);}, 600);
			}
		}
	}, false);
};

