// ------------------------------------------------
 
window.addEvent('domready', function() {
	toggleOmatic();
	if ($('content')) {
		if ($('childid').value != 60) {
			makeScrollbar( $('content'), $('scrollbar1'), $('handle1') );
		} else {
			makeScrollbar( $('contentFrame'), $('scrollbar1'), $('handle1') );
			$('content').addClass('noPadContent');
//			$('scrollbar1').addClass('hide');
//			alert($('childid').value);
		}
	}
	fireSNav();
});


// ------------------------------------------------

var toggleOmatic = function() {
	var toggleAll = $(document.body).getElements('[class$=_toggle]');
	var theEl = $('navs');
	var morph = new Fx.Morph('navs',{duration:'400'});
	var morphSN = new Fx.Morph('SNavC',{duration:'200'});

	toggleAll.each(function(item){
		item.setStyle('cursor', 'pointer');
		var toggleAllClass = item.getProperty('class');
		toggleAllClass = toggleAllClass.replace("_toggle", "");

		$(item).addEvent('click', function(){

			id = $(item).getProperty('id');
			targetHtml = $(id + '_info').get('html');

			if ($(item).hasClass('selected')) {
				$(item).removeClass('selected');
				morph.start({ 'padding-left':190 });
				theEl.addClass('collapse');
			} else {
				$$('#MNav span').removeClass('selected');
				$(item).addClass('selected');

				if (theEl.hasClass('collapse')) {
					$('SNavC').setProperty('html',targetHtml);
					morph.start({ 'padding-left':0 });
					theEl.removeClass('collapse');
				} else {
					morphSN.start({ 
						'opacity':0 
					}).chain(function(){
						$('SNavC').setProperty('html',targetHtml);
						morphSN.start({
							'opacity':1
						});
					});
				}
			}

		}); // end click
	}); // end f~ toggleAll.each
} // end f~ toggleOmatic

// ------------------------------------------------

function fireSNav() {

	id = $('parentid').value;
	if ( (id != "") && (id != 0) && (id != null) ) {

		// main nav add class
		link = "group" + $('parentid').value;
		if($(link)) { $(link).addClass('selected'); }

		// subnav add class
		link = "child" + $('childid').value;
		if($(link)) { $(link).addClass('selected'); }

		var morph = new Fx.Morph('navs',{duration:'400'});
		ele = 'group' + id + '_info';
		if ($(ele)) {
			targetHtml = $(ele).get('html');
			$('SNavC').setProperty('html',targetHtml);
			morph.start({ 'padding-left':0 });
		} else {
			targetHtml = $('group0_info').get('html')	
		}
//		theEl.removeClass('collapse');

	}

}

// ------------------------------------------------

function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
// http://solutoire.com/2008/03/10/mootools-css-styled-scrollbar/
	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
	var slider = new Slider(scrollbar, handle, {
//		steps: steps,
		steps: 100,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			// Scrolls the content element in x or y direction.
			var x = (horizontal?step:0);
//			var y = (horizontal?0:step);
			var y = (horizontal?0:(((content.getScrollSize().y-content.getSize().y)/100)*step));
			content.scrollTo(x,y);
		}
	}).set(0);
	if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the 
		// content or the scrollbar element.
		$$(content, scrollbar).addEvent('mousewheel', function(e){
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 10;
			slider.set(step);
		});
	}
	// Stops the handle dragging process when the mouse leaves the document body.
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}

// ------------------------------------------------

function fclear(ele) {
	ele.value = "";
}

// ------------------------------------------------

function freset(ele,val) {
	if (ele.value == "") {
		ele.value = val;
	}
}

// ------------------------------------------------


function setPortal(){
//	alert($('portalsDropDown').value);
	val = $('portalsDropDown').value;
	if (val == "Physician") { 
		document.location.href = "pg-physician-portal.html"; 
	}
	if (val == "Employee") { 
		document.location.href = "pg-employee-portal.html"; 
	}
	
}

