/*	smartwebstdio.com | sws.scripts.js */



window.addEvent('domready', function() {

	// path
	var jsFullPath = document.getElement('script[src$=template.js]').get('src');
	var jsFullPathMatrix = jsFullPath.match(/^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/); // ref: http://stackoverflow.com/questions/27745/getting-parts-of-a-url-regex
	/*
		0: full
		1,2: protocol
		3: host
		4: dir
		5: lastdir
		6: file
		7,8: anchor
	*/
	var jsPath = jsFullPathMatrix[4];
	
	// lazyClass
	var classes = ['URI', 'FxGlow', 'mooClouds'];
	var options = { path: jsPath + 'classes/{class}.class.js' };
	LazyClass.prepare(classes, options);
	
	
	// var jsPath = thisURI.get('directory');
	// var thisURI = new URI(location.href);
	var thisURI = document.location.href;
	
	var jsSubdomain = false;
	var subdomainRE = /(.*)\..*\..*/i; // "/([^\..]*)[\.].*\..*/i";
	
	
	/*	test subdomains */
	var runFx = false;
	var allowedSubdomains = { 'tools':"", 'office':"", 'labs':"" };
	var hostURI = document.location.host;
	// var hostURI = thisURI.get('host');
	
	// get subdomain
	if (hostURI.test(subdomainRE, "i")) {
		jsSubdomain = hostURI.match(subdomainRE)[1];

		// allow in allowed subdomains
		if (jsSubdomain in allowedSubdomains) { runFx = true; }
		else { runFx = false; }
	}
	// allow if no subdomain
	else { runFx = true; }
	
	// forbid for IE < 7
	if (Browser.Engine.trident4) { runFx = false; }
	// throw new Error('ajax requests not possible on subdomains: [' + jsSubdomain[1] + ']');
	
	
	if (runFx)
	{
	
		$('clouds').addEvents({ 
			
			'click': function(el) {
				
				var mc = new mooClouds({
					maxDynClouds: 	1,
					maxStatClouds: 	0,
					cloudsClassesNum: 4,
					cloudsClasses:	"clouds",
					containerID:	"inner",
					contX:			null,
					contY:			null
				});
				mc.generateClouds();
				
				$('inner').setStyles({
					height: 	'auto',
					width: 		'100%',
					position: 	'relative'
				});
			}
		});
		
		
		/*
		// var Fx = new Object();
		// FxGlow = new LazyClass('FxGlow', { path: jsPath + 'classes/{class}.class.js' }); // '/templates/labs/js/'
		$each($$('a'), function(el) {
			var myFx = new FxGlow(el, {
				duration: 	200,
				// transition:	Fx.Transitions.Quad.easeOut, // 'quad:out',
				property: 	'text', // 'text', // 
				color: 		'#2288ff',
				opacity: 	.6,
				strength:	8
			});
			
			el.addEvents({
				'mouseenter' : function() { myFx.start(el.retrieve('glow'), 1); },
				'mouseleave' : function() { myFx.start(el.retrieve('glow'), 0); }
			});
		});
		*/
	
	}
	
	
	//	email cloaking
	//	ref: http://davidwalsh.name/email-protection-mootools-javascript-v2
	$$('.email').each(function(el) {
		var anchor = new Element('a', {
			href: 'mailto:' + el.get('rel').replace('|','@'),
			'class': el.get('class'),
			'html': el.get('html')
			// 'text': el.get('text')
		}).replaces(el);
	});
});
