function orderAjax( artID , num ){
  var myRequest = new Request.HTML({
      method: 'get',
      url: 'ajax.php?add=toCart&artID=' + artID + '&num=' + num,
      onSuccess: function( responseTree , responseElements , responseHTML , responseJavaScript ) {
        var content = responseHTML.split( '###' );
        $( 'cartPulldown' ).innerHTML = content[ 2 ];
        $( 'miniCart_numArticles' ).innerHTML = content[ 1 ];
        $( 'miniCart_totalPrice' ).innerHTML = content[ 0 ];
      }
  });
  myRequest.send();
}

function hightlight( elm , doHightlight ){
  if( doHightlight )
    elm.style.backgroundColor = "#b2b4bf";
  else
    elm.style.backgroundColor = "#fff";
}

// Auto fill search boxes.
function autoFill( v ){
  return true;

  if( v.length < 3 ){
    $( 'autoFillResult' ).style.display = 'none';
    return false;
  }

  var location = 'ajax.php?get=articles&label=' + v;

  var myRequest = new Request.HTML({
      method: 'get',
      url: location,
      onSuccess: function( responseTree , responseElements , responseHTML , responseJavaScript ) {
        if( responseHTML != '' ){
          $( 'autoFillResult' ).innerHTML = responseHTML;
          $( 'autoFillResult' ).style.display = '';
        }else{
          $( 'autoFillResult' ).style.display = 'none';
        }
      }
  });
  myRequest.send();

  return true;

}

function clickResult( v ){
  $( 'searchField' ).value = v;
  $( 'autoFillResult' ).style.display = 'none';
}

var timer = 0;
function changeArticleNum( artID , direction , recalculate , min , max ){
  if( !min ) var min = 0;
  if( !max ) var max = 0;
  var num = $( 'num_' + artID + '' ).value;
  if( ( ( direction == 'minus' && num <= min ) || ( direction == 'plus' && num >= max ) ) && ( min != 0 || max != 0 ) ){
		//console.log( max );
		//console.log( num );
		if( max > 0 ){
			if( direction == 'minus' && num <= min && ( min != 0 ) ){
				$( 'btn_minus_' + artID + '' ).style.opacity = '0.4';
				$( 'btn_minus_' + artID + '' ).style.filter = 'alpha(opacity=40)';
			}
			if( direction == 'plus' && num >= max && ( max != 0 ) ){
				$( 'btn_plus_' + artID + '' ).style.opacity = '0.4';
				$( 'btn_plus_' + artID + '' ).style.filter = 'alpha(opacity=40)';
			}
			return;
		}else{
			if( direction == 'minus' && num <= min ){
				$( 'btn_minus_' + artID + '' ).style.opacity = '0.4';
				$( 'btn_minus_' + artID + '' ).style.filter = 'alpha(opacity=40)';
				return;
			}
		}
  }
	// Normale order
	if( min == 0 && max == 0 ){
		if( direction == 'minus' && num <= 0 ){
			$( 'btn_minus_' + artID + '' ).style.opacity = '0.4';
			$( 'btn_minus_' + artID + '' ).style.filter = 'alpha(opacity=40)';
			return;
		}
	}
	//console.log( num );
  if( direction == 'plus' )
    $( 'num_' + artID + '' ).value = ( num * 1 ) + 1;
    $( 'btn_minus_' + artID + '' ).style.opacity = '1.0';
    $( 'btn_minus_' + artID + '' ).style.filter = 'alpha(opacity=100)';
  if( direction == 'minus' ){
		//console.log( 'minus' , num , ( num * 1 ) - 1 );
    /*if( ( ( num * 1 ) - 1 ) < 0 ) $( 'num_' + artID + '' ).value = 0; else*/ $( 'num_' + artID + '' ).value = ( num * 1 ) - 1;
		//console.log( $( 'num_' + artID + '' ).value );
    $( 'btn_plus_' + artID + '' ).style.opacity = '1.0';
    $( 'btn_plus_' + artID + '' ).style.filter = 'alpha(opacity=100)';
  }
  if( recalculate == true )
    recalculateSubtotal();


  var num = $( 'num_' + artID + '' ).value;
	//console.log( num );

  //if( ( min + max ) > 0 ){
    if( direction == 'minus' && num <= min ){
      $( 'btn_minus_' + artID + '' ).style.opacity = '0.4';
      $( 'btn_minus_' + artID + '' ).style.filter = 'alpha(opacity=40)';
    }
    if( direction == 'plus' && num >= max && max != 0 ){
      $( 'btn_plus_' + artID + '' ).style.opacity = '0.4';
      $( 'btn_plus_' + artID + '' ).style.filter = 'alpha(opacity=40)';
    }
  /*}else{
    if( num <= 0 ){
      $( 'btn_minus_' + artID + '' ).style.opacity = '0.4';
      $( 'btn_minus_' + artID + '' ).style.filter = 'alpha(opacity=40)';
    }
  }*/
	
  //if( num >= 100 ){
  //  return false;
  //}
  //timer = window.setTimeout( changeArticleNum( artID , direction , recalculate ), 1000 );
  return true;
}

/*function cancelArticleNum(){
http://www.stermediastore.com/ajax.php?add=toCart&artID=340902&num=5
  window.clearTimeout(timer);
}*/







var timeout = 300;
var closetimer  = 0;
var ddmenuitem  = 0;
function mopen(id){
  mcancelclosetime();
  if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
  ddmenuitem = document.getElementById(id);
  ddmenuitem.style.visibility = 'visible';
}
function mclose(){
  if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
function mclosetime(){
  closetimer = window.setTimeout(mclose, timeout);
}
function mcancelclosetime(){
  if(closetimer)  {
    window.clearTimeout(closetimer);
    closetimer = null;
  }
}
document.onclick = mclose;



function onHold () {
  // Settings for holder
  this.start = 600; // When to start
  this.speedUp = 3; // After how much cycles go to hyperspeed

  this.actionSpeed = 200; // How fast when holded
  this.hyperSpeed = 70; // How fast when holded with hyperspeed

  this.timer = null; // Tmp-holder timer
  this.speedCounter = 0;
  this.element = null; // Tmp-holder element

  this.down = function ( elm , artID )
  {
    // Init
    this.element = elm;
    this.speedCounter = 0;

    elm.onmouseup = function ()
    {
      onHold.up ();
			/*if( artID ){
				var src = elm.src.split( 'gfx/' );
				if( src[ 1 ] == 'btn_plus' ){
					var num = ( $( 'num_' + artID ).value * 1 ) + 1;
				}else{
					var num = ( $( 'num_' + artID ).value * 1 ) - 1;
				}
				orderAjax( artID , num );
			}*/
    }

    // Wait until start
    this.timer = setTimeout ( 'onHold.click ();', this.start );
  }

  this.click = function ( )
  {
    if ( this.element.onclick () )
    {
      this.timer = setTimeout ( 'onHold.click ();', ( this.speedCounter ++ > this.speedUp ? this.hyperSpeed : this.actionSpeed ) );
      return true;
    }
    return false;
  }

  this.up = function ( )
  {
    clearTimeout ( this.timer );
    this.element = null;

    return false;
  }
}
var onHold = new onHold ();

function displayOldArticles( elm , location ){
  if( elm.checked ){
    window.location = location + '&displayOld=1';
  }else{
    window.location = location + '&displayOld=0';
  }
}

function clearPopular(){
  document.getElementById( 'tab_films' ).className = '';
  document.getElementById( 'articleExpected_films' ).style.display = 'none';
  document.getElementById( 'tab_muziek' ).className = '';
  document.getElementById( 'articleExpected_muziek' ).style.display = 'none';
  document.getElementById( 'tab_games' ).className = '';
  document.getElementById( 'articleExpected_games' ).style.display = 'none';
}

function switchPopular( id ){
  clearPopular();
  document.getElementById( 'tab_' + id ).className = 'active';
  document.getElementById( 'articleExpected_' + id ).style.display = '';
}
