jQuery.fn.center = function () {
	this.css("position","absolute");
	this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
	this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
	return this;
}
jQuery.fn.topCenter = function () {
	this.css("position","absolute");
	this.css("top","0");
	this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
	return this;
}
jQuery.fn.updateNav = function() {
	var curl = location.href;
	var page = this.text();
	if (curl.indexOf("page=" + page) >= 0) 
		this.addClass('there');
	else
		this.removeClass('there');
	return this;
}

function loading(){
	resizing();
	$("#layer1").show();
	$("#layer2").show();
	$("#layer3").show();
	$("#logo").show();
	$("#hex").show();
	$("#bottomgrey").show();
	$("#briance").show();
	$("#copyright").show();
	
	$("#btn_hex1").show();
	$("#btn_hex2").show();
	$("#btn_hex3").show();
	$("#slide1").show();
	$("#branding").show();
	$("#identity").show();
	$("#logos").show();
	$("#slide2").show();
	$("#design").show();
	$("#web").show();
	$("#print").show();
	$("#slide3").show();
	$("#web2").show();
	$("#development").show();
	$("#hosting").show();
	$("#nav_hex_bkg").show();
	$("#nav").show();
	
	
	$("#layer2").animate({opacity: 1}, {
		speed: 300,
		queue: 'first',
		postDelay: 200
	});
	$("#layer3").animate({opacity: 1}, {
		speed: 300,
		queue: 'first', 
		postDelay: 200
	});
	$("#logo").animate({opacity: 1},{
		speed: 300,
		queue: 'first', 
		postDelay: 200
	});
	$("#briance").animate({opacity: .3},{
		speed: 300,
		queue: 'first',
		postDelay: 200
	});

	$("#hex").animate({opacity: 1}, {
		speed: 300,
		queue: 'first'
	});
	$("#bottomgrey").animate({opacity: 1}, {
		speed: 300,
		queue: 'first'
	});
	
	$("#nav_hex_bkg").animate({opacity:1},{
		speed:400, 
		queue:'first',
		complete: function(){
			$("#btn_hex1").css({opacity: 1});
			$("#btn_hex2").css({opacity: 1});
			$("#btn_hex3").css({opacity: 1});
		}
	});
	
	//$("#btn_hex1").animate({opacity: 1}, {
	//	speed: 1,
	//	queue: 'first'
	//});
	//$("#btn_hex2").animate({opacity: 1}, {
	//	speed: 1,
	//	queue: 'first'
	//});
	//$("#btn_hex3").animate({opacity: 1}, {
	//	speed: 1,
	//	duration: 1,
	//	queue: 'first'
	//});
	
	// nav open and close animation	
	//$("#nav").animate({opacity: 1},{
	//	speed:1500, 
	//	queue:'first', 
	//	postDelay: 500
	//});
	//$("#dropmenuopen").css("height", "15").animate({
	//	height: "75"
	//}, {speed:300, 
	//	queue:'first'
	//});
	//$("#dropmenuopening").css("top", "-60").animate({
	//	top: "0"
	//}, {speed:300, 
	//	queue:'first'
	//});
	//$("#dropmenuopen").show({
	//	duration: 0,
	//	queue: 'first'
	//});
	//$("#dropmenuclose").hide({
	//	duration: 0,
	//	queue:'first', 
	//	postDelay:500
	//});
	
	//$("#dropmenuopening").animate({	top: "-60"},{
	//	speed: 200, 
	//	queue:'first'
	//});
	//$("#dropmenuopen").animate({height: "15"},{
	//	speed: 200, 
	//	queue:'first', 
	//	complete: function(){
	//		$("#dropmenuclose").show();
	//		$("#dropmenuopen").hide();
	//	}
	//});

	// hex slide menu
	$("#slide1").show({
		duration: 1,
		queue: 'first',
		postDelay: 800,
		complete: function(){
			open_slide1();
		}
	});
	$("#slide1").show({
		duration: 1,
		queue: 'first',
		complete: function(){
			close_slide1();
		}
	});
	$("#slide2").show({
		duration: 0,
		queue: 'first',
		postDelay: 800,
		complete: function(){
			open_slide2();
		}
	});
	$("#slide2").show({
		duration: 0,
		queue: 'first',
		complete: function(){
			close_slide2();
		}
	});
	$("#slide3").show({
		duration: 0,
		queue: 'first',
		postDelay: 800,
		complete: function(){
			open_slide3();
		}
	});
	$("#slide3").show({
		duration: 0,
		queue: 'first',
		postDelay: 1000,
		complete: function(){
			close_slide3();
		}
	});
	
	$("#splash").css({left: "796", width: "0", height: "0"})
				.animate({ left: "285", width: "511", height: "305"},
					{speed: 1500, queue:'first'});
	
	$(".flash").animate({display:"block"},
					{speed:1, 
					queue:'first',
					complete: function(){
						flashIt();
					}
				});			
				
	$("#copyright").animate({opacity:1}, {
		speed: 300,
		queue: 'first'
	});
}
function open_slide1(){
	$("#logos_container").css({width:"84"});
	$("#identity_container").css({width:"97"});
	$("#branding_container").css({width:"171"});
	$("#slide1").css({width:"330"});
	$("#branding").stop().animate({left: "-10"},200, function(){
		$("#identity").stop().animate({left: "0"},150, function(){
			$("#logos").stop().animate({left: "0"}, 100);
		});
	});
}
function keep_open_slide1(){
	$("#branding").stop().css({left:"-10"});
	$("#identity").stop().css({left:"0"});
	$("#logos").stop().css({left:"0"});
}
function close_slide1(){
	$("#logos").stop();
	$("#identity").stop();
	$("#branding").stop();
	$("#logos").stop().animate({left: "-85"},100, function(){
		$("#identity").stop().animate({left: "-100"},100, function(){
			$("#branding").stop().animate({left: "-170"}, 100, function(){
				$("#slide1").css({width:"0"});
				$("#logos_container").css({width:"0"});
				$("#identity_container").css({width:"0"});
				$("#branding_container").css({width:"0"});
			});
		});
	});
}
function open_slide2(){
	$("#print_container").css({width:"73"});
	$("#web_container").css({width:"71"});
	$("#design_container").css({width:"156"});
	$("#slide2").css({width:"268"});
	$("#design").stop().animate({left: "0"},200, function(){
		$("#web").stop().animate({left: "0"},150, function(){
			$("#print").stop().animate({left: "0"}, 100);
		});
	});
}
function keep_open_slide2(){
	$("#design").stop().css({left:"0"});
	$("#web").stop().css({left:"0"});
	$("#print").stop().css({left:"0"});
}
function close_slide2(){
	$("#print").stop();
	$("#web").stop();
	$("#design").stop();
	$("#print").stop().animate({left: "-72"},100, function(){
		$("#web").stop().animate({left: "-71"},100, function(){
			$("#design").stop().animate({left: "-156"}, 100, function(){
				$("#slide2").css({width:"0"});
				$("#print_container").css({width:"0"});
				$("#web_container").css({width:"0"});
				$("#design_container").css({width:"0"});
			});
		});
	});
}
function open_slide3(){
	$("#web2_container").css({width:"128"});
	$("#development_container").css({width:"146"});
	$("#hosting_container").css({width:"99"});
	$("#slide3").css({width:"268"});
	$("#web2").stop().animate({left: "-10"},200, function(){
		$("#development").stop().animate({left: "0"},150, function(){
			$("#hosting").stop().animate({left: "0"}, 100);
		});
	});
}
function keep_open_slide3(){
	$("#web2").stop().css({left:"-10"});
	$("#development").stop().css({left:"0"});
	$("#hosting").stop().css({left:"0"});
}
function close_slide3(){
	$("#hosting").stop();
	$("#development").stop();
	$("#web2").stop();
	$("#hosting").stop().animate({left: "-99"},100, function(){
		$("#development").stop().animate({left: "-146"},100, function(){
			$("#web2").stop().animate({left: "-128"}, 100, function(){
				$("#slide3").css({width:"0"});
				$("#hosting_container").css({width:"0"});
				$("#development_container").css({width:"0"});
				$("#web2_container").css({width:"0"});
			});
		});
	});
}
function open_nav(){
	var dropmenuopen = $("#dropmenuopen");
	var dropmenuopening = $("#dropmenuopening");
	var dropmenuclose = $("#dropmenuclose");
	var nav = $("#nav");
	dropmenuopen.css("height", "15");
	dropmenuopening.css("top", "-60");
	dropmenuopen.show();
	dropmenuclose.hide();
	dropmenuopen.stop().animate({
		height: "75"
	}, 300);
	dropmenuopening.stop().animate({
		top: "0"
	}, 300);
	nav.stop().animate({
		height: "96"
	}, 300);
}
function close_nav(){
	var dropmenuclose = $("#dropmenuclose");
	var dropmenuopening = $("#dropmenuopening");
	var dropmenuopen = $("#dropmenuopen");
	var nav = $("#nav");
	dropmenuopen.stop().animate({
		height: "15"
	}, 200);
	dropmenuopening.stop().animate({
		top: "-60"
	}, 200, function(){
		dropmenuclose.show();
		dropmenuopen.hide();
	});
	nav.stop().animate({
		height: "36"
	}, 200);
}
function resizing(){
	$("#layer1").topCenter();
	$("#layer2").topCenter();
}
function flashIt(){
	var flsh = location.href + "assets/style/default/flash/welcome2.swf";
	$('.flash').flash({
        src:flsh,
        width:511,
        height:305,
        color:"#fff",
		loop:"false",
        quality:"high",
        wmode:"transparent",
        access:"domain",
        express:"express_install.swf",
        classid:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
        codebase:"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=",
        plugin:"http://get.adobe.com/flashplayer",
        mime:"application/x-shockwave-flash",
        version:"9.0.24"
    });
}
//function current_page(){
//	var curl = location.href;
//	
//}
$(document).ready(function() {
	
	window.setTimeout('loading();', 50);

	$("#topnav .nlink").each(function(){
		$(this).updateNav();
	})
	
	$("#nav").hover(
		function(){
			open_nav();
		},
		function(){
			close_nav();
		}
	);

	var btn_hex1 = $("#btn_hex1");
	btn_hex1.hover(
		function(){
			open_slide1();
			$(this).addClass('on');
			$(this).removeClass('off');
		},
		function(){
			close_slide1();
			$(this).addClass('off');
			$(this).removeClass('on');
		}
	);

	var btn_hex2 = $("#btn_hex2");
	btn_hex2.hover(
		function(){
			open_slide2();
			$(this).addClass('on');
			$(this).removeClass('off');
		},
		function(){
			close_slide2();
			$(this).addClass('off');
			$(this).removeClass('on');
		}
	);

	var btn_hex3 = $("#btn_hex3");
	btn_hex3.hover(
		function(){
			open_slide3();
			$(this).addClass('on');
			$(this).removeClass('off');
		},
		function(){
			close_slide3();
			$(this).addClass('off');
			$(this).removeClass('on');
		}
	);
	
	$("#slide1 .slide1").hover(
		function(){
			keep_open_slide1();
		},
		function(){
			close_slide1();
			$("#btn_hex1").addClass('off');
			$("#btn_hex1").removeClass('on');
		}	
	);
	$("#slide2 .slide2").hover(
		function(){
			keep_open_slide2();
		},
		function(){
			close_slide2();
			$("#btn_hex2").addClass('off');
			$("#btn_hex2").removeClass('on');
		}	
	);
	$("#slide3 .slide3").hover(
		function(){
			keep_open_slide3();
		},
		function(){
			close_slide3();
			$("#btn_hex3").addClass('off');
			$("#btn_hex3").removeClass('on');
		}	
	);
	
	$("#branding").click(function(){
		$("#slidemenu").animate({left: "-40"}, 2000);
		$("#nav_hex_bkg").animate({left: "-40"}, 2000);
	})
	$("#identity").click(function(){
		$("#slidemenu").animate({left: "-40"}, 2000);
		$("#nav_hex_bkg").animate({left: "-40"}, 2000);
	})
	$("#logos").click(function(){
		$("#slidemenu").animate({left: "-40"}, 2000);
		$("#nav_hex_bkg").animate({left: "-40"}, 2000);
	})
	$("#design").click(function(){
		$("#slidemenu").animate({left: "-40"}, 2000);
		$("#nav_hex_bkg").animate({left: "-40"}, 2000);
	})
	$("#web").click(function(){
		$("#slidemenu").animate({left: "-40"}, 2000);
		$("#nav_hex_bkg").animate({left: "-40"}, 2000);
	})
	$("#print").click(function(){
		$("#slidemenu").animate({left: "-40"}, 2000);
		$("#nav_hex_bkg").animate({left: "-40"}, 2000);
	})
	$("#web2").click(function(){
		$("#slidemenu").animate({left: "-40"}, 2000);
		$("#nav_hex_bkg").animate({left: "-40"}, 2000);
	})
	$("#development").click(function(){
		$("#slidemenu").animate({left: "-40"}, 2000);
		$("#nav_hex_bkg").animate({left: "-40"}, 2000);
	})
	$("#hosting").click(function(){
		$("#slidemenu").animate({left: "-40"}, 2000);
		$("#nav_hex_bkg").animate({left: "-40"}, 2000);
	})
});
$(window).resize(function() { 
	window.setTimeout('resizing();', 50);
});
var now = new Date();
function record(e){
	var t = $("#debug").html();
	var justNow = new Date();
	var secs = justNow - now;
	$("#debug").html(t + '<div style=\'width:240px;\'>' + e + ' - ' + secs + ' ' + '</div>');
}
