<script type="text/javascript">
var YachtListing;
(function () {
	"use strict";
	var isSafari = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor),

	loadCssHack = function(url, callback){
		var link = document.createElement('link');
		link.type = 'text/css';
		link.rel = 'stylesheet';
		link.href = url;

		document.getElementsByTagName('head')[0].appendChild(link);

		var img = document.createElement('img');
		img.onerror = function(){
			if (callback && typeof callback === "function") {
				callback();
			}
		};
		img.src = url;
	},
	loadRemote = function(url, type, callback) {
		if (type === "css" && isSafari) {
			loadCssHack(url, callback);
			return;
		}
		var _element, _type, _attr, scr, s, element;
		
		switch (type) {
		case 'css':
			_element = "link";
			_type = "text/css";
			_attr = "href";
			break;
		case 'js':
			_element = "script";
			_type = "text/javascript";
			_attr = "src";
			break;
		}
		
		scr = document.getElementsByTagName(_element);
		s = scr[scr.length - 1];
		element = document.createElement(_element);
		element.type = _type;
		if (type == "css") {
			element.rel = "stylesheet";
		}
		if (element.readyState) {
			element.onreadystatechange = function () {
				if (element.readyState == "loaded" || element.readyState == "complete") {
					element.onreadystatechange = null;
					if (callback && typeof callback === "function") {
						callback();
					}
				}
			};
		} else {
			element.onload = function () {
				if (callback && typeof callback === "function") {
					callback();
				}
			};
		}
		element[_attr] = url;
		s.parentNode.insertBefore(element, s.nextSibling);
	},
	loadScript = function (url, callback) {
		loadRemote(url, "js", callback);
	},
	loadCss = function (url, callback) {
		loadRemote(url, "css", callback);
	},
	options = {
		server: "<?php echo PJ_INSTALL_URL; ?>",
		folder: "<?php echo PJ_INSTALL_FOLDER; ?>",
		min_year: 1900,
		max_year: <?php echo date('Y'); ?>
	};
	loadScript("<?php echo PJ_INSTALL_URL . PJ_THIRD_PARTY_PATH; ?>jquery/jquery-1.11.3.min.js", function () {
		loadScript("<?php echo PJ_INSTALL_URL . PJ_THIRD_PARTY_PATH; ?>jquery_ui/js/jquery-ui-1.9.2.custom.js", function () {
			loadScript("<?php echo PJ_INSTALL_URL . PJ_THIRD_PARTY_PATH; ?>validate/jquery.validate.1.14.0.min.js", function () {
				loadScript("<?php echo PJ_INSTALL_URL . PJ_THIRD_PARTY_PATH; ?>bootstrap/js/bootstrap.min.js", function () {
					loadScript("<?php echo PJ_INSTALL_URL . PJ_THIRD_PARTY_PATH; ?>flexslider/jquery.flexslider-min.js", function () {
						loadScript("<?php echo PJ_INSTALL_URL . PJ_THIRD_PARTY_PATH; ?>lytebox/lytebox.js", function () {
							loadScript("<?php echo PJ_INSTALL_URL . PJ_TEMPLATE_PATH . basename(dirname(dirname(__FILE__))); ?>/js/website.js", function () {
								YachtListing = new YachtListing(options);
							});
						});
					});
				});
			});
		});
	});
})();
</script>