if (window.adgroupid == undefined) {
window.adgroupid = Math.round(Math.random() * 1000);
}

var $ = jQuery;	

$(document).ready(function() {
    // Captify images
    $('img.captify').captify({});

    $('p.summary').each(function() {
    	read_more_element = $(this).next('a.readMore');
    	if (read_more_element.length > 0) {
			url = read_more_element.attr('href');
	        text = $(url).text();
	        $(this).append('<a href="' + url + '" class="readmore" title="' + text + '"><span>Les mer</span></a>');
    	}
    });
    
    $('p.summary').each(function() {
    	read_more_element = $(this).next('p.readMore');
    	if (read_more_element.length > 0) {
    		link = $(read_more_element).find('a');
	    	url = $(link).attr('href');
	        text = $(link).text();
	        $(this).append('<a href="' + url + '" class="readmore" title="' + text + '"><span>Les mer</span></a>');
    	}
    });

    $('.topstory p.summary').each(function() {
      url = $(this).parent().parent().find('a').attr('href');
      $(this).append('<a href="' + url + '" class="readmore" title="Les mer"><span>Les mer</span></a>');
    });
    
    /*$('.logo input.field').placeholder();*/
    
    //Set style on selected tab
    $('#tabs').tabs();
    
   /* $('ul.tabs>li>a').click(function() {
    	delay(500);
        $("ul.tabs>li:has(a)").removeClass("active");
    	$("ul.tabs>li:has(a.current)").addClass("active");
    });*/
    
    // Sticky skyskraper
    var $banner = jQuery("#skyskraper2"),
    $window = jQuery(window),
    offset = $banner.offset(),
    topPadding = 16;
    $window.scroll(
    	function() {
    		if(offset){
			    if ($window.scrollTop() > offset.top) {
			    	$banner.stop().animate({
			    		marginTop: parseInt($window.scrollTop() - offset.top + topPadding)
			    	});
			    } else {
			    	$banner.stop().animate({
			    		marginTop: 0
			    	});
			    }
    		}
    	}
    );
});

function openLink(href, target) {
    window.open(href, target);
    return false;
}

