/* Navigáció */

(function($) {
	$.fn.jumpToPage = function() {
		return this.each(function() {

			var home = $('#home'),
				pages = ['about', 'portfolio', 'contact'],
				currentPage = home,
				isMainPage = (location.href == 'http://insolis.hu/') ? true : false;

			function fadeAndSwitch(divOut, divIn) {
				divOut.fadeOut('normal', function() {
					divIn.fadeIn('normal');
					currentPage = divIn;
				});
			}

			$.each(pages, function(key, value) {
				$('#link_' + value).click(function(event) {
					if(isMainPage == true) {
						event.preventDefault();
					}
					return fadeAndSwitch(home, $('#' + value));
				});
			});

			$('#contactlink').click(function(event) {
				if(isMainPage == true) {
					event.preventDefault();
				}
				return fadeAndSwitch(currentPage, $('#contact'));
			});

			$('p.back a').click(function(event) {
				if(isMainPage == true) {
					event.preventDefault();
				}
				return fadeAndSwitch(currentPage, home);
			});

			if(window.location.hash == '#kapcsolat') {
				fadeAndSwitch(currentPage, $('#contact'));
			}

		});
	};
})(jQuery);

$(document).ready(function() {
	$('#wrapper').jumpToPage();
});
