$(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 = "<span id='fancybox-title-over'>" + title + "</span>";
					
					// caption
					img.caption({
						'attr'     : 'alt',
					    'position': 'below'   
					});
									
					// 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' 
					});
				}
			});
		}
	});
		
	$(".galleri_img").zoomtip( {
		'fadeOutTo': 0,
		'text': 'Klikk for st&oslash;rre',
		'css': 'zoomtip' 
	});
	
	$(".galleri_img").caption({
		'attr'     : 'alt',
	    'position': 'bottom'   
	});
	
	$(".galleri_link").fancybox({
		'overlayOpacity': 0.6,
		'overlayColor'  : '#000000',
		'titlePosition' : 'over',
	});	
	
	
	// img roller in top
	
	//topimages
	var topImages = new Array();
	for (i=1;i<=15;i++) {
		topImages[i]="/site/images/top" + i + ".jpg";
	}
	$('.topImg').imgroller(topImages);
});