$(document).ready(function(){	var ind = location.href.indexOf('#');
	var l;
	if (ind != -1){
		l = location.href.substring(ind+1);
	}
	if (l && l=='order'){
		$('div.form').show();
		$('div.bg').css('height',$(document.body).height());
	}

	if (l && l=='feedback'){
		$('div.feedback').show();
		$('div.bg').css('height',$(document.body).height());
	}


	if (l!='' && $('a#'+l).length){		var fpos = $('a#'+l).offset().top;
		$('html,body').scrollTop(fpos);
		$('div.menu').css('top',fpos);

		var ali = $('div.menu a[href=#'+l+']').parent().addClass('active');
		$('div.menu ul').css('top', ($('div.menu ul li').index(ali)+1)*(-1)*ali.height());	}else{
		var ind = $('div.menu li:eq(0) a').attr('href').indexOf('#');
		var l = $('div.menu li:eq(0) a').attr('href').substring(ind+1);
		var fpos = $('a#'+l).offset().top;
		$('div.menu').css('top',fpos);
		$('div.menu li:eq(0)').addClass('active');
		$('div.menu ul').css('top', (-1)*$('div.menu li:eq(0)').height());
	}


	$('a[href=#order]').click(function(){
		$('div.form').show();
		$('html,body').animate({scrollTop: 0},500);
		$('div.bg').css('height',$(document.body).height());
	});
	$('div.bg').click(function(){
		$(this).parent().hide();
		location.href='#';
	});
	$('div.close').click(function(){
		$(this).parent().parent().hide();
		location.href='#';
	});

	$('a[href=#feedback]').click(function(){
		$('div.feedback').show();
		$('html,body').animate({scrollTop: 0},500);
		$('div.bg').css('height',$(document.body).height());
	});
	$('div.feedback div.bg').click(function(){
		$(this).parent().hide();
	});

	$('div.menu a').click(function(){		var ind = this.href.indexOf('#');
		var l = this.href.substring(ind+1);
		var fpos = $('a#'+l).offset().top;

		$('div.menu ul').animate({			top: ($('div.menu ul li').index($(this).parent())+1)*(-1)*($(this).parent().height())
		},500);
		$('div.menu li').removeClass('active');
		$(this).parent().addClass('active');

		$('div.menu').animate({top: fpos},500);
		$('html,body').animate({scrollTop: fpos},500);	});

	$('h1').click(function(){
		$('div.menu a[href=#services]').click();
	});

	$('ul.tabs a').click(function(){
		$(this).parent().parent().find('li').removeClass('active');
		$(this).parent().addClass('active');

		$(this).parent().parent().parent().find('div.tab').removeClass('active');
		$(this).parent().parent().parent().find('div.tab:eq('+$(this).parent().parent().find('li').index($(this).parent())+')').addClass('active');
		return false;
	});

	$('div.form input[type=button]').click(function(){
		$(this).parents('div.form').find('ul.tabs a:eq('+($(this).parents('div.form').find('div.tab').index($(this).parent().parent())+1)+')').click();
	});

	$('<input type="hidden" name="formid" value="order" />').appendTo('div.form form');
	$('<input type="hidden" name="formid" value="feedback" />').appendTo('div.feedback form');

	//	gallery

	$('a[rel=gallery]').click(function(){		var stop = $('html').scrollTop();
		if (stop==0) stop = $('body').scrollTop();

		var gallery = $('<div class="gallery"><div class="bg"></div><div class="cnt"><div></div></div></div>');
		gallery.find('div.bg, div.cnt').click(function(){
			$(this).parent().remove();
		});

		var gcnt = gallery.find('div.cnt').css('top',stop+100);
		gcnt.addClass('loading');

		gallery.insertAfter('div.footer');
		gallery.find('div.bg').css('height',$(document.body).height());

		var gimg = $('<img />').load(function(){			gcnt.find('div').empty();
			gcnt.find('div').animate({				height: this.height,
				width: this.width			},500,'linear',function(){				gcnt.removeClass('loading').find('div').empty();				gimg.appendTo(gcnt.find('div'));
				$('<span class="close"></span>')
				.click(function(){					gallery.remove();				}).appendTo(gcnt.find('div'));			});		});
		gimg.attr('src',this.href);		return false;	});});

