function BM_fixmenu() {
	if ($.browser.msie && $.browser.version < 7) 
	{
	$('.menu > ul > li.folder').hover(
			function (){
				$(this).addClass('hover');
			},
			function () {
				$(this).removeClass('hover');
			}
		);
		$('.menu > ul > li.folder > ul > li.folder').hover(
			function (){
				$(this).addClass('hover');
			},
			function () {
				$(this).removeClass('hover');
			}
		);
	}
}

function BM_forms() {
	$('form:not(.default) input:text').each(function() {
		$(this).addClass('textInput');
	});
	$('form:not(.default) input:submit').each(function() {
		var width = $(this).outerWidth();
		var offset = $(this).offset();
		$(this).after('<b style="padding-left: ' + width + 'px;"></b>');
		$(this).wrap('<b class="submit"><b class="tl"><b class="tr"><b class="br"><b class="bl"></b></b></b></b></b>');
		if ($(this).attr('title') == '') $(this).attr('title', $(this).val());
	});
}

function BM_search() {
	$('.search span').click(function() {
		$(this).parent().find('span').addClass('link');
		$(this).removeClass('link');
		var hidden = $(this).parent().find('input:hidden');
		if (hidden.val() == 0) {
			hidden.val(1);			
		} else {
			hidden.val(0);
		}
	});
}

function BM_career() {
	var list = '';
	$('.career dt').each(function(){
		list = list + '<li><span>' + $(this).text() + '</span></li>';
	});
	$('.career').after('<ul class="clist">' + list +'</ul>');
	$('.clist li:first').addClass('current');
	$('.career dt:not(:first)').hide();
	$('.career dd:not(:first)').hide();
	$('.clist li span').click(function() {
		var li = $(this).parent();
		if (!li.is('.current')) {
			var index = li.prevAll().length;
			$('.career dt').hide();
			$('.career dd').hide();
			$('.career dt').eq(index).show();
			$('.career dd').eq(index).show();
			$('.clist li.current').removeClass('current');
			li.addClass('current').unbind('click');
		}
	});
}


function BM_exceptions() {
	var result = "";
	var prev = Get_Cookie('hist');
	if (prev) {
		var histarr = prev.split('||');
		if (histarr.length > 10) histarr.shift();
		result = histarr.join('||');
	}
	Set_Cookie('hist', result + "||" + location.href, '', '/', '', '');
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


//this fixes an issue with the old method, ambiguous values
//with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}


var IEHTMLSelectElement = (function() {
    
    //see documentation for the ActiveX control
    //http://www.devguru.com/features/tutorials/ComboControl/combocontrol.html
    var p_isIE = !!(document.uniqueID && document.expando);
    var p_isIE6 = !!(p_isIE && !window.XMLHttpRequest);
    var p_n = 0 * Date.parse(new Date);
    
    var oApi = {
        
        
        
        _onResize: function() {
            
            var e = window.event;
            var dHTMLSel = e.srcElement;
            IEHTMLSelectElement.fix(dHTMLSel);
        },
        
        
        VBonActiveXChangeForJS: function(dActiveXSel) {
            
            var sId = dActiveXSel.__CLONE_PARENT_ID;
            if ( ! sId)
                return;
            var dHTMLSel = document.getElementById(sId);
            dHTMLSel.selectedIndex = dActiveXSel.listindex;
            dHTMLSel.fireEvent('onChange');
            
        },
        
        _onPropertyChange: function() {
            
            var e = window.event;
            var sN = e.propertyName;
            switch(sN) {
                
                case 'value': ;
                case 'selectedIndex': ;
                
                var dHTMLSel = e.srcElement;
                var dActiveXSel = document.getElementById(dHTMLSel.__CLONE_CHILD_ID);
                if (dHTMLSel.selectedIndex < 0)
                    dHTMLSel.selectedIndex = 0;
                
                if (dHTMLSel.selectedIndex != dActiveXSel.listindex) {
                    dActiveXSel.listindex = dHTMLSel.selectedIndex;
                };
                
                break;
                default: ;
                if (sN.indexOf('style') === 0) {
                    dActiveXSel.style.display = dActiveXSel.currentStyle.display;
                } else if (sN === 'focus') {
                    } else {
                    };
                return;
                
                
            };
        },
        
        
        
        
        find: function(x) {
            var dEl;
            if (typeof(x) == 'string')
                return document.getElementById(x);
            if ( ! x || !x.tagName || x.tagName != 'SELECT')
                return null;
            return x;
        },
        
        unfix: function(x) {
            if ( ! p_isIE6)
                return false;
            var dSel;
            if (x.length && x.namedItem && !x.tagName) {
                
                //nodeList
                var a = [];
                for (var i = 0, dEl; dEl = x[i]; i ++ ) {
                    try {
                        a.push(this.unfix(dEl));
                    }
                    catch(err) {
                        alert(dEl.tagName + err.message);
                    }
                };
                return a;
                
            } else {
                dSel = this.find(x);
            };
            
            if ( ! dSel)
                return null;
            if (dSel.__CLONE_CHILD_ID) {
                
                var dActiveXSel = document.getElementById(dSel.__CLONE_CHILD_ID);
                dActiveXSel.removeNode(true);
                dSel.detachEvent('onpropertychange', this._onPropertyChange);
                dSel.detachEvent('onresize', this._onResize);
                dSel.style.cssText = dSel.__defaultCssText;
                dSel.__CLONE_CHILD_ID = undefined;
                dSel.__defaultCssText = undefined;
                
            };
            
        },
        
        
        fix: function(x) {
            
            
            if ( ! p_isIE6)
                return false;
            var dSel;
            
            if (x.length && x.namedItem && !x.tagName) {
                
                //nodeList
                var a = [];
                for (var i = 0, dEl; dEl = x[i]; i ++ ) {
                    try {
                        a.push(this.fix(dEl));
                    }
                    catch(err) {
                        alert(dEl.tagName + err.message);
                    }
                };
                return a;
                
            } else {
                dSel = this.find(x);
            };
            
            if ( ! dSel)
                return null;
            
            
            
            
            
            if (dSel.__CLONE_CHILD_ID) {
                this.unfix(dSel);
            };
            
            
            var sId = (dSel.id = dSel.id || ('IEHTMLSelectElement' + (p_n ++ )));
            var sId2 = 'IEHTMLSelectElement' + (p_n ++ );
            
            var dStyle = dSel.currentStyle;
            var sW = dSel.offsetWidth + 'px';
            //dStyle['width'];
            var sH = dSel.offsetHeight + 'px';
            //dStyle['height'];
            //sW = (sW=='auto')?dSel.offsetWidth  + 'px' : sW;
            //sH = (sH=='auto')?dSel.offsetHeight + 'px' : sH;
            
            if (typeof(dSel.__defaultCssText) != 'string') {
                dSel.__defaultCssText = dSel.style.cssText;
                dSel.hideFocus = true;
                dSel.tabIndex = -1;
            };
            
            
          
            
            
            
            var s = ['<object classid="clsid:8BD21D30-EC42-11CE-9E0D-00AA006002F3"  id="', sId2, '"  style="width:', sW, ';height:', sH, ';margin:0;vertical-align:bottom;">', '<param name="VariousPropertyBits" value="746604571" />', '<param name="BackColor" value="2147483653" />', '<param name="ForeColor" value="2147483656" />', '<param name="MaxLength" value="0" />', '<param name="BorderStyle" value="0" />', '<param name="ScrollBars" value="0" />', '<param name="DisplayStyle" value="7" />', '<param name="MousePointer" value="0" />', '<param name="Size" value="1588;635" />', '<param name="PasswordChar" value="0" />', '<param name="ListWidth" value="0" />', '<param name="BoundColumn" value="0" />', '<param name="TextColumn" value="65535" />', '<param name="ColumnCount" value="1" />', '<param name="ListRows" value="8" />', '<param name="ColumnInfo" value="0" />', '<param name="MatchEntry" value="1" />', '<param name="ListStyle" value="0" />', '<param name="ShowDropButtonWhen" value="2" />', '<param name="ShowListWhen" value="0" />', '<param name="DropButtonStyle" value="1" />', '<param name="MultiSelect" value="0" />', '<param name="Value" value="', dSel.options[dSel.selectedIndex].innerText, '" />', 
            '<param name="Caption" value="" />', '<param name="PicturePosition" value="458753" />', '<param name="BorderColor" value="2147483654" />', '<param name="SpecialEffect" value="2" />', '<param name="Accelerator" value="0" />', '<param name="GroupName" value="" />', '<param name="FontName" value="Tahoma" />', '<param name="FontEffects" value="1073741824" />', '<param name="FontHeight" value="', Math.round(dSel.offsetHeight * 8), '" />', '<param name="FontOffset" value="0" />', '<param name="FontCharSet" value="0" />', '<param name="FontPitchAndFamily" value="0" />', '<param name="ParagraphAlign" value="0" />', '<param name="FontWeight" value="0" />', 
            '</object>'
            ];
            
            
            dSel.insertAdjacentHTML('BeforeBegin', s.join(''));
            var dSel2 = document.getElementById(sId2);
            
            var nCharLength = 0;
            
            for (var i = 0, dOpt; dOpt = dSel.options[i]; i ++ ) {
                var sT = dOpt.innerText;
                var sVB = 'document.getElementById("' + sId2 + '").additem("' + sT + '")';
                nCharLength = Math.max(nCharLength, sT.length);
                try{
                    window.execScript(sVB, "VBSCRIPT");
                }catch(err){
                    //Object is not supported
                    dSel2.removeNode(true);
                    IEHTMLSelectElement.fix = function(){return false;}; 
                    IEHTMLSelectElement.unfix = function(){return false;}; 
                    return;
                };
            };
            
            with(dSel.style) {
                display = 'block';
                //'none';
                position = 'absolute';
                top = 0;
                left = '-5000px';
            };
            
            
            dSel.__CLONE_CHILD_ID = sId2;
            dSel2.__CLONE_PARENT_ID = sId;
            dSel2.ListWidth = nCharLength * dSel.offsetHeight / 5 + 20;
            
            dSel.attachEvent('onpropertychange', this._onPropertyChange);
            dSel.attachEvent('onresize', this._onResize);
            
            dSel.focus = function() {
                document.getElementById(this.__CLONE_CHILD_ID).focus();
            };
            
            
            
            var sVB = [
            'Private Sub ' + sId2 + '_Change()', 'window.IEHTMLSelectElement.VBonActiveXChangeForJS(document.getElementById("' + sId2 + '"))', 'End Sub'
            ].join('\n');
            
            
            window.execScript(sVB, "VBSCRIPT");
            return dSel2;
        }
        
        
    };
    
    return oApi;
    
})();
$(document).ready(function(){
	BM_fixmenu();
	BM_forms();
	BM_search();
	BM_career();
	BM_exceptions();
	if ($('select').length > 0) {IEHTMLSelectElement.fix(document.getElementsByTagName("select"));}
});
