function getBubble(selector,type,id) {
	jQuery(function($) {
		$(selector).load('/bubble.php?type='+type+'&id='+id);
	});
}

function jumpSlowly(id) {
	(function ($) {
		//$('html,body').animate({scrollTop: $("#"+id).offset().top-30},'slow'); 
	}(jQuery));
	return true;
}

/*
//last working sticky_ad

(function ($) {
	$(window).load(function() {
		var $sidebar   = $("#sticky_ad");
		
		//only add the sticky effect if the left column is smaller than the middle column (2 cases: vb adn drupal)
		dosticky = $('#left_column').height()!=null ? $('#left_column').height()>$('#middle_column').height() : $(".panel-col-first").height()>$(".panel-col").height();

		if($sidebar.length && dosticky) {
			var	$window    = $(window),
				offset     = $sidebar.offset(),
				topPadding = 3;
				
			$sidebar.css('top','3px');

			$window.scroll(function() {
				if ($window.scrollTop() > offset.top) {
					$sidebar.css('position','fixed');
					$sidebar.css('left',$sidebar.parent().offset().left);
					//$sidebar.css('marginTop',$window.scrollTop() - offset.top + topPadding);
				
					//$sidebar.stop().animate({
					//	marginTop: $window.scrollTop() - offset.top + topPadding
					//}, 1000);
				
				} else {
					$sidebar.css('position','static');
					$sidebar.css('marginTop',0);
				
					//$sidebar.stop().animate({
					//	marginTop: 0
					//}, 1000);
				
				}
			});
			
			$(window).resize(function() {
			  $sidebar.css('left',$sidebar.parent().offset().left);
			});
		}
	});
}(jQuery));
*/

/*
(function ($) {
	$(function() {
    var $sidebar   = $("#sticky_ad"),
        $window    = $(window),
        offset     = $sidebar.offset(),
        topPadding = 15;

    $window.scroll(function() {
        if ($window.scrollTop() > offset.top) {
            $sidebar.stop().animate({
                marginTop: $window.scrollTop() - offset.top + topPadding
            });
        } else {
            $sidebar.stop().animate({
                marginTop: 0
            });
        }
		alert(offset.top);
    });
	alert(offset.top);
});
});
*/

var showingPuff=1;
var puffar=4;
function displayPuff(i) {
	(function ($) {
		// fade in static content
		//$('.puff'+showingPuff).fadeOut('fast');
		//$('.skribent'+showingPuff).fadeOut('fast');
		showingPuff = i;
		//$('.puff'+showingPuff).fadeIn('slow');
		$('.puff'+showingPuff).show();
		//$('.skribent'+showingPuff).fadeIn('slow');
		$('.skribent'+showingPuff).show();
	}(jQuery));
}
function nextPuff() {
	displayPuff(showingPuff%puffar+1);
}
function prevPuff() {
	displayPuff((showingPuff+puffar-2)%puffar+1);
}
(function ($) {
	// start typing onload
	$(document).ready(function() {
		//$('.puff'+showingPuff).hide();
		displayPuff(Math.floor(Math.random()*puffar)+1);
		//setInterval('nextPuff();',8000);
	});
}(jQuery));

(function ($) {
	//empty the standard comment when selected
	$(document).ready(function() {
		$('.comment-form textarea').click(function() {
			$textarea = $('.comment-form textarea');
			//alert($textarea.val());
			if($textarea.val() == 'Skriv din kommentar här') {
				$textarea.val('');
			}
		});
	});
}(jQuery));

function toggleAtillO() {
	(function ($) {
		atillo = $("#AtillO");
		if(atillo.is(':visible')) {
			atillo.slideUp('fast',function(){});
		} else {
			atillo.show();
			//atillo.slideDown('fast',function(){});
		}
	}(jQuery));
	return false;
}

//validate mollom
(function ($) {
	$(document).ready(function() {
		$('.comment-form').submit(function() {
			if($('.mollom-captcha-content')[0]) {
				if($('#edit-comment-body-und-0-value--3').val().length==0) {
					alert("Du måste fylla i kommentarsfältet!");
					return false;
				}
				if($('input:text[name="mollom[captcha]"]').val().length==0) {
					alert("Du måste fylla i fältet Word verification!");
					return false;
				}
			}
		});	
	});
}(jQuery));

function show_submenu(title,btn) {
	return false;
}
function reset_submenu() {
	return false;
}

/* Inaktiveringsdatum: 2011-09-29 //Flommy
var submenu_timer;

//hover submenu
function show_submenu(title,btn) {
	//alert(standard_menu);
	clearInterval(submenu_timer);
	(function ($) {
		//remove active style
		$('.menu_item.active a').removeClass('darkbyggahuscolor');
		$('.menu_item.active').removeClass('active');
		//add active style to hover
		$('#'+btn.id+' a').addClass('darkbyggahuscolor');
		$('#'+btn.id).addClass('active');
		//show right submenu
		$('.header_subrow').hide();
		$('#subrow_'+title).show();
	}(jQuery));
}

function reset_submenu() {
	submenu_timer = setInterval("_reset_submenu();",1000);
}
function _reset_submenu() {
	(function ($) {
		//remove active style
		$('.menu_item.active a').removeClass('darkbyggahuscolor');
		$('.menu_item.active').removeClass('active');
		//add active style to standard
		$('#btn_'+standard_menu+' a').addClass('darkbyggahuscolor');
		$('#btn_'+standard_menu).addClass('active');
		//show right submenu
		$('.header_subrow').hide();
		$('#subrow_'+standard_menu).show();
	}(jQuery));
}

(function ($) {
	$(document).ready(function() {
		$('.header_subrow').bind({
		  mouseleave: function() {
			reset_submenu();
		  },
		  mouseenter: function() {
			clearInterval(submenu_timer);
		  }
		});
	});
}(jQuery));
*/

/* Script by: www.jtricks.com
 * Version: 1.7 (20110408)
 * Latest version: www.jtricks.com/javascript/navigation/floating.html
 */
var floatingMenu =
{
    hasInner: typeof(window.innerWidth) == 'number',
    hasElement: typeof(document.documentElement) == 'object'
        && typeof(document.documentElement.clientWidth) == 'number'
};

var floatingArray =
[
];

floatingMenu.add = function(obj, options)
{
    var name;
    var menu;

    if (typeof(obj) === "string")
        name = obj;
    else
        menu = obj;
        

    if (options == undefined)
    {
        floatingArray.push( 
            {
                id: name,
                menu: menu,

                targetLeft: 0,
                targetTop: 0,

                distance: .07,
                snap: true
            });
    }
    else
    {
        floatingArray.push( 
            {
                id: name,
                menu: menu,

                targetLeft: options.targetLeft,
                targetRight: options.targetRight,
                targetTop: options.targetTop,
                targetBottom: options.targetBottom,

                centerX: options.centerX,
                centerY: options.centerY,

                prohibitXMovement: options.prohibitXMovement,
                prohibitYMovement: options.prohibitYMovement,

                distance: options.distance != undefined ? options.distance : .07,
                snap: options.snap,
                ignoreParentDimensions: options.ignoreParentDimensions,

                scrollContainer: options.scrollContainer,
                scrollContainerId: options.scrollContainerId
            });
    }
};

floatingMenu.findSingle = function(item)
{
    if (item.id)
        item.menu = document.getElementById(item.id);

    if (item.scrollContainerId)
        item.scrollContainer = document.getElementById(item.scrollContainerId);
};

floatingMenu.move = function (item)
{
    if (!item.prohibitXMovement)
    {
        item.menu.style.left = item.nextX + 'px';
        item.menu.style.right = '';
    }

    if (!item.prohibitYMovement)
    {
        item.menu.style.top = item.nextY + 'px';
        item.menu.style.bottom = '';
    }
};

floatingMenu.scrollLeft = function(item)
{
    // If floating within scrollable container use it's scrollLeft
    if (item.scrollContainer)
        return item.scrollContainer.scrollLeft;

    var w = window;

    // Find top window scroll parameters if we're IFRAMEd
    while (w != w.parent)
        w = w.parent;

    return this.hasInner
        ? w.pageXOffset  
        : this.hasElement  
          ? w.document.documentElement.scrollLeft  
          : w.document.body.scrollLeft;
};

floatingMenu.scrollTop = function(item)
{
    // If floating within scrollable container use it's scrollTop
    if (item.scrollContainer)
        return item.scrollContainer.scrollTop;

    var w = window;

    // Find top window scroll parameters if we're IFRAMEd
    while (w != w.parent)
        w = w.parent;

    return this.hasInner
        ? w.pageYOffset
        : this.hasElement
          ? w.document.documentElement.scrollTop
          : w.document.body.scrollTop;
};

floatingMenu.windowWidth = function()
{
    return this.hasElement
        ? document.documentElement.clientWidth
        : document.body.clientWidth;
};

floatingMenu.windowHeight = function()
{
    if (floatingMenu.hasElement && floatingMenu.hasInner)
    {
        // Handle Opera 8 problems
        return document.documentElement.clientHeight > window.innerHeight
            ? window.innerHeight
            : document.documentElement.clientHeight
    }
    else
    {
        return floatingMenu.hasElement
            ? document.documentElement.clientHeight
            : document.body.clientHeight;
    }
};

floatingMenu.documentHeight = function()
{
    var innerHeight = this.hasInner
        ? window.innerHeight
        : 0;

    var body = document.body,
        html = document.documentElement;

    return Math.max(
        body.scrollHeight,
        body.offsetHeight, 
        html.clientHeight,
        html.scrollHeight,
        html.offsetHeight,
        innerHeight);
};

floatingMenu.documentWidth = function()
{
    var innerWidth = this.hasInner
        ? window.innerWidth
        : 0;

    var body = document.body,
        html = document.documentElement;

    return Math.max(
        body.scrollWidth,
        body.offsetWidth, 
        html.clientWidth,
        html.scrollWidth,
        html.offsetWidth,
        innerWidth);
};

floatingMenu.calculateCornerX = function(item)
{
    var offsetWidth = item.menu.offsetWidth;

    if (item.centerX)
        return this.scrollLeft(item) + (this.windowWidth() - offsetWidth)/2;

    var result = this.scrollLeft(item) - item.parentLeft;
    if (item.targetLeft == undefined)
    {
        result += this.windowWidth() - item.targetRight - offsetWidth;
    }
    else
    {
        result += item.targetLeft;
    }
        
    if (document.body != item.menu.parentNode
        && result + offsetWidth >= item.confinedWidthReserve)
    {
        result = item.confinedWidthReserve - offsetWidth;
    }

    if (result < 0)
        result = 0;

    return result;
};

floatingMenu.calculateCornerY = function(item)
{
    var offsetHeight = item.menu.offsetHeight;

    if (item.centerY)
        return this.scrollTop(item) + (this.windowHeight() - offsetHeight)/2;

    var result = this.scrollTop(item) - item.parentTop;
    if (item.targetTop === undefined)
    {
        result += this.windowHeight() - item.targetBottom - offsetHeight;
    }
    else
    {
        result += item.targetTop;
    }

    if (document.body != item.menu.parentNode
        && result + offsetHeight >= item.confinedHeightReserve)
    {
        result = item.confinedHeightReserve - offsetHeight;
    }

    if (result < 0)
        result = 0;
        
    return result;
};

floatingMenu.computeParent = function(item)
{
    if (item.ignoreParentDimensions)
    {
        item.confinedHeightReserve = this.documentHeight();
        item.confinedWidthReserver = this.documentWidth();
        item.parentLeft = 0;  
        item.parentTop = 0;  
        return;
    }

    var parentNode = item.menu.parentNode;
    var parentOffsets = this.offsets(parentNode, item);
    item.parentLeft = parentOffsets.left;
    item.parentTop = parentOffsets.top;

    item.confinedWidthReserve = parentNode.clientWidth;

    // We could have absolutely-positioned DIV wrapped
    // inside relatively-positioned. Then parent might not
    // have any height. Try to find parent that has
    // and try to find whats left of its height for us.
    var obj = parentNode;
    var objOffsets = this.offsets(obj, item);
    while (obj.clientHeight + objOffsets.top
           < item.menu.offsetHeight + parentOffsets.top)
    {
        obj = obj.parentNode;
        objOffsets = this.offsets(obj, item);
    }

    item.confinedHeightReserve = obj.clientHeight
        - (parentOffsets.top - objOffsets.top);
};

floatingMenu.offsets = function(obj, item)
{
    var result =
    {
        left: 0,
        top: 0
    };

    if (obj === item.scrollContainer)
        return;

    while (obj.offsetParent && obj.offsetParent != item.scrollContainer)
    {  
        result.left += obj.offsetLeft;  
        result.top += obj.offsetTop;  
        obj = obj.offsetParent;
    }  

    if (window == window.parent)
        return result;

    // we're IFRAMEd
    var iframes = window.parent.document.body.getElementsByTagName("IFRAME");
    for (var i = 0; i < iframes.length; i++)
    {
        if (iframes[i].contentWindow != window)
           continue;

        obj = iframes[i];
        while (obj.offsetParent)  
        {  
            result.left += obj.offsetLeft;  
            result.top += obj.offsetTop;  
            obj = obj.offsetParent;
        }  
    }

    return result;
};

floatingMenu.doFloatSingle = function(item)
{
    this.findSingle(item);

    var stepX, stepY;

    this.computeParent(item);

    var cornerX = this.calculateCornerX(item);

    var stepX = (cornerX - item.nextX) * item.distance;
    if (Math.abs(stepX) < .5 && item.snap
        || Math.abs(cornerX - item.nextX) == 1)
    {
        stepX = cornerX - item.nextX;
    }

    var cornerY = this.calculateCornerY(item);

    var stepY = (cornerY - item.nextY) * item.distance;
    if (Math.abs(stepY) < .5 && item.snap
        || Math.abs(cornerY - item.nextY) == 1)
    {
        stepY = cornerY - item.nextY;
    }

    if (Math.abs(stepX) > 0 ||
        Math.abs(stepY) > 0)
    {
        item.nextX += stepX;
        item.nextY += stepY;
        this.move(item);
    }
};

floatingMenu.fixTargets = function()
{
};

floatingMenu.fixTarget = function(item)
{
};

floatingMenu.doFloat = function()
{
    this.fixTargets();
    for (var i=0; i < floatingArray.length; i++)
    {
        this.fixTarget(floatingArray[i]);
        this.doFloatSingle(floatingArray[i]);
    }
    setTimeout('floatingMenu.doFloat()', 20);
};

floatingMenu.insertEvent = function(element, event, handler)
{
    // W3C
    if (element.addEventListener != undefined)
    {
        element.addEventListener(event, handler, false);
        return;
    }

    var listener = 'on' + event;

    // MS
    if (element.attachEvent != undefined)
    {
        element.attachEvent(listener, handler);
        return;
    }

    // Fallback
    var oldHandler = element[listener];
    element[listener] = function (e)
        {
            e = (e) ? e : window.event;
            var result = handler(e);
            return (oldHandler != undefined) 
                && (oldHandler(e) == true)
                && (result == true);
        };
};

floatingMenu.init = function()
{
    floatingMenu.fixTargets();

    for (var i=0; i < floatingArray.length; i++)
    {
        floatingMenu.initSingleMenu(floatingArray[i]);
    }

    setTimeout('floatingMenu.doFloat()', 100);
};

// Some browsers init scrollbars only after
// full document load.
floatingMenu.initSingleMenu = function(item)
{
    this.findSingle(item);
    this.computeParent(item);
    this.fixTarget(item);
    item.nextX = this.calculateCornerX(item);
    item.nextY = this.calculateCornerY(item);
    this.move(item);
};

floatingMenu.insertEvent(window, 'load', floatingMenu.init);


// Register ourselves as jQuery plugin if jQuery is present
if (typeof(jQuery) !== 'undefined')
{
    (function ($)
    {
        $.fn.addFloating = function(options)
        {
            return this.each(function()
            {
                floatingMenu.add(this, options);
            });
        };
    }) (jQuery);
}

/* init */
floatingMenu.add('sticky_ad',{targetLeft: 0, targetTop: 10, snap: true});

;
/*
   var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-2455119-1']);
  _gaq.push(['_setDomainName', 'byggahus.se']);
  _gaq.push(['_setAllowHash', false]);
  _gaq.push(['_setLocalRemoteServerMode']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_trackPageLoadTime']);

  (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);
  })();
  */
;

