function startUp() {
	// global functions
	function calc_total(supply, value) {
		switch (supply) {
			case 'drapes':
				price = 245;
				break;
			case 'small_paper':
				price = 180;
				break;
			case 'large_paper':
				price = 300;
				break;
			case 'large_film':
				price = 425;
				break;
			case 'apron':
				price = 250;
				break;
		}
		if (value == 0)
			value = 0;
		else
			value = parseInt(value);
		if (supply == 'drapes' && value>=5) {
			if (value>=10)
				total = ((value * price) * .9).toFixed(2);
			else
				total = ((value * price) * .95).toFixed(2);
		}
		else
			total = (value * price).toFixed(2);
	}
	
	function get_ie_ver() {
	  var rv = -1;
	  if (navigator.appName == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		  rv = parseFloat( RegExp.$1 );
	  }
	  return rv;
	}
	
	
	// home
	if ($('#img-home').length) {
		if (get_ie_ver() != 0) {
			img = 1;
			src = '';
			
			var href = new Array();
			href[1] = '/mini-c-arms';
			href[2] = '/mini-c-arms/fd';
			href[3] = '/mini-c-arms/hd';
			href[4] = '/mini-c-arms/uc';
			
			function fade_in() {
				$('#img-home').attr('src', src);
				$('#anchor').attr('href', href[img]);
				$('#img-home').animate({opacity:1}, 2000, function(){
					img_preload();
				});
			}
			
			function fade_out() {
				$('#img-home').delay(6000).animate({opacity:0}, 2000, function (){
					fade_in();
				});
			}
			
			function img_preload() {
				preload = new Image();
				preload.onLoad = fade_out();
				img++;
				if (img > 4)
					img = 1;
				src = '/wordpress/media/orthoscan-home-alt0' + img + '.jpg';
				$(preload).attr('src', src);
			}
			
			img_preload();
		}
	}
	
	//fd summary
	if ($('.fd-common').length) {
		$('.fd-common p').css('display','none');
		$('.fd-common').css('margin-top','0');
		$('.fd-common h3').addClass('h3-no-line pointer');
		$('.fd-common h3').prepend('<div class="toggle">+</div>');
		$('.toggle').css('float','right');
		
		$('.fd-common h3').toggle(function() {
			$(this).addClass('h3-line');
			$(' + p', this).slideDown();
			$(' > div', this).html('-');
		}, function() {
			$(this).removeClass('h3-line');
			$(' + p', this).slideUp();
			$(' > div', this).html('+');
		});
	}
	
	
	// clinical images
	if ($('#clinical-gallery').length) {
		imgMain = document.createElement('img');
		if ($('h1').html() == 'OrthoScan FD')
			$(imgMain).attr('src', '/wordpress/media/clinical-fd01.jpg');
		else
			$(imgMain).attr('src', '/wordpress/media/clinical01.jpg');

		direct = document.createElement('p');
		direct.innerHTML = 'Hover over a thumbnail for a larger image.';

		$(imgMain).insertBefore($("#clinical-gallery"));
		$(direct).insertBefore($(".download-clinical"));
		
		$('#clinical-gallery br').detach();

		$.each($("#clinical-gallery").children(), function(i) {
			if (this.nodeType == 1) {
				$(this).css({
					'height':'120px',
					'width':'120px',
					'position':'static',
					'padding-top':'0',
					'padding-right':'12px',
					'padding-bottom':'0',
					'padding-left':'0'
				});

				$(this).mouseover(function(){
					$(imgMain).stop().animate();
					ci_stop = true;
					$(imgMain).animate({opacity:1}, 1500);
					$(imgMain).attr('src', $(this).attr('src'));
				});
				$(this).click(function(){
					$(imgMain).stop().animate();
					ci_stop = true;
					$(imgMain).animate({opacity:1}, 1500);
					$(imgMain).attr('src', $(this).attr('src'));
				});
			}
		});
		
		$(imgMain).css('padding-left', '90px');
		$("#clinical-gallery").css({'padding-left':'10px', 'margin-top':'42px'});
		$(direct).css('margin','21px 0 0 10px');
		
		i = 1;
		function ci_fade_out() {
			if (!ci_stop) {
				$(imgMain).delay(6000).animate({opacity:0}, 1500, function() {
					if (!ci_stop) {
						i++;
						if (i > 7)
							i = 1;
						if ($('h1').html() == 'OrthoScan FD') {
							path = '/wordpress/media/clinical-fd0' + i + '.jpg';
						}
						else 
							path = '/wordpress/media/clinical0' + i + '.jpg';
						$(this).attr('src', path);
						ci_fade_in();
					}
				});
			}
		}
		
		function ci_fade_in() {
			if (!ci_stop) {
				$(imgMain).animate({opacity:1}, 1500, function() {
					ci_fade_out();
				});
			}
		}
		
		ci_stop = false;
		ci_fade_out();
	}
	
	
	// financial analysis
	if ($('#financial-table').length) {
		
		i = 0;
		
		function calculate_values() {
			function add_column(scope) {
				column_total = 0;
				$('.table-' + scope).each( function() {
						column_total += parseInt($(this).text().slice(1));
				});
				$('.table-' + scope + '-total').text('$' + column_total);
				
				column_difference = column_total - parseInt($('.table-' + scope + '-payment').text().slice(1));
				$('.table-' + scope + '-difference').text('$' + column_difference);
			}
			
			add_column('month');
			add_column('annual');
		}
		
		//create inputs and assign blur function
		$('.table-input').each( function create_inputs() {
			$(this).html('<input type="text" value="0" id="test-el' + i + '" />');
			
			$(this).next().text('$' + $('#test-el' + i).attr('value') * $(this).prev().text().slice(1));
			$(this).next().next().text('$' + $('#test-el' + i).attr('value') * $(this).prev().text().slice(1) * 12);
			
			$('#test-el' + i).focus(function() {
				original_val = $(this).val();
			});
			
			$('#test-el' + i).blur(function() {
				new_val = $(this).val();
				if (isNaN(new_val)) {
					new_val = original_val;
					$(this).val(new_val);
				}
				amount_string = $(this).parent().prev().text();
				amount = amount_string.slice(1);
				$(this).parent().next().text('$' + (amount * new_val));
				$(this).parent().next().next().text('$' + amount * new_val * 12);
				
				calculate_values();
			});
			i++;
		});
		
		//create dynamic finance amount with blur
		finance_amount = $('.table-finance').text();
		$('.table-finance').html('<input type="text" value="' + finance_amount + '" id="finance_amount" />');
		$('.table-finance').attr('class', 'table-input');
		$('#finance_amount').focus(function(){
			original_val = $(this).val().substr(1);
			$(this).val(original_val);
	    });
		$('#finance_amount').blur(function(){
			new_val = $(this).val();
			if (isNaN(new_val)) {
				new_val = original_val;
				$(this).val(new_val);
			}
			$(this).val('$' + new_val);
			i = (.07/12);
			p = parseFloat(new_val);
			n = 60;
			monthly_amount = parseInt((p*i*Math.pow((1+i),n)/(Math.pow((1+i),n)-1)));
			$('.table-month-payment').html('$'+monthly_amount);
			$('.table-annual-payment').html('$'+monthly_amount*12);
			calculate_values();
	    });
		
		calculate_values();
	}
	
	//supply catalog
	if ($('#supply-catalog').length) {
		var content_array = new Array();
		var insert_content = new String();
		var total = new Number();
		var subtotal = new Number();
			
		function define_content() {
			function get_item(title, supply) {
				value = $('#quantity_'+supply).val();
				if (isNaN(value) || value == '') {
					value = 0;
					$('#quantity_'+supply).val(0);
				}
				calc_total(supply, value);
				insert_content += '<dt>'+title+'</dt>';
				insert_content += '<input type="text" id="disp_qty_'+supply+'" value="'+value+'" />';
				insert_content += '<dd id="disp_total_'+supply+'">$'+total+'</dd>';
				subtotal += parseFloat(total);
			}
			
			insert_content = '<h3>Order Summary:</h3>';
			insert_content += '<dl class="supply-order">';
			get_item('Drapes', 'drapes');
			get_item('Small Printer Paper', 'small_paper');
			get_item('Large Printer Paper', 'large_paper');
			get_item('Large Printer Film', 'large_film');
			get_item('Apron', 'apron');
			insert_content += '<dt>&nbsp;</dt>';
			insert_content += '<dd class="line-top">Subtotal</dd>';
			insert_content += '<dd class="line-top" id="disp_subtotal">$'+subtotal.toFixed(2)+'</dd>';
			insert_content += '</dl>';
		}
		
		define_content();
		
		$('.submit').before(insert_content);
		
		$('input').blur(function() {
			supply = $(this).attr('id').slice(9);
			value = parseInt($(this).val());
			if (isNaN(value))
				value = 0;
			calc_total(supply, value);
			$('#quantity_'+supply).val(value);
			$('#disp_qty_'+supply).val(value);
			$('#disp_total_'+supply).text('$'+total);
			subtotal = parseFloat($('#disp_total_drapes').text().slice(1));
			subtotal += parseFloat($('#disp_total_small_paper').text().slice(1));
			subtotal += parseFloat($('#disp_total_large_paper').text().slice(1));
			subtotal += parseFloat($('#disp_total_large_film').text().slice(1));
			subtotal += parseFloat($('#disp_total_apron').text().slice(1));
			$('#disp_subtotal').text('$'+subtotal.toFixed(2));
			if ($('#disp_subtotal').text().slice(1) == 0.00) {
				$('.submit').attr('disabled', 'true');
				$('.submit').after('<div class="validation-inline">Order is empty</div>');
			}
			else {
				$('.submit').removeAttr('disabled');
				$('.validation-inline').detach();
			}
	    });
		
		// disable submit until quantity != 0
		$('.submit').mousedown(function() {
			if ($('#disp_subtotal').text().slice(1) == 0.00) {
				$('.submit').attr('disabled', 'true');
				$('.submit').after('<div class="validation-inline">Order is empty</div>');
			}
		});
	}
	
	
	// shipping info
	if ($('#shipping_info').length) {
		$('#use_same_billing_information').attr('checked','true');
		$('#shipping_info').hide();
		
		$('#use_same_billing_information').change(function() {
			if ($(this).attr('checked') == false) {
				$('#shipping_info input').attr('value', '');
				$('#shipping_info').show();
			}
			else
				$('#shipping_info').hide();
		});
		
		function insert_inputs(supply) {
			value = $('#disp_qty_'+supply).text();
			$('#disp_qty_'+supply).replaceWith('<input type="text" id="disp_qty_'+supply+'" value="'+value+'" />');
		}
		
		insert_inputs('drapes');
		insert_inputs('small_paper');
		insert_inputs('large_paper');
		insert_inputs('large_film');
		insert_inputs('apron');
		
		$('.supply-order input').blur(function() {
			supply = $(this).attr('id').slice(9);
			value = parseInt($(this).val());
			if (isNaN(value)) {
				value = 0;
				$(this).val(0);
			}
			calc_total(supply, value);
			$(this).val(value);
			$('#disp_total_'+supply).text('$'+total);
			subtotal = parseFloat($('#disp_total_drapes').text().slice(1));
			subtotal += parseFloat($('#disp_total_small_paper').text().slice(1));
			subtotal += parseFloat($('#disp_total_large_paper').text().slice(1));
			subtotal += parseFloat($('#disp_total_large_film').text().slice(1));
			subtotal += parseFloat($('#disp_total_apron').text().slice(1));
			$('#disp_subtotal').text('$'+subtotal.toFixed(2));
			$('#quantity_'+supply).val(value);
			$('#total_'+supply).val(total);
			$('#change_quantity_'+supply).val(value);
		});
	}
	
	
	// events
	if ($('.events').length) {
		$.each($('.events'), function() {
			$('h3').after('<a class="to-top">Back to top</a>');
			$('.to-top').css({'float':'right','marginTop':'-42px', 'font-size':'9px', 'text-transform':'uppercase'});
			$('.to-top').hover(function() {
				$(this).css({'cursor':'pointer','color':'#777786'});
			}, function() {
				$(this).css({'cursor':'auto','color':'#d4d9d7'});
			});
			$('.to-top').click(function() {
				window.scrollTo(0,0);
			});
		});
	}
	
	
	// contact
	if ($('#contact').length) {
		$('#referral_other_input').hide();
		$('#field_other_input').hide();
		
		$('.radio-check').change(function() {
			if ($('#referral_other').attr('checked') == true) {
				$('#referral_other_input').show();
			}
			else
				$('#referral_other_input').hide();
				
			if ($('#field_other').attr('checked') == true) {
				$('#field_other_input').show();
			}
			else
				$('#field_other_input').hide();
		});
	}
	
	
	// email confirmation
	if ($('#confirmation\\:toggle').length) {
		$('#confirmation\\:email').prev().hide(); // double slash escapes colon for jquery
		$('#confirmation\\:email').hide();
		
		$('#confirmation\\:toggle').change(function() {
			if ($(this).attr('checked') == false) {
				$('#confirmation\\:email').prev().hide();
				$('#confirmation\\:email').hide();
				if ($('.validation' !== null))
					$('.validation').hide();
			}
			else {
				$('#confirmation\\:email').prev().show();
				$('#confirmation\\:email').show();
				if ($('.validation' !== null))
					$('.validation').show();
			}
	    });
		
		$('#confirmation\\:email').blur(function() {
			if ($(this).val() == '')
				validation = 0;
			else if ($(this).val().search('\\.') == -1 && $('.validation') !== null)
				validation = 1;
			else if ($(this).val().search('@') == -1 && $('.validation') !== null)
				validation = 1;
			else
				validation = 0;
			
			if (validation == 1)
				$(this).after('<div class="validation-inline">Invalid email address</div>');
			else if ($('.validation' !== null))
				$('.validation').detach();
	    });
	}			
	
	
	// auto select on input focus
	$('input').mouseup(function(e){
		e.preventDefault();
	});
	$('input').focus(function() {
		$(this).select();
	});


	// search form
	$('.search').attr('value', 'Search OrthoScan...');
	$('.search').focus(function() {
		if ($(this).attr('value') == 'Search OrthoScan...')
			$(this).attr('value', '');
	});
	$('.search').blur(function() {
		if ($(this).attr('value') == '')
			$(this).attr('value', 'Search OrthoScan...');
	});
	
	// resource management system
	if ($('#resources').length) {
		// set ajax path
		t_path = $('#logo').attr('src');
		t_path = t_path.substring(0, t_path.search('images'));
		t_path = t_path + 'ajax/';
		
		// name validation
		function name_validation(selector, name) {
			original_val = $(selector).val();
			
			$(selector).blur(function() {
				val = $(this).val();
				if (val != original_val) {
					$(' + .validation-inline', this).detach();			
					$.post(t_path + 'validation.php', {field:name,value:val},
						function(data) {
							if (data) {
								$(selector).after('<div class="validation-inline">' + data + ' already in use</div>');
							}
						}
					);
				}
				if (val == '') {
					$(' + .validation-inline', this).detach();	
					$(selector).after('<div class="validation-inline">Name not entered</div>');
				}
			});
		}
		
		// file name validation
		if ($('#file-name').length)
			name_validation('#file-name', 'file_name');
		
		// username validation
		if ($('#username').length)
			name_validation('#username', 'username');
		
		// password validation
		if ($('#password').length) {
			$('#password').blur(function() {
				$(' + .validation-inline', this).detach();
				if ($(this).val().length == 0)
					$(this).after('<div class="validation-inline">Password not entered</div>');
				else if ($(this).val().length < 6)
					$(this).after('<div class="validation-inline">Password must be at least 6 characters long</div>');
			});
		}
		
		// group selection
		if ($('#user-type').length) {
			function check_files(group) {
				$.post(t_path + 'validation.php', {field:'user_type',value:group},
					function(data) {
						if (data) {
							$f_array = data.split(',');
							$.each($f_array, function(key, value) {
								selector = 'input[value=' + value + ']';
								$(selector).attr('disabled', 'disabled');
								$(selector).attr('checked', 'checked');
							});
							set_prev = group;
						}
					}
				);
			}
			
			function uncheck_files() {
				$.each($f_array, function(key, value) {
					selector = 'input[value=' + value + ']';
					$(selector).removeAttr('disabled');
					$(selector).removeAttr('checked');
				});
			}
			
			$('#user-type').blur(function() {
				if (typeof(set_prev) != 'undefined')
					uncheck_files();
				
				if ($(this).val() != 'admin' && $(this).val() != 'none')
					check_files($(this).val());
			});
			
			selected_group = $('#user-type option[selected="selected"]').val();
			if (selected_group != 'admin' && selected_group != 'none' && selected_group != null) {
				check_files(selected_group);
			}
		}
		
		
		// event validation
		if ($('.input-date').length) {
			$('#start_month').focus(); // set focus on start month
			
			// get original values for start_day and title
			start_day_orig = $('#start_day').val();
			title_orig = $('#title').val();
			
			// create activator array
			activator = [];
			activator['start_day_act'] = false;
			activator['start_year_act'] = false;
			activator['end_day_act'] = false;
			activator['end_year_act'] = false;
			
			function is_date_activated(selector) {
				if (!start_day_orig) { // if create form
					function activate(field) {
						if (!activator[field]) { // field has never been activated
							activator[field] = true;
						}
					}
				
					function is_activated(field, partner){
						if (activator[field] && activator[partner]) { // if both fields have been activated
							return true;
						}
						else {
							return false;
						}
					}
					
					// switch to match selector to activator
					switch (selector) {
						case 'start_day':
							field = 'start_day_act';
							partner = 'start_year_act';
							activate(field);
							break;
						case 'start_year':
							field = 'start_year_act';
							partner = 'start_day_act';
							activate(field);
							break;
						case 'end_day':
							field = 'end_day_act';
							partner = 'end_year_act';
							activate(field);
							break;
						case 'end_year':
							field = 'end_year_act';
							partner = 'end_day_act';
							activate(field);
							break;
						case 'start_month':
							field = 'start_day_act';
							partner = 'start_year_act';
							break;
						case 'end_month':
							field = 'end_day_act';
							partner = 'end_year_act';
							break;
					}
					
					return is_activated(field, partner);
				}
				else { // if edit form
					return true;
				}
			}
			
			function is_duplicate_event() {
				if ($('#start_day').val() && $('#start_year').val() && $('#end_day').val() && $('#end_year').val()) { // if all date fields exist
					function pad(num, type) { // pad days and years
						str = $(num).val().toString();
						if (type == 'year') {
							if (str.length < 4) 
								str = '20' + str;
						}
						else {
							if (str.length < 2) 
								str = '0' + str;
						}
						return str;
					}
					
					// concatenate dates
					start_date = pad('#start_year', 'year') + pad('#start_month', 'date') + pad('#start_day', 'date');
					end_date = pad('#end_year', 'year') + pad('#end_month', 'date') + pad('#end_day', 'date');
					
					$('#end_year + .validation-inline').detach(); // detach error from end_year
									
					if (start_date > end_date) { // if start_date is after end_date
						$('#end_year').after('<div class="validation-inline" id="end_before">End date must be on or after start date.</div>');
					}
					else {
						if ($('#title').val()) { // if title exists
							$('#title + .validation-inline').detach(); // detach error from title
							if ($('#title').val() != title_orig) {// if change has been made to title
								// send start_date, end_date, title to validation.php
								$.post(t_path + 'validation.php', {field:'event', s_date:start_date, e_date:end_date, e_title:$('#title').val()},
									function(data) {
										if (data) {
											$('#title').after('<div class="validation-inline">' + data + '</div>');
										}
									}
								);
							}
						}
					}
				}
			}
			
			$('#start_month, #start_day, #start_year').blur(function() { // start date fields
				$('#start_year + .validation-inline').detach();
				$('#end_before').detach();
				if (is_date_activated($(this).attr('id'))) {
					if (!$('#start_day').val() || !$('#start_year').val()) { // if any date fields are blank
						$('#start_year').after('<div class="validation-inline">Start date cannot be blank.</div>');
					}
					else {
						is_duplicate_event();
					}
				}
			});
			
			$('#end_month, #end_day, #end_year').blur(function() { // end date fields
				$('#end_year + .validation-inline').detach();
				if (is_date_activated($(this).attr('id'))) {
					if (!$('#end_day').val() || !$('#end_year').val()) { // if any date fields are blank
						$('#end_year').after('<div class="validation-inline">End date cannot be blank.</div>');
					}
					else {
						is_duplicate_event();
					}
				}
			});
			
			$('#title').blur(function() { // title field
				$('#title + .validation-inline').detach();
				if (!$('#title').val()) { // if title is blank
					$('#title').after('<div class="validation-inline">Title cannot be blank.</div>');
				}
				else {
					is_duplicate_event();
				}
			});
			
			$('#location1').blur(function() { // location1 field
				$('#location1 + .validation-inline').detach();
				if (!$('#location1').val()) { // if title is blank
					$('#location1').after('<div class="validation-inline">Event must contain at least one location.</div>');
				}
			});
		}
		
		
		// month view	
		if ($('#header_date').length) {
			function create_options() {
				month_list = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
				options = '<select name="nav-month" id="nav-month">';
				for (i=0; i<12; i++) {
					if (i < 9)
						val = '0' + (i+1);
					else
						val = i+1;
						
					if ($('#header_month').html() == month_list[i])
						selected = ' selected="selected"';
					else
						selected = '';
						
					options += '<option value="' + val + '"' + selected + '>' + month_list[i] + '</option>';
				}
				options += '</select>';
				return options;
			}
			
			header_form = '<form action="resources?events_nav=input" method="post" id="nav_form">';
			header_form += create_options();
			header_form += '<input type="text" value="' + $('#header_year').html() + '" name="nav-year" id="nav-year" />';
			header_form += '<input type="submit" value="Go" class="submit float-left" id="nav-submit" />';

			if (get_ie_ver() == -1) {
				$('#header_date').bind('click.event', function(){
					$(this).html(header_form);
					$(this).unbind('click.event');
				});
			}
		}
		
		// download tracking
		$('#files_table a').click(function(){
			file_name = $(this).html();
			$.post(t_path + 'tracking.php', {file: file_name});
		})
	}
}