
// TinyMCE 3.2.2.3 http://tinymce.moxiecode.com/
var Util_Platform = {
	get_baseurl : function() {
		var t = this, lo = window.location;
		t._init();
		
		t.documentBaseURL = lo.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
		if (!/[\/\\]$/.test(t.documentBaseURL))
			t.documentBaseURL += '/';
		
		t.baseURL = new Util_URI(t.documentBaseURL).toAbsolute(t.baseURL);
		return t.baseURL;
	},
	
	_init : function() {
		var t = this, d = document, i, nl, n, base, p, v;
		
		// Get suffix and base
		t.suffix = '';

		// If base element found, add that infront of baseURL
		nl = d.getElementsByTagName('base');
		for (i=0; i<nl.length; i++) {
			if (v = nl[i].href) {
				// Host only value like http://site.com or http://site.com:8008
				if (/^https?:\/\/[^\/]+$/.test(v))
					v += '/';

				base = v ? v.match(/.*\//)[0] : ''; // Get only directory
			}
		}

		function getBase(n) {
			if (n.src && /platform.js/.test(n.src)) {
				
				if ((p = n.src.indexOf('?')) != -1)
					t.query = n.src.substring(p + 1);

				t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));

				// If path to script is relative and a base href was found add that one infront
				if (base && t.baseURL.indexOf('://') == -1)
					t.baseURL = base + t.baseURL;

				return t.baseURL;
			}

			return null;
		};

		// Check document
		nl = d.getElementsByTagName('script');
		for (i=0; i<nl.length; i++) {
			if (getBase(nl[i]))
				return;
		}

		// Check head
		n = d.getElementsByTagName('head')[0];
		if (n) {
			nl = n.getElementsByTagName('script');
			for (i=0; i<nl.length; i++) {
				if (getBase(nl[i]))
					return;
			}
		}
		return;
	}
}

var Util_Each = function(o, cb, s) {
	var n, l;

	if (!o)
		return 0;

	s = s || o;

	if (typeof(o.length) != 'undefined') {
		// Indexed arrays, needed for Safari
		for (n=0, l = o.length; n<l; n++) {
			if (cb.call(s, o[n], n, o) === false)
				return 0;
		}
	} else {
		// Hashtables
		for (n in o) {
			if (o.hasOwnProperty(n)) {
				if (cb.call(s, o[n], n, o) === false)
					return 0;
			}
		}
	}

	return 1;
}

var Util_URI = function(u, s) {
	var t = this, o, a, b;

	// Default settings
	s = t.settings = s || {};

	// Strange app protocol or local anchor
	if (/^(mailto|tel|news|javascript|about):/i.test(u) || /^\s*#/.test(u)) {
		t.source = u;
		return;
	}

	// Absolute path with no host, fake host and protocol
	if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
		u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;

	// Relative path
	if (u.indexOf(':/') === -1 && u.indexOf('//') !== 0) {
		u = (s.base_uri.protocol || 'http') + '://mce_host' + t.toAbsPath(s.base_uri.path, u);
	}

	// Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
	u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
	u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
	Util_Each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
		var s = u[i];

		// Zope 3 workaround, they use @@something
		if (s)
			s = s.replace(/\(mce_at\)/g, '@@');

		t[v] = s;
	});

	if (b = s.base_uri) {
		if (!t.protocol)
			t.protocol = b.protocol;

		if (!t.userInfo)
			t.userInfo = b.userInfo;

		if (!t.port && t.host == 'mce_host')
			t.port = b.port;

		if (!t.host || t.host == 'mce_host')
			t.host = b.host;

		t.source = '';
	}

	//t.path = t.path || '/';
}

Util_URI.prototype = {
	toAbsolute : function(u, nh) {
		var u = new Util_URI(u, {base_uri : this});

		return u.getURI(this.host == u.host ? nh : 0);
	},
	
	toAbsPath : function(base, path) {
		var i, nb = 0, o = [], tr;

		// Split paths
		tr = /\/$/.test(path) ? '/' : '';
		base = base.split('/');
		path = path.split('/');

		// Remove empty chunks
		Util_Each(base, function(k) {
			if (k)
				o.push(k);
		});

		base = o;

		// Merge relURLParts chunks
		for (i = path.length - 1, o = []; i >= 0; i--) {
			// Ignore empty or .
			if (path[i].length == 0 || path[i] == ".")
				continue;

			// Is parent
			if (path[i] == '..') {
				nb++;
				continue;
			}

			// Move up
			if (nb > 0) {
				nb--;
				continue;
			}

			o.push(path[i]);
		}

		i = base.length - nb;

		// If /a/b/c or /
		if (i <= 0)
			return '/' + o.reverse().join('/') + tr;

		return '/' + base.slice(0, i).join('/') + '/' + o.reverse().join('/') + tr;
	},
	
	getURI : function(nh) {
		var s, t = this;

		// Rebuild source
		if (!t.source || nh) {
			s = '';

			if (!nh) {
				if (t.protocol)
					s += t.protocol + '://';

				if (t.userInfo)
					s += t.userInfo + '@';

				if (t.host)
					s += t.host;

				if (t.port)
					s += ':' + t.port;
			}

			if (t.path)
				s += t.path;

			if (t.query)
				s += '?' + t.query;

			if (t.anchor)
				s += '#' + t.anchor;

			t.source = s;
		}

		return t.source;
	}
}

var PLATFORM_BASEURL = Util_Platform.get_baseurl();
var SITE_BASEURL = PLATFORM_BASEURL.substring(0, PLATFORM_BASEURL.lastIndexOf('/'));


// PLATFORM
var WIN = navigator.platform == "Win32";
var MAC = navigator.platform == "MacPPC";
var MACIntel = navigator.platform == "MacIntel";
var NN = navigator.appName.charAt(0) == "N";
var IE = navigator.appName.charAt(0) == "M";
var FFX = (navigator.userAgent.lastIndexOf("Firefox") != -1)? true : false;
var SAF = (navigator.appVersion.lastIndexOf("Safari") != -1)? true : false;
var OPR = (navigator.userAgent.lastIndexOf("Opera") != -1)? true : false;

var NN6IE5 = (document.getElementById)?true:false;
var NN4 = (document.layers && !NN6IE5)?true:false;
var IE4 = (document.all && !NN6IE5)?true:false;
var IE5 = (navigator.userAgent.lastIndexOf("MSIE 5") != -1)?true:false;

if(MACIntel && FFX || MAC && FFX){
document.write('<script src="' + SITE_BASEURL + '/temp/header_navi1.js" type="text/javascript"></script>');
document.write('<script src="' + SITE_BASEURL + '/temp/DropDownMenu.js" type="text/javascript"></script>');
document.write('<script src="' + SITE_BASEURL + '/temp/swfobject.js" type="text/javascript"></script>');
document.write('<link href="' + SITE_BASEURL + '/temp/DropDownMenu.css" rel="stylesheet" type="text/css" media="all">');
}
else if(OPR){
document.write('<script src="' + SITE_BASEURL + '/temp/header_navi1.js" type="text/javascript"></script>');
document.write('<script src="' + SITE_BASEURL + '/temp/DropDownMenu.js" type="text/javascript"></script>');
document.write('<link href="' + SITE_BASEURL + '/temp/DropDownMenu.css" rel="stylesheet" type="text/css" media="all">');
document.write('<link href="' + SITE_BASEURL + '/temp/DropDownMenu2.css" rel="stylesheet" type="text/css" media="all">');
}
else if(IE5||NN4){
document.write('<script src="' + SITE_BASEURL + '/temp/header_navi2.js" type="text/javascript"></script>');
document.write('<script src="' + SITE_BASEURL + '/temp/swfobject.js" type="text/javascript"></script>');
document.write('<link href="' + SITE_BASEURL + '/temp/DropDownMenu.css" rel="stylesheet" type="text/css" media="all">');
}
else{
document.write('<script src="' + SITE_BASEURL + '/temp/header_navi1.js" type="text/javascript"></script>');
document.write('<script src="' + SITE_BASEURL + '/temp/DropDownMenu.js" type="text/javascript"></script>');
document.write('<script src="' + SITE_BASEURL + '/temp/swfobject.js" type="text/javascript"></script>');
document.write('<link href="' + SITE_BASEURL + '/temp/DropDownMenu.css" rel="stylesheet" type="text/css" media="all">');
document.write('<link href="' + SITE_BASEURL + '/temp/DropDownMenu2.css" rel="stylesheet" type="text/css" media="all">');
}