
$(document).ready(function() {
	var C = {
		overlayOpacity : 0.9,
		overlayColor   : '#191b1a',
		titlePosition  : 'over'
	};
	if($('.Ierror')[0]) {
		$('html, body').animate({scrollTop:$('.Ierror:eq(0)').offset().top}, 'fast',
			function() {
					$.fancybox(
					'<h2>'+$('h1').text()+'</h2><p style="color:red">'+$('legend').text()+'</p>',
					{
			        		'autoDimensions'	: false,
						'width'         		: 350,
						'height'        		: 'auto',
						'transitionIn'		: 'none',
						'transitionOut'		: 'none'
					}
					);	
			}
		
		);
			
	}
	$(".gallery a").fancybox(C);
	$('a[target="_fancybox"]').fancybox(C);
	$('a.media').media();
    $(".openGallery").click(function() {
		var Imgs = [];
		$('#gal'+$(this).attr('rel')+' a').each(function() {
			Imgs.push({
				'href' : this.href,
				'title' : $(this).html()
			});
		});
		$.fancybox(Imgs, C);
	});

	$('.nav li').hover(function() {
		$('.img img',this).show();
	},function() {
		if($(this).hasClass('on')) return false;
		$('.img img',this).hide();
	}).css('cursor','pointer').click(function() {
		window.location.href = $('a',this).attr('href');
	});
	
	
	var FadeTime = 400;
	$('.nav li.level1').hover(function() {
		if (!$(this).hasClass('on')) {
			$(this).parent().find('li.on ul').fadeOut(FadeTime);
		}
		if($(this).find('a:eq(0)').hasClass('on')) {
			$(this).find('a:eq(0)').attr('act',1);
		}
		$(this).find('a:eq(0)').addClass('on');
		$(this).find('ul').slideDown(FadeTime);
		
		$(this).attr('act',1);
	},function() {
		if (!$(this).find('a:eq(0)').attr('act')) {
			$(this).find('a:eq(0)').removeClass('on');
		}
		$(this).attr('act',0);
		$(this).find('ul').fadeOut(FadeTime,function() {
			
			if(!$(this).parent().parent().find('ul:visible').length) {
			//	$(this).parent().parent().find('li.on ul').show();
			}
		});
		
		
	});
	
});