var navActive=null;
var prettyPhotoConfig={
	animationSpeed: 'normal', /* fast/slow/normal */
	padding: 40, /* padding for each side of the picture */
	opacity: 0.35, /* Value betwee 0 and 1 */
	showTitle: true, /* true/false */
	allowresize: true, /* true/false */
	counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
	theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
}

$(document).ready(function() {
	$('#nav>a').each(function() {
		s=$('<span>'+$(this).html()+'</span>')
		.mouseover(function() {
			o=$(this).parent().find('div');
			o.fadeIn();
		}).mouseout(function() {
			o=$(this).parent();
			if (navActive!=o.attr('name')) o.find('div').fadeOut();
		}).click(function() {
			p=$(this).parent();
			hr=p.trigger('blur').attr('name');
			if (navActive!=hr) {
				navOld=navActive;
				navActive=hr;
				if (navOld) $('#nav>div[name="'+navOld+'"]>span').trigger('mouseout');
				$('#middle').fadeOut(function() {
					$(this).load('content/pages/'+hr+'.html',function() {
						if (hr=='galerie') {$("a[rel^='prettyPhoto']").prettyPhoto(prettyPhotoConfig);}
						if (hr=='contact') {$('#contactForm').submit(submitContact);}
						$(this).fadeIn();
					});
				})
				$(this).trigger('mouseover');
			}
			return false;
		});

		d=$('<div name="'+$(this).attr('href').substring(6)+'"><div><img src="images/spacer.gif" alt=""/></div></div>').append(s);

		$(this).replaceWith(d);
	});

	$('#header').fadeIn(function() {
		$('#nav>div:last').append($('<b/>'));
		$('#nav>div:first').append($('<i/>'));
		$('#nav').fadeIn(function() {
			$('#nav>div:first>span').trigger('click');

			$('#newspane').load('news.php',function() {
				$('#left').add('#footer').fadeIn();
			});
		});
	});

	$('input[type=submit]').live('mouseover',function() {
		$(this).css('background-position','bottom');
	}).live('mouseout',function() {
		$(this).css('background-position','top');
	});
});

function submitContact() {
	subm=$('#contactForm').find('input[type=submit]');
	subm.fadeOut();
	$('<div>').appendTo($('body')).load('sendmail.php',{
		'name':$('#name').attr('value'),
		'email':$('#email').attr('value'),
		'message':$('textarea').attr('value')
	},function() {
		subm.parent().html('Mesajul a fost trimis cu succes');
		//subm.fadeIn();
	});
	return false;
}