function DDPanel(aa){var ba=document.getElementById(aa.source_id);if(!ba)return;this.iname=aa.iname;this.offset_wdg=document.getElementById(aa.offset_id);this.offset_tag_x=aa.offset_tag_x;this.offset_tag_align=aa.offset_tag_align;this.offset_tag_valign=aa.offset_tag_valign;this.offset_cnt_x=aa.offset_cnt_x;this.offset_cnt_align=aa.offset_cnt_align;this.offset_y=aa.offset_y;this.speed=aa.speed;this.interval=aa.interval;this.state=0;this.timer=0;this.progress=0;this.y_start=0;var ca=null,src_cnt_node=null;ba=ba?ba.firstChild:null;while(ba){if(ba.nodeType==1){var da=ba.firstChild;while(da&&da.nodeType!=1)da=da.nextSibling;var ea='';if(da&&da.tagName=='H3'){ca=da;ba.removeChild(da);}
src_cnt_node=ba;break;}
else{ba=ba.nextSibling;}}
this.wdg_tag=document.createElement('div');this.wdg_tag.style.display='none';document.getElementsByTagName('body')[0].appendChild(this.wdg_tag);var fa=document.createElement('table');this.wdg_tag.appendChild(fa);fa.setAttribute('cellSpacing',0);fa.setAttribute('cellPadding',0);var ga=document.createElement('tbody');fa.appendChild(ga);var td=this.mkrow(ga,aa.class_tag_l,aa.class_tag_c,aa.class_tag_r,true);td.appendChild(ca);this.make_clickable(td.firstChild);this.wdg_tag_sz=this.getwh(this.wdg_tag,0,0);this.wdg_tag.style.display='block';this.wdg_cnt=document.createElement('div');this.wdg_cnt.style.display='none';document.getElementsByTagName('body')[0].appendChild(this.wdg_cnt);this.wdg_cnt.style.overflow='hidden';var fa=document.createElement('table');this.wdg_cnt.appendChild(fa);fa.setAttribute('cellSpacing',0);fa.setAttribute('cellPadding',0);var ga=document.createElement('tbody');fa.appendChild(ga);this.mkrow(ga,aa.class_cnt_tl,aa.class_cnt_tc,aa.class_cnt_tr,false);var td=this.mkrow(ga,aa.class_cnt_ml,aa.class_cnt_mc,aa.class_cnt_mr,false);this.mkrow(ga,aa.class_cnt_bl,aa.class_cnt_bc,aa.class_cnt_br,false);td.appendChild(src_cnt_node);this.wdg_cnt_sz=this.getwh(this.wdg_cnt,0,0);this.set_position();}
DDPanel.prototype.getwh=function(ha,w,h){ha.style.position='absolute';ha.style.left='0px';ha.style.top='0px';ha.style.visibility='hidden';if(w>0)ha.style.width=w+'px';if(h>0)ha.style.height=h+'px';ha.style.display='block';var ia={w:ha.offsetWidth,h:ha.offsetHeight};ha.style.display='none';ha.style.visibility='visible';return ia;}
DDPanel.prototype.make_clickable=function(ja){ja.style.cursor='pointer';ja.setAttribute('iname',this.iname);ja.onclick=function(){document[this.getAttribute('iname')].h_click();}}
DDPanel.prototype.mkrow=function(ka,cl,cc,cr,la){var td;var tr=document.createElement('tr');ka.appendChild(tr);td=document.createElement('td');tr.appendChild(td);td.className=cl;if(la)this.make_clickable(td);var ma=document.createElement('td');tr.appendChild(ma);ma.className=cc;if(la)this.make_clickable(td);td=document.createElement('td');tr.appendChild(td);td.className=cr;if(la)this.make_clickable(td);return ma;}
DDPanel.prototype.set_position=function(){if(this.wdg_tag.style.display=='block'){this.y_start=this.offset_y;var x=0,obj=this.offset_wdg;while(obj){x+=obj.offsetLeft;this.y_start+=obj.offsetTop;obj=obj.offsetParent;}
if(this.offset_tag_align=='right')tag_x=x+this.offset_wdg.offsetWidth-this.wdg_tag_sz.w-this.offset_tag_x;else if(this.offset_tag_align=='center')tag_x=x+Math.round((this.offset_wdg.offsetWidth-this.wdg_tag_sz.w)/2);else tag_x=x+this.offset_tag_x;if(this.offset_cnt_align=='right')cnt_x=x+this.offset_wdg.offsetWidth-this.wdg_cnt_sz.w-this.offset_cnt_x;else if(this.offset_cnt_align=='center')cnt_x=x+Math.round((this.offset_wdg.offsetWidth-this.wdg_cnt_sz.w)/2);else cnt_x=x+this.offset_cnt_x;y=this.y_start;if(this.wdg_cnt.style.display=='block'){if(this.offset_tag_valign=='top')this.wdg_cnt.style.top=(y+this.wdg_tag.offsetHeight)+'px';else this.wdg_cnt.style.top=y+'px';this.wdg_cnt.style.left=cnt_x+'px';y+=this.wdg_cnt.offsetHeight;}
if(this.offset_tag_valign=='top')this.wdg_tag.style.top=this.y_start+'px';else this.wdg_tag.style.top=y+'px';this.wdg_tag.style.left=tag_x+'px';}}
DDPanel.prototype.h_click=function(){this.state=this.state<1?2:-1;if(this.timer==0)this.h_timer();}
DDPanel.prototype.h_timer=function(){this.timer=0;if(this.state==2){var na=Math.round((100-this.progress)*this.speed/100);if(na==0)na=1;this.progress+=na;if(this.progress>=100){this.progress=100;this.state=1;}}
else if(this.state==-1){var na=Math.round(this.progress*this.speed/100);if(na==0)na=1;this.progress-=na;if(this.progress<=0){this.progress=0;this.state=0;}}
var h=0;if(this.state!=0)h=Math.round(this.wdg_cnt_sz.h*this.progress/100);var y=this.y_start;if(h==0){this.wdg_cnt.style.display='none';}
else{if(this.wdg_cnt.style.display!='block'){this.wdg_cnt.style.display='block';this.set_position();}
this.wdg_cnt.style.height=h+'px';this.wdg_cnt.scrollTop=this.wdg_cnt_sz.h-h;y+=h;}
if(this.offset_tag_valign=='bottom')this.wdg_tag.style.top=y+'px';if(this.state==-1||this.state==2)this.timer=setTimeout('document["'+this.iname+'"].h_timer()',this.interval);}

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


// CMenu handlers

function viphost_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 viphost_ch_create(mi) {
	if (mi.is_header) {
		var wdg = viphost_get_wdg(mi.wdg);
		wdg.left.style.cursor = 'pointer';
		wdg.center.style.cursor = 'pointer';
		wdg.right.style.cursor = 'pointer';
	}
}

function viphost_ch_mouseover(mi) {
	if (document.page_loaded && mi.is_header) {
		var wdg = viphost_get_wdg(mi.wdg);

		mi.panel_ch_x = 0; //wdg.left.offsetWidth;
		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_sel_l';
		wdg.center.className = 'cmenu_hd_sel_c';
		wdg.right.className = 'cmenu_hd_sel_r';
	}
}

function viphost_menu_close(mi) {
	if (document.page_loaded) {
		var wdg = viphost_get_wdg(mi.wdg);
		if (typeof mi.td_center_class != 'undefined') {
			wdg.left.className = mi.td_left_class;
			wdg.center.className = mi.td_center_class;
			wdg.right.className = mi.td_right_class;
		}
	}
}

function viphost_ch_mouseout(mi) {
	if (mi.is_header && mi.menuitems.length == 0)
		viphost_menu_close(mi);
}

function viphost_ch_panel_hide(mi) {
	if (mi.is_header)
		viphost_menu_close(mi);
}


// window handlers

window_w = 0;
window_h = 0;
function viphost_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['viphostDdp1'])
			document['viphostDdp1'].set_position();
	}
}
bt_add_event(window, 'resize', viphost_h_resize);


// page initialization

function viphost_page_init() {
	document.page_loaded = true;

	document['viphostDdp1'] = new DDPanel({
		iname: 'viphostDdp1',
		source_id: 'pos_ddp1',
		interval: 20,
		speed: 10,
		offset_id: 'r1_up',
		offset_tag_align: 'right',
		offset_tag_valign: 'bottom',
		offset_tag_x: 0,
		offset_cnt_align: 'right',
		offset_cnt_x: 0,
		offset_y: 12,
		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',

			edge_min: 'r1_up',

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

			animate: true,
			anim_step: 10,
			anim_interval: 30,

			transparency: true,
			transparency_ie6: false,

			min_opacity: 0,
			max_opacity: 100,

			ch_create: viphost_ch_create,
			ch_mouseover: viphost_ch_mouseover,
			ch_mouseout: viphost_ch_mouseout,
			ch_panel_hide: viphost_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();
		}
	}

	document.side_mods = new Array();
	load_side_positions('left_up');
	load_side_positions('right_up');
}

bt_add_event(window, 'load', viphost_page_init);


function load_side_positions(position_name) {
	var host = document.getElementById(position_name + '_container');
	var node = document.getElementById('pos_' + position_name);

	if (!host || !node)
		return;

	node = node.firstChild;
	var first = true;
	while (node) {
		if (node.nodeType == 1) {
			// if the node is a regular DOM element, handle it as a data source

			// try to find the header
			var header = node.firstChild;
			while (header && header.nodeType != 1)
				header = header.nextSibling;

			var header_str = '';
			if (header && header.tagName == 'H3') {
				header_str = header.firstChild.nodeValue;
				node.removeChild(header);
			}
			else {
				header = null;
			}

			// cache next data block
			var content_node = node;
			node = node.nextSibling;


			// position header
			if (first) {
				first = false;
			}
			else {
				var div = document.createElement('div');
				div.className = 'upmod_modgap';
				host.appendChild(div);
			}

			document.side_mods.push(new SideModule(document.side_mods.length, host, header_str, content_node));
		}
		else {
			// move to the next data block
			node = node.nextSibling;
		}
	}
}

function SideModule(idx, host, header_str, content_node) {
	this.idx = idx;

	var host_header = document.createElement('div');
	host.appendChild(host_header);
	host_header.className = 'upmod_c';

	var header_l = document.createElement('div');
	host_header.appendChild(header_l);
	header_l.className = 'upmod_l';

	var header_r = document.createElement('div');
	header_l.appendChild(header_r);
	header_r.className = 'upmod_r';

	var header_h = document.createElement('div');
	header_r.appendChild(header_h);
	header_h.className = 'upmod_h';
	header_h.appendChild(document.createTextNode(header_str == '' ? '-' : header_str));

	this.host_content = document.createElement('div');
	this.host_content.className = 'upmod_content';
	this.host_content.style.display = 'none';

	var div = document.createElement('div');
	div.className = 'upmod_headergap';
	this.host_content.appendChild(div);

	this.host_content.appendChild(content_node);

	this.host_content.style.visibility = 'hidden';
	this.host_content.style.position = 'absolute';
	this.host_content.style.left = '0px';
	this.host_content.style.top = '0px';
	this.host_content.style.width = host.offsetWidth + 'px';
	this.host_content.style.display = 'block';
	document.getElementsByTagName('body')[0].appendChild(this.host_content);
	this.height = this.host_content.offsetHeight;
	this.host_content.style.display = 'none';
	this.host_content.style.visibility = 'visible';
	this.host_content.style.position = 'static';
	host.appendChild(this.host_content);

	header_h.setAttribute('idx', this.idx);
	header_h.onclick = function () {
		document.side_mods[this.getAttribute('idx')].h_click();
	}

	this.state = 0;
	this.progress = 0;
	this.timer = 0;
	this.interval = 20;
	this.step = 0.2;
}

SideModule.prototype.h_click = function () {
	this.state = this.state > 0 ? -1 : 2;
	if (this.timer == 0)
		this.timer = setTimeout('document.side_mods[' + this.idx + '].h_timer()', this.interval);
}

SideModule.prototype.h_timer = function () {
	this.timer = 0;

	var prev_state = this.state;

	if (this.state == 2) {
		this.progress += (100 - this.progress) * this.step;
		if (this.progress > 100) {
			this.progress = 100;
			this.state = 1;
		}
	}
	else if (this.state == -1) {
		this.progress -= this.progress * this.step;
		if (this.progress < 0) {
			this.progress = 0;
			this.state = 0;
		}
	}

	this.host_content.style.display = this.progress == 0 ? 'none' : 'block';
	this.host_content.style.height = Math.ceil(this.height * this.progress / 100) + 'px';

	if (this.state == 2 || this.state == -1)
		this.timer = setTimeout('document.side_mods[' + this.idx + '].h_timer()', this.interval);
}

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);
	}
}


