/**
 * General namespace
 */
var salamatina = {
	/**
	 * Adjust settings here:
	 */
	settings: {
		logoAnimationSpeed: 		4000,
		contentFadeInSpeed: 		'slow',
		navigationAnimationSpeed: 	800,
		fadeSpeedAfterLink: 		'slow'
	},	
	/**
	 * Initialize all objects
	 */
	init: function() {
		for (var i in this) {
			if (typeof this[i].init == 'function') {
				this[i].init();
			}
		}
	},
	animateBranding: {
		init: function() {
			// we're not going to keep bothering visitors with animation
			//if ($.cookie('animated') || $.browser.msie) {
				var bh = Math.ceil($(document).height());
				$('#wrapper').css({
					backgroundPosition: '50% ' + Math.ceil(bh - 53) + 'px'
				});
				// hide background image onresize
				$(window).resize(function() {
					var bh = Math.ceil($(document).height());
					$('#wrapper').css({						
						backgroundPosition: '50% ' + Math.ceil(bh - 53) + 'px'
					});
				});
				this.doSimpleFade();
			/*} else {
				this.doExtraFancyFade();
				$.cookie('animated', 1);
			}*/
		},
		doSimpleFade: function() {
			// jQuery bug; in IE it can't read the opacity from a stylesheet
			$('#wrapper').attr('opacity', 0);
			$('#wrapper').fadeTo(salamatina.settings.contentFadeInSpeed, 1, function() {
				$('#wrapper').attr('opacity', 1);
			});
		},
		doExtraFancyFade: function() {
			var wrapper = $('#wrapper');
			var content = $('#content');
			var wh = Math.ceil($(window).height());
			var bh = Math.ceil($(document).height());
			
			// prepare the body and branding element for animation
			wrapper.css({
				backgroundPosition: '50% ' + (bh + Math.ceil(bh/2)) + 'px'
			});
			// select the branding element
			var branding = $('#branding');
			// center the branding element
			branding.css({
				top: (wh/2)-(branding.height()/2)
			});
			
			wrapper.fadeTo(salamatina.settings.logoAnimationSpeed, 1, function() {
				// second, animate them both. Since they both have to travel an equal amount to get to their destinations,
				// the animation config values such as the speed can be set to equal integers.
				branding.animate({
					top: '-53px'
				}, salamatina.settings.logoAnimationSpeed, 'easein', function() {
					// fade content in
					content.fadeTo(salamatina.settings.contentFadeInSpeed, 1);
					
					// hide background image onresize
					$(window).resize(function() {
						var bh = Math.ceil($(document).height());
						wrapper.css({
							backgroundPosition: '50% ' + Math.ceil(bh - 53) + 'px'
						});
					});
				});
				wrapper.animate({
					backgroundPosition: '(50% ' + Math.ceil(bh - 53) + 'px)'
				}, salamatina.settings.logoAnimationSpeed, 'easein');
			});
			
			return true;
		}
	},
	animateNavigation: {
		init: function() {
			var nav = $('#main-navigation'), originalx, elementOffset = 0;
			nav.lavaLamp({
				fx: 'backout',
				speed: salamatina.settings.navigationAnimationSpeed
			});
		}
	},
	fadeLinks: {
		init: function() {
			$('a').click(function(e) {
				var href = $(this).attr('href');
				if (href.indexOf('mailto') === -1 && !$(this).attr('target')) {
					e.preventDefault();
					$('#wrapper').fadeTo(salamatina.settings.fadeSpeedAfterLink, 0, function() {
						document.location.href = href;
					});
				}
			});
		}
	},
	subnavigation: {
		init: function() {
			var t = null;
			$('#main-navigation > li').mouseover(function() {
				if (t) {
					clearTimeout(t);
					t = null;
				}
				$(this).addClass('hover');
			});
			$('#main-navigation > li').mouseout(function() {
				var s = $(this);
				t = setTimeout(function(){
					s.removeClass('hover');
				}, 50);
			});
		}
	},
	linkFade: {
		init: function() {
			$('.pressLinks a').css('opacity', 0.3);
			$('.pressLinks a').mouseover(function() {
				$(this).css('opacity', 1.0);
			});
			$('.pressLinks a').mouseout(function() {
				$(this).css('opacity', 0.3);
			});
			$('.lightbox a').lightBox();
			
		}
	}
};

/**
 * Initialize general namespace
 */
salamatina.init();
