var current;

var fk_9_caption_big = new Image();
fk_9_caption_big.src = 'images/fk_9_caption_big.png';

var fk_9_plane_big = new Image();
fk_9_plane_big.src = 'images/fk_9_plane_big.png';

var bg9 = new Image();
bg9.src = 'images/bg9.jpg';

var fk_12_caption_big = new Image();
fk_12_caption_big.src = 'images/fk_12_caption_big.png';

var fk_12_plane_big = new Image();
fk_12_plane_big.src = 'images/fk_12_plane_big.png';

var bg12 = new Image();
bg12.src = 'images/bg12.jpg';

var fk_14_caption_big = new Image();
fk_14_caption_big.src = 'images/fk_14_caption_big.png';

var fk_14_plane_big = new Image();
fk_14_plane_big.src = 'images/fk_14_plane_big.png';

var bg14 = new Image();
bg14.src = 'images/bg14.jpg';



$(document).ready(function(){

	$('#fk_9_plane').hover(function(){
		$('#fk_9_plane img').animate({'width':'350px','marginLeft':'-12px','height':'158px','marginTop':'-6px'},200);
	},function(){
		$('#fk_9_plane img').animate({'width':'325px','marginLeft':'0px','height':'147px','marginTop':'0px'},200);
	})
	
	
	$('#fk_12_plane').hover(function(){
		$('#fk_12_plane img').animate({'width':'669px','marginLeft':'-12px','height':'285px','marginTop':'-6px'},200);
	},function(){
		$('#fk_12_plane img').animate({'width':'639px','marginLeft':'0px','height':'272px','marginTop':'0px'},200);
	})
	
	
	$('#fk_14_plane').hover(function(){
		$('#fk_14_plane img').animate({'width':'314px','marginLeft':'-12px','height':'125px','marginTop':'-6px'},200);
	},function(){
		$('#fk_14_plane img').animate({'width':'289px','marginLeft':'0px','height':'115px','marginTop':'0px'},200);
	})
	
	
	
	
	$('.pic_block').click(function(){
		var h = $(document).height();
		var pages = '';
		var i = 0;
		var descr = $(this).attr('title');
		var path = $(this).attr('href');
		
		
		var big = new Image();
		big.src = path;
		
		big.onload = function(){
			$('#popup img').attr('src',path);
			$('#popup').css({'margin':'-'+(big.height/2)-50+'px 0px 0px -'+(big.width/2)+'px'});
			
			$('#video_photo_block a').each(function(){
				i++;
				if($(this).attr('href')===path)
				{
					pages += '<a id="big_pic_'+i+'" style="color: #000; text-decoration: none;" href="'+$(this).attr('href')+'" title="'+$(this).attr('title')+'">'+i+'</a>';
					current = i;
				}
				else pages += '<a id="big_pic_'+i+'" href="'+$(this).attr('href')+'" title="'+$(this).attr('title')+'">'+i+'</a>';
			})
			
			$('#pages').html(pages);
			$('#pic_description').html(descr);
			
			$('#overlay').fadeIn(500,function(){
				$('#overlay').css({'opacity':'0.7','minHeight':h+'px'});
				$('#popup').fadeIn(500);
			})
		
		}
	
		return false;
	})
	
	
	$('#pages a').live('click',function(){
		var descr = $(this).attr('title');
		var path = $(this).attr('href');
		$('#pages a').css({'color':'#3366cc','text-decoration':'underline'});
		$(this).css({'color':'#000','text-decoration':'none'});
		
		current = parseInt($(this).text());
		
		$('#popup').animate({'opacity':'0'},500,function(){
		
			var big = new Image();
			big.src = path;
			
			big.onload = function(){
				$('#popup img').attr('src',path);
				$('#popup').css({'margin':'-'+(big.height/2)-50+'px 0px 0px -'+(big.width/2)+'px'});
				
				$('#pic_description').html(descr);
				
				$('#popup').animate({'opacity':'1'},500);
			}
		
		})
		
	
		return false;
	})
	
	
	$('#lightbox_right').click(function(){
		$('#big_pic_'+(current+1)).click();		
	});
	
	$('#lightbox_left').click(function(){
	$('#big_pic_'+(current-1)).click();		
	});
	
	
	$('#overlay,#closer').click(function(){
		$('#popup,#overlay').fadeOut(300);
	})
	
	
	
	
	
	
	
	
	$('#hide_all').click(function(){
		$('.ttx_block_content').hide();
		$('.ttx_block_head').css({'border-bottom-left-radius':'7px','-moz-border-bottom-left-radius':'7px','-webkit-border-bottom-left-radius':'7px','border-bottom-right-radius':'7px','-moz-border-bottom-right-radius':'7px','-webkit-border-bottom-right-radius':'7px'});
		$('.toggler').hide();
		$('.toggler2').show();
		
		return false;
	})
	
	$('#show_all').click(function(){
		$('.ttx_block_content').show();
		$('.ttx_block_head').css({'border-bottom-left-radius':'0px','-moz-border-bottom-left-radius':'0px','-webkit-border-bottom-left-radius':'0px','border-bottom-right-radius':'0px','-moz-border-bottom-right-radius':'0px','-webkit-border-bottom-right-radius':'0px'});
		$('.toggler2').hide();
		$('.toggler').show();
		
		return false;
	})
	
	
	
	$('.toggler').click(function(){
		$(this).parent().next('.ttx_block_content').hide();
		$(this).parent().css({'border-bottom-left-radius':'7px','-moz-border-bottom-left-radius':'7px','-webkit-border-bottom-left-radius':'7px','border-bottom-right-radius':'7px','-moz-border-bottom-right-radius':'7px','-webkit-border-bottom-right-radius':'7px'});
		$(this).hide();
		$(this).next('.toggler2').show();
		
		return false;
	})
	
	$('.toggler2').click(function(){
		$(this).parent().next('.ttx_block_content').show();
		$(this).parent().css({'border-bottom-left-radius':'0px','-moz-border-bottom-left-radius':'0px','-webkit-border-bottom-left-radius':'0px','border-bottom-right-radius':'0px','-moz-border-bottom-right-radius':'0px','-webkit-border-bottom-right-radius':'0px'});
		$(this).hide();
		$(this).prev('.toggler').show();
		
		return false;
	})
	
	
	
	
	$('#preview_fk_9').click(function(){
		$('#fk_caption_big').css('background','url("images/fk_9_caption_big.png") left top no-repeat');
		$('#fk_big').css('background','url("images/fk_9_plane_big.png") left top no-repeat');
		$('#planes_stuff').css('background','url("images/bg9.jpg") left top no-repeat');		
		$(this).addClass('preview_current');
		$('#preview_fk_12,#preview_fk_14').addClass('preview');
		$('#preview_fk_12,#preview_fk_14').removeClass('preview_current');
	})
	
	$('#preview_fk_12').click(function(){
		$('#fk_caption_big').css('background','url("images/fk_12_caption_big.png") left top no-repeat');
		$('#fk_big').css('background','url("images/fk_12_plane_big.png") left top no-repeat');
		$('#planes_stuff').css('background','url("images/bg12.jpg") left top no-repeat');	
		$(this).addClass('preview_current');
		$('#preview_fk_9,#preview_fk_14').addClass('preview');	
		$('#preview_fk_9,#preview_fk_14').removeClass('preview_current');		
	})
	
	$('#preview_fk_14').click(function(){
		$('#fk_caption_big').css('background','url("images/fk_14_caption_big.png") left top no-repeat');
		$('#fk_big').css('background','url("images/fk_14_plane_big.png") left top no-repeat');
		$('#planes_stuff').css('background','url("images/bg14.jpg") left top no-repeat');
		$(this).addClass('preview_current');
		$('#preview_fk_12,#preview_fk_9').addClass('preview');	
		$('#preview_fk_12,#preview_fk_9').removeClass('preview_current');		
	})
	

	$(document).pngFix();
})


$(document).keyup(function(event){
	if(event.keyCode==27)
	{
		$('#popup,#overlay').fadeOut(300);
	}
})
