(function($){
	if('DD_belatedPNG' in window)DD_belatedPNG.fix('h1,img[src$=png]');
	if('google' in window)BWMAP=new google.maps.StyledMapType([{featureType:'all',elementType:'all',stylers:[{saturation:-100}]}],{name:'Grayscale'});

	Core={
		scroll:$('html,body'),
		scrollto:$('dt.scrollto'),
		layers:$('#parallax div'),

		map:function(){var w=window.open('http://www.google.com/maps?q='+encodeURIComponent(this.title))},
		scrolling:function(){Core.bg.style.backgroundPosition='0 '+Math.round(493-(Math.floor((document.documentElement.scrollTop||window.pageYOffset||0)/0.5)%494))+'px'},
		accordination:function(){$(this).toggleClass('cur').next().slideToggle().siblings('dt.cur').not(this).removeClass('cur').next().slideUp()},
		parallax:function(e){
			var w=this.offsetWidth/2,h=this.offsetHeight/2,i=0,el,iw,ih;
			while(el=Core.layers[i++]){
				el.style.left=parseInt(((((iw=el.offsetWidth/2)-e.pageX)/i)*0.09)-(iw-w),10)+'px';
				el.style.top=parseInt(((((ih=el.offsetHeight/2)-e.pageY)/i)*0.09)-(ih-h),10)+'px';
			}
		},
		vimeo:function(){
			var video=this.href.replace(/\/$/gi,'').split('/').pop()+'?byline=0&portrait=0&title=0&autoplay=1&color=cccac7';
			return !$(this).siblings('iframe').attr('src','http://player.vimeo.com/video/'+video);
		}
	}

	$('a[title],img[title]').removeAttr('title');
	$('div.vimeo').delegate('a[href*="vimeo"]','click',Core.vimeo);
	$('dl').delegate('dt:not(.header)','click',Core.accordination).find('dd').hide();
	if(Core.scrollto.length)$(window).load(function(){setTimeout(function(){window.scrollTo(0,Core.scrollto.offset().top-100)},200)});
	if(Core.layers.length)Core.scroll.css('overflow','hidden').filter('body').bind('mousemove',Core.parallax);
	if(Core.bg=$('#ballerina:visible').get(0))$(window).bind('scroll DOMMouseScroll mousewheel',Core.scrolling);
	
	$('div.map').each(function(){
		var opt=$.parseJSON(this.innerHTML),map=new google.maps.Map(this,{
				mapTypeControlOptions:{mapTypeIds:[google.maps.MapTypeId.ROADMAP,'tehgrayz']},
				center:opt.pos=new google.maps.LatLng(opt.lat,opt.lng),disableDefaultUI:true,zoom:opt.zoom
			}),mark=new google.maps.Marker({position:opt.pos,map:map,title:opt.address});
		google.maps.event.addListener(mark,'click',Core.map);
		map.mapTypes.set('tehgrayz',BWMAP);
		map.setMapTypeId('tehgrayz');
	});
	$(window).load(function(){setTimeout(function(){
		var w=$('#parallax img').each(function(){this.style.width=(this.offsetWidth+1)+'px'});		//Forces webkit to faster image-rendering
		$(window).resize(function(){if(w)w=!$('#parallax img').removeAttr('style')});
	},200)});
})(jQuery);

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2741865-27']);
_gaq.push(['_setDomainName', '.papercutart.no']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
