/**
 * DonReY Wavetrex Portfolio Website
 */
donrey.wavetrex = donrey.BASE._extend(function() {
	var self = this,
		site_section,
		authenticated = false;
	
	// public/priviledged functions
	this._public({
		
		// Callback from jQuery, here there is no "this"
		init: function() {
			// delayed loading of jUI and other css
			donrey.load_CSS("/dryfe/js/lib/jquery/jquery-ui/smoothness/smoothness.min.css");
			donrey.load_CSS("/dryfe/js/lib/jquery/jquery-fancybox2/jquery.fancybox.css");

			site_section = get_Cookie('site-section');
			authenticated = get_Cookie('wtx-authenticated') == 'yes';
			
			// Initialize DonReY Control ( only if authenticated )
			if(authenticated) {
				donrey.LAB.script("/dryfe/js/control/donrey-control-bar.js").wait(function() {donrey.control.init();});	
			}
/*
			donrey.load_ImageResources({
				// some image preload
			}, function(images, success) {
				
				donrey.wavetrex.images = images;
			}, 2000);
*/			
			// application loading tracker
			donrey.eventTracker_Init(['modules'],function(event_id, completed_so_far, when) { // ,'graphics'
				// TODO: Display a loading notification ( percentage perhaps ? )
			}, function(completed, completed_total, when) {
				switch(site_section) {
				case 'surface':
					surface.ui.init();
					surface.dragger.init();
					surface.container.init();
					
					// Reinitialize surface positions on screen in case of browser resize (because coordinates change)
					$(window).resize(function(e) {
						if(e.target == window)
							donrey.smart_Delay('browser_resize', function() {
								 surface.dragger.init();
								 surface.container.init();
							}, 200);
					});
					break;
				case 'blog':
					wavetrex.blog.init();
					break;
				}
				
			}, 3000);  // wait up to N milisecs for initialization ( loading )
			
			var needed_modules = [];
			switch(site_section) {
			case 'surface':
				needed_modules.push("dragger", "container", "ui"); break;
			case 'blog':
				needed_modules.push("blog"); break;
			}
				
			donrey.load_Modules(needed_modules, function() {
				// done with modules, signal event
				donrey.eventTracker_Signal('modules');
			});

			// DOM Initialization
			$("#container")
				.disableSelection();
//			$('body')
//				.disableSelection();
			
			
			$('#header').click(function() {
				location.href = '/';
			});
			
			$("#mainmenu a").mouseover(function(e) {

				// get coords for menu-link being hovered
				var
					target_left = $(e.target).position().left - 39;
//					target_id = '#menu_' + e.target.id.substr(9);
				
				// move/animate marker (while canceling any previous animation)
				$('#menumarker').stop(true).show().animate({
					marginLeft: target_left,
					width: $(e.target).width() + 39,
					opacity: 0.34
				}, 500).click(function() {
					location.href = e.target.href;
				});
			});
			
			$( "#index" ).accordion({
				autoHeight: false,
				clearStyle: true,
				create: function() {
					setTimeout(function() {
						$("#index").animate({
							opacity: 1
						}, 'slow');
					}, 250);
				}
			});
			
		}
	});
});

surface = {
	// some global application configuration
	CFG: {
		
	}
};

wavetrex = {
		
};
