﻿var cp = 0;
jQuery.fn.center = function()
{	
	function c(container){
		var w = $(container);
		var content = $(".content",w);
		content.css("position","absolute");
		//content.css("top",(w.height()-content.height())/2+w.scrollTop() + "px");
		content.css("left",(w.width()-content.width())/2+w.scrollLeft() + "px");
	}
	
	function f(container){
		var win  = $(window);
		var w = win.width();
		var h = win.height();
		if(w < 1024) w = 1024;
		if(h < 900) h = 850;
		$(container).css({width:w,height:h});
	}
	
	function r(container,i){		
		$(container).css("left",$(container).width()*i + "px");
		$("#containers").css("left","-"+ $(container).width()*cp + "px")
	}
	
	
	$(".container",this).each(function(index){
			f($(this));
			c($(this));	
			r($(this),index);
			$(".content",$(this)).fadeIn(1000);				
	});
	var ct = this;
	$(window).resize(function(){
			$(".container",$("#containers")).each(function(index){
				f($(this));
				c($(this));
				r($(this),index);	
			});
	});
	return this;
}

$(document).ready(function() {
	var cntrs = $("<div/>");
	cntrs.load("LatentThreat.html .container",function(){
		$(".container",cntrs).appendTo("#containers");
		cntrs.load("TheVirus.html .container",function(){
			$(".container",cntrs).appendTo("#containers");
			cntrs.load("MostDangerous.html .container",function(){
				$(".container",cntrs).appendTo("#containers");
				cntrs.load("WhatNext.html .container",function(){
					$(".container",cntrs).appendTo("#containers");
					$("#containers").center();
				});
			});
		});
	});
	/*
	cntrs.load("LatentThreat.html .container",function(){
		$(".container",cntrs).appendTo("#containers");
	}).load("TheVirus.html .container",function(){
		$(".container",cntrs).appendTo("#containers");
	}).load("MostDangerous.html .container",function(){
		$(".container",cntrs).appendTo("#containers");
	}).load("WhatNext.html .container",function(){
		$(".container",cntrs).appendTo("#containers");
		$("#containers").center();
	});
	*/
	//
	var cnt = $("#containers");
	
	$("#logo").live("click",function(e){
		cp = 0;
		$(".buttons a").removeClass("active");
		if((e && ((e.button == 1) || (e.which ==1))) || $.browser.msie){	
			cnt.animate({left:"0px", top:"0px" },1000);
			return false;
		}
	});
	
	$("#b1").live("click",function(e){
		cp = 1;
		$(".buttons a").removeClass("active");
		if (cp == 1){$(this).addClass("active");}
		if((e && ((e.button == 1) || (e.which ==1))) || $.browser.msie){	
			//cnt.animate({left: ($(window).width()*(-1)) +"px", top:"0px" },1000);
			var w = $(window).width();
			if(w < 1024) {w = 1024}
			cnt.animate({left: (w*(-1)) +"px", top:"0px" },1000);
			return false;
		}
	});
	
	$("#b2").live("click",function(e){
		cp = 2;
		$(".buttons a").removeClass("active");
		if (cp == 2){$(this).addClass("active");}
		if((e && ((e.button == 1) || (e.which ==1))) || $.browser.msie){	
			cnt.animate({left: ($(window).width()*(-2)) +"px", top:"0px" },1000);
			return false;
		}
	});
	$("#b3").live("click",function(e){
		cp = 3;
		$(".buttons a").removeClass("active");
		if (cp == 3){$(this).addClass("active");}		
		if((e && ((e.button == 1) || (e.which ==1))) || $.browser.msie){	
			cnt.animate({left: ($(window).width()*(-3)) +"px", top:"0px" },1000);
			return false;
		}
	});
	$("#b4").live("click",function(e){
		cp = 4;
		$(".buttons a").removeClass("active");
		if (cp == 4){$(this).addClass("active");}
		if((e && ((e.button == 1) || (e.which ==1))) || $.browser.msie){	
			cnt.animate({left: ($(window).width()*(-4)) +"px", top:"0px" },1000);
			return false;
		}
	});
	/*
	$("#b5").live("click",function(e){
		cp = 5;
		if((e && ((e.button == 1) || (e.which ==1))) || $.browser.msie){	
			cnt.animate({left: ($(window).width()*(-5)) +"px", top:"0px" },1000);
			return false;
		}
	});
	*/
	
});
