// RANDOM HEADER IMAGE START //
// Set up the image files to be used.
var theImages = new Array()

// To add more image files, continue with the
// pattern below, adding to the array.
theImages[0] = 'HeaderImage1.jpg'


var j = 0
var p = theImages.length;

var preBuffer = new Array()

for (i = 0; i < p; i++){
    preBuffer[i] = new Image()
    preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));

// RANDOM HEADER IMAGE END //

function showShops(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}

function countCheckedBrandBoxed()
{
    
}

$(document).ready(function() {
    swapValues = [];
    
    $(".WaterMark").each(function(i){
        swapValues[i] = $(this).val();
            if ($(this).val() == swapValues[i]) {
                $(this).css("color", "#999");
            }
        $(this).focus(function(){
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
                $(this).css("color", "#FFF");
            }
        }).blur(function(){
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValues[i]);
                $(this).css("color", "#999");
            }
        });
    });
    
    $(".OfferRequestBrandList input").each(function(i){
        
        $(this).click(function(){
            
            if( $(".OfferRequestBrandList input:checkbox:checked").length > 2 )
            {
                alert('Er mogen maximaal 2 merken geselecteerd worden');
                return false;
            }
            
        });
        
    });
    
    $("input:text.ShirtsShotsSocks").each(function(i){
        $(this).change(function () {
            if($(this).val() != "")
            {
                $(".ShirtsShotsSocks input:checkbox").attr('checked', true);
            }
        });
    });
    $("input:text.Shirts").each(function(i){
        $(this).change(function () {
            if($(this).val() != "")
            {
                $(".Shirts input:checkbox").attr('checked', true);
            }
        });
    });
    $("input:text.TrainingSuits").each(function(i){
        $(this).change(function () {
            if($(this).val() != "")
            {
                $(".TrainingSuits input:checkbox").attr('checked', true);
            }
        });
    });
    $("input:text.SportBags").each(function(i){
        $(this).change(function () {
            if($(this).val() != "")
            {
                $(".SportBags input:checkbox").attr('checked', true);
            }
        });
    });
    $("input:text.CoachJacks").each(function(i){
        $(this).change(function () {
            if($(this).val() != "")
            {
                $(".CoachJacks input:checkbox").attr('checked', true);
            }
        });
    });
    
    $(".PopUpCloseBtn").click (function() {
        $("#PopUpAdBg").hide();
        $("#PopUpAd").hide();
        $("PopUpClose").hide();
    });
    
    
});

function twitterCallback2(twitters) {
  var statusHTML = [];
  for (var i=0; i<twitters.length; i++){
    var username = twitters[i].user.screen_name;
    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
      return '<a href="'+url+'">'+url+'</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
    });
    statusHTML.push('<li><span class="twitter_message">'+status+'</span> <a class="twitter_time" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'" target="_blank">'+relative_time(twitters[i].created_at)+'</a></li>');
  }
  if(document.getElementById('twitter_update_list') != null){
    document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
  }
}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return 'Minder dan een minuut geleden';
  } else if(delta < 120) {
    return 'Een minuut geleden';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + ' minuten geleden';
  } else if(delta < (120*60)) {
    return 'Een uur geleden';
  } else if(delta < (24*60*60)) {
    return (parseInt(delta / 3600)).toString() + ' uur geleden';
  } else if(delta < (48*60*60)) {
    return '1 dag geleden';
  } else {
    return (parseInt(delta / 86400)).toString() + ' dagen geleden';
  }
}



