// Developed by Christopher Amirian

$(document).ready(function() {

 /*=====================================  Cursors =====================================*/
 
	$("html").css("cursor","url('images/BWait.ani'), progress");
	
	setTimeout(function(){
		$("#dude").animate({
			bottom: "0"
		}, 500);

		if ($("li#home a").attr("class") == "current")
		{
			setTimeout(function(){
				$("#dude").trigger("mouseenter");
			}, 800);
		}
		
		$("#dude").sprite({fps: 2, no_of_frames: 2});
		
	}, 3000)


 /*=====================================  Header Animations =====================================*/
 
	$("#robot, #robot1").sprite({fps: 8, no_of_frames: 10});  //Robot Animation
	$("#bubble").pan({fps: 30, speed: 2, dir: 'left'});	  //Bubble Animation
	$("body").pan({fps: 30, speed: 0.4, dir: 'left'});	  //Stars Animation
	$("#button, #contactsubmit").sprite({fps: 3, no_of_frames: 3});  //Button Animation		

 /*=====================================  Prevent Context Menu =====================================*/

	$(this).bind("contextmenu", function(event){
		event.preventDefault();
	})

 /*=====================================  Safari Fix =====================================*/

	if ($.browser.safari)
	{
 		$("#text h1").first().css("padding-top","32px");
		$("#text p").first().css("margin-bottom","8px");
 	}
	
 /*=====================================  IE7 Fix =====================================*/

 if ($.browser.msie && $.browser.version < 8)
	{
		$("#main").next().css("margin-top","45px");
		$("#contactsubmit").parents("#content").next().next().css("position","relative").css("top","40px");		
		
	}
 /*=====================================  Company Profile Hover State =====================================*/
	
	setInterval(function()
	{	
		$("#profilethumb").animate({marginLeft: "-4px"}, 200)
									.animate({marginLeft: "0px"}, 200)
									.animate({marginLeft: "-4px"}, 200)
									.animate({marginLeft: "0px"}, 200)
									.sprite({fps: 6, no_of_frames: 6, play_frames:6});
	}, 4000);
						
	setInterval(function()
	{	
		$("#aecthumb").animate({marginLeft: "-4px"}, 200)
									.animate({marginLeft: "0px"}, 200)
									.animate({marginLeft: "-4px"}, 200)
									.animate({marginLeft: "0px"}, 200)
									.sprite({fps: 6, no_of_frames: 6, play_frames:6});
	}, 4100);
						
/*=====================================  Products Cycle =====================================*/

	$("#rightarrow").bind("click", righthandler);

	$("#leftarrow").click(lefthandler);

	function righthandler()
	{	
 		if ($("#RM").css("left") != "63px")
		{
			$("#rightarrow").unbind("click", righthandler);
			$('#productrotator div').css("backgroundPosition","-250px 0");
			$('#productrotator div').animate({left: "-=654"},1000);
			setTimeout(function(){
									$("#rightarrow").bind("click", righthandler)
									$('#productrotator div').css("backgroundPosition","0 0");								
								}, 1000);						
		}
		else 
		{
			return false;
		}
	
	}
	
	function lefthandler()
	{
 		if ($("#EA860").css("left") != "390px")
		{
			$("#leftarrow").unbind("click");
			$('#productrotator div').css("backgroundPosition","-250px 0");
			$('#productrotator div').animate({left: "+=654"},1000);	
			setTimeout(function(){
								$("#leftarrow").bind("click", lefthandler)
								$('#productrotator div').css("backgroundPosition","0 0");																
								}, 1000);						
		}
		else
		{
			return false;
		}
	}
	
/*=====================================  Products Sandbox =====================================*/

	$("#sandbox, #alert").css("opacity","0");
	
	$('#productrotator div').bind("click", function(){
					$("#alert a").attr("href","pdf/" + $(this).attr("id") + ".pdf");
					$("#alert img").not("#alert img#power").attr("src","images/" + $(this).attr("id") + "big.jpg")
					$("#sandbox, #alert").css("display","block");
					$("#sandbox").animate({opacity: 0.7}, 300);
					setTimeout(function(){$("#alert").animate({opacity: 1}, 600);}, 300);
								
	});
	
	$("#sandbox, #alert img#power").bind("click", function(){
					$("#sandbox, #alert").animate({opacity: 0}, 300, function(){$(this).css("display","none")});
	});

/*=====================================  Dude Animation =====================================*/


 	$(window).load(function(){
		$("html").css("cursor","url('images/BoltArrow.ani'), url('images/BiBNormal.cur'), auto");
		
		setInterval(function(){$("#dude").effect("bounce", {}, 300)}, 5000);
	});

 
 
	$("#dude").hover(dudehoverhandler);

	function dudehoverhandler(){
		$("#dude").unbind("mouseenter mouseleave");

 		$("#comic").show("fold", {horizFirst: true}, 500).css("opacity","0.9");
 		
	}
	
	$("#comic").click(comicclickhandler);
	
	function comicclickhandler(){
		$("#comic").unbind("click");
		$("#dude").bind("mouseenter mouseleave", dudehoverhandler)
 

		$("#comic").hide(400);
 
		setTimeout(function(){
			$("#comic").bind("click", comicclickhandler);
		}, 400);		
	}

/*=====================================  Services Animation =====================================*/

	setInterval(function()
	{
		$(".servicescontent img#firstimg").animate(
											{
												marginTop: "105px"
											}, 200,
											function()
											{
												$(this).animate(
														{
															marginTop: "28px"
														}, 1000)
											});
	}, 5500);

/*=====================================  Form Submit =====================================*/

	$("#contactsubmit").click(function(){
		var name = $("form input#contactname").val();
		var company = $("form input#contactcompany").val();
		var phone = $("form input#contactphone").val();
		var mail = $("form input#contactemail").val();
		var comment = $("form textarea#contactcomment").val();
		var datastring = "contactname=" + name + "&contactcompany=" + company + "&contactphone=" + phone + "&contactemail=" + mail + "&contactcomment=" + comment;
		
		if(name == "") 
		{
			alert("Please enter a Name");
		} else if (mail == "")
		{
			alert("Please enter your Email");
		} else if (mail.search("@") == -1)
		{
			alert("Please enter a valid Email");
		} else
		{
			$("#sandbox").css("display","block");
			$("#sandbox").animate({opacity: 0.7}, 300);
			$.ajax({
			type: "POST",
			url: "process.php",
			data: datastring,
			success:function(html)
				{
					$("#sandbox").append(html);
				}
			});	
		}
		return false;
	});
});
 
  
 

 
 
 
 
 
 
 
 
 
