// BOTTOM SCROLLER ARROW ACTIONS

var slide = true;
var slide_left=true;
var thumbwith = 115;
var thumbXItems = thumbwith*4;
var isanimating = false;
	
function goright() { 
			 	slide= false;  
				//alert($('#block ul li').eq(-6).html()); 
				$('#block ul li').eq(-1).clone().prependTo('#block ul');
				$('#block ul li').eq(-2).clone().prependTo('#block ul');
				$('#block ul li').eq(-3).clone().prependTo('#block ul');
				$('#block ul li').eq(-4).clone().prependTo('#block ul');
				
				$("#block").stop().css('left','-'+thumbXItems+'px').animate({left: '0px'},800, function(){
							$('#block ul li:last').remove();
							$('#block ul li:last').remove();
							$('#block ul li:last').remove();
							$('#block ul li:last').remove();
							
				});
				
				$('#blocktexts ul li').eq(-1).clone().prependTo('#blocktexts ul');
				$('#blocktexts ul li').eq(-2).clone().prependTo('#blocktexts ul');
				$('#blocktexts ul li').eq(-3).clone().prependTo('#blocktexts ul');
				$('#blocktexts ul li').eq(-4).clone().prependTo('#blocktexts ul');
				
				$("#blocktexts").stop().css('left','-'+thumbXItems+'px').animate({left: '0px'},800, function(){
							$('#blocktexts ul li:last').remove();
							$('#blocktexts ul li:last').remove();
							$('#blocktexts ul li:last').remove();
							$('#blocktexts ul li:last').remove();
							
				});
				
				$('#blockframe ul li').eq(-1).clone().prependTo('#blockframe ul');
				$('#blockframe ul li').eq(-2).clone().prependTo('#blockframe ul');
				$('#blockframe ul li').eq(-3).clone().prependTo('#blockframe ul');
				$('#blockframe ul li').eq(-4).clone().prependTo('#blockframe ul');
				
				$("#blockframe").stop().css('left','-'+thumbXItems+'px').animate({left: '0px'},800, function(){
							$('#blockframe ul li:last').remove();
							$('#blockframe ul li:last').remove();
							$('#blockframe ul li:last').remove();
							$('#blockframe ul li:last').remove();
							isanimating=false;
				});
				refreshProjects();
}

function goleft() {  
				slide= false;    
				$('#block ul li:first').clone().appendTo('#block ul');
				$('#block ul li:nth-child(2)').clone().appendTo('#block ul');
				$('#block ul li:nth-child(3)').clone().appendTo('#block ul');
				$('#block ul li:nth-child(4)').clone().appendTo('#block ul');
							   
				$("#block").stop().animate({left: '-'+thumbXItems+'px'},800, function(){
							$('#block ul li:first').remove();
							$('#block ul li:first').remove();
							$('#block ul li:first').remove();
							$('#block ul li:first').remove();
							$("#block").css('left','0px');
				});
				
				$('#blocktexts ul li:first').clone().appendTo('#blocktexts ul');
				$('#blocktexts ul li:nth-child(2)').clone().appendTo('#blocktexts ul');
				$('#blocktexts ul li:nth-child(3)').clone().appendTo('#blocktexts ul');
				$('#blocktexts ul li:nth-child(4)').clone().appendTo('#blocktexts ul');
							   
				$("#blocktexts").stop().animate({left: '-'+thumbXItems+'px'},800, function(){
							$('#blocktexts ul li:first').remove();
							$('#blocktexts ul li:first').remove();
							$('#blocktexts ul li:first').remove();
							$('#blocktexts ul li:first').remove();
							$("#blocktexts").css('left','0px');
				});
				
				$('#blockframe ul li:first').clone().appendTo('#blockframe ul');
				$('#blockframe ul li:nth-child(2)').clone().appendTo('#blockframe ul');
				$('#blockframe ul li:nth-child(3)').clone().appendTo('#blockframe ul');
				$('#blockframe ul li:nth-child(4)').clone().appendTo('#blockframe ul');
							   
				$("#blockframe").stop().animate({left: '-'+thumbXItems+'px'},800, function(){
							$('#blockframe ul li:first').remove();
							$('#blockframe ul li:first').remove();
							$('#blockframe ul li:first').remove();
							$('#blockframe ul li:first').remove();
							$("#blockframe").css('left','0px');
							isanimating=false;
				});
				refreshProjects();
}

function refreshProjects(){
		$("#blockframe ul li a").mouseover(function(){
			slide=false;
			$(".projdetails").stop(true,true).hide();
			$("#block").stop(true,true);
			$("#blockframe").stop(true,true);
			$("#blocktexts").stop(true,true);
			// flag left if last 3 
			// get number of shown pics
			
			var numpics = 8;
			var rightflag = numpics-3;
						
			var indexer = $(this).parent().index();
			var h5content = $(this).next().children().children().html();
			if (h5content!="null"){
				if (indexer >rightflag){
					$(this).next().css('background','url(/images/_home/proj_details2_rev.png)');
					$(this).next().css('margin-left','-45px');
					if (navigator.appVersion.indexOf("MSIE 7.") != -1){
						$(this).next().css('margin-left','-158px'); // ie7
					}
				}else{
					$(this).next().css('background','url(/images/_home/proj_details2.png)');
					$(this).next().css('margin-left','20px');
					if (navigator.appVersion.indexOf("MSIE 7.") != -1){
						$(this).next().css('margin-left','-93px');// ie7
					}
				}
				
				// show details div
				if (indexer<numpics){
				$(this).next().fadeIn();
				}
			
			}
			
		});
		
		$("#blockframe ul li img").mouseout(function(){			
			$(this).next().hide();			
		});
		
		$("#blockframe").mouseout(function(){
			$(".projdetails").hide();	
		});
		
		
	// white rollover	
	$("#blockframe ul li a").hover(function () {
		$(this).children().attr('src','/images/_home/thumb_over2.png');
	 },function () {
		$(this).children().attr('src','/images/_home/thumb_over.png');
	 }); 
		
}

$(document).ready(function() {
	// refreshprojects to show the labels from first screen
	refreshProjects();

	$("#arrow_left").click(function(){
			if (isanimating==false){
				isanimating=true;
				$("#block").stop();
				goright();
			}
		});
	$("#arrow_right").click(function(){
			if (isanimating==false){
				isanimating=true;
				$("#block").stop();
				goleft();
			}
		});
	
});



// SLIDE BOTTOM SCROLLER
var down_x = null;
var up_x = null;

$(document).ready(function(){
  $("#blockframe").bind('touchstart', function(e){
    down_x = e.originalEvent.touches[0].pageX;
  });
  $("#blockframe").bind('touchmove', function(e){
    e.preventDefault();
    up_x = e.originalEvent.touches[0].pageX;
	$(".projdetails").hide();	
  });
  $("#blockframe").bind('touchend', function(e){
	
    do_slide_bottom();
  });
  
});

function do_slide_bottom()
{
  if (down_x && up_x && (down_x - up_x) > 50)
    {	
			if (isanimating==false){
				isanimating=true;
				$("#block").stop();
				goleft();
			}
    }
    if (down_x && up_x && (up_x - down_x) > 50)
    {	
			if (isanimating==false){
				isanimating=true;
				$("#block").stop();
				goright();
			}
    }
	down_x = 0;
	up_x = 0;
}
