// designed bu Mohammad Zatkhahi [ZATSOFTCMS]
// drop down menu script
function dropdownmenu(config)
{
	this.parentitem = config.parent ;
	this.subitem = config.child ;
	this.speed = config.speed ? config.speed : 100 ;
	this.previous = 0 ;
	this.prevsub = 0 ;
	this.pause = 10 ; //milli sec
}
dropdownmenu.prototype.onSlideToggle = function()
{
	l = parseInt($("#content_left").height());
	r = parseInt($("#content_right").height());
	if(r<=l)
	{
		h = parseInt($("#mainc").height())+l-r;
		$("#mainc").height(h);
		$("#loading").height(h+10);
	}
};
dropdownmenu.prototype.init = function(params)
{
	var instance = this ;
	//alert(params.opened) ;
	$("." + this.subitem).hide() ;
	$op = $("#"+params.opened).next();
	$op.show();
	
	$("#"+params.opened).children('a').css('background','url(images/imdc/sdown.png) right center no-repeat');
	instance.opened = $("#"+params.opened).next();
	instance.init_size = parseInt($("#mainmenu").css('height')) ;
	// event use instance of object because "this" is not defined for them
	slide = function()
	{
		//parentitem.mouseEntered = new Date().getTime();
		if($("." + instance.subitem + ":animated").size() > 0) return ;
		$curparent = $(this) ;
		setTimeout(function(){
			subi = $curparent.next("." + instance.subitem);
			if( instance.opened.prev().html() != subi.prev().html() )
			{
				instance.opened.slideUp(instance.speed,instance.onSlideToggle);
				instance.opened.prev().children('a').css('background','url("images/imdc/left.png") right center no-repeat');
				instance.opened.prev().removeClass("current");
				subi.slideToggle(instance.speed,instance.onSlideToggle);
				//alert($curparent.children('div'));
				$curparent.children('a').css('background','url("images/imdc/sdown.png") right center no-repeat');
				$curparent.addClass("current");
				instance.opened = subi ;
			}
			else
			{
				instance.opened.slideToggle(instance.speed,instance.onSlideToggle);
			}
			
		},instance.pause);
		

	};
	$parentitem = $("." + this.parentitem) ; 
	//$parentitem.bind("mousemove",slide);
	$parentitem.bind("click",slide) ;
};

