var x = 0;
var curPage = 0;  
var thumbWidth = 	160;  
var thumbsVis = 2;

$(document).ready(function() {
  
  $(".sub").hide();
  $("#main-mask").addClass("js");
  //Get OS
  var os = navigator.platform;
  if(os.toLowerCase().search("mac") > -1) {
    $("body").addClass("mac");
  }
  
  //Side scrolling
	$(".jump").click(function() {
	  attrHref = $(this).attr("href");
	  if (attrHref == "#main") { goLeft = 0; } else { goLeft = -3000; }
    $(attrHref).show();
    if($("#jobs").attr("class") == "open") {
      $("#jobs").slideToggle({ duration: 1000, easing: "expoinout" });
      $("#jobs").toggleClass("open");
    }
    $("#main-scroll").animate({ left: goLeft }, 2000, "expoinout", function(){
      //callback animation is done
      if (goLeft == 0) { 
        $(".sub").hide();
        $("#jobs-inner").css({ left: 100 });
      }
    });
		return false;
	});
	
	//Job slide down
	$(".jobs-slide, #close, #main-list a").click(function() {
	  if($(this).attr("rel") == "sub") {
	    $("#jobs-inner").css({ left: 3100 });
	  }
	  $("#jobs").toggleClass("open");
	  $("#jobs").slideToggle({ duration: 1000, easing: "expoinout" });
	  return false;
	});
	
	//Job load
	$("#jobs-list a, #main-list a").click(function(){
	  $("#jobs-list a[@class=cur]").removeClass("cur");
  	$(this).addClass("cur");
    $("#jobs-content").load("jobs/"+$(this).attr("rel")+".html");
    $("#jobs-content").slideDown(500);
    return false;
	});
	
	//Work popup
	$("#work-scroll a, .pop, #design-shots a").click(function() {
	  window.open($(this).attr("href"), "newWin");
	  return false;
	});
	
  //Work Scroller
	var numThumbs = $("#work-scroll img").length;
	
	$("#next").click(function() { 
		updateOffset(1,numThumbs);
		$("#work-scroll").animate({ left: x }, 1000, "expoinout");	
		return false;
	});
	$("#prev").click(function() { 
		updateOffset(0,numThumbs);
		$("#work-scroll").animate({ left: x }, 1000, "expoinout");
		return false;
	});	
	
});// end doc ready


function updateOffset(next,thumbs) {
	if(next == 1) {
		if (x == (0 - ((thumbs - thumbsVis) * thumbWidth))) {
			x = 0;
		} else {
			x = x - (thumbWidth*thumbsVis);
		}
	}
	if(x <= 0 && next != 1) {
		if (x == 0) {
			x = (0 - ((thumbs - thumbsVis) * thumbWidth));
		} else {
			x = x + (thumbWidth*thumbsVis);
		}
	}
	
}// end updateOffset