function initPage() {
	// Initialize History
	if (window.History !== undefined && window.History.Adapter !== undefined)
		window.History.Adapter.bind(window,'hashchange', historyHashChange);

	// Show Content
	var initContent = '';
	if (location.hash.length > 0)
		initContent = location.hash.substring(1);
	showContent(initContent, false);
	
	// Cotent Menu Events
	$('.content-menu a').click(function(evt){
		var content = $(this).attr('href').substring(1);
		showContent(content);
		evt.preventDefault();
		return false;
	});
	
	// Icons Events
	$('.icons a').mouseover(function(){
		var el = $('<div id="icon-title">'+$('img', this).attr('alt')+'</div>');
		$('.icons').append(el);
		var l = $('img', this).position().left + ($('img', this).width() - el.width()) / 2 - 10;
		el.css({left:l, top:80});
		
	}).mouseout(function(){
		$('#icon-title').remove();
	});
	
	// Screenshot UI
	$('#leftarrow').css('opacity', 0.2);
	var html = '';
	for (var i = 0; i < $('.screenshot').length; i++) {
		html += '<li>'+(i+1)+'</li>';
	}
	$('.dots').html(html);
	showScreenShot(0);
	//$('.dots>li').eq(0).addClass('on');

	// Dots Event
	$('.dots>li').click(function(){
		var index = parseInt($(this).html()) - 1;
		showScreenShot(index);
	});
	
	// FAQ events
	$('.faq-item h2').click(function() {
		var answer = $('.answer' ,$(this).parent('div'));
		if (answer.css('display') == 'none') {
			$('.faq-item .answer').slideUp(200);
			answer.slideDown(200);
		} else
			answer.slideUp(200);
	});
}

function showContent(content, updateHistory) {
	if (g_defaultContent === undefined || g_defaultContent.length == 0)
		return;

	if (updateHistory === undefined) updateHistory = true;
	if (content.length == 0) content = g_defaultContent;

	if ($('.content:visible').hasClass(content))
		return;

	// update menu
	$('.content-menu li').removeClass('on');
	$(".content-menu a[href='#"+content+"']").closest('li').addClass('on');
	
	// update history
	if (updateHistory) {
		window.History.pushState({page:content}, '', '#'+content);
	}
		
	// show content
	if ($('.content:visible').length > 0) {
		$('.content:visible').fadeOut(250, function(){
			$('.content-container .'+content).fadeIn(250);
		});
	} else {
		$('.content-container .'+content).fadeIn(250);
	}
}

function historyHashChange() {
	var hash = window.History.getHash();
	showContent(hash, false);
}

function moveScreenShot(direction) {
	showScreenShot(g_screenShotIndex + direction);
}

function showScreenShot(index) {
	var wWidth = $('.screenbox').width();
	var left = -index * wWidth;
	var nScreenshot = $('.screenshot').length;

	// scroll
	if (left > 0)
		return;
	if (left < -(nScreenshot - 1) * wWidth)
		return;
	
	g_screenShotIndex = index;
	$('.screenshots-scroll').animate({left:left}, 250);
	
	// title
	$('.screentitle').html($('.screenshot img').eq(index).attr('alt'));
	
	// update arrow and dots
	$('#leftarrow').css('opacity', left == 0 ? 0.2 : 1.0);
	$('#rightarrow').css('opacity', left == -(nScreenshot - 1) * wWidth ? 0.2 : 1.0);
	$('.dots>li').removeClass('on');
	$('.dots>li').eq(-left / wWidth).addClass('on');
}

function toggleOtherDownloads() {
	
	if ($('.otherdownloads').css('display') == 'none') {
		$(document).bind('keydown.otherDownloads', function(evt){
			if (evt.keyCode == 27)
				toggleOtherDownloads();
		}).bind('click.otherDownloads', function(evt){
			if ($(evt.target).attr('id') != 'here' && $(evt.target).parents('.otherdownloads').length == 0)
				toggleOtherDownloads();
		});
		$('.otherdownloads').fadeIn(200);
	} else {
		$(document).unbind('keydown.otherDownloads').unbind('click.otherDownloads');
		$('.otherdownloads').fadeOut(200);
	}
}
