$(document).ready(function(){
  
    $(".mladdress").click(function(){
      //alert("test1");
        $.post("code/mladdress_post.php",{
          group: $("#mladdress_group").attr('value'),
          address: $("#mladdress_address").attr('value')
          },function(data){
            $("#mladdress_div").html(data);
        });
    });
  
    $(".atb").click(function(e){
      e.preventDefault();
      var new_item=$(this).attr("val");
      if($("#Qty").attr('value')){
        var new_qty=$("#Qty").attr('value');
      }else{
        var new_qty="1";
      }
      $("#shopping_cart").load('code/basket_add.php?product='+new_item+'&qty='+new_qty+'',function(responseText) {
        //alert("Added to Cart");
		window.location = 'index.php?p=basket';
      });
    });
    $(".remove_from_basket").click(function(e){
      e.preventDefault();
      var old_item = $(this).attr("value");
      $("#shopping_cart").load('code/basket_remove.php?product='+old_item+'');
    });
    $("#gst").click(function(){
        var elem = $(".gex")[0];
        if(elem.style.display == 'none'){// || elem.style.display==''
             $(".ginc").hide();
             $(".gex").show();
        }else{
             $(".gex").hide();
             $(".ginc").show();
        }
        $.post("code/toggle_gst.php");
    });
    $("#cPayType").change(function(){
        var paychoice=$("#cPayType").val();
        $.post("code/toggle_discount.php",{sel:paychoice});
        var elem = $(".creditcard")[0];
        if(paychoice == 'Credit Card (+ 2.5%)'){
             $(".banktransfer").hide();
             $(".creditcard").show();
        }else{
             $(".banktransfer").show();
             $(".creditcard").hide();
        }
    });
    $("#cSalesPerson").change(function(){
        var personchoice=$("#cSalesPerson").val();
        $.post("code/toggle_person.php",{sel:personchoice});
    });    
  	//$("#searchBox").autocomplete("code/search_auto.php", {
    //  selectFirst: false
  	//});    
    $("#specsBut").addClass('active');
    $(".prodButs").click(function(){
      $('.active').addClass('prodButs').removeClass('active');
      $(this).addClass('active').removeClass('prodButs');
      $(".alldivs").hide();
      var whichshow=$(this).attr('divid');
      $("#"+whichshow).show();
    });
    //$("#choose_stores").addClass('active');
    $(".store_select").click(function(){
      //$('.active').addClass('prodButs').removeClass('active');
      //$(this).addClass('active').removeClass('prodButs');
      $(".store_info").hide();
      var whichshow=$(this).attr('divid');
      $("#"+whichshow).show();
    });    
    $(".mainprodimage").click(function(){
      $('.active').addClass('prodButs').removeClass('active');
      $('#imageBut').addClass('active').removeClass('prodButs');
      $(".alldivs").hide();
      $("#images1").show();
    });
    $("#mainprodimage").click(function(){
      $("#bigprodimage").toggle();
    });
    $("#bigprodimage").click(function(){
      $("#bigprodimage").toggle();
    });
    $("#submitreview").click(function(e){
      e.preventDefault();
      $.post("code/ajax_review.php",{ uid: $("#uID").attr('value'), uname: $("#uname").attr('value'), pid: $("#pID").attr('value'), revtext: $("textarea#new_review").attr('value') },function(data){
        $("#reviews").html(data);
      });
    });
    $(".edu").click(function(e){
      e.preventDefault();
      $(".edu_div").hide();
      var whichshow=$(this).attr('divid');
      $("#"+whichshow).show();
    });
    $(".like").click(function(){      
      $.post("code/ajax_like.php",{ pid: $(this).attr('value'), which: '1' },function(data){
        $("#ajax_feedback").html(data);
      });
    });
    $.post("code/ajax_window.php",{width:$(window).width()});
    
    $("#ad1").show();
    $("#ad_but1").addClass('ad_but');
    $(".ad_buts").click(function(){
      $('.ad_but').addClass('ad_buts').removeClass('ad_but');
      $(this).addClass('ad_but').removeClass('ad_buts');
      $(".ads").hide();
      var whichshow=$(this).attr('trid');
      var cur=whichshow.substring(2);
      $("#adnum").attr('current',cur);
      $("#"+whichshow).show();
      clearInterval(timerval);
      timerval=setTimeout(function(){ 
        var numads=$("#adnum").attr('total');
        var curads=$("#adnum").attr('current');
        var nextad=(parseInt(curads)+1);
        if(nextad == numads){nextad=0;}
        $("#ad_but"+nextad).trigger('click');
      }, 7000);      
    });
    
  });

