/**
*
*  VZ.LT window click event handler
*
**/

var clickEventHandler = {

	//public method to handle mouse click on VZ.LT window
	register : function (e)	{
		e  = e || window.event;
		
	    var tg = (window.event) ? e.srcElement : e.target;
	    
	    if(tg == null)
	    {
       	    if (typeof linker != 'undefined') {
				linker.hide_pop_up();
			}	
			if (typeof search_select != 'undefined') {
				search_select.hide_cat();
			}	
			if (typeof electionsSubmenu != 'undefined') {
				electionsSubmenu.rinkimaiSubmenuHideAll();
			}
	        return;
	    }    
		
	    if (typeof linker != 'undefined') {
			clickEventHandler._handleLinker(e, tg);
		}	
	    if (typeof search_select != 'undefined') {
			clickEventHandler._handleSearchSelect(tg);
		}
	    if (typeof electionsSubmenu != 'undefined') {
			clickEventHandler._handleElectionsSubmenu(tg);
		};
	},
		
	//public method to register Handler function
	go : function()	{
		 document.onclick = this.register;
	},	
		
	//private method to handle Linker pop-up window
	_handleLinker : function (e, tg) {

		linker.pop_up = $('linker_pop_up');

	    if(tg.className == 'linker_activate')
	    {
		   if(linker.pop_up.style.display == 'block')
			   linker.hide_pop_up();
		   else 
			   linker.show_pop_up(e);
	    }
		else
		{
		   linker.hide_pop_up();
		}
	},	

	//private method to handle Search Selection
	_handleSearchSelect : function (tg)	{
	    if( (tg.id == 'activeSearchSelect')||(tg.id =='activeSearchIcon')||(tg.id =='activeSearchText') )
	    {
	        if( search_select.cat_list.style.display == 'block' )
	            search_select.hide_cat();
	        else
	            search_select.show_cat();
	    }
	    else
	    {
	        search_select.hide_cat();
	    }
	},	

	//private method to handle Elections Submenu
	_handleElectionsSubmenu : function (tg)	{
	    var id = -1;
	    
	    for (var idx=0; idx<electionsSubmenu.parents.length; idx++)
	    	if (tg.id == electionsSubmenu.parents[idx])
	    		id = idx;
	    
	    if (id != -1)
	    {
	        if( $(electionsSubmenu.children[id]).style.display == 'none' ) {
	            electionsSubmenu.rinkimaiSubmenuHideAll();
	            electionsSubmenu.rinkimaiSubmenuShow(electionsSubmenu.parents[id], electionsSubmenu.children[id]);  }
	        else 
	            electionsSubmenu.rinkimaiSubmenuHide(electionsSubmenu.children[id]);
	    }
	    else
            electionsSubmenu.rinkimaiSubmenuHideAll();
	}	
}