/**
 * @author pad
 */
var Navigation = {
	
	currentNavItem : null,
	currentNavItems : null,
	
	onLoad : function () {
		//this.loadMenu('3', '', false);
	},
	
	fadeIn : function () {
		$('#content_container').animate({
		    opacity: 1
		}, 500, function() {
		   // Animation complete.
		});
		$('ul.navigation_left').fadeIn();
	},
	
	loadMenu : function (id, type, fade) {
		// convert to string
		this.currentNavItem = id;
		
		if (fade !=  false) {
			$('#content_container').animate({
			    opacity: 0
			}, 500, function() {
			   // Animation complete.
			   Navigation.displayMenu(id, type);
			});
		}
		else {
			   Navigation.displayMenu(id, type);
		}
	},
	
	displayMenu : function (id, type) {
		// fetch content
		$.post('modules/content/view.php', {
			id: id
		}, function (response) {
			if (response.length > 0) {
				
				$('div#content_container').html(response);
				Navigation.fadeIn();
			}
			// Remove all classes
			$('.navigation_bottom').find('td a').each(function () {
				$(this).removeClass();
			});			
			
			// Set class manually
			Navigation.currentNavItems = Navigation.currentNavItem.split('.');
			
			$('a#link_item_' + Navigation.currentNavItems[0]).addClass('active');
			
			if (type == undefined || type != 'sub') {
				$.post('modules/navigation/left.php', {
					id: Navigation.currentNavItem
				}, function(response){
					$('div#navigation_left').html(response);
					Navigation.fadeInNextElement($('ul.navigation_left').find('li:first'));
				});
			}
			
			if (type == 'sub') {
				$('ul.navigation_left').find('li a').each(function () {
					$(this).removeClass();
				});	
			}
			
			if (Navigation.currentNavItems[1]) {
				$('a#link_item_sub_' + Navigation.currentNavItems[1]).addClass('active');
			}
			
			$.each($.browser, function(i, val) {
				if (i ==  'webkit')
				{
				    $('img.img_mixed').css('margin-left', '0px');
				    $('img.img_full').css('margin-left', '322px');
				}
		    });
		});
	},
	
	fadeInNextElement: function(ele) {
		if (ele.length > 0) {
			$(ele).fadeIn('slow');
			nextElement = ele.next();
			setTimeout("Navigation.fadeInNextElement(nextElement)", 200);
		}
	}
}

