// Load Project Image

	Cufon.set('fontFamily', 'Droid Sans').replace('#menu a',{hover:true})('h1')('h2')('.newslist a',{hover:true});

var slides= 0;
var projects = 0;
var currentProject = 2;
var prevProject = 0;
var fakeClick = false;



$(document).ready(function(){
		
		
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
		
		
		
		
		
		
		
		
		$.fn.hoverscroll.params = $.extend($.fn.hoverscroll.params, {
	vertical : true,
	width: 280,
	height: 433,
	arrows: true,
	arrowsOpacity:	1  ,
	moveIt:		true,
	moveItTo:	0
});

// Generate hoverscroll with overridden default parameters

function stopMoving(){
	
		myList[0].stopMoving();
	//	alert("stop");
}




$('.slideshow-loader').hide();


	var myList= $('#projectlist').hoverscroll();
	
	
	
	
	
		//amm of projects
		projects = $('#projectlist li').length;
		
		$('#projectlist li').click(function(){
		
			$("#next").unbind();
							
		
		
			prevProject = currentProject;
			currentProject = $(this).index();
			
			if(fakeClick){
				
				if(prevProject>currentProject){
					myList[0].startMoving(-1, 100);
			
					
				}else{
					myList[0].startMoving(1, 9);
					
					
				
					
				setTimeout(stopMoving, $($('#projectlist li').get(currentProject)).height()*7);
					
				}
			fakeClick=false;
				
			}
			
	
			
				
			$('#projectlist li').each(function(){
		
				$(this).removeClass('selected');
			})
			
			
				$(this).addClass('selected');
				url = basePath+"/ajax.php?action=loadproject";
				project =$(this).attr('id');
				
				
				Cufon.set('fontFamily', 'Droid Sans').replace(('h2'));
				
				
				//$("#slideshow").html("laden");
				$('.slideshow-loader').fadeIn(function(){
				
				
				$.post(url, { "project": project},
				 function(data){
					 
					
				//	$("#slideshow").css({'visibility':'hidden'});
				   $("#slideshow2").html(data);
						
				   
				   
						$('.slideshow-loader').fadeOut(function(){
									
							
							//	$("#slideshow").css({'visibility':'visible'});
												
							
							
					slides = $("#slideshow2 img").length;
			
				
							
							
								
					//alert(slides);
					
					
					//GEEN SLIDESHOWWW
					if(slides==1){
						
						
						$('#next').click(function(){
						$("#next").unbind();
						if(currentProject == (projects-1)){
								
								fakeClick=true;
								$($('#projectlist li').get(0)).click();
								
							//next
							}else{
								fakeClick=true;
								$($('#projectlist li').get(currentProject+1)).click();
								
								
							}
						})
							
							
					}else{
				
				
				
				
				 $('#slideshow2').cycle({ 
              fx:     'scrollHorz', 
					 startingSlide: 0,  // start on the slide that was in the markup 
					timeout:  0, 
					speed:    700,
					width:650, 
			
					next:    '#next',
					
					onPrevNextEvent: function(isNext, zeroBasedSlideIndex, slideElement){
						
						
						// Load next project
						if(zeroBasedSlideIndex == 0){
							
							
					$("#slideshow2").cycle('stop');
							
								$("#next").unbind();
							
							
							
							
							//first project
							if(currentProject == (projects-1)){
								
								fakeClick=true;
								$($('#projectlist li').get(0)).click();
								
							//next
							}else{
								fakeClick=true;
							
								$($('#projectlist li').get(currentProject+1)).click();
								
									
								//	$('.listcontainer').css({"margin-top":"-110px"});
									///alert("test");
									
								//$('#projectlist').css({"padding-top":"-110px"});
								
							}
							
							
							
							
							
						
							
						}
					
				
					}
                }); 		
							}	
							});	

						
								
					//$("#slideshow").show();			
							
							
				 }, "html");
				 
				
				
				
				});	
				
				
		
		
		})
		
		
		
			$($('#projectlist li').get(0)).click();
		
		
				
	$('#thumbContainer .toggle').click(function(){
		
		$('#thumbContainer .container').slideToggle();

		
	})
	
	
	$('.newsb').hide();
	
	$('#newsblock').hover(
		  function () {
			$('.newsb').fadeIn();
		  },
		  function () {
			$('.newsb').fadeOut();
		  }
		);

		
		
		
		
		
	
	
	
	$(".imageThumb").fancybox({
		'overlayShow'	:	true
	});
	
	
	/* Thumb images */
	$('#loading').hide();	
	
	
	/* news menu */
	
	
	

	/*
	$('.imageThumb').click(function(){
	 	$('#loading').show();	
	 	var imageLink = $(this).attr('image');
		
		$.ajax({
			url: basePath+'/ajax.php?action=template/pages/loadImage.php',
			data: 'img=' + imageLink, // the image url links up in our fake database
			dataType: 'html'
			
			,success: function (html) {
				// because we're inside of the success function, we must refer
				// to the image as 'img' (defined originally), rather than 'this'
				
				$('#projectImage').html(html);
				$('#loading').hide();	
				
				$("#single_image").fancybox({
					'overlayShow'	:	true
				});


				// now show the image
				//$(img).fadeIn();
			  }
			});
			
	})
	*/

})

