
$(document).ready(function(){ 
		var t=0;
		var pos=0;
		var n=0;
		var b=0;
		var li_num=$("#all_frames > li").length;
		var scroll=$("#all_frames > li:first").width();	
		var scrolled=$('#all_frames');

		b=setTimeout('$("#r_arr img").animate({"paddingLeft":20},100).animate({"paddingLeft":0},500)',500); 
		
		$('#r_arr, .opt').click(function() {
			
			clearTimeout(t);
			if(n==0) {
			$('a.first').attr('class','');
			$('#all_frames > li:eq(1)').clone().appendTo('#all_frames');
			$('#all_frames > li:eq('+(li_num-1)+')').clone(true).insertAfter('#all_frames > li:eq(0)').end();
			n=1;
			}
			
			if (pos == scroll*(li_num)  ) 
			{pos = scroll*2; scrolled.css({'left':'-'+pos/2 +'px'}).animate({'left':'-'+pos +'px'},500); }
			else {
			scrolled.animate({'left':'-'+(pos + scroll) +'px'},500);
			pos =pos + scroll;
			}
			t=setTimeout('$("#r_arr img").animate({"paddingLeft":10},200).animate({"paddingLeft":0},200)',500);
			return false;
		})

		$('#l_arr').click(function() {
			if (pos == scroll) {
			pos=li_num*scroll-scroll;
			scrolled.css({'left':'-'+(pos+scroll) +'px'}).animate({'left':'-'+pos +'px'},500);
			}
			else {
			scrolled.animate({'left':'-'+(pos - scroll) +'px'},500);
			pos =pos - scroll;
			}
			return false;
		});

		$('#opt, #pro, #ad').click(function() {
			if (n==0) {
				$('a.first').attr('class','');
				$('#all_frames > li:eq(1)').clone().appendTo('#all_frames');
				$('#all_frames > li:eq('+(li_num-1)+')').clone(true).insertAfter('#all_frames > li:eq(0)');
				n=1;
				return false;
			};
		});		
		
			$('#top_menu > li:eq(0) a').click(function() {
				if (n==1) {
				$('#r_arr, #l_arr').attr('class','first');
				$('#all_frames  > li:eq(1)').remove();
				$('#all_frames  > li:eq(5)').remove();
				pos=0;
				scrolled.animate({'left':'-'+pos +'px'},500);
				n=0;
				return false;
				};
				
			});	
		
		
		$('#opt').click(function() {
			pos=scroll;
			scrolled.animate({'left':'-'+pos +'px'},500);
			
		});	
		
		$('#pro').click(function() {
			pos=scroll*2;
			scrolled.animate({'left':'-'+pos +'px'},500);
			
		});	
		
		$('#ad').click(function() {
			pos=scroll*3;
			scrolled.animate({'left':'-'+pos +'px'},500);
		});		
		
		$('#opt, #pro, #ad, #r_arr, #l_arr').click(function()
		{
			if(pos==scroll || pos==4*scroll) {
				$('#opt').addClass('not_dashed');
				$('#pro, #ad').removeClass('not_dashed');
			}
			if(pos==2*scroll) {
				$('#pro').addClass('not_dashed');
				$('#opt, #ad').removeClass('not_dashed');
			}
			if(pos==3*scroll) {
				$('#ad').addClass('not_dashed');
				$('#pro, #opt').removeClass('not_dashed');
			}
			return false;
		});
		
		$('#all_frames  .dashed').click(function()
		{ 	
			$(this).next('.closed').slideToggle('fast');
			return false;
		});
		
		$('.step_to_open').click(function()
		{
			$(this).parent().parent().find('div.step_opened').slideToggle();
			return false;
		});
		
		$('#primer').fancyZoom({scaleImg: true});
    }); 


		

