var scrollactive = 0 ;
var move = 0 ;
var curimageheight = 1;
function scrolll () {};
$(document).ready(function(){
	setInterval(scrolll,100);	
	resizemenu ();

	/*$('.tarr').hover(
		function(){ move = '-=15px';scrollactive = '1';	},
		function(){	scrollactive = '0';	}
	);
	
	$('.darr').hover(
		function(){	move = '+=15px';scrollactive = '1';	},
		function(){	scrollactive = '0';	}
	);*/	

	/*$('.darr, .tarr').click(function(){return false});*/
	$('.header .contacts .work a').click(function(){
		$('.textext ').load('/work/', function() {
		  $('.mainimage').hide();
		  $('.image').hide();
		  $('.textext').show();
		  
		});
		return false;
	});

	
	$('.tarr').click(function(){
		
		if ($('.menu li.object.active').length){
			if ($('.menu li.object.active').prev().is('li')){
				$('.menu li.object.active').prev().find('.title').click();
			} else {
				if ($('.menu li.object.active').parents('.year').is(':first-child')){
					$('.scroll .year:last-child').find('.menu li.object:last-child').find('.title').click();
					
				} else {
					$('.menu li.object.active').parents('.year').prev().find('.menu li.object:last-child').find('.title').click();
					}
			}
			$('.case .sidebar .scroll-wrap').scrollTo($('.menu li.object.active'),150,{axis:'y'})
			
		} else {
			$('.scroll .year:first-child').find('.menu li.object:first-child').find('.title').click();
		}
		return false;
	});
	$('.darr').click(function(){
		if ($('.menu li.object.active').length){
		if ($('.menu li.object.active').next().is('li')){
			$('.menu li.object.active').next().find('.title').click();
		} else {
			if ($('.menu li.object.active').parents('.year').is(':last-child')){
				$('.scroll .year:first-child').find('.menu li.object:first-child').find('.title').click();
				
			} else {
				$('.menu li.object.active').parents('.year').next().find('.menu li.object:first-child').find('.title').click();
				}
		}
		//$('.case .sidebar .scroll-wrap').scrollTo($('.menu li.object.active'),100,{axis:'y'})
				
		} else {
			$('.scroll .year:first-child').find('.menu li.object:first-child').find('.title').click();
		}
		return false;
	});
	
	$('.menu li.object.active .body').show();
	$('.menu li.object .head .title').click(function(){
		$('.mainimage').hide();
		$('.image:hidden').show();
		$('.textext:visible').hide();
		
		$('.menu li.object').not($(this).parents('.object')).removeClass('active');
		$('.menu li.object .body:visible').not($(this).parents('.object').find('.body')).slideUp();
		$(this).parents('.object').addClass('active');
		$(this).parents('.object').find('.body').slideDown();
		
		
		var thisimageCount = $(this).parents('.object').find('.imagelinks p').length
		var thisimage = new Array()

		for(var i=1; i<thisimageCount+1; i++) {
			thisimage[i] = $(this).parents('.object').find('.imagelinks p:nth-child('+i+')').html()
			//alert(i + thisimage[i]);
		}

		var thiscat = $(this).parents('.object').find('.cat').html()
		
		show(thiscat,thisimage);
	
		return false;
	});
	function show(thiscat,thisimage) {
		$('.content .image').hide();
		$('.content .preloader').show();
		
		$('.objectishe img').attr('src', thisimage[1]).load(function() {
			$('.content .preloader').hide();
			$('.content .image').show();
			curimageheight = $(this).height()
			//alert(curimageheight);
			if (thiscat == 4){
				$('.content .image').html('');
				for(var i=1; i<thisimage.length; i++) {
					$('.content .image').html($('.content .image').html()+'<div class="single"><div class="bt">&nbsp;</div><div class="imagecontent"><img src="'+thisimage[i]+'" /></div><div class="bd">&nbsp;</div></div>');
				}
				resizemenu ();
				$('.case .imagecontent').jScrollPane({showArrows: true,	autoReinitialise: true, verticalArrowPositions: 'after' });}
			else {
				$('.content .image').html('');
				for(var i=1; i<thisimage.length; i++) {
					$('.content .image').html($('.content .image').html()+'<div class="single"><img src="'+thisimage[i]+'" /></div>');
				}
				resizemenu ();			
			}
			$('.objectishe img').attr('src','').unbind();
			$('.case .content .buttons').html('');
			if (thisimage.length>2)	{
				for(var i=1; i<thisimage.length; i++) {	
					$('.single:nth-child('+(i*1+1)+')').hide();
					$('.case .content .buttons').html($('.case .content .buttons').html()+'<a href="#" rel="'+i+'" class="btn">'+i+'</a> ');
				$('.buttons a').click(function(){
					$('.buttons a').removeClass('active');
					$(this).addClass('active');
					$('.single:visible').fadeOut();
					var active = $(this).attr('rel')
					$('.single:nth-child('+active+')').fadeIn();
					resizemenu ();
				})
				}
			}			
		});	
		

		return false;
		
	}	
	function resizemenu (){
		sHeight = $(window).height();
		if (sHeight < 720){ sHeight = 720 }
		//$('.email').text(sHeight);
		$('.case').css('height',sHeight-150);
		$('.case .content, .case .image, .case .single').css('height',sHeight-270);
		if (curimageheight<sHeight-320){
			$('.case .imagecontent').css('height',curimageheight);
		} else {
			$('.case .imagecontent').css('height',sHeight-320);			
		}
		//$('.case .imagecontent').css('height',sHeight-320);		
		$('.case .sidebar').css('height',sHeight-280);
		$('.case .scroll-wrap').css('height',sHeight-300);}

	$(window).resize(function() {
		resizemenu ();
		
	});
	function scrolll () {
		
		if (scrollactive != 0 ){
			$('.case .sidebar .scroll-wrap').scrollTo(move, 40,  {axis:'y'})
		}	
		//$('.email').text(move+' + '+ scrollactive);
		
	}	
});
	

