

function navigateLeft() {

var act_width = $('.current').width();
		
		var next_scroll = 0;//$('.current').width();
		
		if ($.browser.msie && $.browser.version.substr(0,1)<9) {
			var act_scroll = $('body,html').scrollLeft();
		} else {
			var act_scroll = window.pageXOffset;
		}
		
		//alert(act_scroll);
		
		var pic_stream = 1;
		
		
		$(".pix").children('img').each(function() {
			pic_stream += $(this).width() + 10;
			//alert((pic_stream) );
			//alert((act_scroll) );
			//alert("NS:" + next_scroll + " AS:" + act_scroll + " PS:" + pic_stream);
			if (act_scroll <= pic_stream + 10) {
				//alert('hallo');
				
					//next_scroll = next_scroll;
					next_scroll = pic_stream - $(this).width() - 10;
					
					
				
				return false;
			}
		});
		
		if (next_scroll == 30) {
			
			next_scroll = 0;
			$('html,body').animate({scrollLeft: next_scroll + 'px'}, 400); 
		} else {
		
		
		
		
		$('.current').removeClass('current').prev().addClass('current');
		
		//$('.pix').children('.current').removeClass('current').next().addClass('current');
		
		//$('html,body').scrollTo('+=800px', 300 );
		$('html,body').animate({scrollLeft: next_scroll + 'px'}, 500, 'easeOutExpo'); 
		}

}


function navigateRight() {
	var next_scroll = 0;//$('.current').width();
		
		
		
		if ($.browser.msie && $.browser.version.substr(0,1)<9) {
			var act_scroll = $('body,html').scrollLeft();
		} else {
			var act_scroll = window.pageXOffset;
		}
			
		
		var pic_stream = 00;
		//alert(act_scroll);
		
		$(".pix").children('img').each(function() {
		
			pic_stream += $(this).width() + 10;
			//alert($(this).offset().left);
			//alert((act_scroll) );
			if (act_scroll <= pic_stream) {
					next_scroll += pic_stream + 1;
					
				
				return false;
			}
		});
		
		
		//next_scroll = next_scroll + 250;
		
		
		$('.current').removeClass('current').next().addClass('current');
		
		//$('.pix').children('.current').removeClass('current').next().addClass('current');
		
		//$('html,body').scrollTo('+=800px', 300 );
		$('html,body').animate({scrollLeft: next_scroll + 'px'}, 500, 'easeOutExpo'); 
}

function initiateTooltips() {
	var wList = [];
	var i = 0;
	var overall = 0;
	$(".pix").children('img').each(function() {
		wList.push($(this).width());
		/*Üvar target = $(".p_label:eq("+i+")");
		$(this).hoverIntent(function(){
			target.fadeIn();
		}, function() {
			target.fadeOut();
		});*/
		i += 1;
	});
	//alert(wList);
	i = 0;
	$(".pix").children('div').each(function() {
		
		//alert(overall);
		if ( i == 0) {
			
			$(this).css('left', '11px');
			overall = overall + wList[i] + 21;	
			i = i + 1;
		} else {
			$(this).css('left', overall);
			//alert(((wList[i-1]-200)/2));
			i = i + 1;
			overall += wList[i-1] + 10;
			//overall += 200 + ((wList[i-1]-200)/2) + 11;
			
		}
		
	});
	/*$.each(wList, function() {
		//alert($(".p_label").text);
	});*/
}


function changeCurrentMenu(number) {
	var i = 0;
	$('#menu ul li').each(function() {
    	if (i == (number - 1)) {
    		$(this).addClass('current_page');
    	} else {
    		$(this).removeClass('current_page');
    	}
    	i += 1;
	});

}


function hideInfo() {
	$('#information_toggler').hide();
}


$(document).ready(function(){

	



	$('#the_toggler').click(function()  {
		if($(this).html() == "off") {
			initiateTooltips();
			$(this).html("on");
			$(".pix").children('div').each(function() {
				$(this).fadeIn('slow');
			});
		}
		else if($(this).html() == "on") {
			$(this).html("off");
			$(".pix").children('div').each(function() {
				$(this).fadeOut('slow');
			});
		}
		
	});

	$(document).keydown(function(e){
    if (e.keyCode == 39) { 
       navigateRight();
       return false;
    }
    if (e.keyCode == 37) { 
       navigateLeft();
       return false;
    }
     if (e.keyCode == 73) { 
      if($('#the_toggler').html() == "off") {
			initiateTooltips();
			$('#the_toggler').html("on");
			$(".pix").children('div').each(function() {
				$(this).fadeIn('slow');
			});
		}
		else if($('#the_toggler').html() == "on") {
			$('#the_toggler').html("off");
			$(".pix").children('div').each(function() {
				$(this).fadeOut('slow');
			});
		}
       return false;
    }
    if (e.keyCode == 38) { 
       $('html,body').animate({scrollLeft: '0px'}, 1000, 'easeOutExpo');
       return false;
    }
});
	

	$('#scrollerRight').qtip({
     content: '<img src="http://bastisteiner.com/images/nright.png" alt=">"/>',
      position: {
         my: 'left center',
         target: 'mouse',
         viewport: $(window), // Keep it on-screen at all times if possible
         adjust: {
            x: 10,  y: 10
         }
      },
      hide: {
         fixed: true // Helps to prevent the tooltip from hiding ocassionally when tracking!
      },
      style: 'ui-tooltip-shadow'
 
   });
   
   $('#scrollerLeft').qtip({
     content: '<img src="http://bastisteiner.com/images/nleft.png" alt=">"/>',
      position: {
         my: 'right center',
         target: 'mouse',
         viewport: $(window), // Keep it on-screen at all times if possible
         adjust: {
            x: 0,  y: 10
         }
      },
      hide: {
         fixed: true // Helps to prevent the tooltip from hiding ocassionally when tracking!
      },
      style: 'ui-tooltip-shadow'
 
   });

	 
	
	//HOVER STUFF - MOSTLY FADE FX

	//$("#menu li").corner('30px');

	
	$("#menu li").hover(function(){
		
		if($(this).hasClass("current_page") != true) {
		$(this).animate({
			backgroundColor: "#f4f4f4"
		}, 310); 
		$(this).children().animate({
			color: '#a2a2a2'
		}, 210);
		}
		},
		function() {
			if($(this).hasClass("current_page") != true) {
				$(this).animate({
					backgroundColor: "#fff"
				}, 310);
				$(this).children().animate({color: '#a2a2a2'}, 310);

			} else {
				$(this).animate({
					backgroundColor: "#dedee0"
				}, 310);
			}
	});
	
	
	
	
	
	//END HOOVER STUFF
	
	
	$('#bck_btn').click(function()  {
		$('html,body').animate({scrollLeft: '0px'}, 1000, 'easeOutExpo');
	});
	
	$('#back_img').click(function()  {
		$('html,body').animate({scrollLeft: '0px'}, 1000, 'easeOutExpo');
	});

	
	
	$('#left_btn').click(function()  {
		navigateLeft();
	});
	
	$('#right_btn').click(function()  {
		navigateRight();
	});

	
	
	
	
	
	
	
	$("#scrollerRight").mousedown(function() {
		navigateRight();
	});
	
	$("#scrollerLeft").mousedown(function() {
		navigateLeft();
	});
	

});




