﻿function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {left:curleft,top:curtop};
}

function getObj(name) {
	if( typeof(name) == 'object' ) {
		this.obj = name;
	} else {
		if (document.getElementById) {
			this.obj = document.getElementById(name);
		} else if (document.all)  {
			this.obj = document.all[name];
		} else if (document.layers)  {
			this.obj = document.layers[name];
		}
	}
	return this.obj;
}

function DMenu() {
	this.dmenu = getObj('dmenu');
	this.main_content_area	= getObj('home_body_content');
	
	var self = this;
	
	this.show = function(what){
		
		//divDsp('dmenu_'+what+'_container');
		//change the image 
		var img = getObj('dmenu_'+what+'_image');
		var obj= getObj('dmenu_'+what+'_container');
//			if(img.src.indexOf('_up.gif')>0){
//				img.src = img.src.replace('_up.gif','_down.gif');
//			} else {
//				img.src = img.src.replace('_down.gif','_up.gif');
//
//			}
		var imgs=self.dmenu.getElementsByTagName('img');
		for(var i=0; i<imgs.length; i++) {
			var img=getObj(imgs[i]);
			var str=img.id;
			if(str.indexOf('dmenu')>=0 && str.indexOf('image')>=0){
				if(img.id=='dmenu_'+what+'_image') {
					if(img.src.indexOf('_down.gif')>=0) {
						img.src=img.src.replace('_down.gif','_up.gif');
					}
					else {
						// if they are clicking on the one that's already up, do nothing
						return;
					}
				}
				else {
					if(img.src.indexOf('_up.gif')>=0) {
                                                   img.src= img.src.replace('_up.gif','_down.gif');
					}
				}
			}
		}

		var el=self.dmenu.getElementsByTagName('div');
		for(var i=0; i<el.length; i++) {
			var str=el[i].id
			var obj2 = getObj(el[i].id);
			if(str.indexOf('container')>= 0) {
				//alert('element '+ el[i].id + ' is a container div, comparing to dmenu_'+what+'_container');
				if(str=='dmenu_'+what+'_container') {
					new Effect.BlindDown(obj2);
				}
				else  {
					new Effect.BlindUp(obj2);
				}
			}
		}
	};
	
}


