

function create_elements() {
	$("body").data("Loaded").Elements = 10

		
		$.bt.options.fill = '#CBD3D5';
		$.bt.options.strokeWidth = 2;
		$.bt.options.strokeStyle = '#004499';
		$.bt.options.width = 400;
		$.bt.options.cssStyles = {color: 'white', fontWeight: 'bold', width: 'auto'};
		$.bt.options.padding = 10;
		$.bt.options.cornerRadius = 10;
		$.bt.options.animate = 'false';
		$.bt.options.spikeLength = 15;
		$.bt.options.spikeGirth = 5;
		$.bt.options.cssClass = 'tree_item_preview_bubble';

		$.bt.options.positions =  ['right'];
														
									
	$('#BodyData').append("<br><strong>CONVERT ELEMENTS</strong>")
	$('#BodyData').append("<br>Start: Loaded.Elements: ")
	$('#BodyData').append($("body").data("Loaded").Elements)
		
	$(":input").filter("[mytype='popup_form']").each(function(){
			var main_width = $(this).attr('width')
			var field_name = $(this).attr('id')
			var this_value = $(this).attr('value')
			var this_type = $(this).attr('type')


			if (main_width == undefined) {
				main_width = $(this).css('width')
			} 
			main_width = parseInt(main_width)
			if (main_width == undefined) {
				main_width = 200 // default
			} 

			outer_width = main_width + 10
			text_field_width = main_width 


			new_text_field  = '							<div class="default_text_box_p" style="width:'+outer_width+'px;">';
			new_text_field += '								<div class="default_text_box_p left"></div>';
			new_text_field += '								<div class="default_text_box_p slice" style="width:'+main_width+'px;"> ';
			new_text_field += '								<input type="'+this_type+'" name="'+field_name+'" id="'+field_name+'" value="'+this_value+'" class="text_field" style="width:'+text_field_width+'px; background:white">';
			new_text_field += '								</div>';
			new_text_field += '								<div class="default_text_box_p right"></div>';
			new_text_field += '								<div class="clear_both"></div>';
			new_text_field += '							</div>';
			new_text_field += '							<div class="clear_both"></div>';
			
			attach_to = $(this).parent()
			
			attach_to.append(new_text_field)
			$(this).remove()

	})
		
	$(":input").filter("[mytype='select']").each(function(){
		var main_w = 250
		if ($(this).attr('width') != undefined) {
			main_w = parseInt($(this).attr('width'))
		}
		field_w = main_w + 50
		item_holder_w = main_w - 2 - 24
		item_parent_w = main_w - 24
		item_w = item_holder_w - 8 + 4
		var this_id = $(this).attr('id') 
		is_required = $(this).attr('required') 
		if (is_required==1) {
			is_required = 1
		} else {
			is_required = 0
		}

		open_dir = $(this).attr('open_dir')
		if (open_dir == 'up') {
			open_dir = 'up'
			item_holder_w = main_w - 2
		} else {
			open_dir = 'down'
		}

		attach_to = $(this).parent()
		select_pulldown = '<div class="pull_down_holder" style=" width:'+item_parent_w+'px  ">'; // start pull_down_holder

		if ( $(this).attr('create_label')  != undefined) {
			select_pulldown += '<div class="form_row_new">';
			select_pulldown += '<div style="width:90px" class="text_right" id="'+this_id+'_title">'+$(this).attr('display')+':</div>';
			select_pulldown += '<div style="width:'+field_w+'px" class="form_row_field">';
		}

		select_pulldown += '<div class="select_holder"  style="width:'+main_w+'px" id="select_'+this_id+'" selected_id="1" required="'+is_required+'">';
		select_pulldown += '<div id="main_trigger" class="select_trigger" open_dir="'+open_dir+'" field_name="'+this_id+'">Select '+$(this).attr('display')+'</div>';
		select_pulldown += '<div id="items" style="position:absolute; display:none; border:1px solid #370901; border-top:0px solid blue; z-index:10000;width:'+item_holder_w+'px">';
		item_w = item_w - 15
		
		$(this).find("option").each(function(){
				var this_value = $(this).text();
				var starts_with = this_value.substring(0, 1).toUpperCase();
				select_pulldown += '<div style="" starts_with="'+starts_with+'">';


	
				if (typeof $(this).attr('extra_class') != 'undefined') {
					this_extra_class = $(this).attr('extra_class')
					select_pulldown += '<div id="list_item_'+$(this).attr('value')+'" class="list_item '+this_extra_class+'"  style="width:'+item_w+'px" primary_id="'+$(this).attr('value')+'" selected="0">';
				} else {
					select_pulldown += '<div id="list_item_'+$(this).attr('value')+'" class="list_item"  style="width:'+item_w+'px" primary_id="'+$(this).attr('value')+'" selected="0">';
				}
				
				select_pulldown +=   $(this).text();
				select_pulldown += '</div>'; 
				select_pulldown += '</div>';
		})
		select_pulldown += '</div>';
		select_pulldown += '</div>';
		
		if ( $(this).attr('create_label')  != undefined) {
			select_pulldown += '</div>';
			select_pulldown += '<div class="clear_both"></div>';
			select_pulldown += '</div>';
		}
		select_pulldown += '<input type="hidden" name="'+this_id+'" id="'+this_id+'" value="">';
		
		select_pulldown += '</div>'; // end pull_down_holder
		attach_to.append(select_pulldown); 

		var force_scroll = $(this).attr('force_scroll')
		var this_open_height = $(this).attr('open_height')

		if (this_open_height == undefined) {
			this_open_height = 100
		}
		if (force_scroll == undefined) {
			force_scroll = 0
		}
		
		if ($(this).attr('selected_id') != undefined) {
			var this_selected_id = $(this).attr('selected_id')
			var this_selected_text = $('#select_'+this_id).find("div[primary_id='"+this_selected_id+"']").text()
			// alert('this_selected_id: ' + this_selected_text + ' this_id '+this_id )
			$('#select_'+this_id).find("div[primary_id='"+this_selected_id+"']").addClass('selected').attr('selected','1')
			$('#select_'+this_id).find("div[id='main_trigger']").html(this_selected_text).attr('force_scroll',force_scroll).attr('open_height',this_open_height)
			$("input[id='"+this_id+"']").val(this_selected_id)
		} 
		/* HIDE AND CHANGE NAME OF ORIGINAL SELECT BOX */
		$(this).attr('id', 'hidden_'+this_id).attr('name', 'hidden_'+this_id).attr('mytype', 'done_select_'+this_id).hide()
		
		$(this).closest('.pull_down_holder').width(item_parent_w)
	})	

	

	/***********************/
	/* PULL DOWN FUNCTIONS */
	/**********************/ 
	$("[id^='main_trigger']").each(function() {
		$(this).click(function() {
			if ($(this).next().attr('open') == 1) {
				$(this).removeClass('opened').next().slideUp('fast')
				$(this).parent().removeClass('opened')
				$(this).next().attr('open', '0')
			} else {
				
				$("[open='1']").each(function() {
					$(this).hide()
				})
				if ($(this).attr('open_dir') == 'up') {
						$(this).addClass('opened_up')
						old_w = $(this).closest('.pull_down_holder').width()
						new_w = old_w 
						$(this).closest('.pull_down_holder').addClass('opened_up').width(new_w)
						p = $(this).position()
						my_top = p.top
						$(this).next().css({'max-height': '100px', 'border-top':'1px solid #370901' , 'top':my_top-100+'px','overflow-y':'hidden', 'overflow-x':'hidden'}).scrollTo($(this).find('.selected'), 300 ).show();
						this_items = $(this).next()
						//	alert('f'+this_items.hasScrollBar())
						if (this_items.hasScrollBar()) {

							if (this_items.attr('this_old_w') == undefined) {

								this_old_w = this_items.width()
								this_new_w = this_old_w 
								this_items.addClass('list_item_text_scroll').height(100).width(this_new_w).attr('this_old_w',this_old_w).attr('this_new_w',this_new_w).scrollbar_pulldown();
							} else {
								this_items.addClass('list_item_text_scroll').height(100).scrollbar_pulldown();
							}
						}
				} else {
					$(this).addClass('opened').parent().addClass('opened')
					$(this).closest('.pull_down_holder').addClass('opened')
					force_scroll = $(this).attr('force_scroll')
					open_height = $(this).attr('open_height')
					if (open_height == undefined) {
						open_height = 100
					}
					
					
				
					$(this).next().attr('open', '1').slideDown('fast', function() {
						/*
						if($(this).css('max-height') == 'none') {
							$(this).css({'max-height': '100px'})
						} 
						$(this).css({'overflow-y':'auto', 'overflow-x':'hidden'}).scrollTo($(this).find('.selected'), 300 );
						if ($(this).height() >= 100) {
							//$('.list_item').width(100) 
						}
						*/ 
//						alert($(this).width()) -- looking for 155

						


						$(this).height(open_height)
						if ((!$('#items').hasScrollBar()) || (force_scroll == 1)) {
							if (!$(this).hasClass('list_item_text_scroll')) {
								if ($(this).attr('this_old_w') == undefined) {
									this_old_w = $(this).width()
									this_new_w = this_old_w + 24
									$(this).addClass('list_item_text_scroll').height(open_height).width(this_new_w).attr('this_old_w',this_old_w).attr('this_new_w',this_new_w).scrollbar_pulldown();
								} else {
									$(this).addClass('list_item_text_scroll').height(open_height).scrollbar_pulldown();
								}
							}
						} else {
							if ($(this).attr('this_old_w') == undefined) {
								this_old_w = $(this).width()
								this_new_w = this_old_w + 24
								$(this).addClass('list_item_text_scroll').height(open_height).width(this_new_w).attr('this_old_w',this_old_w).attr('this_new_w',this_new_w);
								$(this).find('.list_item').width(this_new_w)
							} else {
								$(this).addClass('list_item_text_scroll').height(open_height)
							}
						}

					})
				}
				
				

			}
		})

	})
	
$("[id^='list_item_']").live("mouseover mouseout", function(event) {
  if ( event.type == "mouseover" ) {
    $(this).addClass('hover')
  } else {
    $(this).removeClass('hover')
  }
});	
$("[id^='list_item_']").live("click", function(event) {
if ($(this).attr('primary_id') != 'NA') {
	
			
				$(this).closest('.select_holder').find("[selected^='1']").each(function() {
					$(this).attr('selected','0').removeClass('selected')
				})
				var main_trigger = $(this).closest('.select_holder').find('#main_trigger')
				var select_holder = $(this).closest('.select_holder')


				var field_name = main_trigger.attr('field_name')
				var open_dir = main_trigger.attr('open_dir')
				main_trigger.removeClass('opened')
				select_holder.removeClass('opened')

				$("input[id='"+field_name+"']").val($(this).attr('primary_id'))
				
				main_trigger.html($(this).html());//.addClass('selected').height($(this).height())
				
				$(this).addClass('selected').attr('selected','1')
				if (open_dir == 'up') {
					// alert($(this).attr('id'))
					$(this).closest('#items').attr('open', '0').hide().parent().attr('selected_id', $(this).attr('primary_id'))
					$(this).closest('#main_trigger').removeClass('opened_up')
					$('.opened_up').removeClass('opened_up')
					$(this).closest('.pull_down_holder').removeClass('opened_up')
					
					
				} else {
					$(this).closest('#main_trigger').removeClass('opened')
					$(this).closest('.pull_down_holder').removeClass('opened')
					$(this).closest('#items').slideUp('fast').attr('open', '0').parent().attr('selected_id', $(this).attr('primary_id'))
				}
				if ($(this).parent().parent().parent().hasClass('error')) {
					$(this).parent().parent().parent().removeClass('error').parent().removeClass('error')
				}
				if ($(this).parent().parent().parent().parent().hasClass('required')) {
					$(this).parent().parent().parent().parent().addClass('validated')
				}
			//	display_error_message() 
			}
			if ($(this).attr('primary_id') == 0) {
				if ($(this).parent().parent().parent().parent().hasClass('required')) {
					$(this).parent().parent().parent().parent().removeClass('validated')
				}
			}
}); 

  $('.select_trigger').hover(
			function(){
				$(this).addClass('hover').closest('.pull_down_holder').addClass('hover')
			},
			function(){
				$(this).removeClass('hover').closest('.pull_down_holder').removeClass('hover')
			}
	)


	
	
	


/****************/
/* END PULLDOWN */
/****************/





/* RADIO */

	$(":input").filter("[type='radio']").each(function(){
		var attach_to = $(this).parent()
		var this_label = $(this).attr('label')
		var this_name = $(this).attr('name')
		var this_label_position = $(this).attr('label_position')
		var this_set_width = $(this).attr('set_width')
		var this_checked = $(this).attr('checked')


		if (!this_set_width ) {
			this_set_width = '80px'
		} 
		if (this_set_width == 'auto') {
			this_set_width = 80
		} else {
			this_set_width = this_set_width+'px'
		}
		this_id = $(this).attr('id')
		this_required_val = $(this).attr('required')
		if (this_required_val == undefined) {
			this_required = 0
		} else {
			this_required = this_required_val
		}
		if (this_label_position == 'left') {
			this_checkbox = '<div class="radio_block" style="width:'+this_set_width+'" id="'+this_id+'_block" required_name="'+this_name+'" this_id="'+this_id+'">'
			this_checkbox += '<div id="radio_text" style="float: left;"><label style="cursor:pointer" id="'+this_id+'_text" for="'+this_id+'">'+this_label+':</label></div>'
			this_checkbox += '<div style="float: left; padding-top: 2px;"><div class="radio" id="'+this_id+'_check" name="'+this_name+'"></div></div>'
			this_checkbox += '<div style="clear: both;"></div></div>'
		} else if (this_label_position == 'none') {
			this_checkbox = '<div class="radio_block" style="width:'+this_set_width+'; " id="'+this_id+'_block" required_name="'+this_name+'" this_id="'+this_id+'">'
			this_checkbox += '<div style="float: left; padding-top: 2px;"><div class="radio" id="'+this_id+'_check" name="'+this_name+'"></div></div>'
			this_checkbox += '<div style="clear: both;"></div></div>'
		} else {

			this_checkbox = '<div class="radio_block" style="float:left; width:'+this_set_width+';" id="'+this_id+'_block" required_name="'+this_name+'" this_id="'+this_id+'">'
			this_checkbox += '<div style="float: left; padding-top:2px;"><div style="" class="radio" id="'+this_id+'_check" name="'+this_name+'"></div></div>'
			this_checkbox += '<div id="radio_text" class="radio_text" style=" float: left; margin-left:3px; line-height:15px"><label style="cursor:pointer" id="'+this_id+'_text" for="'+this_id+'">'+this_label+'</label></div>'
			
			this_checkbox += '<div style="clear: both;"></div></div>'
		}
		this_checkbox  += '<input type="hidden" name="'+this_id+'" id="'+this_id+'" value="" required_name="'+this_name+'">';
		attach_to.append(this_checkbox); 
		$(this).remove()
		
		if (this_checked != undefined) {
			// alert(this_checked + ' - ' + this_id) 
			if ((this_checked == 'checked') || (this_checked == true)) {
				$('#'+this_id+'_check').addClass('checked')
				$('#'+this_id).val(1);
			} else {
				$('#'+this_id).val(0);
			}
		} else {
				$('#'+this_id).val(0);
		}


	})

	
/*************/
/* END RADIO */
/*************/

		$(".radio_block").live("click", function(event) {
				this_name = $(this).attr('required_name')
				this_id = $(this).attr('this_id')
				$('.radio').filter("[name='"+this_name+"']").removeClass('checked')
				$('input').filter("[required_name='"+this_name+"']").val(0)

				$(this).find('.radio').addClass('checked')
				$('#'+this_id).val(1)
		}); 
		
	
/******************/
/* START CHECKBOX */
/******************/
$(":input").filter("[type='checkbox']").each(function(){
		var attach_to = $(this).parent()
		var this_label = $(this).attr('label')
		var this_label_position = $(this).attr('label_position')
		var this_multi_action = $(this).attr('multi_action')
		var this_set_width = $(this).attr('set_width')
		var this_checked = $(this).attr('checked')

		if (!this_set_width ) {
			this_set_width = '80px'
		} 
		if (this_set_width == 'auto') {
			this_set_width = 80
		} else {
			this_set_width = this_set_width+'px'
		}
		this_id = $(this).attr('id')
		if (this_label_position == 'left') {
			this_checkbox = '<div class="check_box_block" style="width:'+this_set_width+'; " id="'+this_id+'_block">'
			this_checkbox += '<div id="checkbox_text" style="float: left;"><label style="cursor:pointer; line-height:18px; padding-right:3px" id="'+this_id+'_text" for="'+this_id+'">'+this_label+':</label></div>'
			this_checkbox += '<div style="float: left; padding-top: 2px;"><div class="check_box" id="'+this_id+'_check"></div></div>'
			this_checkbox += '<div style="clear: both;"></div></div>'
		} else if (this_label_position == 'none') {
			this_checkbox = '<div class="check_box_block" style="width:'+this_set_width+'; " id="'+this_id+'_block">'
			this_checkbox += '<div style="float: left; padding-top: 2px;"><div class="check_box" id="'+this_id+'_check"></div></div>'
			this_checkbox += '<div style="clear: both;"></div></div>'
		} else {

			this_checkbox = '<div class="check_box_block" style=" width:'+this_set_width+';" id="'+this_id+'_block">'
			this_checkbox += '<div style="float: left; padding-top:2px;"><div class="check_box" id="'+this_id+'_check"></div></div>'
			this_checkbox += '<div id="checkbox_text" class="checkbox_text" style=""><label style="cursor:pointer; line-height:18px" id="'+this_id+'_text" for="'+this_id+'">'+this_label+'</label></div>'
			
			this_checkbox += '<div style="clear: both;"></div></div>'
		}
		this_checkbox += '<div style="clear: both;"></div>'
		this_checkbox  += '<input type="hidden" name="'+this_id+'" id="'+this_id+'" value="">';
		attach_to.append(this_checkbox); 
		$(this).remove()
		// CLICK FUNCTION - FOR: CHECKBOX
		if (this_multi_action == 'three') {
			$('#'+this_id+'_check').bind('click', function() {
				check_name = $(this).attr('id') 
				check_name = check_name.replace("_check", "");
				if ($(this).hasClass('dim')) {
				} else {
					if ($(this).hasClass('checked')) {
						$(this).removeClass('checked')
						$(this).addClass('dont_checked')
						$('#'+check_name).val(2);
					} else if ($(this).hasClass('dont_checked')) {
						$(this).removeClass('dont_checked')
						$('#'+check_name).val(0);
					} else {
						$(this).addClass('checked')
						$('#'+check_name).val(1);
					}
				}
			})	

		} else {
			$('#'+this_id+'_check').bind('click', function() {
				if (!$(this).hasClass('noedit')) {
					check_name = $(this).attr('id') 
					check_name = check_name.replace("_check", "");
					if ($(this).hasClass('dim')) {
					} else if ($(this).hasClass('cant_edit')) {
					} else {
						if ($(this).hasClass('checked')) {
							$(this).removeClass('checked')
							$('#'+check_name).val(0);
						} else {
							$(this).addClass('checked')
							$('#'+check_name).val(1);
						}
					}
				}
			})	
		}
		// CLICK FUNCTION - FOR: CHECKBOX TEXT
		$('#'+this_id+'_text').bind('click', function() {
			if ($('#'+this_id+'_check').hasClass('un_checked')) {
				$('#'+this_id+'_check').removeClass('un_checked')
				$('#'+this_id).val(0);
			} else {
				$('#'+this_id+'_check').addClass('un_checked')
				$('#'+this_id).val(1);
			}
		})

		//	alert(this_checked + ' - ' + this_id) 
		if (this_checked != undefined) {
			// alert(this_checked + ' - ' + this_id) 
			if ((this_checked == 'checked') || (this_checked == true)) {
				$('#'+this_id+'_check').addClass('checked')
				$('#'+this_id).val(1);
			} else {
				$('#'+this_id).val(0);
			}
		} else {
				$('#'+this_id).val(0);
		}

 
						

	})


	$('.checkbox_text').each(function() {
			$(this).click(function() {
				
				$(this).prev().children().trigger('click')
			})
	})
	
	/**** CHECKBOX */
	
	
		$("body").data("Loaded").Elements = 1
		$('#BodyData').append("<br>End: Loaded.Elements: ")
		$('#BodyData').append($("body").data("Loaded").Elements)
}

	
/********************************/
/* END FUNCTION create_elements */
/********************************/
function Chr(AsciiNum) {
	return String.fromCharCode(AsciiNum)
}
function not_over_main_trigger(over_what_trigger) {
	$(document).unbind("keyup")
}
function over_main_trigger(over_what_trigger) {


	$(document).bind("keyup", function(event) { 
		event.preventDefault()
		event.stopPropagation()
		
		inner_scroll_length = over_what_trigger.parent().find('.inner_scroll').length
		if (inner_scroll_length != 0) {
			var this_key_pressed = Chr(event.which)  
			var inner_scroll_obj = over_what_trigger.parent().find('.pane')
			var scroll_list_to = over_what_trigger.parent().find("[starts_with='"+this_key_pressed+"']")
			
			if (event.which == 38) { // up arrow
				var trigger_me = over_what_trigger.next().find('#this_arrow_up')
				over_what_trigger.next().find('#this_arrow_up').trigger('click') 
				trigger_me.trigger('click')

								var full_open_height = over_what_trigger.parent().find('#items').height()
								var inner_scroll_height = over_what_trigger.parent().find('.inner_scroll').height()
								inner_scroll_obj_top = inner_scroll_obj.css('top')
								if (inner_scroll_obj_top < 0){ 
									inner_scroll_obj_top -= 22
								}
								inner_scroll_obj.css({ 'top':'-'+inner_scroll_obj_top+'px'})
			} else if (event.which == 40) { // down arrow
				var trigger_me = over_what_trigger.next().find('#this_arrow_down')
				trigger_me.trigger('click')
								var full_open_height = over_what_trigger.parent().find('#items').height()
								var inner_scroll_height = over_what_trigger.parent().find('.inner_scroll').height()
								inner_scroll_obj_top = inner_scroll_obj.css('top')
								scroll_me_to = inner_scroll_height - full_open_height
								if (inner_scroll_obj_top > scroll_me_to){ 
									inner_scroll_obj_top += 22
								}
								inner_scroll_obj_top -= 22
								inner_scroll_obj.css({ 'top':'-'+inner_scroll_obj_top+'px'})
			} else if (scroll_list_to != undefined) {
						var scroll_list_to_offset = scroll_list_to.position()
						if (scroll_list_to_offset != null) {
								var scroll_list_to_offset_top = scroll_list_to_offset.top
								var full_open_height = over_what_trigger.parent().find('#items').height()
								var inner_scroll_height = over_what_trigger.parent().find('.inner_scroll').height()
								
								var scroll_me_to = scroll_list_to_offset_top
								if (full_open_height < scroll_list_to_offset_top) {
									scroll_me_to = inner_scroll_height - full_open_height
								}
								inner_scroll_obj.css({ 'top':'-'+scroll_me_to+'px'});
						}
		//	over_what_trigger.html('aa'+event.which + ' - ' + this_key_pressed + inner_scroll_obj.css('top') + ' - ' + inner_scroll_height)
			}
			//scrollbar_pulldown arrow down
			             // calculate distance since last fireing of this handler
            //var distance = this.mousePosition(ev) - this.mouse.start;

            // calculate new handle position
        //    this.handle.top = this.handle.start + distance;

			// inner_scroll_obj.scrollTo( {top:'10px', left:'0px'}, 800 );//( { 'top':'-20px'},  800 );
		//	inner_scroll_obj.scrollTo(scroll_list_to,  800 );
		}
		// scroll_list_to.children().css({'background-color':'pink'})
	})

}
/**************************************************************************************************************/
/* MEASURE SCREEN */
/**************************************************************************************************************/
function measure_screen() {
		$("body").data("Loaded").ScreenSize = 10
		
		$('#BodyData').append("<br><strong>MEASURE SCREEN</strong>") // Debug Info
		$('#BodyData').append("<br>Start: Loaded.ScreenSize: ") // Debug Info
		$('#BodyData').append($("body").data("Loaded").ScreenSize) // Debug Info
		
		/* 	SET VARIABLES 	*/	
		screen_width = $(window).width() - 20 // add scrollbar even if it doesnt show
		screen_height = $(window).height()
		if (screen_width > 1235) {
			$('#LeftContainer').attr('main_content_columns', 2); // Set this here but could change later in align_main_column()
			left_right_margins = 100;
			if (screen_width > 1400) {
				// grow search textarea
				$('#TopNavSearchGrow').width(258).children().width(258)
			} else {
				$('#TopNavSearchGrow').width(158).children().width(158)
			}
		} else {
			if (screen_width < 970) {
				left_right_margins = 0;
				$('#TopNavSearchGrow').width(85).children().width(85)
			} else {
				left_right_margins = 20;
				$('#TopNavSearchGrow').width(158).children().width(158)
			}
		}

		
		
		
		page_content_width = screen_width - (left_right_margins*2)
		$('#MenuBarInfo').html('screen_width: '+screen_width) // Debug Info

		// PLACE ABSOLUTE ELEMENTS

		// 1. TopNavSearch
		top_nav_search_left = left_right_margins
		$('#TopNavSearch').css({'left':top_nav_search_left+'px'}).show()
		
		// 2. MainTopMenu
		top_nav_bar_left = screen_width - $('#MainTopMenu').width() - left_right_margins
		if (screen_width < 835) {
			top_nav_bar_left = 220
		}
		
		
		loaded_menu_width = $('body').data('MainTopMenuWidth') + 10
		$('#MainTopMenu').css({'width':loaded_menu_width+'px', 'left':top_nav_bar_left+'px'})
		$('#MainTopMenu').show()
		
		// Set Menu Loaded so the page can continue to load
		$("body").data("Loaded").ScreenSize = 1
		$('#BodyData').append("<br>End: Loaded.ScreenSize: ") // Debug Info
		$('#BodyData').append($("body").data("Loaded").ScreenSize) // Debug Info 								


		// UserSettings == font_size|no_of_columns|SiteUserID
		if ($.cookie('UserSettings') != null){ 
			this_settings = $.cookie('UserSettings');
			this_settings_each = this_settings.split('|')
			UserSettings_FontSize = this_settings_each[0];
			UserSettings_NumberColumns = this_settings_each[1];
			UserSettings_SiteUserID = this_settings_each[2];
		} else {
			if (screen_width > 1235) {
				UserSettings_NumberColumns = 1;
			} else {
				UserSettings_NumberColumns = 1;
			}
			UserSettings_FontSize = 2;
			UserSettings_SiteUserID = 0;
		}
		

		$('body').data('UserSettings', { 
			NumberColumns: 	UserSettings_NumberColumns, 
			FontSize: 			UserSettings_FontSize, 
			SiteUserID: 		UserSettings_SiteUserID
		});
		
		// USELESS DATA TO SAVE
		browser_info = navigator.userAgent
		browser_platform = navigator.platform
		browser_width = $(window).width(); 
		browser_height = $(window).height(); 
		
		screenheight = screen.height;
		screenwidth = screen.width;
		
		if ($.cookie('SessionID') == null) {
			var ThisSessionID = 0;
		} else {
			var ThisSessionID = $.cookie('SessionID');
		}

		$.post("page_includes/save_session.php",  
			{ 
				SitePageID:SitePageID, 
				ScreenWidth:screenwidth, 
				ScreenHeight:screenheight,  
				BrowserWidth:browser_width, 
				BrowserHeight:browser_height, 				
				Referer:Referer, 
				Browser:browser_info, 
				Platform:browser_platform ,
				ThisSessionID:ThisSessionID,
				SiteUserID:UserSettings_SiteUserID,
				FontSize:UserSettings_FontSize,
				NoColumns: UserSettings_NumberColumns
			},    
			function(data){
			 		returned_data = $.trim(data);
					returned_data_parts = returned_data.split('|')
					if (returned_data_parts.length == 2) {
						$("body").data("UserSettings").SessionID = returned_data_parts[0]
						$("body").data("UserSettings").SiteUserID = returned_data_parts[1]
					}
					save_user_cookies()
			}
		) 
		
		// SET PADDING ON SiteContainer 
		$('#SiteContainer').css({'margin':'0px ' + left_right_margins+'px'})
		$('#SiteLogo').css({'padding':'37px ' + left_right_margins+'px 0 '})
		site_container_width = screen_width - (left_right_margins * 2)
		$('#SiteContainer').width(site_container_width);
		


	

}
function save_user_cookies() {
			UserSettings_NumberColumns 	= $('body').data('UserSettings').NumberColumns;
			UserSettings_FontSize 			= $('body').data('UserSettings').FontSize;
			UserSettings_SiteUserID 		= $('body').data('UserSettings').SiteUserID;
			UserSettings_SessionID 			= $('body').data('UserSettings').SessionID;

			$.cookie('UserSettings', UserSettings_FontSize+'|'+UserSettings_NumberColumns+'|'+UserSettings_SiteUserID, {expires: 300});
			$.cookie('SessionID', UserSettings_SessionID);
}
/**************************************************************************************************************/
/* END MEASURE SCREEN */
/**************************************************************************************************************/

					
/**************************************************************************************************************/
/* LOAD MY MENUS */
/**************************************************************************************************************/
function load_top_menus_function() {

	$("body").data("Loaded").Menus = 10
		
		$('#BodyData').append("<br><br><strong>LOAD AND MEASURE MENUS</strong>") // Debug Info
		$('#BodyData').append("<br>Start: Loaded.Menus: ") // Debug Info
		$('#BodyData').append($("body").data("Loaded").Menus) // Debug Info
		
	/* 
	ON LOAD
	1. SHOW ALL MENUS
	2. PLACE ALL MENUS - TOP AND LEFT 
	3. PLACE ARROWS WHERE THEY NEED TO BE
	4. SET HEIGHTS OF ALL SUB MENUS
	5. PUT SCROLLBARS WHERE THEY NEED TO BE
	6. HIDE COVER LAYER (TopMenuCover)
	*/

	/* 	SET COUNTERS  	*/
	$('#MainTopMenu').find('.sub_link').attr('item_placed', 0)
	countdown_timer = setTimeout('countdown_trigger()', 10);
		 
	$('#MainTopMenu').find('.sub_menu_box').attr('set_width', 0)
	count_down_w = setTimeout('countdown_widths()', 10); ///* STARTS A CHAIN OF EVENTS --> place_all_menus() */
	
	/* 	SET VARIABLES 	*/	
	menu_offset = parseInt($('#MainTopMenu').css('left'));//200;// $(window).width()
	screen_width = menu_offset + $('#MainTopMenu').width()
	screen_height = $(window).height()
	max_menu_height = screen_height - $('#MainTopMenu').height() - 50;
	max_sub_menu_top = $('#MainTopMenu').height() + 30;
	drop_down_menu_width = 260;
	$('#MainTopMenu').attr('level_open', 0).attr('menu_loaded', 0).attr('menu_opened', 0)
	
	/* STARTS A CHAIN OF EVENTS */
	$('#MainTopMenu').find('.sub_menu_box').each(function() {
			set_menu_width ($(this))
	})
	
	/* AT THE END OF CHAIN $("body").data("Loaded").Menus = 1 */

}


function set_menu_height(passed_menu) {
	screen_height = $(window).height()  
	max_menu_height = screen_height - $('#MainTopMenu').height() ;
	sub_menu_height =  passed_menu.height() + 20 // adding 20 for padding room
	// passed_menu.children('#SubLine1').height(sub_menu_height)
	if (sub_menu_height > max_menu_height) {
		passed_menu.children('#SubLine1').height(max_menu_height).attr('has_scrollbar', 1).scrollbar_menu();
	}	
	passed_menu.attr('my_height', sub_menu_height)
	full_height = passed_menu.find('#SubLine1').height()
	//alert(sub_menu_height)
	
	line_height = full_height - 20 
	passed_menu.find('#LeftLineGrow, #RightLineGrow').height(line_height)
	
}
function set_sub_menu_height(passed_menu) {
		/* SET HEIGHTS */
		full_height = passed_menu.children('#SubLine1').height()
		line_height = full_height - 20
		// alert(passed_menu.attr('id'))
	
		passed_menu.find('#LeftLineGrow, #RightLineGrow').height(line_height)
		this_sub_menu_offset =  passed_menu.offset()
		this_sub_menu_offset_left = this_sub_menu_offset.left
		this_sub_menu_offset_top = this_sub_menu_offset.top
		
		this_max_menu_height = screen_height - 50 - this_sub_menu_offset_top;
		sub_menu_height =  passed_menu.height() - 2
		
		if (sub_menu_height > this_max_menu_height) {
			if (passed_menu.find('#SubLine1').attr('has_scrollbar') == undefined) {
				/* THE BOX WANTS TO SCROLL - 
					DO I HAVE ROOM TO MOVE THE ENTIRE BOX UP AND THEREFORE HAVE NO SCROLL ?
					MAX TOP = max_sub_menu_top
					possible_height = max_menu_height
				*/
				if ( sub_menu_height + 20 < max_menu_height) {
						passed_menu.children('#SubLine1').height(full_height)
						.attr('sub_menu_height', sub_menu_height)
						/*
						.attr('full_height', full_height)
						.attr('line_height', line_height)
						.attr('this_max_menu_height', this_max_menu_height)
						.attr('this_sub_menu_offset_top', this_sub_menu_offset_top)
						*/
						.attr('has_scrollbar', 2);
				} else {
					passed_menu.children('#SubLine1').height(this_max_menu_height)
					.attr('sub_menu_height', this_max_menu_height)
					/*
					.attr('this_max_menu_height', this_max_menu_height)
					.attr('this_sub_menu_offset_top', this_sub_menu_offset_top)
					*/
					.attr('has_scrollbar', 1).scrollbar_menu();
					line_height = this_max_menu_height - 20 
					passed_menu.find('#LeftLineGrow, #RightLineGrow').height(line_height)
				}
			}
		}
}	
function set_sub_menu_arrows (passed_menu) {
		/* MY PARENT IS THE BOX HOLDING THE INFO AND SHADOWS */		
		my_level_position = passed_menu.position()
		my_level_position_left = my_level_position.left
		
		my_level_offset = passed_menu.offset()
		my_level_offset_left = my_level_offset.left

		this_menu = passed_menu.attr('id')
		this_sub_menu =  this_menu.replace("_Menu", "")+'_Sub';
		this_sub_menu = $('#'+this_sub_menu);
		
		this_sub_menu_top = my_level_position.top + 18 - 8

		my_level_parent_offset = passed_menu.parents('.sub_menu').offset()
		my_level_parent_offset_left = my_level_parent_offset.left
		
		my_parent_width = passed_menu.closest('.sub_menu').width() // 2 = borders
		my_sub_menu_width = passed_menu.children('.sub_menu').width()

		to_compare = my_parent_width + my_sub_menu_width + my_level_parent_offset_left
		prev_arrow = passed_menu.parents('.sub_link').attr('arrow_placement')
		force_arrow = passed_menu.attr('force_arrow')
		
		if (screen_width < to_compare) {
			
			
			passed_menu.css({'background-image':'url("/images/drop_down/left_nav_arrow.png")', 'background-position':'left center', 'background-repeat':'no-repeat'}).attr('arrow_placement', 'left')
			.attr('prev_arrow', prev_arrow)
			this_sub_menu_left = my_sub_menu_width - 25
			this_sub_menu.css({'left':'-'+this_sub_menu_left+'px', 'top':this_sub_menu_top+'px'})
		} else {
			// if ((prev_arrow == 'left') || (force_arrow == 'left')) {
			if (force_arrow == 'left') {
			
				passed_menu.css({'background-image':'url("/images/drop_down/left_nav_arrow.png")', 'background-position':'left center', 'background-repeat':'no-repeat'}).attr('arrow_placement', 'left')
				.attr('prev_arrow', prev_arrow)
				this_sub_menu_left = my_sub_menu_width - 25
				this_sub_menu.css({'left':'-'+this_sub_menu_left+'px', 'top':this_sub_menu_top+'px'})
			} else {
				passed_menu.css({'background-image':'url("/images/drop_down/right_nav_arrow.png")', 'background-position':'right center', 'background-repeat':'no-repeat'}).attr('arrow_placement', 'right')
				.attr('prev_arrow', prev_arrow)
				this_sub_menu_left = my_parent_width - 28;//11 - 11 - 4 - 4
				this_sub_menu.css({'left':this_sub_menu_left+'px', 'top':this_sub_menu_top+'px'})

			}
			
		} 
		passed_menu.attr('item_placed', 1)
}
function set_menu_width (passed_menu) {
		/* SETS WIDTHS FOR SubLine1 */			
		sub_menu_width =  passed_menu.width() // class = sub_menu 
		passed_menu.attr('set_w',sub_menu_width).attr('set_width',1)
		passed_menu.width(sub_menu_width)
		
		sub_parent_menu_width = sub_menu_width + 24
		bottom_line_width = sub_menu_width - 20
		top_line_width = bottom_line_width

		passed_menu.parent().width(sub_parent_menu_width).find('#BottomLineGrow').width(bottom_line_width)
		passed_menu.parent().find('#TopLineGrow').width(top_line_width)

		$('#MenuNotes').append('<br>passed_menu width: ' +passed_menu.parent().attr('id') + ' sub_menu_width:'+sub_menu_width  )			
}

function countdown_trigger() {
		countdown_number = $('#MainTopMenu').find('.sub_link').filter("[item_placed='1']").length
		goal_number = $('#MainTopMenu').find('.sub_link').length
		//	alert(countdown_number + ' - ' + goal_number)
    if (countdown_number != goal_number) {
			countdown_timer = setTimeout('countdown_trigger()', 10);
		} else {


			$('#MenuNotes').append('<br>has_scrollbar length: ' + $("[has_scrollbar='1']").length   )

			$('#MenuNotes').append('<br>has_scrollbar length: ' + $("[has_scrollbar='1']").length  )			
			$('#MenuNotes').append('<br>has_scrollbar has_subs: ' + $("[has_scrollbar='1']").find("[has_subs='1']").length )	

			$('#MainTopMenu').find("[has_scrollbar='1']").find("[has_subs='1']").each(function() {
				
					// $(this).attr('id') === _Menu ==  Menu_42_Sub_1_Menu 
					this_offset = $(this).offset()
					this_offset_left = this_offset.left
					this_width = $(this).width()
			
					this_sub_menu =  $('#MainTopMenu').find('#'+$(this).attr('id').replace("_Menu", "")+'_Sub')	
					this_sub_menu_id = this_sub_menu.attr('id')
					this_arrow_placement = $(this).attr('arrow_placement')
					$('#MenuNotes').append('<br>this id: ' + $(this).attr('id') + ' this_offset_left: '+this_offset_left + ' -this_sub_menu_w ' +this_sub_menu.width() + 'this_arrow_placement:'+this_arrow_placement )
					
					this_sub_menu_width = this_sub_menu.width();
					if (this_arrow_placement == 'left') { 
						new_left = this_offset_left - this_sub_menu_width - menu_offset + 15
					} else {
						parent_menu_width = $(this).parent().width()
						parent_menu_offset = $(this).closest('.sub_menu').offset()
						parent_menu_offset_left = parent_menu_offset.left

						new_left = parent_menu_width + parent_menu_offset_left + 8 - menu_offset - 11
						old_left =  this_sub_menu.css('left')
					}
					this_sub_menu.appendTo($('#TopLine')).css({'left':new_left+'px'}).attr('ab_placed', '1')

					.attr('my_parent', $(this).attr('id'));//.show().attr('id','HoldMenu')

			})
			 
			/* DO NOT REMOVE THIS */
			$('#MainTopMenu').find('.sub_menu').hide() 
			$('#MainTopMenu').find('#SubLine1').filter("[has_scrollbar!='1']").attr('has_scrollbar', 0)
			$('body').attr('menu_loaded', 1)
						
			// CRAZY IDEA - WRITE MENU BAR TO FILE
			// SET VARIABLES ON SAVE
			$('#MainTopMenu').find('#MainTopMenuHolder')
				.attr('top_left', $('#MainTopMenu').css('left'))
				.attr('top_width', $('#MainTopMenu').width())
			pass_menu = $('#MainTopMenu').html() 
			screen_width = $(window).width() - 20 // add scrollbar even if it doesnt show
			screen_height = $(window).height()  

			
			$("body").data("Loaded").Menus = 1
			
			$('#BodyData').append("<br>End: Loaded.Menus: ")
			$('#BodyData').append($("body").data("Loaded").Menus)
			clearTimeout(countdown_timer);
    }
}

function countdown_widths() {
		w_countdown_number = $('#MainTopMenu').find('.sub_menu_box').filter("[set_width='1']").length
		w_goal_number = $('#MainTopMenu').find('.sub_menu_box').length
		//	alert(w_countdown_number + ' - ' + w_goal_number)
    if (w_countdown_number != w_goal_number) {
			count_down_w = setTimeout('countdown_widths()', 10);
		} else {
			clearTimeout(count_down_w);

			place_all_menus()
    }
}




function set_top_menu_arrows (passed_menu) {
			/* SEE IF SUB MENU WILL FIT ON RIGHT  */
			my_level_position = passed_menu.position()
			my_level_position_left = my_level_position.left
			
			my_level_offset = passed_menu.offset()
			my_level_offset_left = my_level_offset.left			
			
			/* MY PARENT IS THE BOX HOLDING THE INFO AND SHADOWS */						
			my_level_parent_offset = passed_menu.parents('.sub_menu').offset()
			my_level_parent_offset_left = my_level_parent_offset.left
												
			this_menu = passed_menu.attr('id')
			this_sub_menu =  this_menu.replace("_Menu", "")+'_Sub';
			this_sub_menu = $('#MainTopMenu').find('#'+this_sub_menu);
			this_sub_menu_top = my_level_position.top + 18 - 11

			my_parent_width = passed_menu.parents('.sub_menu').width() // 2 = borders
			my_sub_menu_width = passed_menu.children('.sub_menu').width()
			
			to_compare = my_parent_width + my_sub_menu_width + my_level_parent_offset_left
			if (screen_width < to_compare) {
				passed_menu.css({'background-image':'url("/images/drop_down/left_nav_arrow.png")', 'background-position':'left center', 'background-repeat':'no-repeat'}).attr('arrow_placement', 'left')
				this_sub_menu_left = my_sub_menu_width - 25
				this_sub_menu.css({'left':'-'+this_sub_menu_left+'px', 'top':this_sub_menu_top+'px'})
			} else {
				passed_menu.css({'background-image':'url("/images/drop_down/right_nav_arrow.png")', 'background-position':'right center', 'background-repeat':'no-repeat'}).attr('arrow_placement', 'right')
				this_sub_menu_left = my_parent_width - 28;//11 - 11 - 4 - 4
				this_sub_menu.css({'left':this_sub_menu_left+'px', 'top':this_sub_menu_top+'px'})
			} 
			passed_menu.attr('item_placed', 1)
}

function place_all_menus() {
		/* LOOP OVER ALL TOP MENU ITEMS */
		$('#MainTopMenu').find('#TopLine').children().each(function(){
		
			top_menu_item_offset = $(this).offset()
			top_menu_item_left = top_menu_item_offset.left
			
			top_menu_item_position = $(this).position()	
			top_menu_item_position_left = top_menu_item_position.left
			
			top_menu_item_width = $(this).width() + parseInt($(this).css('padding-left')) + parseInt($(this).css('padding-right'))

			$(this).find('.sub_menu').filter("[menu_level='1']").each(function() {
						this_sub_menu = $(this)	
						drop_down_menu_width = this_sub_menu.width()

						// GET PROPER LEFT FOR TOP LEVEL DROP DOWN 
						if (screen_width < (drop_down_menu_width + top_menu_item_left)) { // Align Right
							new_left_position = (top_menu_item_left + top_menu_item_width) - drop_down_menu_width -  menu_offset + 11 // 11 = shadow width
							this_sub_menu.css({'left':new_left_position+'px'})
						} else {
							new_left_position = top_menu_item_position_left - 11;
							this_sub_menu.css({'left':new_left_position+'px'})
						}
						/* SET BOX HEIGHTS */
						$('#MenuNotes').append('<br>SET HIEGHT: ' +$(this).attr('id') )			
						set_menu_height($(this))
						if ($(this).attr('menu_level') == 1) {
								$(this).children('#TopShadow').remove()
							
						}
						$(this).find("[menu_level='1']").filter("[has_subs='1']").each(function() {
							set_top_menu_arrows($(this))  
						})
					
						$(this).find("[menu_level='1']").filter("[has_subs!='1']").each(function() {
									$(this).attr('item_placed', 1)
						}) 

			})
		}) // END $('#TopLine').children().each(function(){
		
		$('#MainTopMenu').find('#TopLine').find('.sub_link').filter("[menu_level!='1']").filter("[has_subs!='1']").each(function() {
			$(this).attr('item_placed', 1)
		})
		
		$('#MainTopMenu').find('#TopLine').find('.sub_link').filter("[has_subs='1']").each(function() {
				/* 
				ON RESIZE
				IF I HAVE ALREADY MOVED THE SUB MENUS TO BE THEIR OWN ABSOLUTELY PLACED DIVS THEN THIS WILL FAIL 
				NEED TO FIND A WAY TO RELOAD THE MENUS AS THEY WERE BEFORE 
				 */

				set_sub_menu_height($(this).children())
				$(this).find("[has_subs='1']").each(function() {
					if ($(this).attr('item_placed') == 0) {
						set_sub_menu_arrows($(this)) 
					}
				})
		})
		

}


/**************************************************************************************************************/
/* END LOAD MY MENUS */
/**************************************************************************************************************/



/**************************************************************************************************************/
/* ALIGN PAGE */
/**************************************************************************************************************/

function align_main_column () {
 		$("body").data("Loaded").PageContent = 10
		
		$('#BodyData').append("<br><strong>ALIGN PAGE CONTENT</strong>")
		$('#BodyData').append("<br>Start: Loaded.PageContent: ")
		$('#BodyData').append($("body").data("Loaded").PageContent)

		var randomnumber = Math.floor(Math.random()*5)+1

		// PUT IMAGE IN TOP NAV AREA 
		
		image_width = $('#TopAreaImage').width()
		nav_bar_width = parseInt($('body').data('MainTopMenuWidth')) 
		image_left = ( nav_bar_width + top_nav_bar_left ) - image_width
		$('#TopAreaImage').addClass('image_'+randomnumber).css({'left':image_left+'px'}).show()

		// CHECK TO SEE IF I HAVE A RIGHT COLUMN
		if (($('#LeftContainer').next().attr('id') == 'RightContainer') ||  ($('#LeftContainer').next().attr('id') == 'RightModuleContainer') ||  (SitePageID = 103)) {
			if ($('#LeftContainer').next().attr('id') == 'RightContainer') {
				use_as_right = $('#RightContainer')
			} 
			if ($('#LeftContainer').next().attr('id') == 'RightModuleContainer') {
				use_as_right = $('#RightModuleContainer')
			} 
			if (SitePageID == 103) {
				use_as_right = $('#RightModuleContainer')
			}
			screen_width = $(window).width() - 20 // add scrollbar even if it doesnt show
			site_container_width = screen_width - (left_right_margins * 2)
			right_full_size =use_as_right.width() + parseInt(use_as_right.css('margin-left') ) + parseInt(use_as_right.css('margin-right') )
			my_width = site_container_width - right_full_size
			$('#LeftContainer').width(my_width).fadeIn()
			$('#RightContainer').fadeIn()
			
			$('#FooterInfo').html("site_container_width " + site_container_width)
			$('#FooterInfo').append("<br>screen_width " + screen_width)
			$('#FooterInfo').append("<br>left_right_margins " + left_right_margins)
			$('#FooterInfo').append("<br>rc " + right_full_size)
			$('#FooterInfo').append("<br>my_width " +  my_width)

		} else {
			my_width = site_container_width;
			$('#LeftContainer').width(my_width)
			
			$('#FooterInfo').append("<br>my_width " +  my_width)
		}

		left_content_width = my_width - parseInt($('#LeftContainer').find('#ModuleBoxContentContainer').css('padding-left')) - parseInt($('#LeftContainer').find('#ModuleBoxContentContainer').css('padding-right')) - parseInt($('#LeftContainer').find('#ModuleBoxContentContainer').css('border-right-width')) - parseInt($('#LeftContainer').find('#ModuleBoxContentContainer').css('border-left-width'))
		
		// FOR THE TIME BEING LIMITING SITE TO 2 COULMSN
		/*
		if (left_content_width > (min_column_width * 3) + (space_between_columns * 2) ) {
			main_content_columns = 3
			real_column_width = (left_content_width - (space_between_columns * 2)) / 3
		} else 
		1364 
		*/

		if (left_content_width > (min_column_width * 1) + (space_between_columns * 1) ) {
		
			main_content_columns = 2
			each_box_dynamic =  parseInt( ( my_width - 2 - (space_between_columns * 3) ) / 2 )
					
			if (each_box_dynamic < max_column_width) {
				each_space = space_between_columns
				
				module_box_width = each_box_dynamic
				left_right_space = space_between_columns - 15
				if (each_box_dynamic !=   ( my_width - 2 - (space_between_columns * 3) ) / 2 ) {
					each_space = space_between_columns + 1
				}
			} else {
				module_box_width = max_column_width
				each_space = ( my_width - 2 - (max_column_width * 2) ) / 3
				left_right_space = each_space - 15
			}
			
			
					// SET THESE VARIABLE IN  align_main_column () 
					$('body').data('Column1', { 
						MarginLeft: left_right_space, 
						MarginRight: 0, 
						ColumnWidth: module_box_width
					});
					$('body').data('Column2', { 
						MarginLeft: each_space, 
						MarginRight: left_right_space, 
						ColumnWidth: module_box_width
					});
				//	 alert('in function align_main_column - left_right_space:'+left_right_space + ' module_box_width '  + module_box_width)
		if ($('body').data('PageData').PageType == 'Text') {	}
			
			//$('#Column1').width(module_box_width).css({'margin-left':left_right_space+'px'})
			//$('#Column2').width(module_box_width).css({'margin-left':each_space+'px', 'margin-right':left_right_space+'px'})
		} else {
			main_content_columns = 1
			real_column_width = left_content_width
		}

		$('#LeftContainer').attr('main_content_columns', main_content_columns);

		
		
		// $('#MainLogo').append("<br>main_content_columns: " + main_content_columns)

		$("body").data("Loaded").PageContent = 1
		$('#BodyData').append("<br>End: Loaded.PageContent: ")
		$('#BodyData').append($("body").data("Loaded").PageContent)

}
/*
		<link id="StyleSheet1" rel="stylesheet" href="/styles/main_styles_1.css" type="text/css" media="screen, projection"/>
		<link id="StyleSheet2" rel="stylesheet" href="/styles/main_styles_2.css" type="text/css" media="screen, projection"/>
		<link id="StyleSheet3" rel="stylesheet" href="/styles/main_styles_3.css" type="text/css" media="screen, projection"/>
*/
function switchStylestyle(styleSize) 	{ 

			if (styleSize == 1) {
				document.styleSheets[0].disabled = false;
	 			document.styleSheets[1].disabled = true;
				document.styleSheets[2].disabled = true;
			}
			if (styleSize == 2) {
				document.styleSheets[0].disabled = true;
	 			document.styleSheets[1].disabled = false;
				document.styleSheets[2].disabled = true;
			}
			if (styleSize == 3) {
				document.styleSheets[0].disabled = true;
	 			document.styleSheets[1].disabled = true;
				document.styleSheets[2].disabled = false; 
			}
			$.cookie('StyleSet', styleSize, {expires: 300});
	// createCookie('style', styleName, 365);
}
function align_left_column() {

			screen_width = $(window).width() - 20 // add scrollbar even if it doesnt show
			site_container_width = screen_width - (left_right_margins * 2)
		my_width = site_container_width;
		left_content_width = my_width - parseInt($('#LeftContainer').find('#ModuleBoxContentContainer').css('padding-left')) - parseInt($('#LeftContainer').find('#ModuleBoxContentContainer').css('padding-right')) - parseInt($('#LeftContainer').find('#ModuleBoxContentContainer').css('border-right-width')) - parseInt($('#LeftContainer').find('#ModuleBoxContentContainer').css('border-left-width'))

		if (left_content_width > (min_column_width * 1) + (space_between_columns * 1) ) {
		
			main_content_columns = 2
			each_box_dynamic =  parseInt( ( my_width - 2 - (space_between_columns * 3) ) / 2 )
			if (each_box_dynamic < max_column_width) {
				each_space = space_between_columns
				module_box_width = each_box_dynamic
				left_right_space = space_between_columns / 2
				if (each_box_dynamic !=   ( my_width - 2 - (space_between_columns * 3) ) / 2 ) {
					each_space = space_between_columns + 1
				}
			} else {
				module_box_width = max_column_width
				each_space = ( my_width - 2 - (max_column_width * 2) ) / 3
				left_right_space = each_space - 15 
			}

			$('.column_layout').filter("[id='Column1']").width(module_box_width).css({'margin-left':left_right_space+'px'}).attr('resize',1)
			$('.column_layout').filter("[id='Column2']").width(module_box_width).css({'margin-left':each_space+'px', 'margin-right':left_right_space+'px'}).attr('resize',1)
		} else {
			main_content_columns = 1
			real_column_width = left_content_width
		}

		$('#LeftContainer').attr('main_content_columns', main_content_columns);
}

function align_footer () {
 		$("body").data("Loaded").Footer = 10
		
		$('#BodyData').append("<br><strong>ALIGN PAGE Footer</strong>")
		$('#BodyData').append("<br>Start: Loaded.Footer: ")
		$('#BodyData').append($("body").data("Loaded").Footer)

		site_container_height = $('#SiteContainer').height()
		site_container_offset = $('#SiteContainer').offset()
		site_container_offset_top = site_container_offset.top
		screen_height = $(window).height()

		/*
		$('#FooterInfo').html("SiteContainer height: "+site_container_height)
		$('#FooterInfo').append("<br>site_container_offset_top: "+site_container_offset_top)
		$('#FooterInfo').append("<br>screen height: "+screen_height)
		*/

		
		if (screen_height > (site_container_offset_top + site_container_height)){
			my_new_top = screen_height - (site_container_height + site_container_offset_top) - ($('#SiteFooter').height() + 1)
			$('#SiteFooter').css({'margin-top':my_new_top+'px'})
		} else {
			$('#SiteFooter').css({'margin-top':'26px'})
			// 111px
		}
		
 


		$("body").data("Loaded").Footer = 1
		//$('#FooterInfo').append("<br>my_new_top: "+my_new_top)
		$('#BodyData').append("<br>End: Loaded.Footer: ")
		$('#BodyData').append($("body").data("Loaded").Footer)

}


function align_footer_check () {

		
		/*
		$('#FooterInfo').html("SiteContainer height: "+site_container_height)
		$('#FooterInfo').append("<br>site_container_offset_top: "+site_container_offset_top)
		$('#FooterInfo').append("<br>screen height: "+screen_height)
		*/
		top_margin = 37;
		screen_height = $(window).height()


		site_container_offset = $('#SiteContainer').offset()
		site_container_offset_top = site_container_offset.top
		
		right_container_height = $('#RightModuleContainer').height()
		left_container_height = $('#LeftContainer').height()

		right_total = (site_container_offset_top + right_container_height + top_margin)
		left_total = (site_container_offset_top + left_container_height + top_margin)
		
		real_total = left_total
		if (right_total > left_total) {
			real_total = right_total
		}
$('#LeftContainer').attr('left_container_height', left_container_height)
.attr('screen_height', screen_height)
.attr('site_container_offset_top', site_container_offset_top)
.attr('right_container_height', right_container_height)

		if (screen_height > real_total){
			my_new_top = screen_height - real_total - ($('#SiteFooter').height() + 1)  + 11 + 26
			if (my_new_top < 26) {
				$('#SiteFooter').css({'margin-top':'26px'}).css({'padding-top':'0px'})
			} else {
				$('#SiteFooter').css({'margin-top':my_new_top+'px'})
			}
			/*
$('#MainLogo').append('<BR>screen_height: '+screen_height)
$('#MainLogo').append('<BR>my_new_top: '+my_new_top)
$('#MainLogo').append('<BR>SiteFooter: '+$('#SiteFooter').height())
$('#MainLogo').append('<BR>right_container_height: '+right_container_height)
			*/
		} else {
			$('#SiteFooter').css({'margin-top':'26px'}).css({'padding-top':'0px'})
		}
	


}

function align_overlay() {
	screen_height = $(document).height()
	screen_width = $(window).width() // add scrollbar even if it doesnt show
	$('#OverlayContainer').width(screen_width).height(screen_height).attr('screen_height',screen_height).attr('screen_height', screen_height)
					// CENTER BOX VERTICALLY
					var scrollTopInitial = $(window).scrollTop();
					var main_box_height = $('#OverlayContainerBox').height() 
					var vertical_center = (screen_height / 2) - (main_box_height / 2)
					var new_margins_top = (screen_height / 2) - (main_box_height / 2) + scrollTopInitial
					$('#OverlayContainerBox').css({'margin-top':new_margins_top+'px'}).attr('new_margins_top', new_margins_top)

					
					// CENTER BOX ON PAGE HORIZONTAL
					var main_box_width = $('#OverlayContainerBox').width()
					var new_margins = (screen_width / 2) - (main_box_width / 2)
					$('#OverlayContainerBox').css({'margin-left':new_margins+'px'})	
}

function load_overlay_content(load_content) {
		var load_content_location = '/Forms/'+load_content
		
		
		// PLACE TRANSPARENT BACKGROUND
		screen_height = $(window).height()
		document_height = $(document).height() - 5
		screen_width = $(window).width() // add scrollbar even if it doesnt show
		
		// SHOW OVERLAY 
		$('#OverlayContainer').show()
		$('#LoginBody').css({'overflow-x':'hidden'})
		
		$('#OverlayContainer').width(screen_width).height(document_height).attr('document_height',document_height).attr('screen_height', screen_height)
		.attr('load_content',load_content_location) 

		// LOADS CONTENT FROM SOURCE FILE
		$('#OverlayHeaderText').load(load_content_location + ' #OverlayHeader', function(response, status, xhr) { })
		$('#OverlayContentContainer').load(load_content_location + ' #OverlayFormContainer', function(response, status, xhr) { 
					var content_width = $('#OverlayContentContainer').width()
					var header_width = content_width - 36


					$('#OverlayHeaderContent, #OverlayFooterContent').width(header_width)
					// MAKE SURE CLOSE BUTTON IS PROPERLY ALIGNED
					close_button_left = header_width - 21
					$('#OverlayHeaderClose').css({'left':close_button_left+'px'})
					
					// SET OVERLAY HEIGHT AND WIDTH
					var content_height = $('#OverlayContentContainer').height()
					$('#OverlayContainerLeft, #OverlayContainerRight').height(content_height)
					var box_width = content_width + 44
					$('#OverlayContainerBox').width(box_width)

					
					// SPECIFIC OVERLAY FORMATTING
					var load_content_js = load_content.replace('.php', '.js');
					$.getScript("/Forms/page_specific/"+load_content_js, function() {     
					
					}); 
					// CENTER BOX VERTICALLY
					var scrollTopInitial = $(window).scrollTop();
					var main_box_height = $('#OverlayContainerBox').height() 
					var vertical_center = (screen_height / 2) - (main_box_height / 2)
					var new_margins_top = (screen_height / 2) - (main_box_height / 2) + scrollTopInitial
					$('#OverlayContainerBox').css({'margin-top':new_margins_top+'px'}).attr('new_margins_top', new_margins_top)
					

					
					// CENTER BOX ON PAGE HORIZONTAL
					var main_box_width = $('#OverlayContainerBox').width()
					var new_margins = (screen_width / 2) - (main_box_width / 2)
					$('#OverlayContainerBox').css({'margin-left':new_margins+'px'})
					
					// DEAL WITH SCROLLING
					$(window).bind("scroll", function(event) {
							var scrollTop = $(window).scrollTop();
							var my_new_margin_top = vertical_center + scrollTop
							$('#OverlayContainerBox').attr('scrollTop', scrollTop).attr('vertical_center', vertical_center)
							
							$('#OverlayContainerBox').css({'margin-top':my_new_margin_top+'px'})
					});


					
				
		}) 
		
		// MAKE BUTTON
		$('#OverlayFooterContent').load(load_content_location + ' #OverlayBottom', function(response, status, xhr) { 
			$('.make_button').make_my_button();
			$('.close_overlay').show()
		})
		// alert(new_margins)
}

function load_overlay_sent() {
		// PLACE TRANSPARENT BACKGROUND
		screen_height = $(window).height()
		document_height = $(document).height()
		screen_width = $(window).width() // add scrollbar even if it doesnt show
		var load_content = $('#OverlayContainer').attr('load_content') 
		
		// LOADS CONTENT FROM SOURCE FILE
		$('#OverlayHeaderText').load(load_content + ' #OverlayHeaderSent', function(response, status, xhr) { })
		$('#OverlayContentContainer').load(load_content + ' #OverlayFormContainerSent', function(response, status, xhr) { 
					var content_width = $('#OverlayContentContainer').width()
					var header_width = content_width - 36
					$('#OverlayHeaderContent, #OverlayFooterContent').width(header_width)
					// MAKE SURE CLOSE BUTTON IS PROPERLY ALIGNED
					close_button_left = header_width - 21
					$('#OverlayHeaderClose').css({'left':close_button_left+'px'})
					
					var content_height = $('#OverlayContentContainer').height()
					$('#OverlayContainerLeft, #OverlayContainerRight').height(content_height)
					var box_width = content_width + 44
					$('#OverlayContainerBox').width(box_width)
					
					// CENTER BOX VERTICALLY
					var scrollTopInitial = $(window).scrollTop();
					var main_box_height = $('#OverlayContainerBox').height() 
					var vertical_center = (screen_height / 2) - (main_box_height / 2)
					var new_margins_top = (screen_height / 2) - (main_box_height / 2) + scrollTopInitial
					$('#OverlayContainerBox').css({'margin-top':new_margins_top+'px'}).attr('new_margins_top', new_margins_top)
					

					
					// CENTER BOX ON PAGE HORIZONTAL
					var main_box_width = $('#OverlayContainerBox').width()
					var new_margins = (screen_width / 2) - (main_box_width / 2)
					$('#OverlayContainerBox').css({'margin-left':new_margins+'px'})
					
					// DEAL WITH SCROLLING
					$(window).bind("scroll", function(event) {
							var scrollTop = $(window).scrollTop();
							var my_new_margin_top = vertical_center + scrollTop
							$('#OverlayContainerBox').attr('scrollTop', scrollTop).attr('vertical_center', vertical_center)
							
							$('#OverlayContainerBox').css({'margin-top':my_new_margin_top+'px'})
					}); 
					
				
		}) 
		
		// MAKE BUTTON
		$('#OverlayFooterContent').load(load_content + ' #OverlayBottomSent', function(response, status, xhr) { 
			$('.make_button').make_my_button();
		})
		// alert(new_margins)
}



/**************************************************************************************************************/
/* END ALIGN PAGE */
/**************************************************************************************************************/


















/**************************************************************************************************************/
/* MENU FUNCTIONS */
/**************************************************************************************************************/

function top_menu_slide(this_event) {
 clearTimeout(menu_bar_timeout);
	over_what_main_menu = this_event.parents('.top_menu')
	over_what_main_menu_id = over_what_main_menu.attr('id')
	whats_opened = $('#MainTopMenu').attr('menu_opened')
	if (over_what_main_menu_id == undefined) {
		menu_bar_timeout = setTimeout('top_menu_slide(over_what)', 100);
	} else {
						if (whats_opened != 'over_what_main_menu_id') {
							close_all_menus()
							$('#MainTopMenu').find('#'+whats_opened).removeClass('dim')
							$('#MainTopMenu').find('#'+whats_opened.replace("_Menu", "")+'_Sub').hide()
							$('#MainTopMenu').attr('menu_opened', over_what_main_menu_id)
							over_what_main_menu.addClass('dim')
							$('#MainTopMenu').find('#'+over_what_main_menu_id.replace("_Menu", "")+'_Sub').show()
							$('#MainTopMenu').find('#'+over_what_main_menu_id.replace("_Menu", "")+'_Sub').stop().slideDown('fast', function() {
								$('#MenuNotes').append($('#'+over_what_main_menu_id.replace("_Menu", "")+'_Sub').attr('id'))
							}); // end slideDown
							
						} else {
							$('#MainTopMenu').find('#'+over_what_main_menu_id.replace("_Menu", "")+'_Sub').show()
						}
	}
}


// GLOBAL MOUSEOVER FUNCTION 
$(document).bind("mouseover", function(event) { 
	over_what = $(event.target)
	over_what_id = $(event.target).attr('id')
	over_what_class = $(event.target).attr('class')
	if (over_what_id == 'main_trigger') {
		over_main_trigger(over_what)
	} else {
		not_over_main_trigger()
	}

	over_what_top = $(event.target).parents('.main_top_menu')
	over_what_top_id = over_what_top.attr('id')
	
	$('#MouseOverNotes').html("<BR><strong>MOUSE OVER</strong>" );
	$('#MouseOverNotes').append("<BR>over_what_id: " + over_what_id );
	$('#MouseOverNotes').append("<BR>over_what_class: " + over_what_class );
	$('#MouseOverNotes').append("<BR>over_what_top_id: " + over_what_top_id );

	$('#MenuNotes').html("<BR><strong>TOP NAV MENU OPEN</strong>: over_what_top_id: " + over_what_top_id );

	over_what_main_menu = $(event.target).parents('.top_menu')
	over_what_main_menu_id = over_what_main_menu.attr('id')
	
	/* THE BLOCK THAT THIS LINK IS IN */
	my_sub_menu = $(event.target).parents('.sub_menu')
	my_sub_menu_id = my_sub_menu.attr('id')
	my_sub_menu_level = my_sub_menu.attr('menu_level')
	
	my_menu_level = my_sub_menu.attr('menu_level')
	
	my_parent_to_keep_hovered = my_sub_menu.attr('my_parent')

	/* IF THE TOP IS 'MainTopMenu' THEN STILL IN THE MENU AREA */
	
	if ($("body").data("Loaded") != undefined)  { 
		if ($("body").data("Loaded").Menus == 1)  { 
			if (over_what_top_id == 'MainTopMenu') {
				if ($(event.target).parent().attr('menu_level') == '0') {
					menu_bar_timeout = setTimeout('top_menu_slide(over_what)', 100);
					$('#MenuNotes').html("<BR><strong>TOP NAV MENU OPEN</strong>: over_what_id: " + over_what_id + ' - over_what_class: ' + over_what_class + ' - over_what_top: ' + over_what_top);
				} else {
					$('#MenuNotes').html("<BR><strong>KEEP MENU OPEN</strong>: "); 
					over_what.stop().css({'background-color':''}).addClass('hover')

					if (my_sub_menu_id != undefined) {
						all_levels = my_sub_menu_id.split('_')
						previous_level = ''
						for (x=0; x<=all_levels.length-1; x++) {
							$('#MenuNotes').append("<BR>&nbsp;&nbsp;-- <strong>LEVEL</strong>: "+x+" = " + all_levels[x] + ' ----- all_levels length ' +all_levels.length);
							if (x <= all_levels.length-2) {
								previous_level += all_levels[x] ;
								if (x != all_levels.length-2) {
									previous_level += "_";
								}
							}
						}
						if (all_levels.length > 0) {
							Main_Menu_Open = $('#MainTopMenu').find('#'+all_levels[0] + '_Menu').show();
							$('#MenuNotes').append("<BR>&nbsp;&nbsp;-- <strong>TOP MENU OPEN</strong>: " + all_levels[0] );
						}

						$('#MainTopMenu').find('#'+previous_level+'_Menu').addClass('hover')

						/* HIDES ALL OPEN MENUS AT THE NEXT LEVEL */
						next_level = parseInt(my_menu_level) + 1
						
						$('#MainTopMenu').find("[id^='"+all_levels[0]+"_']").filter("[menu_level!='"+my_menu_level+"']").filter("[class='sub_menu']").each(function(){
							//$('#MenuNotes').append("<BR>&nbsp;&nbsp;-- <strong>SHOULD HIDE THIS</strong>: " + $(this).attr('id') + ' menu_level: ' + $(this).attr('menu_level') );
							if (parseInt($(this).attr('menu_level')) > parseInt(my_menu_level) ) {
								$(this).hide()
							}
						});
						
						
						$('#MainTopMenu').find("[id^='"+all_levels[0]+"']").filter("[menu_level='"+next_level+"']").filter("[class='sub_menu']").hide()
						
						$('#MenuNotes').append("<BR> <strong>CLOSE SUBS </strong>: all_levels[0]=  " + all_levels[0]  + ' menu_level <>: '+my_menu_level);

						next_level++
						$('#MainTopMenu').find("[id^='"+all_levels[0]+"']").filter("[menu_level='"+next_level+"']").filter("[class='sub_menu']").hide()
						
						

						if (over_what.attr('has_subs') == 1) {
							sub_menu_to_open = $('#MainTopMenu').find('#'+over_what_id.replace("_Menu", "")+'_Sub');
							this_absolute_placed = 0
							if (sub_menu_to_open.attr('ab_placed') != undefined) {
								if (sub_menu_to_open.attr('ab_placed') == 1) {
									this_offset = over_what.offset()
									this_offset_top = this_offset.top
									new_top = this_offset_top + 7
									sub_menu_to_open.css({'top':new_top+'px'})
									$('#MainTopMenu').find('#'+my_parent_to_keep_hovered).addClass('hover')
									this_absolute_placed = 1
								}
							} 
							sub_menu_to_open.stop(true, true).slideDown('slow', function() {}); // end slideDown
							sub_menu_to_open.children('#SubLine1').css({ 'background-color': '#701E0C' })
							.children().removeClass('dim').removeClass('half').find('#ScrollBarHandle').removeClass('dim').removeClass('half')
							sub_menu_to_open.find('.hover').removeClass('hover')
							
							$('#MenuNotes').append("<BR>&nbsp;&nbsp;-- sub_menu_to_open = " + sub_menu_to_open.attr('id') );
							
							sub_menu_to_open_offset = sub_menu_to_open.offset()
							sub_menu_to_open_offset_top = sub_menu_to_open_offset.top
							
							sub_menu_to_open_height =  parseInt(sub_menu_to_open.children('#SubLine1').attr('sub_menu_height')) 
							over_what_offset = over_what.offset()
							over_what_offset_top = over_what_offset.top
							
							

							/* IF SCROLLBARS == 2 THEN LOAD WANTED TO PUT SCROLLBARS IN BUT DIDNT SO I MUST MOVE THIS BOX UP SO THE THAT BOTTOM IS 50PX FROM THE SCREEN HEIGHT */
							if (sub_menu_to_open.children('#SubLine1').attr('has_scrollbar') == 2) {

								if (this_absolute_placed == 1) {
									/* TO DO - WHAT IF THE TOP IS REALLY LOW */
									new_top = screen_height - 50 - parseInt(sub_menu_to_open.children('#SubLine1').attr('sub_menu_height'))
									new_top = over_what_offset_top
									
								} else { 
									new_top = screen_height - 50 - parseInt(sub_menu_to_open.children('#SubLine1').attr('sub_menu_height'))
								}
								sub_menu_to_open.css({'top':new_top+'px'})

							}
							max_menu_height = screen_height - $('#MainTopMenu').height() ;
							if (sub_menu_to_open.attr('keep_top_as_is') == undefined) {
							
								/* IF PAGE WILL SCROLL BY PLACING IT HERE */
								if ( sub_menu_to_open_offset_top + sub_menu_to_open_height > max_menu_height ) {
									$('#MenuNotes').append("<BR><BR>&nbsp;&nbsp;-- <strong>Page will Scroll</strong>sub_menu_to_open_offset_top = " + sub_menu_to_open_offset_top + ' - sub_menu_to_open_height: '+ sub_menu_to_open_height );
									new_top = sub_menu_to_open_offset_top - sub_menu_to_open_height + 33 + 11 - 18
								
									$('#MenuNotes').append("<BR><strong>new_top</strong> = " + new_top );
									if (new_top < $('#MainTopMenu').height()) {
										new_top = 0
										new_top = centered_top = parseInt(max_menu_height / 2) - (sub_menu_to_open_height / 2) 
										$('#MenuNotes').append("<BR><strong>WHATS MY HEIGHT : sub_menu_to_open_height</strong> = " + sub_menu_to_open_height );
										$('#MenuNotes').append("<BR><strong>OPENER ARROW IS AT : over_what_offset_top</strong> = " + over_what_offset_top );
										new_top = over_what_offset_top - 20 - centered_top
										$('#MenuNotes').append("<BR><strong>NEW NEW NEW new_top</strong> = " + new_top );
										sub_menu_to_open.css({'top':'-'+new_top+'px'}).attr('keep_top_as_is', 1).attr('keep_top_at', new_top)
									} else {
										sub_menu_to_open.css({'top':new_top+'px'}).attr('keep_top_as_is', 1)
									}
								}
							} else {
									new_top = sub_menu_to_open.attr('keep_top_at')
									sub_menu_to_open.css({'top':'-'+new_top+'px'})
							}
						}
						
						
						/* UN DIM AND HALF WHAT IM ON - AND EVERYTHING UNDENEATH ME */
						to_un_dim = over_what.closest('#SubLine1');
						if (to_un_dim.attr('has_scrollbar') == 1) {
								to_un_dim.children().removeClass('dim').removeClass('half').find('#ScrollBarHandle').removeClass('dim').removeClass('half')
								to_un_dim.find('#ScrollContent').stop(true, true).animate({ backgroundColor: '#701E0C' }, 600);
						} else {
								to_un_dim.stop(true, true).animate({ backgroundColor: '#701E0C' }, 600);
								to_un_dim.find('#SubLine1').stop(true, true).animate({ backgroundColor: '#701E0C' }, 600);
						}

						if (my_menu_level > 2) {
							dim_more_level = my_menu_level - 2
							to_dim = $('#MainTopMenu').find("[id^='"+all_levels[0]+"']").filter("[menu_level='"+dim_more_level+"']").closest('#SubLine1')
							if (to_dim.attr('has_scrollbar') == 1) {
								to_dim.children().removeClass('half').addClass('dim').find('#ScrollBarHandle').removeClass('half').addClass('dim')
								to_dim.find('#ScrollContent').stop(true, true).animate({ backgroundColor: '#98726A' }, 600);
							} else {
								to_dim.stop(true, true).animate({ backgroundColor: '#98726A' }, 600);
							}
							$('#MenuNotes').append('<BR>What should dim even more?'+dim_more_level);
							$('#MenuNotes').append("<BR>what gets hovered<strong>TOP MENU OPEN</strong>: " + previous_level );
						}
						
						
						if (my_menu_level > 1) {
							$('#MenuNotes').append('<BR>What should dim ?'+previous_level);
							to_dim = $('#MainTopMenu').find('#'+previous_level+'_Menu').closest('#SubLine1')
							if (to_dim.attr('has_scrollbar') == 1) {
								to_dim.children().removeClass('dim').addClass('half').find('#ScrollBarHandle').removeClass('dim').addClass('half')
								to_dim.find('#ScrollContent').stop(true, true).animate({ backgroundColor: '#793628' }, 600);
							} else {
								to_dim.stop(true, true).animate({ backgroundColor: '#793628' }, 600);
							}
						}

						$('#MainTopMenu').find("[id^='"+all_levels[0]+"']").filter("[menu_level='"+my_menu_level+"']").filter("[class='sub_link']").each(function(){
								$(this).stop().css({'background-color':''})
						})
						top_level_id = all_levels[0]
						// color_change_timeout = setTimeout('color_change(top_level_id,my_menu_level)', 50);
					}		
				}
				
			} else { 
				if ($('#MainTopMenu').attr('menu_opened') != '0') {
					$('#MenuNotes').html("<BR><strong>CLOSE ALL MENUS</strong>: "); 
					if ($('body').attr('menu_loaded') == 1) {
						menu_bar_timeout = setTimeout('close_all_menus(over_what_top_id)', 1000);
					}
				}
			}
		} // end $("body").data("Loaded") is undefined
	}
	$('#MenuNotes').append("<BR><strong>OVER BIND</strong>: "+ over_what_id + ' - my_sub_menu: '+ my_sub_menu_id); 
})

function color_change(top_level_id,my_menu_level) {
	$('#MainTopMenu').find("[id^='"+top_level_id+"']").filter("[menu_level='"+my_menu_level+"']").filter("[class='sub_link']").each(function(){
		$(this).stop().css({'background-color':''})
		$('#MenuNotes').append("<BR><strong>REALLLY TURN BACKGROUND COLOR OFF FOR </strong>: "+ $(this).attr('id') + ' - my_menu_level: '+my_menu_level); 
	})

	
}

	
function close_all_menus(over_what_top_id) {
	$('#MenuNotes').append('<BR>IN FUNCTION close_all_menus ' + over_what_top_id);
	if (over_what_top_id != 'MainTopMenu') {
			$('#MainTopMenu').find('.sub_menu').hide()
			$('#MainTopMenu').find('.sub_link').removeClass('dim').css({'background-color':''});
			$('#MainTopMenu').find('.top_menu').removeClass('dim') 
			$('#MainTopMenu').attr('menu_opened', '0')
			$('#MainTopMenu').find('.hover').removeClass('hover') 
			$('#MainTopMenu').find('.dim').removeClass('dim') 
			$('#MainTopMenu').find('#ScrollContent').stop(true, true).css({ 'background-color': '#701E0C' });
			$('#MainTopMenu').find('#SubLine1').stop(true, true).css({ 'background-color': '#701E0C' });
			$('#MainTopMenu').find('#ScrollBarPane').css({ 'top': '0px' });
			
	}
}


/**************************************************************************************************************/
/* END MENU FUNCTIONS */
/**************************************************************************************************************/


/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	};
	
})(jQuery);
/**
 * jQuery.ScrollTo
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 *
 * @projectDescription Easy element scrolling using jQuery.
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 * Works with jQuery +1.2.6. Tested on FF 2/3, IE 6/7/8, Opera 9.5/6, Safari 3, Chrome 1 on WinXP.
 *
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * @id jQuery.scrollTo
 * @id jQuery.fn.scrollTo
 * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements.
 *	  The different options for target are:
 *		- A number position (will be applied to all axes).
 *		- A string position ('44', '100px', '+=90', etc ) will be applied to all axes
 *		- A jQuery/DOM element ( logically, child of the element to scroll )
 *		- A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
 *		- A hash { top:x, left:y }, x and y can be any kind of number/string like above.
*		- A percentage of the container's dimension/s, for example: 50% to go to the middle.
 *		- The string 'max' for go-to-end. 
 * @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead.
 * @param {Object,Function} settings Optional set of settings or the onAfter callback.
 *	 @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
 *	 @option {Number} duration The OVERALL length of the animation.
 *	 @option {String} easing The easing method for the animation.
 *	 @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.
 *	 @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }.
 *	 @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes.
 *	 @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.
 *	 @option {Function} onAfter Function to be called after the scrolling ends. 
 *	 @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.
 * @return {jQuery} Returns the same jQuery object, for chaining.
 *
 * @desc Scroll to a fixed position
 * @example $('div').scrollTo( 340 );
 *
 * @desc Scroll relatively to the actual position
 * @example $('div').scrollTo( '+=340px', { axis:'y' } );
 *
 * @dec Scroll using a selector (relative to the scrolled element)
 * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } );
 *
 * @ Scroll to a DOM element (same for jQuery object)
 * @example var second_child = document.getElementById('container').firstChild.nextSibling;
 *			$('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){
 *				alert('scrolled!!');																   
 *			}});
 *
 * @desc Scroll on both axes, to different values
 * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
 */
;(function( $ ){
	
	var $scrollTo = $.scrollTo = function( target, duration, settings ){
		$(window).scrollTo( target, duration, settings );
	};

	$scrollTo.defaults = {
		axis:'xy',
		duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1
	};

	// Returns the element that needs to be animated to scroll the window.
	// Kept for backwards compatibility (specially for localScroll & serialScroll)
	$scrollTo.window = function( scope ){
		return $(window)._scrollable();
	};

	// Hack, hack, hack :)
	// Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
	$.fn._scrollable = function(){
		return this.map(function(){
			var elem = this,
				isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1;

				if( !isWin )
					return elem;

			var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem;
			
			return $.browser.safari || doc.compatMode == 'BackCompat' ?
				doc.body : 
				doc.documentElement;
		});
	};

	$.fn.scrollTo = function( target, duration, settings ){
		if( typeof duration == 'object' ){
			settings = duration;
			duration = 0;
		}
		if( typeof settings == 'function' )
			settings = { onAfter:settings };
			
		if( target == 'max' )
			target = 9e9;
			
		settings = $.extend( {}, $scrollTo.defaults, settings );
		// Speed is still recognized for backwards compatibility
		duration = duration || settings.speed || settings.duration;
		// Make sure the settings are given right
		settings.queue = settings.queue && settings.axis.length > 1;
		
		if( settings.queue )
			// Let's keep the overall duration
			duration /= 2;
		settings.offset = both( settings.offset );
		settings.over = both( settings.over );

		return this._scrollable().each(function(){
			var elem = this,
				$elem = $(elem),
				targ = target, toff, attr = {},
				win = $elem.is('html,body');

			switch( typeof targ ){
				// A number will pass the regex
				case 'number':
				case 'string':
					if( /^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(targ) ){
						targ = both( targ );
						// We are done
						break;
					}
					// Relative selector, no break!
					targ = $(targ,this);
				case 'object':
					// DOMElement / jQuery
					if( targ.is || targ.style )
						// Get the real position of the target 
						toff = (targ = $(targ)).offset();
			}
			$.each( settings.axis.split(''), function( i, axis ){
				var Pos	= axis == 'x' ? 'Left' : 'Top',
					pos = Pos.toLowerCase(),
					key = 'scroll' + Pos,
					old = elem[key],
					max = $scrollTo.max(elem, axis);

				if( toff ){// jQuery / DOMElement
					attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );

					// If it's a dom element, reduce the margin
					if( settings.margin ){
						attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
						attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
					}
					
					attr[key] += settings.offset[pos] || 0;
					
					if( settings.over[pos] )
						// Scroll to a fraction of its width/height
						attr[key] += targ[axis=='x'?'width':'height']() * settings.over[pos];
				}else{ 
					var val = targ[pos];
					// Handle percentage values
					if (val != undefined) {
					//	alert(val)
						attr[key] = val.slice && val.slice(-1) == '%' ?  parseFloat(val) / 100 * max : val;
					}
					
				}

				// Number or 'number'
				if( /^\d+$/.test(attr[key]) )
					// Check the limits
					attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max );

				// Queueing axes
				if( !i && settings.queue ){
					// Don't waste time animating, if there's no need.
					if( old != attr[key] )
						// Intermediate animation
						animate( settings.onAfterFirst );
					// Don't animate this axis again in the next iteration.
					delete attr[key];
				}
			});

			animate( settings.onAfter );			

			function animate( callback ){
				$elem.animate( attr, duration, settings.easing, callback && function(){
					callback.call(this, target, settings);
				});
			};

		}).end();
	};
	
	// Max scrolling position, works on quirks mode
	// It only fails (not too badly) on IE, quirks mode.
	$scrollTo.max = function( elem, axis ){
		var Dim = axis == 'x' ? 'Width' : 'Height',
			scroll = 'scroll'+Dim;
		
		if( !$(elem).is('html,body') )
			return elem[scroll] - $(elem)[Dim.toLowerCase()]();
		
		var size = 'client' + Dim,
			html = elem.ownerDocument.documentElement,
			body = elem.ownerDocument.body;

		return Math.max( html[scroll], body[scroll] ) 
			 - Math.min( html[size]  , body[size]   );
			
	};

	function both( val ){
		return typeof val == 'object' ? val : { top:val, left:val };
	};

})( jQuery );

