$(document).ready(function ()
{
  updateShoppingCardIfExists();
 
  $('form#product select, form#product input[type=text]').change(function()
  {
    data = $('form#product').serialize();
    $("div.prijscel1").addClass("loading");
    $.ajax(
    {
      url: '/ajax/product.php',
      type: "POST",
      data: data,
      dataType: "json",
      success: function(r)
      {
        $("div.prijscel1").removeClass("loading");
        if (typeof(r['sales_price_inc']) != 'undefined')
        {
          $("div.prijscel1 span.voorprijsinc").html("&euro;"+r['sales_price_inc']);
          $("div.prijscel1 span.voorprijsex").html("&euro;"+r['sales_price_ex']);
        }
        if (typeof(r['base_price_inc']) != 'undefined')
        {
          $("div.prijscel1 span.vanprijsex").html("Van &euro;"+r['base_price_ex']);
          $("div.prijscel1 span.vanprijsinc").html("Van &euro;"+r['base_price_inc']);
        }
      }
    });
  }); 
  
  $("#zoekveld").autocomplete(
  {
    source: "/ajax/search.php",
    minLength: 2
  });

  
  if(typeof sIFR == "function")
  {
    // This is the preferred "named argument" syntax
    sIFR.replaceElement(named({sSelector:"#menu h2", sFlashSrc:"/files/sifr_futuraltbt.swf", sColor:"#FFFFFF", sLinkColor:"#ffffff", sBgColor:"#ffffff", nPaddingTop:5, sWmode:"transparent", nPaddingBottom:5, sFlashVars:"textalign=left&offsetTop=0"}));
    sIFR.replaceElement(named({sSelector:"#rightcol h2", sFlashSrc:"/files/sifr_futuraltbt.swf", sColor:"#FFFFFF", sLinkColor:"#ffffff", sBgColor:"#ffffff", nPaddingTop:5, sWmode:"transparent", nPaddingBottom:5, sFlashVars:"textalign=left&offsetTop=0"}));
    sIFR.replaceElement(named({sSelector:"#content h2", sFlashSrc:"/files/sifr_futura.swf", sColor:"#df0072", sLinkColor:"#df0072", sBgColor:"#ffffff", nPaddingTop:0, sWmode:"transparent", nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
    sIFR.replaceElement(named({sSelector:".infoblok h1", sFlashSrc:"/files/sifr_futura.swf", sColor:"#FF8C29 ", sLinkColor:"#df0072", sBgColor:"#ffffff", nPaddingTop:0, sWmode:"transparent", nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
    sIFR.replaceElement(named({sSelector:"#content h3", sFlashSrc:"/files/sifr_futura.swf", sColor:"#c0c0c0", sLinkColor:"#c0c0c0", sBgColor:"#ffffff", nPaddingTop:0, sWmode:"transparent", nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
  };
  
});


function addToCard(product,iAmount)
{
  if (!iAmount) 
  {
    iAmount = 1;
  }
  var url="/index.php"
  url=url+"?op=addToCard"
  url=url+"&prod="+product
  url=url+"&count="+iAmount
  url=url+"&sid="+Math.random();

  $.ajax(
  {
    url: url,
    type: "GET",
    success: function()
    {
      if ($('#shopping_card_block').size() == 0) 
      {
        window.location.href="/cart";
      } 
      else
      {
        updateShoppingCardBlock();
      }
    }
  });
}

function updateShoppingCardIfExists()
{
  if ($('#shopping_card_block').size() > 0 && $('#shoppingCardForm').size() == 0)
  {
    updateShoppingCardBlock();
  }
}

function updateShoppingCardBlock()
{
  $.get('/index.php', { op: 'viewCardBlock'}, function(data) 
  {
    $('#shopping_card_block').html(data);
  });
}

function changeImage(sImage) 
{
  if (sImage=="") 
  {
    return;
  }
  sPicDir = $('#pic_dir').val();
  $('#img_small').attr('src', sPicDir+'thumb_'+sImage);
  $('#img_big').attr('href', sPicDir+sImage);
}
