$(document).ready(function () {
	var galleries = $(".gallery");
	if (galleries.length) {
		var imagesetNum = 0;
		$(galleries).each(function() {	
			$(this).find("img").each(function() {
				var img = this;
				var lightboxLink = document.createElement("a");
				lightboxLink.setAttribute("rel", "prettyPhoto[set" + imagesetNum + "]");

				if ($(img).attr("title"))
					lightboxLink.setAttribute("title", $(img).attr("title"));
				else if ($(img).attr("alt"))
					lightboxLink.setAttribute("title", $(img).attr("alt"));
				else 
					lightboxLink.setAttribute("title", " ");

				lightboxLink.href = $(img).attr("src").replace(/(_t|_n)\./, '.');

				$(img).wrap(lightboxLink);
			});
		});
		imagesetNum++;
	}
	$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme: 'dark_rounded'});

	$("#dep_id").change(function() {
		var depId = $(this).val();
		if (!depId)
			return;
		
		$.getJSON("/ajax.php", { "ajaxAction": "loadDepartmentInfo", "depId": depId }, function(r) {
			$("#_department").html(r.title);
			$("#_competence").html(r.descr);
			$("#_phone").html(r.phone);
			$("#_fax").html(r.fax);
			$("#_email").html(r.email);
		});
	});	
});

popup = function(url, opts) {
	var title 	= opts['title']        	|| '';
	var width  	= opts['width']        	|| screen.width;
	var height 	= opts['height']       	|| screen.height;
	var top 	= opts['top']		|| 0;
	var left  	= (opts['left'] && !opts['centered']) ? opts['left'] : 0;
	var status 	= opts['status']       	|| 'no';
	var toolbar 	= opts['toolbar']      	|| 'no';
	var menubar 	= opts['menubar']      	|| 'yes';
	var scrollbars 	= opts['scrollbars']   	|| 'no';
	var centered 	= opts['centered']      ? opts['centered'] : 1;
	var resizable 	= opts['resizable']    	|| 'yes';
	var location 	= opts['location']    	|| 'yes';

	if (centered) {
		_left = (screen.width  - width)  / 2;
		_top  = (screen.height - height) / 2;
	} else {
		_left = _top = 0;
	}


	window.open(
		url, 
		title,
		'width=' + width + ', height=' + height + ', status=' + status +', toolbar='+toolbar+', menubar='+menubar+', scrollbars='+scrollbars+',location=' + location + ',left='+_left+',top='+_top
	);
};


