
	
	website = function() { return {

		element: {

			module: {
			}

		},

		scroll: {

			toTop: function() {

				if( $(document).scrollTop() > 300 ) {

					$.scrollTo({ top: "300px" }, { duration: 800 });

				}

			}

		},

		strategy: {
		},

		session: {
		},

		_: null

	} }();		website.application = function() { return {

		_observer: new observer,
        attachObserver: function(_observer_, _event_, _once_) { this._observer.attachObserver(_observer_, _event_, _once_); },
        detachObserver: function(_observer_, _event_) { this._observer.detachObserver(_observer_, _event_); },

		events: {

			init__called: "8388bb82b5b7b3f546d882956f1b452"

		},

		init: function() {
			
			this._observer.notifyObservers( this.events.init__called );

		},

		setupSkeleton: function() {

			this.attachObserver(
				website.strategy.onInit,
				this.events.init__called
			);

			website.skeleton.attachObserver(
				website.strategy.onInit,
				website.skeleton.events.reload__completed
			);

		},

		setupLocationChange: function() {

			website.page.attachObserver(
				website.strategy.onLocationChange,
				website.page.events.reload__completed__external
			);


			location_hash.attachObserver(
				website.strategy.onLocationChange,
				location_hash.events.hash__changed
			);

			window.setInterval("location_hash.checkChanges()", 50);

		},


		setupAjax: function() {

			$.ajaxSetup({
								error: function( _message_ ) { $.dump( _message_ ); },
								url: "/",
				async: true,
				type: "POST"
			});

		},

		_: null

	} }();
		
	website.skeleton = function() { return {

		_observer: new observer,
        attachObserver: function(_observer_, _event_, _once_) { this._observer.attachObserver(_observer_, _event_, _once_); },
        detachObserver: function(_observer_, _event_) { this._observer.detachObserver(_observer_, _event_); },

		events: {

			reload__completed: "d1ecd26dc3ec46d3d5ee36cce477ab60"

		},

		reload: function() {

			$.ajax({

				dataType: "html",
				data: {

					"_pn": "template",
					"_pa": "website__skeleton",
					"_rt": "text/html"

				},

				success: function(_source_) {

					$("#skeleton").html(_source_);
					website.skeleton._observer.notifyObservers( website.skeleton.events.reload__completed );

				}

			});

		},

		_: null

	} }();
	
	website.page = function() { return {

		_observer: new observer,
        attachObserver: function(_observer_, _event_, _once_) { this._observer.attachObserver(_observer_, _event_, _once_); },
        detachObserver: function(_observer_, _event_) { this._observer.detachObserver(_observer_, _event_); },

		application: null,

		events: {

			reload__completed__external: "dd496688262b67316f18a10a64fc8d0",
			reload__completed__internal: "93daad132d1835c8c2d6f7c143689f9"
			
		},

		setMenuItem: function( _location_ ) {


			if( _location_ == '') {
				_location_ = "what-we-do";
			}
			
			$("#main_menu > li > a").removeClass();
			$("#main_menu > li > a").addClass("menu_item out");;

			if($("#menu_item_" + _location_)) {
				$("#menu_item_" + _location_ + " > a").blur();
				$("#menu_item_" + _location_ + " > a").removeClass();
				$("#menu_item_" + _location_ + " > a").addClass("menu_item selected");
			}
	
			$("#page").fadeOut("slow", function(){

				$("#page_what-we-do").css({display:"none"});
				$("#page_products").css({display:"none"});
				$("#page_about-us").css({display:"none"});
				
				$("#page_" + _location_).css({display:""});
			
			});
			
			$("#page").fadeIn("slow");
		},

		initPage: function() {
			$("#page").css({display:""});
			$("#page").fadeIn("slow");
		},

		reload: function( _location_ ) {
			$("#page").ajaxComplete(function(request, settings){
				$("#page").fadeIn("slow");
			});
			
			$("#page").fadeOut("slow", function() {
				$.ajax({
	
					dataType: "html",
					data: {
	
						"_rt": "text/html",
						"_pn": "template",
						"_pa": "page",
						"_pd" : base64.encode($.toJSON({"location": _location_}))
	
					},
	
					success: function( _source_ ) {
						
						website.page._observer.detachEvent(website.page.events.reload__completed__internal);
						website.page.application = null;
	
						website.page._observer.notifyObservers(website.page.events.reload__completed__internal);
						website.page._observer.notifyObservers(website.page.events.reload__completed__external);

						$("#page").html(_source_);
					}
	
				});
				
			});

		},

		_: null

	} }();	
	website.strategy.onInit = function() { return {

		notifyObserver: function(_event_, _args_) {

			switch( _event_ ) {

				case website.application.events.init__called:
	
					website.application.setupAjax();
					website.skeleton.reload();
	
					break;
	
				case website.skeleton.events.reload__completed:
					website.page.initPage();
					website.application.setupLocationChange();
	
					break;

			}

		},

		_: null

	} }();	
	website.strategy.onLocationChange = function() { return {

		notifyObserver: function(_event_, _location_) {

			switch( _event_ ) {

			case website.page.events.reload__completed__external:
			    //website.scroll.toTop();
				break;

			case location_hash.events.hash__changed:

				if( _location_ != "" && $("a[name='" + _location_ + "']").size() ) {
					return; 
				}
				
				website.page.setMenuItem( _location_ );
				//website.page.reload( _location_ );

				break;

			}

		},

		_: null

	} }();	
	
	website.email = function() {
		
		return {
			
			_observer: new observer,
	        attachObserver: function(_observer_, _event_, _once_) { this._observer.attachObserver(_observer_, _event_, _once_); },
	        detachObserver: function(_observer_, _event_) { this._observer.detachObserver(_observer_, _event_); },
	        
			events: {
	
				reload__completed__external: "email_sent",
				reload__completed__internal: "email_sent"
	
			},

	        sendRequirement: function( fromEmail, requirement ) {

				if(
					$.trim(fromEmail) ==  website.email._inp_from_email_text || $.trim(fromEmail) == "" ||
					$.trim(requirement) == website.email._inp_requirement_text || $.trim(requirement) == ""
				) {
					alert("Please, fill fields.")
					return false;
				}

				$.blockUI.defaults.pageMessageCSS = {
					margin:'-50px 0 0 -125px', 
					top:'45%', 
					left:'50%', 
					textAlign:'center',
					verticalAlign: 'top'
				}
				
				$.blockUI.defaults.fadeOut = 400;
				
				$.blockUI.defaults.pageMessage = "<div style='width:300px;padding:20px;background-color:#ffffff;border:1px solid #cccccc;color:#006699;font-weight:bold;'>Sending...</div>";
				$.blockUI();
	
				$.ajax({
	
					dataType: "html",
					data: {
	
						"_rt": "text/html",
						"_pn": "template",
						"_pa": "send__email",
						"_pd" : base64.encode(
							$.toJSON(
								{
									"fromEmail": fromEmail,
									"requirement": requirement
								}
							)
						)
	
					},
	
					success: function( _source_ ) {

						if(_source_ == true) {
														$.unblockUI();
							$.blockUI.defaults.pageMessage = "<div style='width:300px;padding:20px;background-color:#ffffff;border:1px solid #cccccc;color:#006699;font-weight:bold;'>Your message has been successfuly sent!</div>";
							$.blockUI();
							setTimeout(website.email.unblockMessage, 3500);
							website.email.emaiInputsReset();
						}
						else {
														$.unblockUI();
							$.blockUI.defaults.pageMessage = "<div style='width:300px;padding:20px;background-color:#ffffff;border:1px solid #cccccc;color:#aa0000;font-weight:bold;'>Error sent message...<br>Please try agan.</div>";
							$.blockUI();
							setTimeout(website.email.unblockMessage, 3500);
						}
						
						
											}
	
				});
	        },

			unblockMessage: function() {
				$.unblockUI();
			},

			_inp_from_email_text: "Your e-mail",
			_inp_requirement_text: "Your requirement",

			emaiInputsReset: function() {
				$("#inp_from_email").removeClass();
				$("#inp_requirement").removeClass();
				$("#inp_from_email").addClass("empty");
				$("#inp_requirement").addClass("empty");
				$("#inp_from_email").val(website.email._inp_from_email_text);
				$("#inp_requirement").val(website.email._inp_requirement_text);				
			},

			emaiInputsInit: function() {
				$("#inp_from_email").focus(function(){
					if($.trim($(this).val()) == website.email._inp_from_email_text) {
						$(this).removeClass();
						$(this).addClass("filled");
						$(this).val("");
					}
				});
				
				$("#inp_from_email").blur(function(){
					if($.trim($(this).val()) == "") {
						$(this).removeClass();
						$(this).addClass("empty");
						$(this).val(website.email._inp_from_email_text);
					}
				});

				$("#inp_requirement").focus(function(){
					if($.trim($(this).val()) == website.email._inp_requirement_text) {
						$(this).removeClass();
						$(this).addClass("filled");
						$(this).val("");
					}
				});
				
				$("#inp_requirement").blur(function(){
					if($.trim($(this).val()) == "") {
						$(this).removeClass();
						$(this).addClass("empty");
						$(this).val(website.email._inp_requirement_text);
					}
				});
				
				website.email.emaiInputsReset();

			},
			
			_: null
			
		}
	
	}();	
	$(document).ready(function() {

		website.application.setupSkeleton();
		website.application.init();
		website.email.emaiInputsInit();

	});