  var oCursor = null;
  var iMsgId = 0;
  
  $(document).ready(function() {
    
    $('body').mousemove(function(e){
      oCursor = e;
    });
    
    // message
    if($('.div_msg_ui').length > 0) {
      
      var buttons = {};
      buttons["OK"] = function() {
        $(this).dialog("close");
      }
      
      $('.div_msg_ui').dialog({
        modal: true,
        buttons: buttons,
	open: function(event, ui) {
	  $('.ui-dialog-buttonpane button[type=button]:first').focus();
	}
      });
      
    }
    
    // custom buttons
    $('.div_button_red').hover(function() {
      $(this).addClass('div_button_red_over');
    }, function() {
      $(this).removeClass('div_button_red_over');
    });
    
    //$('.div_button_red').click(function() {
    //  $(this).contents().find('input').trigger('click');
    //  return false;
    //});
    
    $('.div_button_red_round_left').click(function() {
      $(this).next().children('input, button').trigger('click');
    });
    
    $('.div_button_red_round_right').click(function() {
      $(this).prev().children('input, button').trigger('click');
    });
    
    // menu top
    $('.div_header_toplink').hover(function() {
      $(this).addClass('div_header_toplink_over');
    }, function() {
      $(this).removeClass('div_header_toplink_over');
    });
    
    $('#form_contact_nl').submit(function() {
      
      var aVerplicht = new Array();
      aVerplicht[0] = 'gegevens[Naam]';
      aVerplicht[1] = 'gegevens[Telefoon]';
      aVerplicht[2] = 'gegevens[Email]';
      aVerplicht[3] = 'gegevens[Opmerkingen]';
      
      var sInputs = ':input[name=\''+aVerplicht.join('\'][value=\'\'], :input[name=\'')+'\'][value=\'\']';
      
      if($(sInputs).length >= 1) {
        var sMelding = 'De volgende velden zijn verplicht:\n';
        $(sInputs).each(function() {
          var sVeldnaam = $(this).attr('name').replace('gegevens[', '');
          sVeldnaam = sVeldnaam.slice(0, -1);
          sMelding += '- '+sVeldnaam+'\n';
        });
        alert(sMelding);
        return false;
      } else {
        return true;
      }
    });
    
    $('a[href=#]').click(function() {
      return false;
    });
    
    
    
    $('.click_goto_a').click(function() {
      if((sLink = $(this).find('a:first').attr('href')) != undefined) {
        document.location = sLink;
      }
    });
    
    $('.div_nieuwsitem_kort').hover(function() {
      $(this).next('.div_nieuwsitem_kort_seperator').addClass('div_nieuwsitem_kort_seperator_solid');
      $(this).prev('.div_nieuwsitem_kort_seperator').addClass('div_nieuwsitem_kort_seperator_solid');
    }, function() {
      $(this).next('.div_nieuwsitem_kort_seperator').removeClass('div_nieuwsitem_kort_seperator_solid');
      $(this).prev('.div_nieuwsitem_kort_seperator').removeClass('div_nieuwsitem_kort_seperator_solid');
    });
    
    $('.div_nieuws_fotos a').lightBox({txtImage:'Foto',txtOf:'v/d'});
    $('.div_fotos a').lightBox({txtImage:'Foto',txtOf:'v/d'});
    
    // defwaardes instellen voor een rankable product
    $('.div_rankable img').each(function() {
      $(this).attr('def_src', $(this).attr('src'));
    })
    
    // rankable
    $('.div_rankable img').hover(function() {
      $(this).attr('src', 'images/icon_star_active.png');
      $(this).prevAll('img').attr('src', 'images/icon_star.png');
      $(this).nextAll('img').attr('src', 'images/icon_star_grey.png');
    });
    
    $('.div_rankable img').mouseout(function() {
      $('.div_rankable img').each(function() {
         $(this).attr('src', $(this).attr('def_src'));
      });
    });
    
    // ranken van een product
    $('.div_rankable img').click(function() {
      $(this).parent().attr('justvoted', '1');
      $('.div_rankable img').unbind();
      $.post('ajax/rank_product.php', {product_id: $(this).parent().attr('product_id'), rank: $(this).attr('alt')}, function(data) {
        if(data.succes == true) {
          $('.div_rankable img').unbind();
          if(data.new_votecount != '') {
            $('div[justvoted=1] > span').html(data.new_votecount);
          }
          $('div[justvoted=1]').removeAttr('justvoted');
        }
      }, 'json');
    });
		
		//aanbieding op webshop
		$('.div_aanbieding').hover(function() {
			$('.div_aanbieding. .aanbieding_ster').css('background-image', 'url(../images/aanbieding_stert.gif)');
		}, function() {
			$('.div_aanbieding. .aanbieding_ster').css('background-image', 'url(../images/aanbieding_ster.gif)');
    });
    
    var iTimeoutId = null;
    
    // submenu
    $('.div_header_middlelink').hover(function() {
      window.clearTimeout(iTimeoutId);
      
      if($(this).attr('last_hovered')) {
        return false;
      }
      
      $('.div_header_middlelink').each(function() {
        $(this).css('background-image', 'url('+$(this).attr('normal_img')+')');
      });
      $(this).css('background-image', 'url('+$(this).attr('hover_img')+')');
      
      $('.div_header_middlelink[last_hovered=1]').removeAttr('last_hovered');
      $(this).attr('last_hovered', '1');
      
      $('.div_header_middlelink_submenu:animated').stop().slideUp(5, function() {
        $(this).css('height', null);
        $(this).css('padding', null);
      });
      $('.div_header_middlelink_submenu:visible').slideUp(200);
      
      if($(this).children('.div_header_middlelink_submenu').length > 0) {
        $(this).children('.div_header_middlelink_submenu').slideDown();
      }
      
    }, function() {
      window.clearTimeout(iTimeoutId);
      iTimeoutId = window.setTimeout(hide_submenus, 1000);
    });
    
    $('.div_header_middlelink_submenu a').hover(function() {
      window.clearTimeout(iTimeoutId);
    }, function() {
      iTimeoutId = window.setTimeout(hide_submenus, 1000);
    });
    
  });
  
  function hide_submenus() {
    $('.div_header_middlelink[last_hovered=1]').removeAttr('last_hovered');
    $('.div_header_middlelink_submenu:visible').slideUp();
    $('.div_header_middlelink').each(function() {
      $(this).css('background-image', 'url('+$(this).attr('normal_img')+')');
    });
    $('.div_header_middlelink_active').each(function() {
      $(this).css('background-image', 'url('+$(this).attr('hover_img')+')');
    });
  }
  
  function gotoProduct(piProduct) {
    document.location = 'product.php?id='+piProduct;
  }
  
  function addProduct(piProduct) {
    
    iAmount = $('.input_productcount_'+piProduct).val();
    
    iAmount = iAmount == undefined ? 1 : iAmount;
    
    var oMsg = $('#div_message').clone();
    oMsg.removeAttr('id');
    $('body').append($(oMsg));
    $(oMsg).css({'top' : (oCursor.pageY - 10)+'px', 'left' : (oCursor.pageX + 10)+'px'});
    $(oMsg).fadeIn(300);
    
    $.post('ajax/add_product.php', {prId: piProduct, count: iAmount}, function(data) {
      sMessage = '';
      if(data.succes == true) {
        sMessage += 'Het artikel is aan uw winkelwagen toegevoegd';
      } else {
        sMessage += 'Error tijdens toevoegen artikel aan winkelwagen';
        sMessage += '<br />'+data.message;
      }
      $(oMsg).html(sMessage).animate({opacity: 1.0}, 1500).fadeOut(500, function() {
        $(this).remove();
      });
    }, 'json');
  }
  
  function hideMessage(piMessageId) {
    $('#'+piMessageId).fadeOut();
  }
  
  function cdSmallOver(pObj) {
    iId = pObj.getAttribute('id').replace('cd_small_container_', '');
    oBorderAbove = 'div_cd_small_border_border_'+(iId -1);
    oBorderBelow = 'div_cd_small_border_border_'+iId;
    if(oDiv = document.getElementById(oBorderAbove)) {
      document.getElementById(oBorderAbove).className = 'div_cd_small_border_solid';
    }
    if(oDiv = document.getElementById(oBorderBelow)) {
      document.getElementById(oBorderBelow).className = 'div_cd_small_border_solid';
    }
    pObj.className = 'div_cd_small_container_over';
  }
  
  function cdSmallOut(pObj) {
    iId = pObj.getAttribute('id').replace('cd_small_container_', '');
    oBorderAbove = 'div_cd_small_border_border_'+(iId -1);
    oBorderBelow = 'div_cd_small_border_border_'+iId;
    if(oDiv = document.getElementById(oBorderAbove)) {
      document.getElementById(oBorderAbove).className = 'div_cd_small_border_dotted';
    }
    if(oDiv = document.getElementById(oBorderBelow)) {
      document.getElementById(oBorderBelow).className = 'div_cd_small_border_dotted';
    }
    pObj.className = 'div_cd_small_container';
  }
  
  function buttonRedOver(pObj) {
    pObj.className = 'div_button_grey_over';
  }
  
  function buttonRedOut(pObj) {
    pObj.className = 'div_button_grey';
  }
  
  function buttonResultsClick(pObj) {
    if(pObj.id == 'div_button_results') var sTar = 'div_content_resultpage';
    else if(pObj.id == 'div_button_search') var sTar = 'div_content_searchpage';
    oTar = document.getElementById(sTar);
    // activate right page
    oTar.style.display = 'block';
    var aChilds = pObj.parentNode.childNodes;
    for(var i = 0; i < aChilds.length; i ++) {
      // hide all other pages
      if(aChilds[i].className == 'div_content_normal' && aChilds[i].id != oTar.id) {
        aChilds[i].style.display = 'none';
      }
      // set events for other buttons and make them grey again
      if((aChilds[i].className == 'div_button_grey_active' || aChilds[i].className == 'div_button_grey_over' || aChilds[i].className == 'div_button_grey') && aChilds[i].id != pObj.id) {
        aChilds[i].onclick = Function("buttonResultsClick(this)");
        aChilds[i].onmouseover = Function("buttonRedOver(this)");
        aChilds[i].onmouseout = Function("buttonRedOut(this)");
        aChilds[i].className = 'div_button_grey';
      }
    }
    // remove events for active item, clicking it wont do anything anyway and make it red
    pObj.onclick = null;
    pObj.onmouseover = null;
    pObj.onmouseout = null;
    pObj.className = 'div_button_grey_active';
  }
  
  function buttonProductClick(pObj) {
    if(pObj.id == 'div_button_resultaten') var sTar = 'div_content_resultpage';
    else if(pObj.id == 'div_button_zoeken') var sTar = 'div_content_searchpage';
    else if(pObj.id == 'div_button_details') var sTar = 'div_content_detailpage';
    else if(pObj.id == 'div_button_kassa') var sTar = 'div_content_kassapage';
    oTar = document.getElementById(sTar);
    // activate right page
    oTar.style.display = 'block';
    var aChilds = pObj.parentNode.childNodes;
    for(var i = 0; i < aChilds.length; i ++) {
      // hide all other pages
      if(aChilds[i].className == 'div_content_normal' && aChilds[i].id != oTar.id) {
        aChilds[i].style.display = 'none';
      }
      // set events for other buttons and make them grey again
      if((aChilds[i].className == 'div_button_grey_active' || aChilds[i].className == 'div_button_grey_over' || aChilds[i].className == 'div_button_grey') && aChilds[i].id != pObj.id) {
        aChilds[i].onclick = Function("buttonProductClick(this)");
        aChilds[i].onmouseover = Function("buttonRedOver(this)");
        aChilds[i].onmouseout = Function("buttonRedOut(this)");
        aChilds[i].className = 'div_button_grey';
      }
    }
    // remove events for active item, clicking it wont do anything anyway and make it red
    pObj.onclick = null;
    pObj.onmouseover = null;
    pObj.onmouseout = null;
    pObj.className = 'div_button_grey_active';
  }
  
  function buttonWinkelClick(pObj) {
    if(pObj.id == 'div_button_winkelwagen') var sTar = 'div_content_winkelwagen';
    else if(pObj.id == 'div_button_gegevens') var sTar = 'div_content_gegevens';
    oTar = document.getElementById(sTar);
    // activate right page
    oTar.style.display = 'block';
    var aChilds = pObj.parentNode.childNodes;
    for(var i = 0; i < aChilds.length; i ++) {
      // hide all other pages
      if(aChilds[i].className == 'div_content_normal' && aChilds[i].id != oTar.id) {
        aChilds[i].style.display = 'none';
      }
      // set events for other buttons and make them grey again
      if((aChilds[i].className == 'div_button_grey_active' || aChilds[i].className == 'div_button_grey_over' || aChilds[i].className == 'div_button_grey') && aChilds[i].id != pObj.id) {
        aChilds[i].onclick = Function("buttonWinkelClick(this)");
        aChilds[i].onmouseover = Function("buttonRedOver(this)");
        aChilds[i].onmouseout = Function("buttonRedOut(this)");
        aChilds[i].className = 'div_button_grey';
      }
    }
    // remove events for active item, clicking it wont do anything anyway and make it red
    pObj.onclick = null;
    pObj.onmouseover = null;
    pObj.onmouseout = null;
    pObj.className = 'div_button_grey_active';
  }
  
  function makeEven(pObj1, pObj2) {
    obj1 = document.getElementById(pObj1);
    obj2 = document.getElementById(pObj2);
    if(obj1.offsetHeight < obj2.offsetHeight) {
      obj1.style.minHeight = obj2.offsetHeight+'px';
    } else {
      obj2.style.minHeight = obj1.offsetHeight+'px';
    }
  }
  
  function blockHeights() {
    var divs = document.getElementsByTagName('div');
    var iHighest = 0;
    //kijk even welk blok het hoogst is
    for(var i = 0; i < divs.length; i ++) {
      if(divs[i].className == 'div_contentblock') {
        if(divs[i].offsetHeight > iHighest) {
          iHighest = divs[i].offsetHeight;
        }
      }
    }
    var divs = document.getElementsByTagName('div');
    //loop door alle 2 of 3 contenblokken
    for(var i = 0; i < divs.length; i ++) {
      if(divs[i].className == 'div_contentblock') {
        if(divs[i].offsetHeight < iHighest) {
          divNodes = document.getElementById(divs[i].id).childNodes;
          //bekijk de hoogte van de eerste child-div
          var first = true;
          for(var j = 0; j < divNodes.length; j ++) {
            if(divNodes[j].nodeName == 'DIV' && first) {
              //-2 ivm de border-bottom van 2 px
              iContentHeight = (iHighest - document.getElementById(divs[i].id).childNodes[j].offsetHeight) -2;
              first = false;
            } else if(divNodes[j].nodeName == 'DIV' && !first) {
              //min-height ivm met fotogallerij en ajax
              document.getElementById(divs[i].id).childNodes[j].style.minHeight = iContentHeight+'px';
              //min-height wordt niet ondersteund door IE6
              /*@cc_on @*/
              /*@if (@_jscript_version < 5.7) {
                document.getElementById(divs[i].id).childNodes[j].style.height = iContentHeight+'px';
              }
              /*@end @*/ 
            }
          }
        }
      }
    }
  }
  
  function selectChange(pObj) {
    ajax('ajax/gen_subgenres.php?id='+pObj.options[pObj.selectedIndex].value, 'td_subgenres');
  }
  
  var newwindow = '';
  
  function openPlayer(piProductId, piNr) {
    var sUrl = 'player.php?id='+piProductId+'&nr='+piNr;
    if (!newwindow.closed && newwindow.location) {
      newwindow.location.href = sUrl;
    }
    else {
      var browser = navigator.appName;
      // var height = browser == 'Microsoft Internet Explorer' ? 245 : 221;
      // var width = 500;
      // newwindow = window.open(sUrl,'sthPlayer','height='+height+',width='+width+', resizable=yes, toolbar=yes, location=yes, menubar=yes');
      var height = 250;
      var width = 480;
      newwindow = window.open(sUrl,'sthPlayer','height='+height+',width='+width+', resizable=yes');
      if (!newwindow.opener) newwindow.opener = self;
    }
    if (window.focus) {newwindow.focus()}
    return false;
  }
  
  function openVideoplayer(psVid, piBreedte, piHoogte) {
    var sUrl = 'videoplayer.php?vid='+psVid+'&width='+piBreedte+'&height='+piHoogte;
    if (!newwindow.closed && newwindow.location) {
      newwindow.close();
      //newwindow.location.href = sUrl;
      //newwindow.resizeTo(piBreedte +30, piHoogte +50);
    }
    //else {
      var browser = navigator.appName;
      // var height = browser == 'Microsoft Internet Explorer' ? 245 : 221;
      // var width = 500;
      // newwindow = window.open(sUrl,'sthPlayer','height='+height+',width='+width+', resizable=yes, toolbar=yes, location=yes, menubar=yes');
      var height = piHoogte +50;
      var width = piBreedte +30;
      newwindow = window.open(sUrl,'sthPlayer','height='+height+',width='+width+', resizable=yes');
      if (!newwindow.opener) newwindow.opener = self;
    //}
    if (window.focus) {newwindow.focus()}
  }
  
  function IsNumeric(strString)
  //  check for valid numeric strings	
  {
  var strValidChars = "0123456789.-";
  var strChar;
  var blnResult = true;

  if (strString.length == 0) return false;

  //  test strString consists of valid characters listed above
  for (i = 0; i < strString.length && blnResult == true; i++)
     {
     strChar = strString.charAt(i);
     if (strValidChars.indexOf(strChar) == -1)
        {
        blnResult = false;
        }
     }
  return blnResult;
  }
  
  function get_url_parameter(name) {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
      return "";
    else
      return results[1];
  }
