﻿function CMenu(aa){if(typeof aa.iname!='string'){alert('CMenu initialization error: Instance name is missing');return;}
this.iname=aa.iname;var ba=navigator.userAgent.toLowerCase().match(/msie (\d(.\d*)?)/);var ca=ba&&ba[1]&&ba[1]<7;this.hide_timeout=typeof aa.hide_timeout!='number'?500:aa.hide_timeout;this.mi_layers=typeof aa.mi_layers!='number'?1:aa.mi_layers;if(this.mi_layers<1)this.mi_layers=1;this.mi_empty_normal_class=typeof aa.mi_empty_normal_class!='string'?'':aa.mi_empty_normal_class;this.mi_empty_hover_class=typeof aa.mi_empty_hover_class!='string'?'':aa.mi_empty_hover_class;this.mi_full_normal_class=typeof aa.mi_full_normal_class!='string'?'':aa.mi_full_normal_class;this.mi_full_hover_class=typeof aa.mi_full_hover_class!='string'?'':aa.mi_full_hover_class;this.rounded_corners=typeof aa.rounded_corners!='boolean'?true:aa.rounded_corners;this.transparency=typeof aa.transparency!='boolean'?true:aa.transparency;if(this.transparency){this.transparency_ie6=typeof aa.transparency_ie6!='boolean'?false:aa.transparency_ie6;if(!this.transparency_ie6&&ca)this.transparency=false;}
if(this.transparency){this.min_opacity=typeof aa.min_opacity!='number'?0:aa.min_opacity;if(this.min_opacity<0)this.min_opacity=0;else if(this.min_opacity>100)this.min_opacity=100;this.max_opacity=typeof aa.max_opacity!='number'?0:aa.max_opacity;if(this.max_opacity<0)this.max_opacity=0;else if(this.max_opacity>100)this.max_opacity=100;}
this.panel_offset1_x=typeof aa.panel_offset1_x!='number'?0:aa.panel_offset1_x;this.panel_offset1_y=typeof aa.panel_offset1_y!='number'?0:aa.panel_offset1_y;this.panel_offset2_x=typeof aa.panel_offset2_x!='number'?0:aa.panel_offset2_x;this.panel_offset2_y=typeof aa.panel_offset2_y!='number'?0:aa.panel_offset2_y;if(!this.rounded_corners){this.panel_offset2_x=0;this.panel_offset2_y=0;}
this.itemborder_class=typeof aa.itemborder_class!='string'?'':aa.itemborder_class;this.separator_class=typeof aa.separator_class!='string'?'':aa.separator_class;this.panel_class=typeof aa.panel_class!='string'?'':aa.panel_class;this.panel_tl_class=typeof aa.panel_tl_class!='string'?'':aa.panel_tl_class;this.panel_tc_class=typeof aa.panel_tc_class!='string'?'':aa.panel_tc_class;this.panel_tr_class=typeof aa.panel_tr_class!='string'?'':aa.panel_tr_class;this.panel_ml_class=typeof aa.panel_ml_class!='string'?'':aa.panel_ml_class;this.panel_mr_class=typeof aa.panel_mr_class!='string'?'':aa.panel_mr_class;this.panel_bl_class=typeof aa.panel_bl_class!='string'?'':aa.panel_bl_class;this.panel_bc_class=typeof aa.panel_bc_class!='string'?'':aa.panel_bc_class;this.panel_br_class=typeof aa.panel_br_class!='string'?'':aa.panel_br_class;this.ch_create=typeof aa.ch_create=='undefined'?null:aa.ch_create;this.ch_mouseover=typeof aa.ch_mouseover=='undefined'?null:aa.ch_mouseover;this.ch_mouseout=typeof aa.ch_mouseout=='undefined'?null:aa.ch_mouseout;this.ch_panel_show=typeof aa.ch_panel_show=='undefined'?null:aa.ch_panel_show;this.ch_panel_hide=typeof aa.ch_panel_hide=='undefined'?null:aa.ch_panel_hide;this.ch_state_change=typeof aa.ch_state_change=='undefined'?null:aa.ch_state_change;this.animate=typeof aa.animate!='undefined'||typeof aa.anim_step!='undefined'||typeof aa.anim_interval!='undefined';if(typeof aa.animate=='boolean'&&!aa.animate)this.animate=false;if(this.animate){this.anim_step=typeof aa.anim_step!='number'?30:aa.anim_step;if(this.anim_step<=0||this.anim_step>100)this.anim_step=1;this.anim_interval=typeof aa.anim_interval!='number'?100:aa.anim_interval;}
this.side=typeof aa.side!='string'?'':aa.side.replace(/^\s+|\s+$/g,'').toLowerCase();if(this.side!='left'&&this.side!='right'&&this.side!='up'&&this.side!='down')this.side='right';this.orientation=typeof aa.orientation!='string'?'':aa.orientation.replace(/^\s+|\s+$/g,'').toLowerCase();if((this.side=='left'||this.side=='right')&&this.orientation!='up'&&this.orientation!='down')this.orientation='down';else if((this.side=='up'||this.side=='down')&&this.orientation!='left'&&this.orientation!='right')this.orientation='right';this.direction=this.side.charAt(0)+this.orientation.charAt(0);this.last_inst_id=0;this.menuitems=new Array();this.registry=new Array();this.timer_hide=0;this.vis_mi=null;this.wdg_base=document.getElementsByTagName('body')[0];}
CMenu.prototype.registry_add=function(mi){this.registry.push(mi);return this.registry.length-1;}
CMenu.prototype.add_item=function(da){da.base=this;da.parent=this;da.iname=typeof da.id!='string'?'':da.id;var mi=new CMenuItem(da,true);this.menuitems.push(mi);return mi;}
CMenu.prototype.run=function(){for(var i=0,len=this.menuitems.length;i<len;i++)this.menuitems[i].run();}
CMenu.prototype.handle_mouseover=function(ea,e){if(this.timer_hide>0){clearTimeout(this.timer_hide);this.timer_hide=0;}
var mi=this.registry[ea];if(this.vis_mi){var fa=new Array();mi.query_panels(fa,true);var ga=new Array();this.vis_mi.query_panels(ga,false);while(true){var ha=ga.shift();var ia=fa.shift();if(!ha)break;if(!ia||ha!=ia){ha.hide_now();while(ha=ga.shift())ha.hide_now();break;}}}
this.vis_mi=mi;mi.handle_mouseover(e);}
CMenu.prototype.handle_mouseout=function(ja,e){if(this.timer_hide==0)this.timer_hide=setTimeout('document["'+this.iname+'"].hide_process('+ja+')',this.hide_timeout);var mi=this.registry[ja];mi.handle_mouseout(e);}
CMenu.prototype.handle_click=function(ka){var mi=this.registry[ka];mi.handle_click();}
CMenu.prototype.hide_process=function(la){var mi=this.registry[la];mi.hide_process();}
function CMenuItem(ma,na){this.is_header=na;this.base=ma.base;this.parent=ma.parent;this.iname=typeof ma.iname!='string'?'':ma.iname;this.link=typeof ma.link!='string'?'':ma.link;this.caption=typeof ma.caption!='string'?'':ma.caption;this.selection=typeof ma.selection!='number'?0:ma.selection;this.type=typeof ma.type!='string'?'':ma.type;if(this.type!='text'&&this.type!='link'&&this.type!='link_new'&&this.type!='link_popup'&&this.type!='separator'){if(this.link!=''&&this.caption!='')this.type='link';else if(this.caption!='')this.type='text';else this.type='separator';}
this.panel_inner=null;this.panel_outer=null;this.panel_x=0;this.panel_y=0;this.panel_outer_w=0;this.panel_outer_h=0;this.panel_inner_w=0;this.panel_inner_h=0;this.panel_ch_x=0;this.panel_ch_y=0;this.panel_ch_min_w=0;this.anim_progress=0;this.anim_speed=0;this.anim_timer=0;this.menuitems=new Array();this.state_mouseover=false;this.state_panelopen=false;if(this.iname==''){this.wdg=document.createElement('div');if(typeof ma.id!='undefined')this.wdg.id=ma.id;var oa=this.parent.panel_inner;if(this.base.itemborder_class!=''&&oa.childNodes.length>0){var ib=document.createElement('div');oa.appendChild(ib);ib.className=this.base.itemborder_class;}
oa.appendChild(this.wdg);oa=this.wdg;for(var i=2;i<=this.base.mi_layers;i++){obj=document.createElement('div');oa.appendChild(obj);obj.className='l'+i;oa=obj;}
if(this.type=='separator'){if(this.base.separator_class!='')this.wdg.className=this.base.separator_class;}
else{if(this.caption!=''){var pa=document.createElement('div');pa.innerHTML=this.caption;pa.className='text';oa.appendChild(pa);}
if(this.type=='link'||this.type=='link_new'||this.type=='link_popup')this.wdg.style.cursor='pointer';this.h_state_change();}}
else{this.wdg=document.getElementById(this.iname);}
this.reg_id=this.base.registry_add(this);this.wdg.setAttribute('base_iname',this.base.iname);this.wdg.setAttribute('reg_id',this.reg_id);this.wdg.onmouseover=function(e){document[this.getAttribute('base_iname')].handle_mouseover(this.getAttribute('reg_id'),e);}
this.wdg.onmouseout=function(e){document[this.getAttribute('base_iname')].handle_mouseout(this.getAttribute('reg_id'),e);}
this.wdg.onclick=function(){document[this.getAttribute('base_iname')].handle_click(this.getAttribute('reg_id'));}
if(this.base.ch_create!=null)this.base.ch_create(this);}
CMenuItem.prototype.last_child=function(qa){while(qa.firstChild)qa=qa.firstChild;return qa;}
CMenuItem.prototype.isMouseEnterOrLeave=function(ra,e){if(e.type!='mouseout'&&e.type!='mouseover')return false;var sa=e.relatedTarget||(e.type=='mouseout'?e.toElement:e.fromElement);while(sa&&sa!=ra)sa=sa.parentNode;return sa!=ra;}
CMenuItem.prototype.add_item=function(ta){if(!this.panel_outer){this.panel_outer=document.createElement('div');this.base.wdg_base.appendChild(this.panel_outer);this.panel_outer.style.overflow='hidden';if(this.base.rounded_corners){var ua=document.createElement('table');this.panel_outer.appendChild(ua);ua.setAttribute('cellSpacing',0);ua.setAttribute('cellPadding',0);var va=document.createElement('tbody');ua.appendChild(va);var tr=document.createElement('tr');va.appendChild(tr);var wa=document.createElement('td');tr.appendChild(wa);if(this.base.panel_tl_class!='')wa.className=this.base.panel_tl_class;var xa=document.createElement('td');tr.appendChild(xa);if(this.base.panel_tc_class!='')xa.className=this.base.panel_tc_class;var ya=document.createElement('td');tr.appendChild(ya);if(this.base.panel_tr_class!='')ya.className=this.base.panel_tr_class;var tr=document.createElement('tr');va.appendChild(tr);var za=document.createElement('td');tr.appendChild(za);if(this.base.panel_ml_class!='')za.className=this.base.panel_ml_class;var Aa=document.createElement('td');tr.appendChild(Aa);var Ba=document.createElement('td');tr.appendChild(Ba);if(this.base.panel_mr_class!='')Ba.className=this.base.panel_mr_class;var tr=document.createElement('tr');va.appendChild(tr);var Ca=document.createElement('td');tr.appendChild(Ca);if(this.base.panel_bl_class!='')Ca.className=this.base.panel_bl_class;var Da=document.createElement('td');tr.appendChild(Da);if(this.base.panel_bc_class!='')Da.className=this.base.panel_bc_class;var Ea=document.createElement('td');tr.appendChild(Ea);if(this.base.panel_br_class!='')Ea.className=this.base.panel_br_class;this.panel_inner=document.createElement('div');Aa.appendChild(this.panel_inner);}
else{this.panel_inner=document.createElement('div');this.panel_outer.appendChild(this.panel_inner);}
if(this.base.panel_class!='')this.panel_inner.className=this.base.panel_class;}
ta.base=this.base;ta.parent=this;var mi=new CMenuItem(ta,false);this.menuitems.push(mi);this.h_state_change();return mi;}
CMenuItem.prototype.run=function(){if(this.panel_outer){this.panel_outer.style.position='absolute';this.panel_outer.style.visibility='hidden';this.panel_outer.style.left='0px';this.panel_outer.style.top='0px';this.panel_outer.style.display='block';this.panel_outer_w=this.panel_outer.offsetWidth;this.panel_outer_h=this.panel_outer.offsetHeight;this.panel_inner_w=this.panel_inner.offsetWidth;this.panel_inner_h=this.panel_inner.offsetHeight;this.panel_outer.style.display='none';this.panel_outer.style.visibility='visible';}
for(var i=0,len=this.menuitems.length;i<len;i++)this.menuitems[i].run();}
CMenuItem.prototype.query_panels=function(ar,Fa){if(Fa&&this.anim_speed<0)this.anim_speed=this.base.anim_step;if(this.panel_outer)ar.unshift(this);if(!this.is_header)this.parent.query_panels(ar,Fa);}
CMenuItem.prototype.handle_timer=function(){this.anim_timer=0;this.anim_progress+=this.anim_speed;var Ga=this.anim_speed>0?Math.ceil(this.anim_progress):Math.floor(this.anim_progress);if(Ga<=0){this.panel_hide();this.anim_speed=0;}
else{this.panel_show();if(Ga>100)Ga=100;this.animateit(Ga);if(Ga<100)this.anim_timer=setTimeout('document["'+this.base.iname+'"].registry['+this.reg_id+'].handle_timer()',this.base.anim_interval);else this.anim_speed=0;}}
CMenuItem.prototype.animateit=function(Ha){if(this.base.transparency){var Ia=Math.round((Ha/100)*(this.base.max_opacity-this.base.min_opacity)+this.base.min_opacity);this.panel_outer.style.opacity=Ia/100;this.panel_outer.style.filter='alpha(opacity='+Ia+')';}
var h=Math.round(this.panel_outer_h*Ha/100);switch(this.base.direction){case 'dl':case 'dr':case 'ld':case 'rd':this.panel_outer.style.height=h+'px';break;case 'ul':case 'ur':case 'lu':case 'ru':this.panel_outer.style.top=(this.panel_y+this.panel_outer_h-h)+'px';this.panel_outer.style.height=h+'px';this.panel_outer.scrollTop=this.panel_outer_h-h;break;}}
CMenuItem.prototype.hide_process=function(){if(this.panel_outer){if(this.base.animate&&this.anim_progress>1){if(this.anim_speed==0)this.anim_progress=100-this.base.anim_step;this.anim_speed=-this.base.anim_step;if(this.anim_timer==0)this.anim_timer=setTimeout('document["'+this.base.iname+'"].registry['+this.reg_id+'].handle_timer()',this.base.anim_interval);}
else{this.panel_hide();}}
if(!this.is_header)this.parent.hide_process();}
CMenuItem.prototype.hide_now=function(){if(this.anim_timer>0){clearTimeout(this.anim_timer);this.anim_timer=0;}
this.anim_speed=0;this.anim_progress=0;if(this.panel_outer)this.panel_hide();}
CMenuItem.prototype.handle_mouseover=function(e){if(!this.isMouseEnterOrLeave(this.wdg,e||window.event))return;if(this.base.ch_mouseover!=null)this.base.ch_mouseover(this);if(this.panel_outer){if(this.panel_ch_x==0&&this.panel_ch_y==0){var x=0,y=0,obj=this.wdg;while(obj){x+=obj.offsetLeft;y+=obj.offsetTop;obj=obj.offsetParent;}
switch(this.base.direction){case 'ul':if(this.is_header){x+=this.wdg.offsetWidth-this.panel_outer_w;y-=this.panel_outer_h;}
else{x-=this.panel_outer_w;y+=this.wdg.offsetHeight-this.panel_outer_h;}
break;case 'ur':if(this.is_header){y-=this.panel_outer_h;}
else{x+=this.wdg.offsetWidth;y+=this.wdg.offsetHeight-this.panel_outer_h;}
break;case 'dl':if(this.is_header){x+=this.wdg.offsetWidth-this.panel_outer_w;y+=this.wdg.offsetHeight;}
else{x-=this.panel_outer_w;}
break;case 'dr':if(this.is_header)y+=this.wdg.offsetHeight;else x+=this.wdg.offsetWidth;break;case 'lu':x-=this.panel_outer_w;y+=this.wdg.offsetHeight-this.panel_outer_h;break;case 'ld':x-=this.panel_outer_w;break;case 'ru':x+=this.wdg.offsetWidth;y+=this.wdg.offsetHeight-this.panel_outer_h;break;case 'rd':x+=this.wdg.offsetWidth;break;}
this.panel_x=x;this.panel_y=y;if(this.is_header){this.panel_x+=this.base.panel_offset1_x;this.panel_y+=this.base.panel_offset1_y;}
else{this.panel_x+=this.base.panel_offset2_x;this.panel_y+=this.base.panel_offset2_y;}}
else{this.panel_x=this.panel_ch_x;this.panel_y=this.panel_ch_y;}
if(this.panel_ch_min_w>0&&this.panel_outer_w<this.panel_ch_min_w)this.panel_inner.style.width=(this.panel_inner_w+this.panel_ch_min_w-this.panel_outer_w)+'px';this.panel_outer.style.left=this.panel_x+'px';this.panel_outer.style.top=this.panel_y+'px';this.panel_show();if(this.base.animate&&this.anim_progress<100){if(this.anim_speed==0){this.anim_progress=1;this.animateit(1);}
this.anim_speed=this.base.anim_step;if(this.anim_timer==0)this.anim_timer=setTimeout('document["'+this.base.iname+'"].registry['+this.reg_id+'].handle_timer()',this.base.anim_interval);}}
this.state_mouseover=true;this.h_state_change();}
CMenuItem.prototype.handle_mouseout=function(e){if(!this.isMouseEnterOrLeave(this.wdg,e||window.event))return;if(this.base.ch_mouseout!=null)this.base.ch_mouseout(this);this.state_mouseover=false;this.h_state_change();}
CMenuItem.prototype.handle_click=function(){if(this.link!=''){switch(this.type){case 'link':window.location=this.link;break;case 'link_new':window.open(this.link,'_blank');break;case 'link_popup':window.open(this.link,'','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550');break;}}}
CMenuItem.prototype.panel_show=function(){if(this.panel_outer.style.display!='block'){if(this.base.ch_panel_show!=null)this.base.ch_panel_show(this);this.panel_outer.style.height='1px';this.panel_outer.style.display='block';this.state_panelopen=true;this.h_state_change();}}
CMenuItem.prototype.panel_hide=function(){if(this.panel_outer.style.display!='none'){if(this.base.ch_panel_hide!=null)this.base.ch_panel_hide(this);this.panel_outer.style.display='none';this.state_panelopen=false;this.h_state_change();}}
CMenuItem.prototype.h_state_change=function(){if(this.base.ch_state_change!=null)this.base.ch_state_change(this);if(!this.is_header){if(this.type!='separator'){var Ja='mi'+(this.panel_outer?'_full':'_empty')+(this.state_mouseover||this.state_panelopen?'_hover':'_normal')+'_class';this.wdg.className=this.base[Ja];}}}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// <![CDATA[
document['cmenu_items'] = new Array();
document['cmenu_items'].push({id: 'cmi29', type: 'link', link: 'http://smilehost.asia/WebHosting.html', selection: 0});
document['cmenu_items'].push({id: 'cmi62', type: 'link', link: 'http://smilehost.asia/DomainName.html', selection: 0});
document['cmenu_items'].push({id: 'cmi71', type: 'link', link: 'http://smilehost.asia/Reseller.html', selection: 0});
document['cmenu_items'].push({id: 'cmi66', type: 'link', link: 'http://smilehost.asia/MediaStreaming.html', selection: 0});
document['cmenu_items'].push({id: 'cmi79', type: 'link', link: 'http://login.in.th/cart.php', selection: 0});
document['cmenu_items'].push({id: 'cmi28', parent_id: 'cmi29', type: 'link', link: 'http://smilehost.asia/WindowsHosting.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> วินโดวส์ โฮสติ้ง', selection: 0});
document['cmenu_items'].push({id: 'cmi30', parent_id: 'cmi29', type: 'link', link: 'http://smilehost.asia/LinuxHosting.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> ลินุกซ์ โฮสติ้ง', selection: 0});
//document['cmenu_items'].push({id: 'cmi54', parent_id: 'cmi29', type: 'link', link: 'http://smilehost.asia/EmailHosting.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> อีเมลล์ โฮสติ้ง', selection: 0});
document['cmenu_items'].push({id: 'cmi63', parent_id: 'cmi62', type: 'link', link: 'http://smilehost.asia/RegisterDomain.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> จดโดเมนเนมใหม่', selection: 0});
document['cmenu_items'].push({id: 'cmi64', parent_id: 'cmi62', type: 'link', link: 'http://smilehost.asia/TransferRenewDomain.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> ย้าย/ต่ออายุโดเมน', selection: 0});
document['cmenu_items'].push({id: 'cmi65', parent_id: 'cmi62', type: 'link', link: 'http://smilehost.asia/whois.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> ข้อมูลโดเมน (Whois)', selection: 0});
document['cmenu_items'].push({id: 'cmi72', parent_id: 'cmi71', type: 'link', link: 'http://smilehost.asia/ResellerHosting.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> ตัวแทนจำหน่ายโฮสติ้ง', selection: 0});
document['cmenu_items'].push({id: 'cmi73', parent_id: 'cmi71', type: 'link', link: 'http://smilehost.asia/ResellerDomain.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> ตัวแทนจำหน่ายโดเมน', selection: 0});
document['cmenu_items'].push({id: 'cmi67', parent_id: 'cmi66', type: 'link', link: 'http://smilehost.asia/RadioStreaming.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> วิทยุออนไลน์ : ShoutCast', selection: 0});
document['cmenu_items'].push({id: 'cmi68', parent_id: 'cmi66', type: 'link', link: 'http://smilehost.asia/TVStreaming.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> ทีวีออนไลน์ : WMS', selection: 0});
document['cmenu_items'].push({id: 'cmi68', parent_id: 'cmi66', type: 'link', link: 'http://smilehost.asia/FlashStreaming.html', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> ทีวีออนไลน์ : Flash <img src=http://smilehost.asia/images/icon_new.gif>', selection: 0});
document['cmenu_items'].push({id: 'cmi80', parent_id: 'cmi79', type: 'link', link: 'http://login.in.th/clientarea.php', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> เข้าสู่ระบบ', selection: 0});
document['cmenu_items'].push({id: 'cmi81', parent_id: 'cmi79', type: 'link', link: 'http://login.in.th/register.php', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> สมัครสมาชิก', selection: 0});
document['cmenu_items'].push({id: 'cmi81', parent_id: 'cmi79', type: 'link', link: 'http://login.in.th/cart.php', caption: '<img src="http://smilehost.asia/images/bullet-7.png" width="16" height="16"> สั่งซื้อ Order Now', selection: 0});
// ]]>

function addEvent(obj, event, func)
{
	if (obj.addEventListener)
		obj.addEventListener(event, func, false);
	else if (obj.attachEvent)
		obj.attachEvent('on' + event, func);
}


// CMenu handlers

function terahost_get_wdg(wdg_center)
{
	return {
		left: wdg_center.previousSibling.nodeType == 1 ? wdg_center.previousSibling : wdg_center.previousSibling.previousSibling,
		center: wdg_center,
		right: wdg_center.nextSibling.nodeType == 1 ? wdg_center.nextSibling : wdg_center.nextSibling.nextSibling
	}
}

function terahost_ch_create(mi)
{
	if (mi.is_header) {
		var wdg = terahost_get_wdg(mi.wdg);
		wdg.left.style.cursor = 'pointer';
		wdg.center.style.cursor = 'pointer';
		wdg.right.style.cursor = 'pointer';
	}
}

function terahost_ch_mouseover(mi)
{
	if (document.page_loaded && mi.is_header) {
		var wdg = terahost_get_wdg(mi.wdg);

		mi.panel_ch_x = 0;
		mi.panel_ch_y = wdg.center.offsetHeight;

		var obj = wdg.left;
		mi.panel_ch_x += obj.offsetLeft;
		obj = obj.offsetParent;
		while (obj) {
			mi.panel_ch_x += obj.offsetLeft;
			mi.panel_ch_y += obj.offsetTop;
			obj = obj.offsetParent;
		}
		mi.panel_ch_min_w = wdg.left.offsetWidth + wdg.center.offsetWidth + wdg.right.offsetWidth;

		if (typeof mi.td_center_class == 'undefined') {
			mi.td_left_class = wdg.left.className;
			mi.td_center_class = wdg.center.className;
			mi.td_right_class = wdg.right.className;
		}

		wdg.left.className = 'cmenu_hd_hover_left';
		wdg.center.className = 'cmenu_hd_hover_body';
		wdg.right.className = mi.td_right_class == 'cmenu_hd_norm_menu' || mi.td_right_class == 'cmenu_hd_sel_menu' ? 'cmenu_hd_hover_menu' : 'cmenu_hd_hover_right';
	}
}

function terahost_menu_close(mi)
{
	if (document.page_loaded) {
		var wdg = terahost_get_wdg(mi.wdg);
		wdg.left.className = mi.td_left_class;
		wdg.center.className = mi.td_center_class;
		wdg.right.className = mi.td_right_class;
	}
}

function terahost_ch_mouseout(mi)
{
	if (mi.is_header && mi.menuitems.length == 0)
		terahost_menu_close(mi);
}

function terahost_ch_panel_hide(mi)
{
	if (mi.is_header)
		terahost_menu_close(mi);
}


// window handlers

window_w = 0;
window_h = 0;
function terahost_h_resize()
{
	var w = 0, h = 0;
	if (window.innerWidth) {
		w = window.innerWidth;
		h = window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientWidth) {
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}

	if (window_w != w || window_h != h) {
		window_w = w;
		window_h = h;

		if (document['terahostDdp1'])
			document['terahostDdp1'].set_position();
	}
}
addEvent(window, 'resize', terahost_h_resize);


// page initialization

function page_init()
{
	document.page_loaded = true;

	document['terahostDdp1'] = new DDPanel({
		iname: 'terahostDdp1',
		source_id: 'pos_ddp1',
		interval: 20,
		speed: 10,
		offset_id: 'r4_r5_r6_edge_l',
		offset_tag_align: 'right',
		offset_tag_valign: 'top',
		offset_tag_x: 40,
		offset_cnt_align: 'right',
		offset_cnt_x: 30,
		offset_y: -19,
		class_cnt_tl: 'ddp1_tl',
		class_cnt_tc: 'ddp1_tc',
		class_cnt_tr: 'ddp1_tr',
		class_cnt_ml: 'ddp1_ml',
		class_cnt_mc: 'ddp1_content',
		class_cnt_mr: 'ddp1_mr',
		class_cnt_bl: 'ddp1_bl',
		class_cnt_bc: 'ddp1_bc',
		class_cnt_br: 'ddp1_br',
		class_tag_l: 'ddp1_tag_l',
		class_tag_c: 'ddp1_tag',
		class_tag_r: 'ddp1_tag_r'
	});

	if (document['cmenu_items']) {
		document['mc'] = new CMenu({
			iname: 'mc',

			side: 'down',
			orientation: 'right',

			animate: true,
			anim_step: 10,
			anim_interval: 40,

			transparency: true,
			transparency_ie6: false,

			min_opacity: 0,
			max_opacity: 100,

			ch_create: terahost_ch_create,
			ch_mouseover: terahost_ch_mouseover,
			ch_mouseout: terahost_ch_mouseout,
			ch_panel_hide: terahost_ch_panel_hide,

			panel_offset1_x: 0,
			panel_offset1_y: 0,
			panel_offset2_x: 0,
			panel_offset2_y: 0,

			itemborder_class: 'cmenu_itemborder',
			separator_class: 'cmenu_separator',
			panel_class: 'cmenu_panel',
			panel_tl_class: 'cmenu_tl',
			panel_tc_class: 'cmenu_tc',
			panel_tr_class: 'cmenu_tr',
			panel_ml_class: 'cmenu_ml',
			panel_mr_class: 'cmenu_mr',
			panel_bl_class: 'cmenu_bl',
			panel_bc_class: 'cmenu_bc',
			panel_br_class: 'cmenu_br',

			mi_empty_normal_class: 'cmenu_mi_empty_normal',
			mi_empty_hover_class: 'cmenu_mi_empty_hover',
			mi_full_normal_class: 'cmenu_mi_full_normal',
			mi_full_hover_class: 'cmenu_mi_full_hover'

		});
	
		var len = document['cmenu_items'].length;
		if (len > 0) {
			for (var i = 0; i < len; i++) {
				var item = document['cmenu_items'][i];
		
				if (typeof item.parent_id == 'undefined')
					this[item.id] = document['mc'].add_item(item);
				else
					this[item.id] = this[item.parent_id].add_item(item);
			}
		
			document['mc'].run();
		}
	}
}

addEvent(window, 'load', page_init);


var goto_top_type = -1;
var goto_top_itv = 0;

function goto_top_timer()
{
	var y = goto_top_type == 1 ? document.documentElement.scrollTop : document.body.scrollTop;
	var moveby = 15;

	y -= Math.ceil(y * moveby / 100);
	if (y < 0)
		y = 0;

	if (goto_top_type == 1)
		document.documentElement.scrollTop = y;
	else
		document.body.scrollTop = y;

	if (y == 0) {
		clearInterval(goto_top_itv);
		goto_top_itv = 0;
	}
}

function goto_top()
{
	if (goto_top_itv == 0) {
		if (document.documentElement && document.documentElement.scrollTop)
			goto_top_type = 1;
		else if (document.body && document.body.scrollTop)
			goto_top_type = 2;
		else
			goto_top_type = 0;

		if (goto_top_type > 0)
			goto_top_itv = setInterval('goto_top_timer()', 50);
	}
}
