(function ($) {

/**
 * A progressbar object. Initialized with the given id. Must be inserted into
 * the DOM afterwards through progressBar.element.
 *
 * method is the function which will perform the HTTP request to get the
 * progress bar state. Either "GET" or "POST".
 *
 * e.g. pb = new progressBar('myProgressBar');
 *      some_element.appendChild(pb.element);
 */
Drupal.progressBar = function (id, updateCallback, method, errorCallback) {
  var pb = this;
  this.id = id;
  this.method = method || 'GET';
  this.updateCallback = updateCallback;
  this.errorCallback = errorCallback;

  // The WAI-ARIA setting aria-live="polite" will announce changes after users
  // have completed their current activity and not interrupt the screen reader.
  this.element = $('<div class="progress" aria-live="polite"></div>').attr('id', id);
  this.element.html('<div class="bar"><div class="filled"></div></div>' +
                    '<div class="percentage"></div>' +
                    '<div class="message">&nbsp;</div>');
};

/**
 * Set the percentage and status message for the progressbar.
 */
Drupal.progressBar.prototype.setProgress = function (percentage, message) {
  if (percentage >= 0 && percentage <= 100) {
    $('div.filled', this.element).css('width', percentage + '%');
    $('div.percentage', this.element).html(percentage + '%');
  }
  $('div.message', this.element).html(message);
  if (this.updateCallback) {
    this.updateCallback(percentage, message, this);
  }
};

/**
 * Start monitoring progress via Ajax.
 */
Drupal.progressBar.prototype.startMonitoring = function (uri, delay) {
  this.delay = delay;
  this.uri = uri;
  this.sendPing();
};

/**
 * Stop monitoring progress via Ajax.
 */
Drupal.progressBar.prototype.stopMonitoring = function () {
  clearTimeout(this.timer);
  // This allows monitoring to be stopped from within the callback.
  this.uri = null;
};

/**
 * Request progress data from server.
 */
Drupal.progressBar.prototype.sendPing = function () {
  if (this.timer) {
    clearTimeout(this.timer);
  }
  if (this.uri) {
    var pb = this;
    // When doing a post request, you need non-null data. Otherwise a
    // HTTP 411 or HTTP 406 (with Apache mod_security) error may result.
    $.ajax({
      type: this.method,
      url: this.uri,
      data: '',
      dataType: 'json',
      success: function (progress) {
        // Display errors.
        if (progress.status == 0) {
          pb.displayError(progress.data);
          return;
        }
        // Update display.
        pb.setProgress(progress.percentage, progress.message);
        // Schedule next timer.
        pb.timer = setTimeout(function () { pb.sendPing(); }, pb.delay);
      },
      error: function (xmlhttp) {
        pb.displayError(Drupal.ajaxError(xmlhttp, pb.uri));
      }
    });
  }
};

/**
 * Display errors on the page.
 */
Drupal.progressBar.prototype.displayError = function (string) {
  var error = $('<div class="messages error"></div>').html(string);
  $(this.element).before(error).hide();

  if (this.errorCallback) {
    this.errorCallback(this);
  }
};

})(jQuery);
;
Drupal.locale = { 'pluralFormula': function ($n) { return Number(($n!=1)); }, 'strings': {"An AJAX HTTP error occurred.":"Ett AJAX HTTP-fel intr\u00e4ffade","HTTP Result Code: !status":"Resultatkod f\u00f6r HTTP: !status","An AJAX HTTP request terminated abnormally.":"Ett AJAX HTTP-anrop avslutades ov\u00e4ntat.","Debugging information follows.":"Fels\u00f6kningsinformation f\u00f6ljer.","Path: !uri":"S\u00f6kv\u00e4g: !uri","StatusText: !statusText":"Statustext: !statusText","ResponseText: !responseText":"Svarstext: !responseText","ReadyState: !readyState":"Tillst\u00e5nd: !readyState","Loading":"Laddar","(active tab)":"(aktiv flik)","Hide":"D\u00f6lj","Show":"Visa","Re-order rows by numerical weight instead of dragging.":"Sortera om rader efter numerisk vikt ist\u00e4llet f\u00f6r drag-och-sl\u00e4pp.","Show row weights":"Visa radernas vikt","Hide row weights":"D\u00f6lj radernas vikt","Drag to re-order":"Drag f\u00f6r att ordna om","Changes made in this table will not be saved until the form is submitted.":"\u00c4ndringar som g\u00f6rs i denna tabell sparas inte f\u00f6rr\u00e4n formul\u00e4ret skickas.","Enabled":"Aktiverad","Edit":"Redigera","Not published":"Inte publicerad","Hide shortcuts":"D\u00f6lj genv\u00e4gar","@title dialog":"Dialog @title","Show shortcuts":"Visa genv\u00e4gar","Disabled":"Ej aktiverad","none":"ingen","Hide summary":"D\u00f6lj sammanfattning","Edit summary":"Redigera sammanfattning","Autocomplete popup":"Popup med automatisk komplettering","Searching for matches...":"S\u00f6ker efter tr\u00e4ffar...","Please wait...":"V\u00e4nligen v\u00e4nta...","Not in menu":"Ej i meny","New revision":"Ny version","No revision":"Inga versioner","By @name on @date":"Av @name @date","By @name":"Av @name","@number comments per page":"@number kommentarer per sida","Select all rows in this table":"Markera alla rader i tabellen","Deselect all rows in this table":"Avmarkera alla rader i tabellen","Customize dashboard":"Anpassa \u00f6versiktspanel","Done":"F\u00e4rdig","Submit":"Skicka","Cancel":"Avbryt","The selected file %filename cannot be uploaded. Only files with the following extensions are allowed: %extensions.":"Den valda filen %filename kan inte laddas upp. Endast filer med f\u00f6ljande \u00e4ndelser \u00e4r till\u00e5tna: %extensions.","Requires a title":"Kr\u00e4ver en titel","Don't display post information":"Visa inte information om inl\u00e4gg","Configure":"Konfigurera","Not restricted":"Ej begr\u00e4nsad","Restricted to certain pages":"Begr\u00e4nsad till vissa sidor","Not customizable":"Ej anpassningsbart","The changes to these blocks will not be saved until the \u003cem\u003eSave blocks\u003c\/em\u003e button is clicked.":"\u00c4ndringarna i dessa block kommer inte att sparas f\u00f6rr\u00e4n knappen \u003cem\u003eSpara block\u003c\/em\u003e klickas p\u00e5.","The block cannot be placed in this region.":"Blocket kan inte placeras i denna region.","Alias: @alias":"Alias: @alias","No alias":"Inga alias","This permission is inherited from the authenticated user role.":"Denna beh\u00f6righet \u00e4rvs fr\u00e5n rollen verifierad anv\u00e4ndare."} };;
jQuery(document).ready(function ($) {
	var urlParams = {};
	var e,
		a = /\+/g,  // Regex for replacing addition symbol with a space
		r = /([^&=]+)=?([^&]*)/g,
		d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
		q = window.location.search.substring(1);
	
	var node = "field_medarbetare_reference_nid=All";
	var tax = 'field_artikelcategory_tid=All';
	var date = 'date_filter_1%5Bvalue%5D%5Bdate%5D=';
	var keys = 'keys=';
	
	//Preserve old data
	if(q.length > 0){	
		while (e = r.exec(q)){
			urlParams[d(e[1])] = d(e[2]);
		}
		for(var attr in urlParams){
			if(attr == 'field_medarbetare_reference_nid'){
				var mark = '#node-' + urlParams[attr];
				node = attr + "=" + urlParams[attr];
			}else if(attr == 'field_artikelcategory_tid'){
				var mark = '#tax-' + urlParams[attr];
				tax = attr + "=" + urlParams[attr];
			}else if(attr == 'date_filter_1[value][date]'){
				var mark = '#date-' + urlParams[attr];
				date = 'date_filter_1%5Bvalue%5D%5Bdate%5D=' + urlParams[attr];
			}else if(attr == 'date_filter[value][date]'){
				var mark = '#year-' + urlParams[attr];
				date = 'date_filter%5Bvalue%5D%5Bdate%5D=' + urlParams[attr];
			}else if(attr == 'keys'){
				keys = 'keys=' + urlParams[attr];
				if(urlParams[attr].length > 0){
					$('#search_key').html('på <i>"' + urlParams[attr] + '"</i>');
				}
			}
			$(mark).addClass('marked-search');
		}
	}

	$('.custom-search').click(function(event){

		var search_id = event.target.id;
		event.preventDefault();
		
		var first = search_id.indexOf("-");
		
		var type = search_id.substr(0,first);
		var id = search_id.substr( (first+1) );
	
		//standard url definitions

		
		//Fetch new data
		if(type == 'node')
			node = "field_medarbetare_reference_nid=" + id;
		if(type == 'tax')
			tax = 'field_artikelcategory_tid=' + id;
		if(type == 'date')
			date = 'date_filter_1%5Bvalue%5D%5Bdate%5D=' + id;
		if(type == 'year')
			date = 'date_filter%5Bvalue%5D%5Bdate%5D=' + id;
		
		window.location.href = 'custom-search?' + node + '&' + tax + '&' + date + '&' + keys;
	});
});
;
(function ($) {

$(document).ready(function() {

  // Accepts a string; returns the string with regex metacharacters escaped. The returned string
  // can safely be used at any point within a regex to match the provided literal string. Escaped
  // characters are [ ] { } ( ) * + ? - . , \ ^ $ # and whitespace. The character | is excluded
  // in this function as it's used to separate the domains names.
  RegExp.escapeDomains = function(text) {
    return (text) ? text.replace(/[-[\]{}()*+?.,\\^$#\s]/g, "\\$&") : '';
  }

  // Attach onclick event to document only and catch clicks on all elements.
  $(document.body).click(function(event) {
    // Catch the closest surrounding link of a clicked element.
    $(event.target).closest("a,area").each(function() {

      var ga = Drupal.settings.googleanalytics;
      // Expression to check for absolute internal links.
      var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
      // Expression to check for special links like gotwo.module /go/* links.
      var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
      // Expression to check for download links.
      var isDownload = new RegExp("\\.(" + ga.trackDownloadExtensions + ")$", "i");
      // Expression to check for the sites cross domains.
      var isCrossDomain = new RegExp("^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\/.*(" + RegExp.escapeDomains(ga.trackCrossDomains) + ")", "i");

      // Is the clicked URL internal?
      if (isInternal.test(this.href)) {
        // Is download tracking activated and the file extension configured for download tracking?
        if (ga.trackDownload && isDownload.test(this.href)) {
          // Download link clicked.
          var extension = isDownload.exec(this.href);
          _gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')]);
        }
        else if (isInternalSpecial.test(this.href)) {
          // Keep the internal URL for Google Analytics website overlay intact.
          _gaq.push(["_trackPageview", this.href.replace(isInternal, '')]);
        }
      }
      else {
        if (ga.trackMailto && $(this).is("a[href^=mailto:],area[href^=mailto:]")) {
          // Mailto link clicked.
          _gaq.push(["_trackEvent", "Mails", "Click", this.href.substring(7)]);
        }
        else if (ga.trackOutbound && this.href) {
          if (ga.trackDomainMode == 2 && isCrossDomain.test(this.href)) {
            // Top-level cross domain clicked. document.location is handled by _link internally.
            _gaq.push(["_link", this.href]);
          }
          else if (ga.trackOutboundAsPageview) {
            // Track all external links as page views after URL cleanup.
            // Currently required, if click should be tracked as goal.
            _gaq.push(["_trackPageview", '/outbound/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
          }
          else {
            // External link clicked.
            _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
          }
        }
      }
    });
  });
});

})(jQuery);
;
jQuery(document).ready(function() {
	(function($){
		$('.node-artikel .btn-forward').bind('click', nextSlide);
		$('.node-artikel .btn-backward').bind('click', lastSlide);
	})(jQuery);
});


function nextSlide() {
	$('.node-image-slideshow .images').append( $('.node-image-slideshow .images').children('div').first().addClass('hidden') );
	$('.node-image-slideshow .images').children().first().removeClass('hidden');
	return false;
}
		
function lastSlide() {
	$('.node-image-slideshow .images').children().first().addClass('hidden');
	$('.node-image-slideshow .images').prepend( $('.node-image-slideshow .images').children('div').last().removeClass('hidden') );
	return false;
}
;

