
var Site = {

	StartFunctions: [],
		
	// ======================================================================
	start: function() {
		this.PrepareModals();
		this.HideRedirectMessage();
		this.PrepareConfirmLinks();
		this.RunStartFunctions();
		this.RunPage(document.body.id ? document.body.id : 'default');
	},
		
	// ======================================================================
	addStartFunction: function(f) {
		this.StartFunctions.push({
			f: f,
			started: false
		});
	},
		
	// ======================================================================
	RunStartFunctions: function() {
		for(var I in this.StartFunctions) {
			if (!this.StartFunctions[I].started) {
				this.StartFunctions[I].started = true;
				this.StartFunctions[I].f();
			}
		}
	},
			
	// ======================================================================
	PrepareModals: function() {
		$('a.ajax-link').click(function(){
			var href = $(this).attr('href');
			if (href.indexOf('?') != -1) href += "&"; else href += "?";
			href += "ajax=1";
			
			$.ajax({
				url: href,
				cache: false,
				success: function(html) {
					$.modal(html);
				}
			});
			
			return false;
		});
	},
	
	// ======================================================================
	PrepareConfirmLinks: function() {
		$('a.confirm-link').click(function(){
			return confirm('Are you sure?');
		});
	},
	
	// ======================================================================
	HideRedirectMessage: function() {
		if ($('#redirect-message')) {
			setTimeout(function() {
				$('#redirect-message').fadeOut();
			},3000);
		}	
	},
		
	// ======================================================================
	RunPage: function(siteId) {
		switch(siteId) {
		
			case 'default':
			
			break;
		
		
		
		
		}
	},
	
	logDebug: function(s) {
		$('#site-debug').append("<div>" + s + '</div>');
	}

}

$(function() {
	Site.start();
})

