var _vortex = {
	
	_is : {
		
		g : function(){
			var svs = 'dev,testing,live,live1,live2'.split(',');
			var dm = window.location.host.toLowerCase();
			var se = dm;
			for( var s = 0; s < svs.length; s++ ) se = se.replace(svs[s]+'.','');
			se = se.split('.');
			if( se.length == 2 ) se.unshift('www');
			var st = {
				website : se[0],
				domain : 'vortexstudio',
				extension : 'com',
				environment : ''
			}
			for( var s = 0; s < svs.length; s++ ) if( dm.indexOf(svs[s]) > -1 ) st.environment = svs[s];
			st.server = st.environment + (st.environment != '' ? '.' : '') + st.domain + '.' + st.extension;
			return st;
		},
		
		i : function(){
			_vortex.url = _vortex._is.g();
			_vortex.servers = {
				www : 'www.' + _vortex.url.server,
				code : 'code.' + _vortex.url.server,
				webmail : 'webmail.' + _vortex.url.server,
				ftp : 'ftp.' + _vortex.url.server,
				apps : 'apps.' + _vortex.url.server,
				sql : 'sql.' + _vortex.url.server,
				templates : 'templates.' + _vortex.url.server,
				images : 'images.' + _vortex.url.server,
				advertisers : 'advertisers.' + _vortex.url.server,
				secure : 'secure.' + _vortex.url.server,
				search : 'search.' + _vortex.url.server,
				live1 : 'live1.' + _vortex.url.server,
				live2 : 'live2.' + _vortex.url.server,
				wwwAlias : _vortex.url.server
			};
			_vortex.progress = {
				development : _vortex.url.environment == 'dev',
				testing : _vortex.url.environment == 'testing',
				live : _vortex.url.environment != 'dev' && _vortex.url.environment != 'testing'
			}
		}
		
	},
	
	regex : {
		email : new RegExp( /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/g ), 
		password : new RegExp( /^.{4,16}$/g ), 
		username : new RegExp( /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/g ),
		nonnumeric : new RegExp( /^[0-9\.]$/g )
	},
	
	server : function(s){
		var sv, svs;
		
		if( typeof($) != 'undefined' && $.vortex && $.vortex.settings && $.vortex.settings.servers ) svs = $.vortex.settings.servers;
		else svs = _vortex.servers;
		
		if( window.location.host.toLowerCase() == svs[s] ){
			return window.location.protocol + '//' + svs[s];
		}else{
			if( window.location.protocol.indexOf('https') > -1 ) sv = window.location.protocol + '//' + svs['secure'] + '/servers/' + s;
			else if( typeof(svs[s]) != 'undefined' ) sv = window.location.protocol + '//' + svs[s];
			else sv = window.location.protocol + '//' + svs.www;
			return sv.toLowerCase().replace('http://' + svs.secure, 'https://' + svs.secure);
		}
	}

}; _vortex._is.i();


// create jquery library if is not defined
if( typeof(MooTools) == 'undefined' ) document.write( unescape('%3Cscript language="javascript" src="' + _vortex.server('code') + '/mootools/core.js"%3E%3C/script%3E') );

if( typeof(jQuery) == 'undefined' ) document.write( unescape('%3Cscript language="javascript" src="' + _vortex.server('code') + '/jquery/core.js"%3E%3C/script%3E') );

// link to jquery UI library
document.write( unescape('%3Cscript language="javascript" src="' + _vortex.server('code') + '/jquery/ui.js"%3E%3C/script%3E') );

		// supporting libraries and useful plugins
		document.write( unescape('%3Cscript language="javascript" src="' + _vortex.server('code') + '/jquery/qtip.js"%3E%3C/script%3E') );

// write links to stylesheets
document.write( unescape('%3Clink rel="stylesheet" type="text/css" href="' + _vortex.server('code') + '/jquery/ui.css" /%3E') );

// write links to stylesheets
document.write( unescape('%3Clink rel="stylesheet" type="text/css" href="' + _vortex.server('code') + '/core.css" /%3E') );
		if( window.navigator.userAgent.toLowerCase().indexOf('msie') > -1 ) document.write( unescape('%3Clink rel="stylesheet" type="text/css" href="' + _vortex.server('code') + '/core.ie.css" /%3E') );
		if( window.navigator.userAgent.toLowerCase().indexOf('msie') > -1 && window.navigator.userAgent.indexOf('7.') > -1 ) document.write( unescape('%3Clink rel="stylesheet" type="text/css" href="' + _vortex.server('code') + '/core.ie7.css" /%3E') );

// write initialization script
document.write( unescape('%3Cscript language="javascript" src="' + _vortex.server('code') + '/init/core.js"%3E%3C/script%3E') );

// google tracking
if( !_vortex.progress.development && window.location.pathname.toLowerCase().indexOf('/admin') == -1 ) document.write( unescape("%3Cscript src='" + ( ( "https:" == document.location.protocol ) ? "https://ssl." : "http://www." ) + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E") );

// insert initial object
document.write( unescape('%3Cscript language="javascript" src="' + _vortex.server('code') + '/init/div.js"%3E%3C/script%3E') );