/**
 * Executed when document is finished loading elements into DOM
 */
$(document).ready(function()
{
	if ($.browser.safari){
		$('#container').css('top', '90px');
	}
	
	// Iitialize scrollable
	var api = $("div.scrollable").scrollable({
			size: 1,
			items: '#pages',
			hoverClass: 'hover',
			keyboard:false,
			clickable:false,
			vertical:false,
			setPage:3
	});

	//Set default page
	var api = $("div.scrollable").scrollable();

	$(".tabs a").click(function(){
		link_ids = $(this).attr('id').split('_');
		id = link_ids[0];
		sub_id = link_ids[1];

		link_text_ids = $(this).parent().attr('class').split(' ');


		openPage(id);

		if (sub_id != undefined){
			if (link_text_ids == ""){
				link_text_ids = $(this).parent().children('ul').children('li:first').attr('class').split(' ');
				$(this).parent().children('ul').children('li:first').children('a').addClass('active');
			}
			openSubpage(link_text_ids[0], link_text_ids[1]);
			$(this).addClass('active');
			$(this).parent().parent().parent().children('a').addClass('active');
		}
	});

	$(".vscroll").jScrollPane({animateInterval: 200});

	if (redirect){
		if (location.hash == ''){
			$('a[href=#0]').click();
		}else{
			$('a[href='+location.hash+']').click();
		}
	}

	$('a.pop').fancybox({
		'hideOnContentClick': false,
		'frameWidth': 230,
		'frameHeight': 220
	});

	$("a.gallery").fancybox({
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'overlayShow': true,
		'overlayOpacity': 0.6
	});
	
	$('a.fancy').fancybox({
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'overlayShow': true,
		'overlayOpacity': 0.6
	});
});

function popCallback(){
	alert('hello!');
}


function openPage(id)
{
	if (id == "0")
	{
		$("#notification").hide();
	}
	else
	{
		$("#notification").show();
	}

	var api = $(".scrollable").scrollable();
	api.setPage(id);

	$(".tabs a").removeClass('active');
	$(".tabs a#"+id).toggleClass('active');

	$('.subpage').hide();

	$('.floater').each(function(){
		$(this).children().children().children('.subpage:first').show();
	});
}

function openSubpage(parent, id)
{
	$("#"+parent+" .subpage").hide();
	$("#"+id).show();
}
