
var actualMenu;


$(document).ready(function(){
	$("#works, #philo, #about, #links").click(swapTab);
	$("#teaser").click(teaserClick);
	$("#blog").click(function(){window.location = "http://nuanceworkshop.tumblr.com/"});
	
	
	$('#y2007 a').lightBox({
		overlayBgColor: "#222222",
		overlayOpacity: 0.7
	});
	$('#y2008 a').lightBox({
		overlayBgColor: "#222222",
		overlayOpacity: 0.7
	});	
	
/*slider*/	
$(".handle").draggable({
	axis : "x",
	containment : "parent",
	drag : function(){
		//$("#philoSlide .items").css("left", Math.round(-1 * (645/520) * parseInt($(this).css("left"))))
		$("#philoSlide .items").css("top", Math.round(-1 * (600/520) * parseInt($(this).css("left"))))

	}
});
if($.browser.safari) $(".handle").css("left","1px");
if($.browser.msie) $(".handle").css("left","0px");




})
function handle(delta) {
	if(/philo/.test($(actualMenu).attr("id"))) {
		if (delta > 0) {		
			if( parseInt($(".handle").css("left")) >= 10 ) $(".handle").css("left", parseInt($(".handle").css("left")) - 10 + "px");
		}
		else 
			if( parseInt($(".handle").css("left")) <= 510 ) $(".handle").css("left", parseInt($(".handle").css("left")) + 10 + "px");
		
		$("#philoSlide .items").css("top", Math.round(-1 * (600/520) * parseInt($(".handle").css("left"))))
	}
}
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { 
                delta = -event.detail/3;
        }

       if (delta) handle(delta);
}
$(window).load(function(){
	$("#pleasewait").fadeOut();
	if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
	window.onmousewheel = document.onmousewheel = wheel;
})

function swapTab(){
	$(actualMenu).children("img").stop().attr("style","").fadeOut();
	$("#" + $(actualMenu).attr("id") + "Slide").fadeOut();
	var t = $(this);
	t.children("img").stop().fadeIn("slow",function(){$("#wrapper").focus();$(this).fadeOut("slow",function(){$("#wrapper").focus();$(this).fadeIn("slow",function(){$("#wrapper").focus();$(this).fadeOut("slow",function(){$("#wrapper").focus();$(this).fadeIn("slow");})})})});
	$("#" + t.attr("id") + "Slide").fadeIn("slow");
	actualMenu = t;

}

function teaserClick(){
	$("#teaser").fadeOut("fast");
	actualMenu = $("#works");
	
	$(actualMenu).children("img").fadeIn("normal");
	$("#" + $(actualMenu).attr("id") + "Slide").fadeIn("slow");
}
