	
var pkmodal = {
	overlay: null,
	window: null,
	w: null,
	pages: new Array(),
	current: 0,
	initialized: false,
	
	init: function(){
		this.overlay = $('#pk-overlay');
		this.overlay.click(function(){ pkmodal.hide(); });
		this.w = $($('html').get(0));
		this.window = $('#pk-modal');
		this.initialized = true;	
		
		$('a.page',this.window).each(function(i){
			pkmodal.pages.push($(this));
		});
	},
	
	show: function(){
		if(!this.initialized)
			this.init();
		
		this.current = 0;
		
		/* overlay */
		this.setOverlaySize();
		$(this.overlay).css({ opacity: 0 }).show();	
		$(this.overlay).animate( { opacity: 0.7 }, 200 );	
		$(window).resize(pkmodal.setOverlaySize);
		
		/* window */
		 
		this.window.show();
		
		this.showPage(this.current);
		
		/* modal bottom*/
		$('#pk-modal-bottom').css({top:'-68px'}).animate( { top: "0px" }, 800 );
		
	},
	hide: function(){
		/* modal bottom*/
		$('#pk-modal-bottom').animate( { top: "-68px" }, 300 );
		
		pkmodal.window.hide();
		pkmodal.overlay.fadeOut();
		$(window).unbind('resize', pkmodal.setOverlaySize);	 
	},
	setOverlaySize: function(){	
		var widthHeight = pkmodal.viewport();						
		$(pkmodal.overlay).css({width:widthHeight[0],height:widthHeight[1]});
	},
	showPage: function(i){
		this.current = i;
		if(i>0){
			$('#pk-modal-back').show();	
		} else {
			$('#pk-modal-back').hide();		
		}
		
		var offset = pkmodal.pages[i].parent().position();
		$('#pk-modal-pages').animate( { left: "-"+offset.left+"px" }, 300 );
	},
	prevPage: function(){
		pkmodal.showPage(pkmodal.current-1);	
	},
	nextPage: function(){
		pkmodal.showPage(pkmodal.current+1);	
	},
	viewport: function() {
			
		// the horror case
		if ($.browser.msie) {
			
			// if there are no scrollbars then use window.height
			var d = $(document).height(), w = $(window).height();
			
			return [
				window.innerWidth || 								// ie7+
				document.documentElement.clientWidth || 	// ie6  
				document.body.clientWidth, 						// ie6 quirks mode
				d - w < 20 ? w : d
			];
		} 
		
		// other well behaving browsers
		return [$(window).width(), $(document).height()];
	
	} 

};

$(function() {
	
	function viewport() {
			
		// the horror case
		if ($.browser.msie) {
			
			// if there are no scrollbars then use window.height
			var d = $(document).height(), w = $(window).height();
			
			return [
				window.innerWidth || 								// ie7+
				document.documentElement.clientWidth || 	// ie6  
				document.body.clientWidth, 						// ie6 quirks mode
				d - w < 20 ? w : d
			];
		} 
		
		// other well behaving browsers
		return [$(window).width(), $(document).height()];
	
	} 
	function setOverlaySize(){	
		var widthHeight = viewport();						
		$('.overlay').css({width:widthHeight[0],height:widthHeight[1]});
	}
	function hide(){
		/* modal bottom*/
		$('.modal').animate( { top: "-68px" }, 300 );
		
		$('.modal').hide();
		$('.overlay').fadeOut();
		$(window).unbind('resize', setOverlaySize);	 
	}
	
	setOverlaySize();
	$(window).resize(setOverlaySize);
	$('.overlay, .modalClose').click(function(){ hide(); });
	
});

