// JavaScript Document


$(document).ready(function()
{
    $(document.body).append('<div id="cover"></div>');
    $('.image_container img').imgpreload(function() { $("#cover").fadeOut("slow", function() {
    $("#nextfade").animate({opacity: 1.0}, 2000)
    $("#nextfade").fadeOut(1200);
  });});
    $('.gallery').append('<div id="nextfade" class="next"></div>');
    
$max_clicks = $("#image_container").children().size();
	/* Kudos to Rob MacKay [http://www.twitter.com/svgrob] for suggesting that we don't have to put a static style="width: 3960px" attribute in the div tag */
	$imgCont = $move_by * $max_clicks;

	$("#image_container").css({width : $imgCont});

	if($start_middle == 1)
		{
			// Get the middle frame, according to the $max_clicks
			$new_frame_no = ($max_clicks/2).toFixed(0)

			// Adjust the frame position
			$new_left = -($new_frame_no * $move_by);
			$new_left_attr = $new_left+"px";

			// Do the move
			$("#image_container").animate({left: $new_left_attr}, 800 );

			// Save the new values
			$frame_left = $new_left;
			$frame_no = ($new_frame_no/1 + 1);
		}

	$(".prev").click(function()
		{
			/* Set the new position & frame number */
			$new_frame_no = (($frame_no/1)-1);
			$new_left = (($frame_left/1) + $move_by);
			/* Check if we're moving too far over */
			if($new_frame_no <= 0)
				{
					/* Move the images all the way left, minus one frame */
					return none;
				}
			$new_left_attr = $new_left+"px";
			$("#image_container").animate({left: $new_left_attr}, 800 );
			$frame_left = $new_left;
			$frame_no = $new_frame_no;

		});
	$(".next").click(function()
		{
			/* Set the new position & frame number */
			$new_frame_no = (($frame_no/1)+1);
			$new_left = (($frame_left/1) - $move_by);
			/* Check if we're moving too far over */
			if($new_frame_no > $max_clicks)
				{
					/* Move all the way right, to the beginning*/
					$new_left = 0;
					$new_frame_no = 1;
				}
			$new_left_attr = $new_left+"px";
			$("#image_container").animate({left: $new_left_attr}, 800 );
			$frame_left = $new_left;
			$frame_no = $new_frame_no;
		});	


    $("#about h1 a").click(function() {
        $("#contact").animate({
            right: "0"
        }, 1200, "easeOutQuint");
        $(".phonecall").show();
        return false;
    });
    $("#contact").click(function() {
        $(this).stop().animate({
            right: "100%"
        }, 1200, "easeOutQuint");
    });
    $(".phonecall").click(function() {
        $(this).fadeOut("slow");
        return false;
    });


    $(".packed a.next").animate({opacity: 0}, 1);
    $(".packed a.prev").animate({opacity: 0}, 1);
    $(".packed ul.skills").animate({opacity: 0}, 1);
    $("a.infobutton").animate({opacity: 0}, 1);

    /*$(".packed").hover(function() {
        $(this).children(".info").stop().animate({top: "0"}, 500, "easeOutQuint");
            }, function() {
        $(this).children(".info").stop().animate({top: "445"}, 500, "easeOutQuint");
    });
*/

   


    $(".packed").hover(function() {

        $(this).children("a").stop().animate({opacity: 1}, 500, "easeOutQuint");
        $(this).children("ul").stop().animate({opacity: 1}, 500, "easeOutQuint");
      }, function() {
        $(this).children("a").stop().animate({opacity: 0}, 500, "easeOutQuint");
        $(this).children("ul").stop().animate({opacity: 0}, 500, "easeOutQuint");
    });


    $("a.infobutton").click(function() {
        $(this).parent().children(".info").animate({bottom: "0"}, 500, "easeOutQuint");
        return false;
    });
    $("div.info").click(function() {
        $(this).stop().animate({bottom: "445"}, 500, "easeOutQuint");
    });
});

