mmove=0;
$(document).ready(function(){
	$('.menu a').click(function(){
		$('.menu').find('.submenu').each(function(){
			if($(this).css('display')=='block') {
				$(this).fadeOut(300);
				$(this).parent().children('a').removeClass('active');
			}
		});
		if($(this).parent().find('.submenu').length>0){
			if($(this).hasClass('active')){
				$(this).parent().find('.submenu').fadeOut(300);
				$(this).removeClass('active');
			} else {
				$(this).parent().find('.submenu').fadeIn(300);
				$(this).addClass('active');
			}
			return false;
		}
	});
	getGalleryWidth();
	$(window).resize(function(){getGalleryWidth();});
	$('.gallery .right').click(function(){
		if(mmove==0){
			mmove=1;
			$('.gallery .container li').first().clone().insertAfter($('.gallery .container li').last());
			ml=(0-$('.gallery .container ul').children('li').first().outerWidth())+'px';
			$('.gallery .container li').first().animate({'margin-left':ml}, 300, function(){
				$(this).remove();
				mmove=0;
			});
		}
	});
	$('.gallery .left').click(function(){
		if(mmove==0){
			mmove=1;
			ml=(0-$('.gallery .container ul').children('li').last().outerWidth())+'px';
			$('.gallery .container li').last().clone().css('margin-left', ml).insertBefore($('.gallery .container li').first()).animate(
				{'margin-left':0}, 300, function (){
					mmove=0;
					$('.gallery .container li').last().remove();
				}
			);
		}
	});
	$('.ask_question').click(function(){
		if($(this).hasClass('active')){
			$('.ask_question_block').css('display','none');
			$(this).removeClass('active');
		} else {
			$(this).addClass('active');
			$('.ask_question_block').css('display','block');
		}
		return false;
	});
});
function getGalleryWidth() {
	mw=0;
	for(i=0;i<$('.gallery .container li').length;i++) {
		mw+=$('.gallery .container li').eq(i).outerWidth();
	}
	if($('.gallery').width()<mw){
		$('.gallery .arrow').css('display','block');
		$('.gallery .container').css('margin','-1px 57px');
	} else {
		$('.gallery .arrow').css('display','none');
		$('.gallery .container').css('margin','-1px 0');
	}
}

