$(window).load(function(){
	// content image processing (fanxybox, caption, maginifier)
	$("#content img").each(function () {
		var img = $(this);
			
		// not already linked
		if (img.parents('a').size() == 0) {
			
			$.getJSON("/site/imgInfo.php", {src: img.attr('src')}, function(data) {
				if (data.isCmsImage) {
					
					// title
					var title = img.attr('alt');
					if (title.length > 0)
						title = title + ' - ';
					
					title = title + '<a href="http://www.harevadet.no/pub/cms331.html" style="color: #ffffff">Sjå fleire bilder i bildekartet</a>';
						
					title = "<span id='fancybox-title-over'>" + title + "</span>";
					
					// caption
					img.caption({
						'attr'     : 'alt',
						'bgColor'  : '#000000',
						'bgOpacity': 0.60
					});
									
					// link
					var link = $("<a href='"+ data.fullPath + "' class='fancybox'></a>");
					img.before(link);
					img.remove();
					img.appendTo(link);
					
					// fancybox
					link.fancybox({
						'overlayOpacity': 0.6,
						'overlayColor'  : '#000000',
						'titlePosition' : 'over',
						'titleFormat'   : function() { return title; }
					});
					
					// zoomtip
					img.zoomtip( {
						'fadeOutTo': 0,
						'text': 'Klikk for st&oslash;rre',
						'css': 'zoomtip' 
					});
				}
			});
		}
	});
		
	$('#gallery a').fancybox({
		'overlayOpacity': 0.6,
		'overlayColor'  : '#000000',
		'titlePosition' : 'over'
	});
	
	$("#email_share").fancybox({
		'width'				: 350,
		'height'			: 250,
        'autoScale'     	: false,
		'overlayOpacity'    : 0.6,
		'overlayColor'      : '#000000',
		'type'				: 'iframe'
	});
		
	$('.galimg').zoomtip();

	// change top
	setTimeout("changeTop()",5000);
	
});
