/**
 * @author samuelme
 */
var FactsPage = function(){

	//private vars

	function remove(){
		//console.log('facts removed')
			$('#factsHolder').remove();
	}

	//public methods
	return {
		init : function(){

		},
		show : function(target){


			HomePage.removeVideo();
				 $.ajax({
				  url: "facts.php",
				  cache: true,
				  success: function(html){
				  	remove();
				    var $facts = $(html).find('#factsHolder');
					$facts.css({display:'none'}).appendTo('#contentHolder');
					$('#videoHolder').hide();
					$facts.fadeIn('slow');
					//home button
					$facts.find('h1 a').unbind('click').bind("click",function(){
						 SWFAddress.setValue("?p=facility");
						 $(this).fadeTo("fast", 0);
						return false;
					});
					//substantiation button
					$('#link-substantiation').unbind('click').bind("click",function(){
						$('#factsHolder').fadeOut('fast',function(){
							$(this).remove();
							 SWFAddress.setValue("?p=substantiation");
						});


						return false;
					});

					$('dt').each(function(i){
						var num = (parseInt(i)+1);
						var fact = "fact"+num;
						$(this).addClass(fact);
						$(this).append('<a name="'+fact+'" id="'+fact+'"></a>');
					});
					$('dd').each(function(i){
						var num = (parseInt(i)+1);
						var fact = "fact"+num;
						$(this).addClass(fact);
					});

					if(typeof target == 'string'){

						target_loc = '#'+target;
						var offset = -($(window).height()/2)+80;

						var timer = setTimeout(function(){
							try{
								$('#contentHolder').scrollTo( target_loc, 800 , {easing:'swing',offset:offset,onAfter:function(){

									$('dt,dd').each(function(){
										var fact_num = $(this).attr('class');
										if(fact_num != target){
											$(this).fadeTo('slow',.15);
										}
									});
									$('#contentHolder').scroll(function () {
								     	 $('dt,dd').css({opacity:1});
								    });

								} } );


							}catch(e){
								debug(e);
							}


						},500);



					}

				  }
				});
				 SWFAddress.setTitle("Reality: Just The Facts");
				 $('#wrapper div.menu ol li a.facts').addClass('Active');
		},
		remove : function(){

			$('#factsHolder').remove();
		}
	}
	function debug($obj) {
		if (window.console && window.console.log)
			window.console.log($obj);
	};


}();
