jQuery.fn.columnizeList = function(settings){
  settings = jQuery.extend({
    cols: 3,
    constrainWidth: 0
  }, settings);
    // var type=this.getNodeType();
    var prevColNum = 10000; // Start high to avoid appending to the wrong column
    var size = $('li',this).size();
    var percol = Math.ceil(size/settings.cols);
    var container = this;
    var tag = container[0].tagName.toLowerCase();
    var classN = container[0].className;
    var colwidth = Math.floor($(container).width()/settings.cols);
    var widthstring = '';
    var maxheight = 0;
    if (settings.constrainWidth) {
      widthstring = 'width:'+colwidth+'px;';
    };
    // Prevent stomping on existing ids with pseudo-random string
    var rand = Math.floor(Math.random().toPrecision(6)*10e6);
    $('<ul id="container'+rand+'" class="'+classN+'"></ul>').insertBefore(container);
    $('li',this).each(function(i) {
      var currentColNum = Math.floor(i/percol);
      if(prevColNum != currentColNum) {
        if ($("#col"+rand+"-"+prevColNum).height() > maxheight) { maxheight = $("#col"+rand+"-"+prevColNum).height()};
        $("#container"+rand).append('<li style="float:left;list-style:none;margin:0;padding:0;'+widthstring+' "><'+tag+' id="col'+rand+'-'+currentColNum+'"></'+tag+'></li>');
      }
      $(this).attr("value",i+1).appendTo("#col"+rand+'-'+currentColNum);
      prevColNum = currentColNum;
    });
    $("#container"+rand).after('<div style="clear: both;"></div>');
    $("#container"+rand+" "+tag).height(maxheight);
    this.remove();
    if($.browser.msie){
      // This hack is an unmitigated disaster
      $('#container'+rand+' li li').css({'margin-right':'10px'});
    }
return this;
}

$(document).ready(function() {  
  $("#intro img").css('height', Math.max(130, (Math.min($('#intro').height(), 250))) + 10).show();  
  
  var $prev = $('#slideshow .prev'),//prev button
	  $next = $('#slideshow .next');//next button
	
	$prev.hide();
	$length = $("#slideshow li").length - 3;
	$("#slideshow li:first").attr("id","first");
  $("#slideshow li:eq(" + $length + ")").attr("id","last");
  
  /*
  $('#slideshow').serialScroll({
		items:'li',
		prev:'#screen2 a.prev',
		next:'#screen2 a.next',
		offset:-5,
		start:0,
		duration:2000,
		force:true,
		cycle: false,
		step: 3,
		exclude: 2,
		jump: false,
		onAfter:function(elem){
    var currentView = $(elem).attr("id");
    if ( currentView == "first" ) { 
      $prev.fadeOut("fast"); 
    } else { 
      $prev.fadeIn("normal"); 
    }

    if( currentView == "last" ) { 
      $next.fadeOut("fast"); 
    } else { 
      $next.fadeIn("normal"); 
    }
    }
	});

	
	var brands = eval({"after eden":11,"agu":11,"bjorn-borg":11,"dolce gabbana":12,"anita maternity":12,"panache":13,"batavus":14,"abrar":14,"berba":14,"birkenstock":14,"g-star":14,"oakley":15,"lingadore":16,"bon giorno":17,"le coq sportif":18,"new balance":18,"nike pro":21,"lacoste":21,"countryfield":26,"eastpak":29,"burberry":29,"pliage":36,"lovable":36,"adidas":38,"fitflop":64});
  for (var i in brands) {
    var pv = brands[i];
    elem = $('<li>' + i + '</li>').css("fontSize", (pv / 10 < 1) ? pv / 10 + 1 + "em": (pv / 10 > 2) ? "2em" : pv / 10 + "em");
    elem.appendTo($('#taglist'));
  }

  $('.gotoShop').click(function() { 
    shopname = $(this).attr('title');
    console.log(shopname);
    $.ajax({
      timeout: 5000,
      async: false,
      error: $('#couponu').html(''),
      url: 'http://www.thuisvergelijk.nl/coupon/getbyshop/' + shopname,
      success: function(data) {
        $('#couponu').html(data);
      }
      console.log($('#couponu').html());
    });
    var $a = $(this);
    if ($('#couponu').html()) {
      jAlert($('#couponu').html(), 'Kortingcode', function() { window.open($a.attr('href')); });
      return false;          
    }
    else {
      return true;
    }
  
  });
    */
  if ($('.columns li').size() > 6) {
    $('.columns').columnizeList({cols:3,constrainWidth:1});
  }
});