(function() {
	// Private functions and variables
	var hart_div;

	//{{{ DOM work
	function hv_all(list, fn) { //{{{
		var idx;
		var all = true;

		for (idx in list) {
			if (!fn(list[idx])) {
				all = false;
			}
		}

		return all;
	} //}}}

	function hv_check_dom_item(name) { //{{{
		if (!document[name]) {
			// If we don't have the DOM methods, we can't use them to show the error.
			document.open();
			document.write("<strong>Error:</strong> Your browser doesn't support "+name+".<br />");
			document.close();
			return false;
		} else {
			return true;
		}
	} //}}}

	function hv_check_dom() { //{{{
		var items = [
			'getElementById',
			'createElement',
			'insertBefore',
			'appendChild',
			'getElementsByTagName'
		];

		return hv_all(items, hv_check_dom_item);
	} //}}}

	function hv_find_by_class(root, tag_name, class_name) { //{{{
		var i, end;
		var tags = root.getElementsByTagName(tag_name);
		var re = new RegExp('\\b'+class_name+'\\b');

		// Safari bugs out here when using for-in syntax.
		end = tags.length
		for (i = 0; i < end; ++i) {
			if (tags[i].className && tags[i].className.match(re)) {
				return tags[i];
			}
		}
	} //}}}

	//}}} end DOM
	//{{{ CSS wrangling
	var head;

	function css_find_head() { //{{{
		var heads = document.getElementsByTagName('head');
		if (heads.length >= 1) {
			return heads[0];
		}

		// No HEAD section? Build me a new one!
		var head_elt = document.createElement('head');

		// make sure it has a child to insert before
		var head_text = document.createTextNode('');
		head_elt.appendChild(head_text);

		// add head to the document
		document.insertBefore(head_elt, document.firstChild);

		return head_elt;
	} //}}}

	function css_new_link(sheet) { //{{{
		var elt = document.createElement('link');
		elt.setAttribute('rel',  'stylesheet');
		elt.setAttribute('type', 'text/css');
		elt.setAttribute('href', sheet);

		return elt;
	} //}}}

	function css_add(sheet, is_override) { //{{{
		var link = css_new_link(sheet);

		if (!head) {
			head = css_find_head();
		}

		if (is_override) {
			head.appendChild(link); // add last to take precedence over designer
		} else {
			head.insertBefore(link, head.firstChild); // add first
		}
	} //}}}

	//}}} end CSS
	//{{{ Selection handling - see docs/load-template.txt!!
	var clear_iv = null;
	var clear_sel;
	var deny_r; // Range which we deny selecting from.

	function hv_should_clear(s_e, e_s) { //{{{
		// if they are equal, or either one is zero, then the selection is allowed (should not clear)
		return !(s_e === e_s || s_e === 0 || e_s === 0);
	} //}}}

	function hv_should_clear_range(sel_r) { //{{{
		var s_e = deny_r.compareBoundaryPoints(Range.END_TO_START, sel_r);
		var e_s = deny_r.compareBoundaryPoints(Range.START_TO_END, sel_r);
		return hv_should_clear(s_e, e_s);
	} //}}}


	function hv_clearsel_std() { //{{{
		var s = window.getSelection();

		if (s.rangeCount === 0 || !s.toString()) { // nothing selected
			return;
		}

		var i;
		var count = s.rangeCount;

		for (i = 0; i < count; ++i) {
			if (hv_should_clear_range(s.getRangeAt(i))) {
				s.removeAllRanges();
				return;
			}
		}
	} //}}}

	function hv_clearsel_std_safari() { //{{{
		var s = window.getSelection();

		if (s.rangeCount === 0 || !s.toString()) { // nothing selected
			return;
		}

		var sel_r = document.createRange();
		sel_r.setStart(s.anchorNode, s.anchorOffset);
		sel_r.setEnd(s.focusNode, s.focusOffset);

		if (hv_should_clear_range(sel_r)) {
			s.removeAllRanges();
		}
	} //}}}

	function hv_clearsel_ie() { //{{{
		var s = document.selection;

		// IE docs are inconsistent with capitalization
		if (s.type !== "Text" && s.type !== "text") {
			return;
		}

		var sel_r = s.createRange();

		if (hv_should_clear(deny_r.compareEndPoints("StartToEnd", sel_r),
				                deny_r.compareEndPoints("EndToStart", sel_r)))
		{
			s.empty();
		}
	} //}}}

	function hv_clearsel_null() { //{{{
		clearInterval(clear_iv);
		clear_iv = null;
	} //}}}


	function hv_sel_setup_std() { //{{{
		var gs = {};
		var s;
		var create = document.createRange;

		if (!create) { return hv_clearsel_null; } // improbable

		s = window.getSelection();
		gs.rm_all = s.removeAllRanges;
		gs.get_at = s.getRangeAt;

		deny_r = document.createRange();
		deny_r.selectNode(hart_div);

		if (gs.get_at)      { return hv_clearsel_std; }
		else if (gs.rm_all) { return hv_clearsel_std_safari; }
		else                { return hv_clearsel_null; } // improbable
	} //}}}

	function hv_sel_setup_ie() { //{{{

		deny_r = document.body.createTextRange();
		deny_r.moveToElementText(hart_div);

		return hv_clearsel_ie;
	} //}}}

	function hv_sel_find() { //{{{
		// select a clear_sel function based on what will work in the browser;
		// this means we're not doing a browser-detect every 33 ms
		var get_sel = window.getSelection;
		var ie_sel  = (document.selection && document.selection.empty);

		if (get_sel)     { return hv_sel_setup_std(); }
		else if (ie_sel) { return hv_sel_setup_ie(); }
		else             { return hv_clearsel_null; }
	} //}}}


	function hv_sel_setup() { //{{{
		if (clear_iv !== null) {
			clearInterval(clear_iv);
		}

		clear_sel = hv_sel_find();
		clear_iv  = setInterval(clear_sel, 33);
	} //}}}

	//}}} end selection

	//{{{ Bootup; all template substitutions MUST be isolated to this section to ease maintenance.
	var booted = {};
	function hv_boot_set_div(div_id) { //{{{
		// Protect against double-boot
		if (booted.set_div === true) { return; }
		booted.set_div = true;

		if (!document.getElementById) { return false; } // improbable

		if (!div_id) { div_id = 'hart_viewer'; }
		hart_div = document.getElementById(div_id);
		return true;
	} //}}}

	function hv_boot_embed() { //{{{
		// Protect against double-boot
		if (booted.embed === true) { return; }
		booted.embed = true;

		// Boot sequence: check browser support, then do work.
		if (!hv_check_dom()) { return; }
		if (booted.set_div !== true) { hv_boot_set_div(); }

		css_add('http://hartonweb.com/System/css/default.css',  false);
		css_add('http://hartonweb.com/System/override.php?id=6', true);

		hart_div.innerHTML = '<h2 class=\"ha_product\">Jasmine Absolute</h2>\n<div class=\"ha_print_mark\">This information is provided by OnlyTheBestHerbs.com</div>\n<div class=\"ha_content\"><div class=\"ha_image\"><img src=\"http://hartonweb.com/Images/ProdPics/Jasmine%20Absolute.jpg\"> \n      &nbsp;</div>\n<div class=\"ha_body\">Jasmine \n        Absolute is one of the most expensive essential oils in the world. A pound \n        of jasmine oil can cost as much as $3,000 to $4,000, largely because of \n        the complex, painstaking and time-consuming process by which the oil is \n        produced. It takes approximately 8 million jasmine blossoms to produce \n        each kilogram (2.20 pounds) of oil, and these white star-shaped blooms \n        must be gathered in the early hours before sunrise when jasmine\'s \n        extraordinarily fragrant essence is at its peak.<span class=\"bodyref\">1-3</span>\n        <p>Jasmine \n          oil\'s mildly euphoric scent has an intensely rich, warm, sweet-floral \n          aroma with a pronounced sensual, musky note. This exquisite fragrance \n          is often described as warmly reassuring and profoundly inspirational, \n          having the ability to bolster one\'s confidence and optimism. Many \n          of jasmine\'s beneficial effects on psychosomatic ills (physical \n          complaints having a more immediate psychological origin) stems from \n          its antidepressant and euphoric characteristics. Jasmine is regarded \n          as a powerful antidepressant that enhances feelings of elation and euphoria, \n          and helps relieve apathy, indifference and depression. In fact, Japanese \n          studies have shown that jasmine even increases alertness by stimulating \n          beta brain-wave activity. However, jasmine also demonstrates sedative \n          properties, which make it useful for relaxing anxiety and calming fear. \n          Thus, jasmine is employed as a psychotherapeutic remedy for a wide range \n          of emotional and stress-related problems, including anger, anxiety, \n          apathy, depression, grief, heartbreak, hypochondria, lack of confidence, \n          lethargy, listlessness, nervous exhaustion, nervous tension, PMS, and \n          panic, as well as simple fear or complex paranoia.<span class=\"bodyref\">1-8</span>\n        <p>In \n          addition, jasmine oil is a reputed aphrodisiac for hypoactive libido \n          (underactive sex drive) and problems of impotence or frigidity. In fact, \n          the combination of jasmine\'s sensually romantic and sedative qualities \n          make it an ideal remedy where there is anxiety surrounding sexuality. \n          Jasmine\'s aphrodisiac effect can also be enhanced by combining \n          it with rose, ylang ylang or clary sage essential oils.<span class=\"bodyref\">1,3,6,7</span>\n        <p>Like \n          rose oil, jasmine oil has an affinity for the female reproductive system. \n          Jasmine is a stabilizing uterine tonic and nervine for painful menstruation, \n          and especially for the uterine pains accompanying childbirth&mdash;jasmine \n          oil provides natural analgesic (pain-relieving), antispasmodic (muscle-relaxing), \n          and anti-inflammatory properties. Plus, jasmine has been shown to help \n          reduce stress for the mother during labor. Following childbirth, jasmine \n          is used to relieve postnatal depression (blend with bergamot or clary \n          sage for added benefit), exhaustion and hormonal changes. During menopause, \n          jasmine is recommended to inspire a woman\'s confidence in her \n          femininity and sensuality and to promote feelings of optimism, warmth \n          and well-being.<span class=\"bodyref\">1,3,5-7,9</span>\n        <p>Used \n          topically, jasmine oil is a superior facial skin oil for both its anti-inflammatory \n          and cell-rejuvenating properties. Jasmine is especially suited for dry, \n          irritated or sensitive skin. Jasmine is can also be used to soothe muscle \n          tension and relieve muscular aches, pains, spasms and sprains.<span class=\"bodyref\">1,3,6-8</span>\n        <p>Furthermore, \n          jasmine oil demonstrates antiseptic, antifungal and antiviral activity. \n          Jasmine also acts as an expectorant. Although jasmine is recognized \n          as a good remedy for bronchial and respiratory ailments (catarrh, chest \n          infections, cough, hoarseness, laryngitis, sore throat, etc.), its high \n          cost may make its use somewhat prohibitive, especially since there are \n          other less expensive oils that are just as, if not, more effective for \n          such purposes.<span class=\"bodyref\">1,3,5-7</span>\n        <p>Jasmine \n          oil\'s many benefits are typically derived through inhalation or \n          topical application via massage or relaxational baths, since the oil \n          is generally too thick for use in a diffuser. Plus, jasmine blends well \n          with other essential oils and is often included in various oil blends.<span class=\"bodyref\">1,5</span>\n        <p>Jasmine \n          oil is non-irritant, non-toxic, and generally non-sensitizing; however, \n          an allergic reaction has been known to occur in some sensitive individuals. \n          Thus, individuals prone to allergies or having highly sensitive skin \n          may need to avoid use. In addition, jasmine oil should not be used during \n          early pregnancy. General recommendations suggest using jasmine oil in \n          moderation, both in terms of frequency and quantity.<span class=\"bodyref\">3,5,6</span></div>\n<div class=\"ha_print_mark\">This information is provided by OnlyTheBestHerbs.com</div>\n<div class=\"ha_references\"><div class=\"reftitle\">References:</div> \n        <p class=\"ref\"><span class=\"refnum\">1</span>Damian, \n        P. &amp; Damian, K. <span class=\"refsource\">Aromatherapy: Scent and Psyche</span>. Rochester, \n        VT: Healing Arts Press, 1995.</p><p class=\"ref\">\n        <span class=\"refnum\">2</span>Schiller, \n        C. &amp; Schiller, D. <span class=\"refsource\">Aromatherapy Oils: A Complete Guide</span>. NY, \n        NY: Sterling Publishing, 1996.</p><p class=\"ref\">\n        <span class=\"refnum\">3</span>Wildwood, \n        C. <span class=\"refsource\">The Encyclopedia of Aromatherapy</span>. Rochester, VT: Healing Arts \n        Press, 1996.</p><p class=\"ref\">\n        <span class=\"refnum\">4</span>\"The \n        Nose Knows: Aromatherapy For Romance.\" <span class=\"refsource\">Delicious-Online</span>; \n        February, 2002.</p><p class=\"ref\">\n        <span class=\"refnum\">5</span>Selby, \n        A. <span class=\"refsource\">Aromatherapy</span>. NY, NY: Macmillan, 1996.</p><p class=\"ref\">\n        <span class=\"refnum\">6</span>McIntyre, \n        A. <span class=\"refsource\">Flower Power</span>. NY, N: Henry Holt and Company, 1996.</p><p class=\"ref\">\n        <span class=\"refnum\">7</span>Lawless, \n        J. <span class=\"refsource\">The Encyclopaedia of Essential Oils</span>. Rockport, MA: Element Books, \n        1992.</p><p class=\"ref\">\n        <span class=\"refnum\">8</span>Chevallier, \n        A. <span class=\"refsource\">The Encyclopedia of Medicinal Plants</span>. NY, NY: Dorling Kindersley, \n        1996.</p><p class=\"ref\">\n        <span class=\"refnum\">9</span>Buckle \n        RGN, J. <span class=\"refsource\">Clinical Aromatherapy in Nursing</span>. San Diego, CA: Singular \n        Publishing Group, 1997 \n</p></div>\n</div><div class=\"ha_copyright\">Copyright 1997-2010 &nbsp;&nbsp;Herb Allure, Inc.</div>\n';
	} //}}}

	function hv_boot_selection() { //{{{
		// Protect against double-boot
		if (booted.selection === true) { return; }
		booted.selection = true;

		if (booted.set_div !== true) { hv_boot_set_div(); }

		// Give browser time to render before trying to find the text inside hart_div.
		setTimeout(hv_sel_setup, 33);
	} //}}}

	function hv_boot_watermark() { //{{{
		// Protect against double-boot
		if (booted.watermark === true) { return; }
		booted.watermark = true;

		var text = '';
		var i, count=50, wm=['<p>'];

		for (i = 0; i < count; ++i) {
			wm.push(text);
		}
		wm.push('</p>');

		var ha_content_div = hv_find_by_class(hart_div, 'div', 'ha_content');

		var wm_div = document.createElement('div');
		wm_div.className = 'ha_h2o';

		wm_div.innerHTML = wm.join("\n</p><p>");

		ha_content_div.appendChild(wm_div);
	} //}}}

	function hv_boot_display() { //{{{
		if (booted.display === true) { return; }
		booted.display = true;

		hart_div.style.display = '';
	} //}}}

	// Run setup code appropriate to the template.
	hv_boot_embed();
hv_boot_watermark();
hv_boot_selection();
	//}}}
})();

