function checkKey(e){
	switch (e.keyCode) {
	case 37:
		jQuery("#browse .back").trigger("click");
        break;
    case 39:
		jQuery("#browse .next").trigger("click");
        break;
     }      
}

$(document).ready(function() {


if ($.browser.mozilla) {
    $(document).keypress (checkKey);
} else {
    $(document).keydown (checkKey);
}

  $("#bigPic").click(function (e) {
   $("#browse .next").trigger("click"); 
e.preventDefault();

} )
/*
var mn=new Array();
mn["portfolio"] = mn["portfoliofashion"] = "/assets/galleries/9/tn_portfolio_fashion_20.jpg";
mn ["portfoliopeople"] = "/assets/galleries/8/tn_portfolio_people_01_test.jpg";

mn["portrait"] = mn["portraitmusic"]  = mn["portraitcelebrity"] = "/assets/galleries/12/tn_portrait_celebrity_01_bvb_marcel_schmelzer.jpg";
mn["portraitbusiness"] =  "/assets/galleries/11/tn_portr_busin_01_koll_jesper_merrillynch01.jpg";
mn["portraitraramuri"]	 =	 "/assets/galleries/14/tn_project_raramuri_01.jpg";





mn["project"] = mn ["projectfootrunners"] = "/assets/galleries/15/tn_rara_01.jpg";
mn["projectfrancis_bacon"]  = "/assets/galleries/13/tn_project_bacon_01.jpg";
mn ["projectsierra_madre"] =	"/assets/galleries/16/tn_project_sierra_madre_01.jpg";

mn["published"] = "/assets/galleries/5/tn_published_01.jpg";
*/
mn["profile"] = "/assets/site/img/tn_profile.png";


$("a[@href^='mailto:']").append('<span class="arrow"><img src="assets/site/img/email.png" alt="" /></span>');

$(".pdflink").css("position" , "relative");
$(".pdflink").append ('<div class="pdfIcon">&nbsp;</div>');

		$('.pdflink').hover(function () {
			
			$(this).children().addClass("active");
					},
					
		function () {

			 $(this).children().removeClass("active");	
			}	
		);


		/*$("#suptitle").text($("#bigPic").attr("rel"));*/
$("#suptitle").text($("#subsubnav a:eq(0)").attr("rel"));

		$('#subsubnav a:first').addClass("active");
		$("#browse .next").attr({href: $("#subsubnav a:eq(1)").attr("href") , rel : $("#subsubnav a:eq(1)").attr("rel")});	
		$("#browse .back").attr({href: $("#subsubnav a:last").attr("href") , rel : $("#subsubnav a:last").attr("rel")});
				
//        var mn;
		var before = "";
		var subBefore = "";
		var supBefore = "";
		var keepThumb = $('#subsubnav a:first').attr("href");
		
		if (!keepThumb) 
        var keepThumb = $('#thumb img').attr("src") ;

		$("#colorParade li a").click(function() {
			$('#additional').attr('href','assets/site/css/' + $(this).attr('class') + '.css');
			$.cookie("css",$(this).attr('class'), {expires: 365, path: '/'});
			return false;
		});

		$('#subsubnav a, #browse a').click(function () {
			keepThumb = url = $(this).attr("href");
			 		
			posSlash = url.lastIndexOf("\/");
			tn_url = url.substring(0,posSlash) + "/tn_" + url.substring(posSlash+1);
			
			
			$('#thumb img').attr("src", tn_url);
			
			$('#subsubnav a').removeClass("active");
/***/
			$(this).addClass("active");
 $("#subsubnav a[href='" + url +"']").addClass("active");

/**/
			$("#suptitle").text("");
                   
			showPic(url);
            $("#suptitle").text($(this).attr("rel"));
            supBefore  = $(this).attr("rel");
            $("#bigPic").attr("alt" , $(this).attr("rel"));
			
			nextUrl = $("#subsubnav a[href='" + url +"']").parent().next().children(0).attr("href");
			nextTitle = $("#subsubnav a[href='" + url +"']").parent().next().children(0).attr("rel");
			backUrl = $("#subsubnav a[href='" + url +"']").parent().prev().children(0).attr("href");
			backTitle = $("#subsubnav a[href='" + url +"']").parent().prev().children(0).attr("rel");
			
			if (!nextUrl)
			{
			nextUrl = $("#subsubnav a:first").attr("href");
                    nextTitle =$("#subsubnav a:first").attr("rel");
              
			}
			
			if (!backUrl)
			{
			backUrl = $("#subsubnav a:last").attr("href");
			backTitle = $("#subsubnav a:last").attr("rel");

			}
			
			
$("#browse .next"). attr("href" , nextUrl);
$("#browse .next"). attr("rel" , nextTitle);
$("#browse .back"). attr("href" , backUrl);
$("#browse .back"). attr("rel" , backTitle);
		
			return false;
		});

		$('#mainnav a, #homenav a').hover(function () {
			before = $("#maincat").text();
            subBefore = $("#subcat").text();
			supBefore = $("#suptitle").text();
			$("#subcat, #suptitle").text("");
			$("#maincat").text($(this).attr("rel"));
			
$("#homenav a[rel='" + $(this).attr("rel") +"']").addClass("active");


			name = $(this).attr("href");
			
			
			name = (name.replace(/\//g , ""));
			
			
			
			$("#thumb img").attr("src" , mn[name] )
				
			
		},
		function () {
			$("#maincat").text(before);
			$("#subcat").text(subBefore);
			$("#suptitle").text( supBefore);
			
			   $("#homenav a").removeClass("active");


			

						if (keepThumb) 
			{ 
			
			
			posSlash = keepThumb.lastIndexOf("\/");
			tn_url = keepThumb.substring(0,posSlash) + "/tn_" + keepThumb.substring(posSlash+1);
		
			
			
			$("#thumb img").attr("src" , tn_url); }
			
			
			
			
		}
		);

		$('#subnav a').hover(function () {
			before = $("#subcat").text();
                        beforeSuptitle = $("#suptitle").text();
                       $("#suptitle").text("");
			$("#subcat").text($(this).attr("rel"));
			name = $(this).attr("href");
			
			name = (name.replace(/\//g , ""));
			
			$("#thumb img").attr("src" , mn[name] )
			},
			function () {
				$("#subcat").text(before);
  $("#suptitle").text(beforeSuptitle);
					if (keepThumb) 
			{ 
			
			
			posSlash = keepThumb.lastIndexOf("\/");
			tn_url = keepThumb.substring(0,posSlash) + "/tn_" + keepThumb.substring(posSlash+1);
		
			
			
			$("#thumb img").attr("src" , tn_url); }
			}
		);

		$('#subsubnav a , #browse a').hover(function () {
			url = $(this).attr("href");	
			supBefore = $("#suptitle").text();  /* einkommentieren*/
			$("#suptitle").text($(this).attr("rel"));  /* einkommentieren*/	
			posSlash = url.lastIndexOf("\/");
			tn_url = url.substring(0,posSlash) + "/tn_" + url.substring(posSlash+1);		
			$("#thumb img").attr("src" ,tn_url);
		},
		function () {

			if (keepThumb) 
			{ 
			posSlash = keepThumb.lastIndexOf("\/");
			tn_url = keepThumb.substring(0,posSlash) + "/tn_" + keepThumb.substring(posSlash+1);		
			$("#thumb img").attr("src" , tn_url); }
			else
			{
			//$("#suptitle").text("empty");
			}
			/*else
			{
			keepThumb = false;
			}*/
			
                     $("#suptitle").text(supBefore);   /* einkommentieren*/
			}	
		);
		
		
		
		
		/*h*/
		
		
		
		$('#footer a , a.imprint').hover(function () {
			
		$("#thumb img").attr("src" ,"assets/site/img/imprint.png");
//			$("#thumb img").attr("src" ,"assets/site/img/tn_imprint.gif");
		},
		function () {

			if (keepThumb) 
			{ 
			
			//$("#suptitle").text(keepThumb);
			posSlash = keepThumb.lastIndexOf("\/");
			tn_url = keepThumb.substring(0,posSlash) + "/tn_" + keepThumb.substring(posSlash+1);
			//alert(tn_url);
			
			
			$("#thumb img").attr("src" , tn_url); }

			}	
		);
	});


function showPic(url) {

  $("#bigPic").fadeOut("fast", function(){
      var image = new Image();
      $(image).load(function() {
        $(this).hide();	
        $("#bigPic").attr({src: url});
        $("#bigPic").fadeIn("fast");
      });
      $(image).attr({src: url});

  });
}

