//------------------------------------------------------------------
//toogle (expand & collapse) menu (2 level) build with jquery 1.3.2
//focus1921 2009/08 @cmmedia
//------------------------------------------------------------------

var mmId;
var smId;
var normalAppend='_b';
var highlightAppend='_a';
var toggleSpeed=150;

/*query string parcer*/
function getParam(_paramStr) {
	var _href=document.location.href;
	var _qStr=_href.split('?')[1];
	if (_qStr==null) return '';
	var _obj=new Object();
	var _valueParamArr=_qStr.split('&');
	for (var i=0; i<_valueParamArr.length; i++) {
		var _param=_valueParamArr[i].split('=')[0];
		var _value=_valueParamArr[i].split('=')[1];
		_obj[_param]=_value;
	}
	return (_obj[_paramStr]==null || _obj[_paramStr]==undefined) ? '' : _obj[_paramStr].replace('#', '');
	_valueParamArr=null;
	_obj=null;
}

/*main menu item "click", "keypress" event handler*/
function mmActivate() {
	/*var _tgt=$(this);
	var _tgtDiv=$('#'+_tgt.attr('id')+'Div');
	if (mmId!='') $('#mm'+mmId).children().eq(0).attr('src', $('#mm'+mmId).children().eq(0).attr('src').replace(highlightAppend, normalAppend));
	mmId=$(this).attr('id').replace('mm', '');
	smId='';
	
	$(_tgtDiv).toggle(toggleSpeed, function () {
		_tgt.blur();
		if (_tgt.children().eq(0).attr('src').indexOf(highlightAppend)!=-1 && _tgtDiv.css('display')=='none') {
			_tgt.children().eq(0).attr('src', _tgt.children().eq(0).attr('src').replace(highlightAppend, normalAppend));
		}else {
			_tgt.children().eq(0).attr('src', _tgt.children().eq(0).attr('src').replace(normalAppend, highlightAppend));
		}
	});
	
	highlightCurrUnit();*/
}

/*main menu item "mouseover", "focus" event handler*/
function mmIn() {
	$(this).children().eq(0).attr('src', $(this).children().eq(0).attr('src').replace(normalAppend, highlightAppend));
}

/*main menu item "mouseout", "blur" event handler*/
function mmOut() {
	if ($(this).attr('id')!='mm'+mmId) {
		$(this).children().eq(0).attr('src', $(this).children().eq(0).attr('src').replace(highlightAppend, normalAppend));
	} 
}

function smIn() {
	$(this).children().eq(0).attr('src', $(this).children().eq(0).attr('src').replace(normalAppend, highlightAppend));
}

function smOut() {
	var _parent=$(this).parent();
	
	if ($(this).attr('href')!=_parent.children().eq(smId-1).attr('href')) {
		$(this).children().eq(0).attr('src', $(this).children().eq(0).attr('src').replace(highlightAppend, normalAppend));
	}
}

function highlightCurrUnit() {
    try {
        if (mmId != '' && smId != '') {
            $('#mm' + mmId + 'Div').show();
            $('#mm' + mmId).children().eq(0).attr('src', $('#mm' + mmId).children().eq(0).attr('src').replace(normalAppend, highlightAppend));
            if (smId > 0) $('#mm' + mmId + 'Div').children().eq(smId - 1).children().eq(0).attr('src', $('#mm' + mmId + 'Div').children().eq(smId - 1).children().eq(0).attr('src').replace(normalAppend, highlightAppend));
        } else if (mmId != '') {
            $('#mm' + mmId).children().eq(0).attr('src', $('#mm' + mmId).children().eq(0).attr('src').replace(normalAppend, highlightAppend));
        }
    }
    catch (e) {
        return;
    }
}

/*initial*/
$(document).ready(function(){
	tmId=getParam('tm');
	mmId=getParam('mm');
	if (mmId=='') mmId='1';
	smId=getParam('sm');
	if (smId=='@') smId='';
	$('.mmDiv').hide();
	highlightCurrUnit();
	$('.mm').mouseover(mmIn).mouseout(mmOut).focus(mmIn).blur(mmOut).click(mmActivate).keypress(mmActivate);
	$('.mm[href="#"]').click(function() {
		return false;
	});
	$('.mm[href="#"]').keypress(function() {
		return false;
	});
	$('.mmDiv>a').mouseover(smIn).mouseout(smOut).focus(smIn).blur(smOut);
});

var cssBtn = {
    mouseEventCss: function(el, cls1, cls2, cls3) {
        var tbEl = el.parentNode.parentNode.parentNode;
        var lrEl = el.parentNode.parentNode;
        var garEl = el.parentNode;

        if (tbEl != undefined && tbEl != null) tbEl.className = cls1;
        if (lrEl != undefined && lrEl != null) lrEl.className = cls2;
        if (garEl != undefined && garEl != null) garEl.className = cls3;
    }
};
