/* iso-8859-1 ÅÄÖ */
jQuery.noConflict();

/*
 * jQuery EasIng v1.1.2 - http://gsgd.co.uk/sandbox/jquery.easIng.php
 *
 * Uses the built In easIng capabilities added In jQuery 1.1
 * to offer multiple easIng options
 *
 * Copyright (c) 2007 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */

// t: current time, b: begInnIng value, c: change In value, d: duration

jQuery.extend( jQuery.easing,
{
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4265 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */

(function($) {

$.event.special.mousewheel = {
	setup: function() {
		var handler = $.event.special.mousewheel.handler;
		
		// Fix pageX, pageY, clientX and clientY for mozilla
		if ( $.browser.mozilla )
			$(this).bind('mousemove.mousewheel', function(event) {
				$.data(this, 'mwcursorposdata', {
					pageX: event.pageX,
					pageY: event.pageY,
					clientX: event.clientX,
					clientY: event.clientY
				});
			});
	
		if ( this.addEventListener )
			this.addEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = handler;
	},
	
	teardown: function() {
		var handler = $.event.special.mousewheel.handler;
		
		$(this).unbind('mousemove.mousewheel');
		
		if ( this.removeEventListener )
			this.removeEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = function(){};
		
		$.removeData(this, 'mwcursorposdata');
	},
	
	handler: function(event) {
		var args = Array.prototype.slice.call( arguments, 1 );
		
		event = $.event.fix(event || window.event);
		// Get correct pageX, pageY, clientX and clientY for mozilla
		$.extend( event, $.data(this, 'mwcursorposdata') || {} );
		var delta = 0, returnValue = true;
		
		if ( event.wheelDelta ) delta = event.wheelDelta/120;
		if ( event.detail     ) delta = -event.detail/3;
		if ( $.browser.opera  ) delta = -event.wheelDelta;
		
		event.data  = event.data || {};
		event.type  = "mousewheel";
		
		// Add delta to the front of the arguments
		args.unshift(delta);
		// Add event to the front of the arguments
		args.unshift(event);

		return $.event.handle.apply(this, args);
	}
};

$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});

})(jQuery);

jQuery.fn.fullHeight = function(options) {
	var options = jQuery.extend({
		margin: null,
		padding: null,
		marginTop: true,
		marginBottom: true,
		paddingTop: true,
		paddingBottom: true
	}, options);
	
	var height = jQuery(this).height();
	var prop = [];
	
	if(options.margin != null) {
		options.marginTop = options.margin;
		options.marginBottom = options.margin;
	}
	if(options.padding != null) {
		options.paddingTop = options.padding;
		options.paddingBottom = options.padding;
	}
	
	if (options.marginTop) {
		prop.push('margin-top');
	}
	if (options.marginBottom) {
		prop.push('margin-bottom');
	}
	if (options.paddingTop) {
		prop.push('padding-top');
	}
	if (options.paddingBottom) {
		prop.push('padding-bottom');
	}
	var n = prop.length;
	if (n > 0) {
		for (var i = 0; i < n; i++) {
			height += jQuery(this).css(prop[i]).toInt();
		}
	}
	return height;
};

jQuery.fn.fullWidth = function(options){
	var options = jQuery.extend({
		margin: true,
		padding: true
	}, options);
	var width = jQuery(this).width();
	var prop = [];
	if (options.margin) {
		prop.push('margin-left', 'margin-right');
	}
	if (options.padding) {
		prop.push('padding-left', 'padding-right');
	}
	var n = prop.length;
	if (n > 0) {
		for (var i = 0; i < n; i++) {
			width += jQuery(this).css(prop[i]).toInt();
		}
	}
	return width;
};
  
String.prototype.toInt = function(){
	var value = this;
	if (value == "auto") {
		value = 0;
	}
	return parseInt(value, 10);
};

jQuery._pf = {
	isSliding: {
		image: false,
		caption: false,
		accordion: false
	},
	slideInterval: 0,
	bluePrintInterval: 0
};

jQuery._slideCenterImages = function() {
	if(jQuery('#pf_slides dt').size() > 0) {
		jQuery('#pf_slides dt').each(function(i, dt) {
			if(jQuery(dt).width() < jQuery('#pf_slides').width()) { //Ta bort if-satsen för centrera ALLA bilder, inte bara de som är mindre i bredd än "fönstret"
				jQuery(dt).css({
					'left': '50%',
					'margin-left': -(jQuery(dt).width()/2),
					'top': (jQuery('#pf_slides').height()/2) - (jQuery(dt).height()/2)
				});
			}
		})
	}
}

jQuery.fn.slidePlay = function(o) {
	var options = jQuery.extend({
		interval: 5000
	}, o);
	jQuery._pf.playInterval = setInterval(function() {
		jQuery('ul#pf_slides_control a.pf_next').trigger('click', {
			doContinue: true
		});
	}, options.interval);
	jQuery('ul#pf_slides_control a:not(.pf_prev):not(.pf_next)').removeClass('pf_play').addClass('pf_pause').html('Pause');
	return this;
};

jQuery.fn.slidePause = function() {
	jQuery('ul#pf_slides_control a:not(.pf_prev):not(.pf_next)').removeClass('pf_pause').addClass('pf_play').html('Play');
	clearInterval(jQuery._pf.playInterval);
};

jQuery.fn.slidePrevImage = function(o) {
	if(jQuery._pf.isSliding.image) {
		return this;
	}
	jQuery._pf.isSliding.image = true;
	var options = jQuery.extend({
		duration: 500,
		step: -1,
		type: 'fade'
	}, o);
	return this.each(function() {
		jQuery(this).doSlide(options);
	});
};

jQuery.fn.slideNextImage = function(o) {
	if(jQuery._pf.isSliding.image) {
		return this;
	}
	jQuery._pf.isSliding.image = true;
	var options = jQuery.extend({
		duration: 500,
		step: 1,
		type: 'fade'
	}, o);
	return this.each(function() {
		jQuery(this).doSlide(options);
	});
};

jQuery.fn.doSlide = function(o) {
	var options = o;
	return this.each(function() {
		jQuery(this).animate({
			opacity: 0
		}, {
			duration: options.duration,
			easing: 'easeOutExpo',
			complete: function() {
				var dt = jQuery(this);
				var i = jQuery(this).parent().children('dt').index(this);
				if(options.step > 0 || options.step < 0) {
					dt = jQuery(this).removeClass('pf_active').parent().children('dt').eq(i+options.step);
					if(dt.size() < 1) {
						if (options.step > 0) {
							dt = jQuery(this).parent().children('dt:first');
						}
						else if(options.step < 0) {
							dt = jQuery(this).parent().children('dt:last');
						}
					}
				}
				
				dt.eq(0).css('opacity',0).addClass('pf_active').animate({
					opacity: 1
				}, {
					duration: options.duration,
					easing: 'easeOutExpo',
					complete: function() {
						jQuery(this).css('opacity','');
						var dd = jQuery(this).next();
						if(dd[0] && dd[0].tagName.toLowerCase() == 'dd') {
							dd.addClass('pf_active').children('img').css('margin-left',-(jQuery(this).children('img').width()+125)).animate({
								marginLeft: 0
							}, {
								duration: 300,
								easing: 'easeOutBack',
								complete: function() {
									jQuery._pf.isSliding.caption = false;
								}
							});
						}
						jQuery._pf.isSliding.image = false;
					}
				});
			}
		});
		var dd = jQuery(this).siblings('dd.pf_active');
		var img = dd.children('img');
		img.animate({
			marginLeft: -img.width() - 125
		}, {
			duration: 300,
			easing: 'easeInBack',
			complete: function() {
				jQuery(this).parent().removeClass('active');
			}
		});
	});
};

jQuery.fn.bluePrintPlay = function(o) {
	var options = jQuery.extend({
		interval: 12000
	}, o);
	jQuery._pf.bluePrintInterval = setInterval(function() {
		jQuery('#pf_blueprints_control a.pf_next').trigger('click', {
			doContinue: true
		});
	}, options.interval);
	jQuery('#pf_blueprints_control a:not(.pf_prev):not(.pf_next)').removeClass('pf_play').addClass('pf_pause');
	return this;
};

jQuery.fn.bluePrintPause = function() {
	jQuery('#pf_blueprints_control a:not(.pf_prev):not(.pf_next)').removeClass('pf_pause').addClass('pf_play');
	clearInterval(jQuery._pf.bluePrintInterval);
};

jQuery.fn.bluePrintPrevImage = function(o) {
	if(jQuery._pf.isSliding.image) {
		return this;
	}
	jQuery._pf.isSliding.image = true;
	var options = jQuery.extend({
		duration: 500,
		step: -1,
		type: 'fade'
	}, o);
	return this.each(function() {
		jQuery(this).doBluePrint(options);
	});
};

jQuery.fn.bluePrintNextImage = function(o) {
	if(jQuery._pf.isSliding.image) {
		return this;
	}
	jQuery._pf.isSliding.image = true;
	var options = jQuery.extend({
		duration: 500,
		step: 1,
		type: 'fade'
	}, o);
	return this.each(function() {
		jQuery(this).doBluePrint(options);
	});
};

jQuery.fn.doBluePrint = function(o) {
	var options = o;
	return this.each(function() {
		var o2 = {
			marginTop: -320
		};
		if(!jQuery.browser.msie) {
			o2.opacity = 0;
		}
		jQuery(this).animate(o2, {
			duration: options.duration,
			easing: 'easeOutExpo',
			complete: function() {
				var dt = jQuery(this);
				var i = jQuery(this).parent().children('dt').index(this);
				if(options.step > 0 || options.step < 0) {
					dt = jQuery(this).removeClass('pf_active').parent().children('dt').eq(i+options.step);
					if(dt.size() < 1) {
						if (options.step > 0) {
							dt = jQuery(this).parent().children('dt:first');
						}
						else if(options.step < 0) {
							dt = jQuery(this).parent().children('dt:last');
						}
					}
				}
				
				var o3 = {
					marginTop: -320
				};
				var o4 = {
					marginTop: 24
				};
				if(!jQuery.browser.msie) {
					o3.opacity = 0;
					o4.opacity = 1 ;
				}
				dt.eq(0).css(o3).addClass('pf_active').animate(o4, {
					duration: options.duration,
					easing: 'easeOutExpo',
					complete: function() {
						var dd = jQuery(this).next();
						if(dd[0] && dd[0].tagName.toLowerCase() == 'dd') {
							dd.addClass('pf_active').children('img').css('margin-left',-(jQuery(this).children('img').width()+125)).animate({
								marginLeft: 0
							}, {
								duration: 400,
								easing: 'easeOutBack',
								complete: function() {
									jQuery._pf.isSliding.caption = false;
								}
							});
						}
						jQuery._pf.isSliding.image = false;
					}
				});
			}
		});
		var dd = jQuery(this).siblings('dd.pf_active');
		var img = dd.children('img');
		img.animate({
			marginLeft: -img.width() - 125
		}, {
			duration: 300,
			easing: 'easeInBack',
			complete: function() {
				jQuery(this).parent().removeClass('active');
			}
		});
	});
};
							
jQuery(document).ready(function() {
	if (jQuery('div#pf_accordion_flashfilm').size() > 0) {
		jQuery('div#pf_accordion_flashfilm').css({
			width: accordion_flashfilm_width,
			height: accordion_flashfilm_height
		});
		if(jQuery('div#pf_accordion_flashfilm').parents('.pf_block').hasClass('pf_pos1')) {
			insertFlashMovie();
		}
	}
	if (jQuery('div#pf_accordion_qtvrfilm').size() > 0) {
		jQuery('div#pf_accordion_qtvrfilm').css({
			width: accordion_qtvrfilm_width,
			height: accordion_qtvrfilm_height
		});
		if(jQuery('div#pf_accordion_qtvrfilm').parents('.pf_block').hasClass('pf_pos1')) {
			insertQTVRMovie();
		}
	}
	if(jQuery('div#pf_accordion').size() > 0) {
		jQuery('div.pf_block').click(function(e) {
			if(jQuery(this).hasClass('pf_pos1') || jQuery._pf.isSliding.accordion) {
				if(e.target.tagName.toLowerCase() == 'a' && e.target.href && e.target.href != '' && e.target.href != '#') {
					return true;
				}
				return false;
			}
			jQuery._pf.isSliding.accordion = true;
			var match = this.className.match(/pf_pos([0-9])/);
			var className = match[0];
			var currentPos = match[1];
			
			jQuery().slidePause();
			jQuery().bluePrintPause();
			jQuery('#pf_accordion_flashfilm').empty();
			jQuery('#pf_accordion_qtvrfilm').empty()
			
			jQuery(this).animate({
				left: -7
			}, {
				duration: 600,
				easing: 'easeOutExpo',
				complete: function() {
					var id = this.id.match(/pf_accordion_([0-9]+)/)[1];
					jQuery(this).css('left',0).removeClass(className).addClass('pf_pos1');
					if (!jQuery.browser.msie || jQuery.browser.version >= 7) {
						jQuery(this).children('.pf_accordion_content').css('opacity', 0).animate({
							opacity: 1
						}, {
							duration: 300,
							easing: 'easeOutExpo'
						});
					}
					jQuery('#pf_accordion').removeClass().addClass('pf_'+id);
					if(id == 1) {
						jQuery._slideCenterImages();
						jQuery().slidePlay();
					}
					else if(id == 2) {
						if (jQuery('#pf_accordion_flashfilm').size() > 0) {
							insertFlashMovie();
						}
						else if (jQuery('#pf_accordion_qtvrfilm').size() > 0) {
							insertQTVRMovie();
						}
					}
					else if(id == 3) {
						jQuery().bluePrintPlay();
					}
					else if(id == 4) {
						window.pf_map.checkResize();
						if(window.pf_gm_point != null) {
							window.pf_gm_callback(window.pf_gm_point);
						}
						else {
							window.geocoder.getLatLng(pf_google_maps_adress, function(point){
								if (!point) {
									alert(pf_google_maps_adress + " not found");
								}
								else {
									window.pf_map.setCenter(point, 13);
								}
							});
						}
					}
					jQuery._pf.isSliding.accordion = false;
				}
			});
			jQuery(this).siblings('.pf_pos1').animate({
				left: 918 - (35 * (4-currentPos)) - (1 * (4-currentPos))
			}, {
				duration: 600,
				easing: 'easeOutExpo',
				complete: function() {
					jQuery(this).removeClass('pf_pos1').addClass(className);
				}
			});
			if (!jQuery.browser.msie || jQuery.browser.version >= 7) {
				jQuery(this).children('.pf_accordion_content').animate({
					opacity: 0
				}, {
					duration: 700,
					easing: 'easeOutExpo',
					complete: function(){
						jQuery(this).css('opacity', 1);
					}
				});
			}
		});
	}
	if(window.agent && /linux/.test(window.agent) && jQuery('div#pf_accordion').size() > 0) { //http://blog.marcoos.com/2006/07/21/html-div-above-a-flash-animation-on-linux-its-possible/
		jQuery('<iframe src="javascript:void();" frameborder="0" scrolling="no"></iframe>').prependTo(jQuery('div#pf_accordion_flashfilm').parent()).css({
			position: 'absolute',
			opacity: 0,
			top: 0,
			left: 853,
			display: 'block',
			width: 107,
			height: 320,
			'z-index': 5
		});
	}
	if (jQuery('ul#pf_slides_control').size() > 0) {
		jQuery('ul#pf_slides_control a.pf_next').click(function(e, o){
			jQuery('#pf_slides dt.pf_active').eq(0).slideNextImage();
			if (!(o && o.doContinue)) {
				jQuery().slidePause();
			}
			return false;
		});
		
		jQuery('ul#pf_slides_control a.pf_prev').click(function(e, o){
			jQuery('#pf_slides dt.pf_active').eq(0).slidePrevImage();
			if (!(o && o.doContinue)) {
				jQuery().slidePause();
			}
			return false;
		});
		
		jQuery('ul#pf_slides_control a.pf_pause').click(function(e){
			if (jQuery(this).hasClass('pf_pause')) {
				jQuery().slidePause();
			}
			else 
				if (jQuery(this).hasClass('pf_play')) {
					jQuery().slidePlay();
				}
			return false;
		});
		
		jQuery().slidePlay();
	}
	
	if (jQuery('#pf_blueprints_control').size() > 0) {
		jQuery('#pf_blueprints_control a.pf_next').click(function(e, o){
			jQuery('#pf_blueprints dt.pf_active').eq(0).bluePrintNextImage();
			if (!(o && o.doContinue)) {
				jQuery().bluePrintPause();
			}
			return false;
		});
		
		jQuery('#pf_blueprints_control a.pf_prev').click(function(e, o){
			jQuery('#pf_blueprints dt.pf_active').eq(0).bluePrintPrevImage();
			if (!(o && o.doContinue)) {
				jQuery().bluePrintPause();
			}
			return false;
		});
		
		jQuery('#pf_blueprints_control a.pf_play').click(function(e){
			if (jQuery(this).hasClass('pf_pause')) {
				jQuery().bluePrintPause();
			}
			else if (jQuery(this).hasClass('pf_play')) {
				jQuery().bluePrintPlay();
			}
			return false;
		});
	}
	
	if (jQuery('div#pf_vacant').size() > 0) {
		var el;
		if(jQuery('dl.pf_contact').size() > 0) {
			el = jQuery('div#pf_content_left p');
			el = el[el.length - 1];
		}
		else if(jQuery('div#pf_content_left div.pf_gloss_button').size() > 0) {
			el = jQuery('div#pf_content_left div.pf_gloss_button');
			el = el[el.length - 1];
		}
		else {
			el = jQuery('div#pf_content_left > :last-child').eq(0);
		}
		var button = jQuery('<div class="pf_gloss_button"><div><a href="#">Lediga lokaler i fastigheten</a></div></div>').insertAfter(jQuery(el).eq(0)).toggle(
			function() {
				var l = ((jQuery(this).offset().left - jQuery('#pf_content').offset().left) + (jQuery(this).width()/2)) - (jQuery('div#pf_vacant').width()/2);
				if(l < 0) {
					l = 0;
				}
				jQuery('div#pf_vacant').removeClass('pf_hide').css({
					left: l,
					top: jQuery(this).offset().top - jQuery('div#pf_vacant').height() - 25
				});
				jQuery('div#pf_vacant .pf_tip').css('left', (jQuery(this).offset().left - jQuery('#pf_content').offset().left) + (jQuery(this).width()/2) + 8 - jQuery('div#pf_vacant').css('left').toInt());
				return false;
			},
			function() {
				jQuery('div#pf_vacant').addClass('pf_hide');
				return false;
			}
		);
		
		var borderDiv = jQuery('div#pf_vacant div.pf_border');
		var vacant = jQuery('div#pf_vacant').addClass('pf_hide pf_popup').append(jQuery('<span class="pf_tip"></span>'));
		
		var contentViewHeight = borderDiv.height();
		var contentPaddingTop = borderDiv.css('padding-top').toInt();
		var contentPaddingBottom = borderDiv.css('padding-bottom').toInt();
		var contentViewFullHeight = contentViewHeight + contentPaddingTop + contentPaddingBottom;
		var tableHeight = jQuery('div#pf_vacant table').height();
		var contentHeight = tableHeight + contentPaddingTop + contentPaddingBottom;
		var vacantHeight = vacant.height();
		var vacantHeaderHeight = vacant.children('h2').eq(0).append(jQuery('<a class="pf_close"><span>St&auml;ng</span></a>').click(function() {
			button.click();
		})).fullHeight({margin:false});
		
		if(vacantHeight > 390) {
			contentViewHeight = 390 - vacantHeaderHeight - contentPaddingTop - contentPaddingBottom;
			if(contentViewHeight%2 != 0) {
				contentViewHeight++;
			}
			borderDiv.css({
				overflow: 'hidden',
				height: contentViewHeight
			});
			vacantHeight = vacant.height();
			var deferred = true;
		}
		
		vacant.css({
			left: ((button.offset().left - jQuery('div#pf_content').offset().left) + (button.width()/2)) - (vacant.width()/2),
			top: button.offset().top - vacantHeight - 25
		});
		
		if(deferred) {
			var o = button.offset().top - vacantHeight - 25;
			var p = jQuery('div#pf_content').offset().top;
			if(o < p) {
				contentViewHeight = button.offset().top - 35 - p - vacantHeaderHeight - contentPaddingTop - contentPaddingBottom;
				borderDiv.height(contentViewHeight);
				vacant.css('top', (button.offset().top - vacantHeight - 25));
			}
		}
		
		if (tableHeight > contentViewHeight) {
			var scroll = jQuery('<div class="pf_scrollbar"><span class="pf_up"></span><span class="pf_face"></span><span class="pf_down"></span></div>');
			vacant.append(scroll).children('span.pf_br').remove();
			
			var scrollAreaHeight = borderDiv.height() + contentPaddingTop + contentPaddingBottom;
			var scrollTrackHeight = scrollAreaHeight - scroll.children('span.pf_up').height() - scroll.children('span.pf_down').height();
			var scrollFaceHeight = Math.round((scrollAreaHeight / contentHeight) * scrollTrackHeight);
			
			scroll.height(scrollAreaHeight);
			var face = scroll.children('span.pf_face').height(scrollFaceHeight);
			
			//up/down = 12% av "viewporten"(!)
			//track = 88% av "viewporten"(!)
			
			var contentTop = 0;
			var faceTop = 18;
			var scrollMouseDown = false;
			var scrollFaceDirection = false;
			var scrollMoveMouseDelta = false;
			var scrollMouseDownFace = false;
			var scrollContentStep = (tableHeight - contentViewHeight) * 0.10;
			var scrollFaceStep = (scrollTrackHeight - scrollFaceHeight) * 0.10;
			
			function intervalScroll(el) {
				scrollMouseDown = setInterval(function(){
					jQuery(el).mousedown();
				}, 140);
				jQuery(el).mousedown();
			}
			
			function scrollUp(k) {
				k = (k) ? k: 1;
				contentTop = Math.round(contentTop + (scrollContentStep * k));
				faceTop = Math.round(faceTop - (scrollFaceStep * k));
				if (faceTop < 18) {
					contentTop = 0;
					faceTop = 18;
				}
				doScroll();
			}
			
			function scrollDown(k) {
				k = (k) ? k : 1;
				contentTop = Math.round(contentTop - (scrollContentStep * k));
				faceTop = Math.round(faceTop + (scrollFaceStep * k));
				if ((faceTop + scrollFaceHeight) > (scrollTrackHeight + 18)) {
					contentTop = -Math.round(tableHeight - (scrollAreaHeight - contentPaddingTop - contentPaddingBottom));
					faceTop = Math.round((scrollTrackHeight + 20) - scrollFaceHeight);
				}
				doScroll();
			}
			
			function doScroll() {
				jQuery('div#pf_vacant table').animate({
					marginTop: contentTop
				}, {
					duration: 150,
					queue: false
				});
				
				face.animate({
					top: faceTop
				}, {
					duration: 150,
					queue: false
				});
			}
			
			function getMouseCoordinates(e) {
				var posx = false;
				var posy = false;
				if (e.pageX || e.pageY) 	{
					posx = e.pageX;
					posy = e.pageY;
				}
				else if (e.clientX || e.clientY) 	{
					posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
					posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
				}
				return [posx,posy];
			}
			
			borderDiv.mousewheel(function(e, delta) {
				if(!jQuery.browser.opera) {
					delta = -delta;
				}
				if(Math.abs(delta) === 0) {
					return false;
				}
				if((delta < 0 && face.css('top').toInt() <= 18) || (delta > 0 && face.css('top').toInt() >= (scrollTrackHeight + 19) - scrollFaceHeight)) {
					return true;
				}
				else if(delta < 0) {
					scrollUp();
				}
				else if(delta > 0) {
					scrollDown();
				}
				return false;
			});
			
			scroll.mousedown(function(e){
				var pos = getMouseCoordinates(e);
				if(pos[1] !== false) {
					if(pos[1] < face.offset().top) {
						scrollFaceDirection = 'up';
					}
					else if(pos[1] > (face.offset().top + scrollFaceHeight)) {
						scrollFaceDirection = 'down';
					}
					else {
						scrollFaceDirection = false;
					}
				}
				if (scrollMouseDown !== false) {
					if (scrollFaceDirection == 'up') {
						scrollUp(7);
					}
					else if (scrollFaceDirection == 'down') {
						scrollDown(7);
					}
				}
				else if (scrollMouseDown === false) {
					intervalScroll(this);
				}
				return false;
			}).children('span.pf_face').mouseover(function() {
				if (!scrollMouseDownFace) {
					jQuery(document).mouseup();
				}
			}).mouseup(function(){
				scrollMouseDownFace = false;
			}).mousedown(function(){
				scrollMouseDown = true;
				scrollMouseDownFace = true;
				jQuery(document).mousemove(function(e) {
					if(scrollMouseDown) {
						var pos = getMouseCoordinates(e);
						if(scrollMoveMouseDelta === false) {
							scrollMoveMouseDelta = pos[1];
						}
						var delta = pos[1] - scrollMoveMouseDelta;
						if(delta === 0 || (delta < 0 && faceTop <= 18) || (delta > 0 && (faceTop + scrollFaceHeight) > (scrollTrackHeight + 18))) {
							return;
						}
						faceTop += delta;
						contentTop -= Math.round(delta * (scrollContentStep / scrollFaceStep));
						if (faceTop < 18) {
							contentTop = 0;
							faceTop = 18;
						}
						else if ((faceTop + scrollFaceHeight) > (scrollTrackHeight + 18)) {
							contentTop = -Math.round(tableHeight - (scrollAreaHeight - contentPaddingTop - contentPaddingBottom));
							faceTop = Math.round((scrollTrackHeight + 20) - scrollFaceHeight);
						}
						face.css('top', faceTop);
						jQuery('div#pf_vacant table').css('margin-top', contentTop);
						scrollMoveMouseDelta = pos[1];
					}
				});
			}).siblings('span.pf_up').mousedown(function(){
				if (scrollMouseDown !== false) {
					scrollUp(1);
				}
				else if (scrollMouseDown === false) {
					intervalScroll(this);
				}
				return false;
			}).siblings('span.pf_down').mousedown(function(){
				if (scrollMouseDown !== false) {
					scrollDown(1);
				}
				else if (scrollMouseDown === false) {
					intervalScroll(this);
				}
				return false;
			});
			
			jQuery(document).mouseup(function(){
				clearInterval(scrollMouseDown);
				scrollMouseDown = false;
				scrollFaceDirection = false;
				scrollMoveMouseDelta = false;
			});
		}
	}
/*
	if(jQuery('#pf_items_back').size() < 1) {
		jQuery('<a id="pf_items_back" onclick="javascript:history.go(-1);"><img src="images/pf/gen/tillbaka.gif" alt="Tillbaka" /></a>').appendTo(jQuery('#pf_top'));
	}
*/
});

jQuery(window).load(function() {
	jQuery._slideCenterImages();
	if(jQuery('#pf_top').size() > 0) {
		var itemsFullWidth= 0;
		jQuery('#pf_items ul li').each(function(i,el) {
			itemsFullWidth += jQuery(el).width();
			itemsFullWidth += parseInt(jQuery(el).css('margin-left'),10);
			itemsFullWidth += parseInt(jQuery(el).css('margin-right'),10);
			itemsFullWidth += parseInt(jQuery(el).css('padding-left'),10);
			itemsFullWidth += parseInt(jQuery(el).css('padding-right'),10); 
		});
		
		if (itemsFullWidth > jQuery('#pf_items').width()) {
			var more = jQuery('<a id="pf_items_more" title="Bläddra höger"><span>Bläddra höger</span></a>').appendTo(jQuery('#pf_top'));
			var less = jQuery('<a id="pf_items_less" title="Bläddra vänster"><span>Bläddra vänster</span></a>').appendTo(jQuery('#pf_top'));
			
			more.click(function(){
				var max = itemsFullWidth - jQuery('#pf_items').width();
				var l = parseInt(jQuery('#pf_items ul').css('margin-left'), 10) - 200;
				if (l < -max) {
					l = -max;
				}
				jQuery('#pf_items ul').animate({
					marginLeft: l
				}, {
					duration: 500,
					easing: 'easeOutExpo'
				});
				return false;
			});
			
			less.click(function(){
				var max = 0;
				var l = parseInt(jQuery('#pf_items ul').css('margin-left'), 10) + 200;
				if (l > max) {
					l = max;
				}
				jQuery('#pf_items ul').animate({
					marginLeft: l
				}, {
					duration: 500,
					easing: 'easeOutExpo'
				});
				return false;
			});
		}
	}
	
	if (typeof(GBrowserIsCompatible) != "undefined" && GBrowserIsCompatible()) {
		window.pf_gm_callback = function(point) {
			if (!point) {
				alert(pf_google_maps_adress + " not found");
			}
			else {
				window.pf_map.setCenter(point, 13);
				var icon = new GIcon();
				icon.image = "/images/map/building-small.png";
				icon.iconSize = new GSize(32, 30);
				icon.iconAnchor = new GPoint(16, 19);
				icon.infoWindowAnchor = new GPoint(15, 0);
				markerOption = { icon:icon }
				markerOption.clickable = false;
				
				window.pf_map.addOverlay(new GMarker(point, markerOption));
			}
		}
		window.pf_map = new GMap2(jQuery('#pf_google_maps')[0]);
		window.geocoder = new GClientGeocoder();
		pf_map.addControl(new GLargeMapControl());
		if(pf_google_maps_lat != null && pf_google_maps_lng != null) {
			window.pf_gm_point = new GLatLng(pf_google_maps_lat, pf_google_maps_lng);
			window.pf_gm_callback(window.pf_gm_point);
		}
		else {
			window.geocoder.getLatLng(pf_google_maps_adress, window.pf_gm_callback);
		}
	}
}).unload(function(){
    try { GUnload(); } catch(e) {}
});
