$(document).ready(function(){
	startGraph();
	
	$("#newsletter .email").focus(function(){
		if ($(this).val() == 'Your Email Address') {
			$(this).val("");
		}
	});
	
	$("#newsletter form").submit(function(){
		if ($("#newsletter .email").val() != 'Your Email Address') {
			$.get('http://www.avertismedia.com/newsletter-signup.php?email=' + $("#newsletter .email").val());
			$("#newsletter .begin").hide();
			$("#newsletter .finish").show();
		}
		return false;
	});

	$("#nav ul.main li.button a").click(function(){
		if (!$(this).parent("li").next("li").is(".subnav")) {
			return true;
		}
		if (!$(this).is(".on")) {
			$("#nav ul.main li.button a").removeClass("on");
			$("#nav .subnav").slideUp("fast");
			$(this).addClass("on").parent("li").next("li").slideDown("normal");
		}
		else {
			$("#nav ul.main li.button a").removeClass("on");
			$("#nav .subnav").slideUp("fast");
		}
		return false;
	});
	
	if ($(".contact #heardabout, .website-review #heardabout").attr('value') != 'Other (specify)') {
		$(".contact #heardabout2,  .website-review #heardabout2").hide();
	}
	$(".contact #heardabout, .website-review #heardabout").change(function(){
		if ($(".contact #heardabout, .website-review #heardabout").attr('value') == 'Other (specify)') {
			$(".contact #heardabout2, .website-review #heardabout2").show();
		}
		else {
			$(".contact #heardabout2, .website-review #heardabout2").hide();
		}
	});
	
	var urls = [ 'checkbox1', 'checkbox2'  ];
	$.preload( urls, {
		base:'http://www.avertismedia.com/images/',
		ext:'.png',
		onComplete:function( data ){
			var img = new Image();
			img.src = data.image;
		},
		onFinish:function(){
			
		}
	});
	
	var urls = [ 'about_hover', 'about_active', 'solutions_hover', 'solutions_active', 'clients_hover', 'clients_active', 'contact_hover', 'contact_active' ];
	$.preload( urls, {
		base:'http://www.avertismedia.com/images/buttons/',
		ext:'.png',
		onComplete:function( data ){
			var img = new Image();
			img.src = data.image;
		},
		onFinish:function(){
			
		}
	});
});

var check_count = 0;

function restartGraph() {
	$(".main #list ul li").removeClass("checked").find("div").css("width", "5px").css("height", 0);
	$(".main #graph .grid").css("width", "240px").css("height", "205px");
	$(".main .bar").css("height", 0);
	check_count = 0;
	startGraph();
}

function startGraph() {
	check();
	//$(".main #list ul li:first").addClass("checked").next().addClass("checked");
	$(".main #graph .grid").animate({width:"55px",height:"70px"},3300).animate({height:0},500);
	//$("#graph .grid").hide();
	//$("#graph .line").animate({opacity: 1.0}, 4000).animate({height:"270px"},1000).parent().animate({opacity: 1.0}, 4000).animate({height:"250px"},1000).parent().animate({opacity: 1.0}, 4800).animate({height:"235px"},1000).parent().animate({opacity: 1.0}, 5600).animate({height:"220px"},1000);
	$(".main #graph .bar1").animate({height:"30px"}, 4000)
	.next().animate({height:"42px"}, 4000)
	.next().animate({height:"50px"}, 4000)
	.next().animate({height:"60px"}, 4000)
	.next().animate({height:"65px"}, 4000)
	.next().animate({height:"75px"}, 4000)
	.next().animate({height:"95px"}, 4000)
	.next().animate({height:"110px"}, 4000)
	.next().animate({height:"125px"}, 4000)
	.next().animate({height:"160px"}, 4000);
}

function expose(section) {
	$("#nav ." + section + " a").addClass("on").parent("li").next("li").show();/*slideDown("normal")*/
}

function check() {
	//check_count++;
	//$(".main #list ul li:not(.checked):first").addClass("checked").css("backgroundImage", "url(images/checkbox2_" + check_count + ".gif)");
	$(".main #list ul li:not(.checked):first").addClass("checked").find("div").animate({height:"25px"}, 500).animate({width:"30px"}, 500);
	setTimeout("check();",675);
}

function rand(min, max) {
	if(max) {
		return Math.floor(Math.random() * (max - min + 1)) + min;
	}
	else {
		return Math.floor(Math.random() * (min + 1));
	}
}