var timer = null;
$i = 0;
$url = null;
$current = null;

$(document).ready(function() {
	// Old functions that would load an external page
	//$(".leftarea").load("home.php #left");
	//$(".rightcontent").load("home.php #right", startTime());
	
	$("#home").show();
	$current = "home";
	
	$(".comment:first").show();
	
	
	$(".navitem").mouseover( function() {
		$(this).addClass("navover");
	}).mouseout(function() {
		$(this).removeClass("navover");
	});

	$(".actionLink").mouseover( function() {
		$(this).addClass("actionLinkHover");
	}).mouseout(function() {
		$(this).removeClass("actionLinkHover");
	});
	
	$(".rate, .hours").keyup( function(event) {
		$arr = $(this).attr('id').split("_");
		$i = $arr[1];
		//alert($("#hours_" + $i).attr('value'));
		//alert($("#rate_" + $i).attr('value'));
		$sum = $("#hours_" + $i).attr('value') * $("#rate_" + $i).attr('value');
		
		$("#rowTotal_" + $i).html($sum.toFixed(2));
		$grand = 0;
		
		$(".total").each (function(index) {
			$grand += parseFloat($(this).html());
		});
		
		$("#grand").html($grand.toFixed(2));
	});
	
	
	$("a.new_window").click( function () {
		window.open(this.href);
		return false;
	}); 
	
	
	$(".doublefix").blur( function() {
		$f = parseFloat($(this).attr('value')).toFixed(2);
		//alert($f);
		$(this).attr('value', $f);
	});

	$(".doublefix").keypress( function(e) {
		if(e.keyCode == 13) {
			return false;
		}
	});
	
	$(".navitem").click( function() {
		
		$("#nav").find(".navitem").removeClass("navclick");
		$(this).addClass("navclick");
		clearTimeout(timer);
		$("#comments").html('');
		$($current).fadeOut("slow", function () {
			$($href).fadeIn("slow");
		});
		$current = $href;
		$i = 1;
		if($current == "home")
		{
			$(".comment").hide();
			$("#c1").show();
			timer = startTime();
		}
		
	});
	
	$(".payrollTable").hide();
	$(".payrollItem").click( function () {
		$next = $(this).next();
		$next.toggle();
		//alert($next.html());
		if($next.is(':visible')) {
			$(this).css('background-image', "url(/assets/img/arrowdown.png)");
		} else {
			$(this).css('background', "url('/assets/img/arrowright.png') no-repeat center left");
		}
	});
	
	$(".payrollItem, .showAllPayroll, .hideAllPayroll").hover( function () {
		$(this).css('cursor','pointer');
	});
	
	$(".showAllPayroll").click( function () {
		$(".payrollTable").show();
		$(".payrollItem").css('background-image', "url(/zelekignited/assets/img/arrowdown.png)");
	});
	
	$(".hideAllPayroll").click( function () {
		$(".payrollTable").hide();
		$(".payrollItem").css('background', "url('/zelekignited/assets/img/arrowright.png') no-repeat center left");
	});
	
	
	$('.quicknav li').each( function(i) {
		if(i%2 == 0) $(this).css('background-color','#DDD');
	});
	
	$('.quicknav li').hover( function () {
		$old = $(this).css('background-color');
		$(this).css('background-color','#CCC'); } ,
		function () {$(this).css('background-color',$old);
	});
	
	$('.servicecat > :not(h2)').css('margin-left' , '12px');
	
	/*$("#user_log").click( function() {
		if($.trim($("#email").value) == "" || $.trim($("#email").value) == "" )
		{
			alert("Please enter valid information");
			location.reload(); 
		}
	
	});*/
	
	$('.confirmAction').click( function () {
		var x = confirm('Would you like to proceed with this action');
		if(!x) return false;
	});

 });
 

function startTime()
{
	timer = setTimeout(nextcomment,6000);
	
	function nextcomment () {
		$(".comment:eq(" + $i + ")").fadeOut("slow", function () {
				if($i == ($('.comment').length-1) ) $i = 0;
				else $i++;
				//alert($i);
				$(".comment:eq(" + $i + ")").fadeIn("slow" );
			});
		
		timer = setTimeout(nextcomment,6000);
		
	}
}


$(window).load(function () {
  timer = startTime();
});


