 $.ajaxSetup ({
    // Disable caching of AJAX responses */
    cache: false
});
 
 
$(document).ready(function(){ 
		
    
						   
						   
						   
	
	$('.error').hide(); 
	var titems = $("#itemsincart").text();					 
	  var opts = "" ;
	var topts ="";
	var loggedin =""; 
	
	
	//$('#loggedin').live('change', function() {
  // Live handler called.
  loggedin = $('#loggedin').val();

	//alert("change");
	
	// set shop nav btns visible/hidden
	//function iflogged (loggedin) { 
	if (loggedin =="" ) { 
	
	$("#shoplogin").show();
	$("#shoplogout").hide();
	
	
	$("#registershopid").show();
	$("#viewaccount").hide();
	
	}
	if (loggedin !="" ) { 
	
	
	
	$("#shoplogin").hide();
	$("#shoplogout").show();
	$("#registershopid").hide();
	$("#viewaccount").show();
	
	}
//	});
	//alert("logged = " + loggedin )
	//}
	
	//iflogged ();
	
	
	$("#itemsincart").html(titems);
	
	$("#basketItemsWrap li:first").hide();
	
	$("#slidingTopContent").hide();
	
	
	$("#slidingTopTrigger").live("click", function(event) {
      	$("#slidingTopContent").slideToggle("slow", function(){
			if ($("#slidingTopContent").is(":visible")) {
				$("#slidingTopFooterLeft").html('<img src="images/arrow-up.png" alt="Hide Basket" /> <a href="no-js.htm" onclick="return false;" id="slidingTopTrigger">Hide Basket</a>');
			} else {
				$("#slidingTopFooterLeft").html('<img src="images/arrow-down.png" alt="Show Basket" /> <a href="no-js.htm" onclick="return false;" id="slidingTopTrigger">Show Basket</a>');
			}
		});
    }); 
	

    
	
	
	/////////////////  shop category function //////////////////////
	
	
	
	$('a.shop_cat ').live('click', function() {									   
	
	$(".update_qtyc").show();
	$("#slidingTopWrap").show();
	$("#yourcart_txt").show();
	
	
	
	
	var  cat = $(this).attr("id");
	 
	 
	 var targetUrl = "shop.ajax.php?cat=" + cat;
	        
			
		$("#s_middle").load(targetUrl,{},function(){
	$("#slidingTopWrap").load("shop_left.ajax.php?#slidingTopWrap",{},function(){
														});
							
												  });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
					//$("#s_middle").fadeIn("slow");
					$("#s_middle").slideUp();
					$("#s_middle").slideDown("slow");	
	 //iflogged ();
	 return false;
							 });
	
	
	
	/////////////////   cart login function //////////////////////
	 
	 
	
	
	$('#custlogin_btn').live('click', function() {									   
	
	$(".update_qtyc").show();
	$("#slidingTopWrap").show();
	 $("#yourcart_txt").show();
	$("#slidingTopWrap").hide();
	
	
	
	var  cat = $('#username').val();
	var  user = $('#username').val();
	var  pass = $('#password').val();
	var  remember = $('#remember').val();
	
	 
	
	  //var targetUrl = "cart_loggedin.ajax.php?user=" + cat + "#s_middle";
	        
			
		$("#s_middle").load('inc/shop_functions.php',{ username: user,cat: user, password: pass,remember : remember, action: 'login'},function(){
	
	//alert( $("#s_middle").html() );
	var smid  = $("#s_middle").html();	
	
	if ( smid != "loginfailed") { 
	
	
	$("#s_middle").load('cart_loggedin.ajax.php?user=' + cat ,{username: user,cat: user, password: pass, action: 'login'},function(){
	
	
	
			   });
		
	
	} else  { 
	
	
	$("#shoplogin").show();
	$("#shoplogout").hide();
	
	
	$("#registershopid").show();
	$("#viewaccount").hide();
	
	
	
	
	}
	});
	
	
		
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
					//$("#s_middle").fadeIn("slow");
					$("#s_middle").slideUp();
					$("#s_middle").slideDown("slow");	
	$("#shoplogin").hide();
	$("#shoplogout").show();
	$("#registershopid").hide();
	$("#viewaccount").show();
	 return false;
							 });
	
	
	
	
	/////////////////  shop detail function //////////////////////
	
	
	
	
	
	$('a.shop_prod ').live('click', function() {
 
	var  cat = $(this).attr("id");
	 
	
	 
	 
	 
	 var targetUrl = "shop_detail.ajax.php?id=" + cat;
	        
			
		$("#s_middle").load(targetUrl,{},function(){
	
	 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
					//$("#s_middle").fadeIn("slow");
					//$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
	 
	 
	 return false;
															 
							 });
	
	
	
	
	
//////////////// go to forgot pass  /////////////////////////


 
	 
	  $('#forgotpassbtn ' ).live('click', function(event,update) {
 
	//var  cat = $(this).attr("id");
	 //loggedin = $('#loggedin').val();
	 
	// if ((loggedin == "") || (loggedin == "undefined")) { 
	// var targetUrl = "checkout.ajax.php?id=" + cat;
	// }
	 
	// if ((loggedin != "") && (loggedin != "undefined")) { 
	 var targetUrl = "shop_forgot.ajax.php";
	// }
			
		$("#s_middle").load(targetUrl,{},function(){
	
	
	//hide cart in side panel
	$(".update_qtyc").hide();
	$("#slidingTopWrap").hide();
	 $("#yourcart_txt").hide();
	  $("#itemsincart").hide("slow");
					$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
					
	 
	 return false;
															 
							 });


	
	
	//////////////// get  forgot pass  /////////////////////////


 
	 
	  $('#getforgotpassbtn ' ).live('click', function(event,update) {
 
	//var  cat = $(this).attr("id");
	 //loggedin = $('#loggedin').val();
	 var  email = $('#username').val();
	 
	 
	 
	// if ((loggedin == "") || (loggedin == "undefined")) { 
	// var targetUrl = "checkout.ajax.php?id=" + cat;
	// }
	 
	// if ((loggedin != "") && (loggedin != "undefined")) { 
	 var targetUrl = "inc/shop_functions.php";
	// }
			
		$("#s_middle").load(targetUrl,{ action: "forgotpassword", email: email },function(){
	
	
	//hide cart in side panel
	$(".update_qtyc").hide();
	$("#slidingTopWrap").hide();
	 $("#yourcart_txt").hide();
	  $("#itemsincart").hide("slow");
					$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
					
	 
	 return false;
															 
							 });


	
	
	
	
	
	

//////////////// go to shop login  function /////////////////////////


 
	 
	  $('#shoplogin' ).live('click', function(event,update) {
 
	//var  cat = $(this).attr("id");
	 //loggedin = $('#loggedin').val();
	 
	// if ((loggedin == "") || (loggedin == "undefined")) { 
	// var targetUrl = "checkout.ajax.php?id=" + cat;
	// }
	 
	// if ((loggedin != "") && (loggedin != "undefined")) { 
	
	
	
	
	
	
	
	 var targetUrl = "shop_login.ajax.php";
	// }
			
		$("#s_middle").load(targetUrl,{},function(){
	
	
	//hide cart in side panel
	$(".update_qtyc").hide();
	$("#slidingTopWrap").hide();
	 $("#yourcart_txt").hide();
	  $("#itemsincart").hide("slow");
					$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
					
	 // iflogged ();
	 return false;
															 
							 });





//////////////// go to login to shop function /////////////////////////

 $('#viewaccount').live('click', function(event,update) {
											  
								  
			$("#s_middle").load("customer_loggedin.ajax.php		",{},function(){
																			  
											  
											  
											  });
	  
});



 
	 
	  $('#logintoshop ' ).live('click', function(event,update) {
 
	//var  cat = $(this).attr("id");
	//loggedin = $('#loggedin').val();
	 
	// if ((loggedin == "") || (loggedin == "undefined")) { 
	// var targetUrl = "checkout.ajax.php?id=" + cat;
	// }
	 
	// if ((loggedin != "") && (loggedin != "undefined")) { 
	
	// }
		
		//if (update == 2)  { alert("lofininn");   } 
		
		
		var usernametxt  = $('#username ' ).val();
		var passwordtxt  = $('#password ' ).val();
		var targetUrl = "customer_loggedin.ajax.php?user=" + usernametxt;
		
		
		$("#s_middle").load(targetUrl,{username: usernametxt ,password: passwordtxt},function(){
	
	
	
	if ($('#loggedin').val() != "") { 
	
	$("#shoplogin").hide();
	$("#shoplogout").show();
	$("#viewaccount").show();
	$("#registershopid").hide();
	}
	
	
	//hide cart in side panel
	$(".update_qtyc").hide();
	$("#slidingTopWrap").hide();
	 $("#yourcart_txt").hide();
	  $("#itemsincart").hide("slow");
					$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
					
	 //iflogged ();
	 return false;
															 
							 });
	  
	  
	  
	  //////////////// logout /////////////////////////


 
	 
	  $('#shoplogout ' ).live('click', function(event,update) {
 
	//var  cat = $(this).attr("id");
	 //loggedin = $('#loggedin').val();
	 
	// if ((loggedin == "") || (loggedin == "undefined")) { 
	// var targetUrl = "checkout.ajax.php?id=" + cat;
	// }
	 
	// if ((loggedin != "") && (loggedin != "undefined")) { 
	
	// }
		
		
		var usernametxt  = $('#username ' ).val();
		var passwordtxt  = $('#password ' ).val();
		 var targetUrl = "inc/shop_functions.php?action=logout";
		
		
		$("#s_middle").load(targetUrl,{doLogout: "true" ,action: "logout"},function(){
	
	//$("#shoplogout").hide();
	
	//$("#shoplogin").show();
	
	//$("#viewaccount").hide();
	//$("#registershopid").show();
	
	// set nav bar btns 
	$("#shoplogin").show();
	$("#shoplogout").hide();
	
	
	$("#registershopid").show();
	$("#viewaccount").hide();
	
	
	//hide cart in side panel
	$(".update_qtyc").hide();
	$("#slidingTopWrap").hide();
	 $("#yourcart_txt").hide();
	  $("#itemsincart").hide("slow");
					$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
					
	
	 return false;
															 
							 });
	  
	  
	  
	  
	  
	  
	  



//////////////// go to register for  shop function /////////////////////////


 
	 
	  $('.registershop ' ).live('click', function(event,update) {
  
	//var  cat = $(this).attr("id");
	 //loggedin = $('#loggedin').val();
	 
	// if ((loggedin == "") || (loggedin == "undefined")) { 
	// var targetUrl = "checkout.ajax.php?id=" + cat;
	// }
	 
	// if ((loggedin != "") && (loggedin != "undefined")) { 
	
	// }
		
		
		//var usernametxt  = $('#username ' ).val();
		//var passwordtxt  = $('#password ' ).val();
		 var targetUrl = "customer_register.ajax.php";
		
		
		$("#s_middle").load(targetUrl,{},function(){
	
	
$('.error').hide(); 

	//hide cart in side panel
	$(".update_qtyc").hide();
	$("#slidingTopWrap").hide();
	 $("#yourcart_txt").hide();
	  $("#itemsincart").hide("slow");
					$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
					
	 
	 return false;
															 
							 });






//////////////// do register for  shop function /////////////////////////


 
	 
	  $('#createaccount' ).live('click', function(event,update) {
												  
											  
		challengeField = $("input#recaptcha_challenge_field").val();
    responseField = $("input#recaptcha_response_field").val();
    //alert(challengeField);
    //alert(responseField);
    //return false;
	
	    var firstname = $('#firstname').val();
		var lastname = $('#lastname').val();
		var address1 = $('#address1').val();
		var address2 = $('#address2').val();
		var city  = $('#city').val();
		//var country  = $('#country').val();
		var country  = $('#country :selected').text();
		var pcode = $('#pcode').val();
		var ship_address1 = $('#ship_address1').val();
		var ship_address2 = $('#ship_address1').val();
		var ship_city = $('#ship_city').val();
		//var ship_country = $('#ship_country').val();
		var ship_country  = $('#country :selected').text();
		var ship_pcode = $('#ship_pcode').val();
		var email = $('#email').val();
		var password = $('#passwordx').val();
		
		
 $('.error').hide();  
        
		firstname = $("input#firstname").val();  
        if (firstname == "") {  
      $("label#firstname_error").show();  
      $("input#firstname").focus();  
       return false;  
     }  
	
    lastname = $("input#lastname").val();  
        if (lastname == "") {  
      $("label#lastname_error").show();  
      $("input#lastname").focus();  
       return false;  
     }  
	 
	 address1 = $("input#address1").val();  
        if (address1 == "") {  
      $("label#address1_error").show();  
      $("input#address1").focus();  
       return false;  
     }  
	 
	  address2 = $("input#address2").val();  
        if (address2 == "") {  
      $("label#address2_error").show();  
      $("input#address2").focus();  
       return false;  
     }  
	 
	 city = $("input#city").val();  
        if (city == "") {  
      $("label#city_error").show();  
      $("input#city").focus();  
       return false;  
     }  
	 
	// country = $("input#country").val();  
       if (country == "Select...") {  
//if (!$("input#country option:selected").length){
    $("label#country_error").show();  
     $("input#country").focus();  
    return false;  
     }  
	 
	  pcode = $("input#pcode").val();  
        if (pcode == "") {  
      $("label#pcode_error").show();  
      $("input#pcode").focus();  
       return false;  
     } 
	 
	  ship_address1 = $("input#address1").val();  
        if (address1 == "") {  
      $("label#ship_address1_error").show();  
      $("input#ship_address1").focus();  
       return false;  
     }  
	 
	  ship_address2 = $("input#ship_address2").val();  
        if (ship_address2 == "") {  
      $("label#ship_address2_error").show();  
      $("input#ship_address2").focus();  
       return false;  
     }  
	 
	 ship_city = $("input#ship_city").val();  
        if (ship_city == "") {  
      $("label#city_error").show();  
      $("input#city").focus();  
       return false;  
     }  
	 
	// ship_country = $("input#ship_country").val();  
        if (ship_country == "Select...") {  
      $("label#ship_country_error").show();  
      $("input#ship_country").focus();  
       return false;  
     }  
	 
	  ship_pcode = $("input#ship_pcode").val();  
        if (ship_pcode == "") {  
      $("label#ship_pcode_error").show();  
      $("input#ship_pcode").focus();  
       return false;  
     }  
	 
	 email = $("input#email").val();  
        if (email == "") {  
      $("label#email_error").show();  
      $("input#email").focus();  
       return false;  
     }  
	 
	 email2 = $("input#email2").val();  
        if (email2 == "") {  
      $("label#email2_error").show();  
      $("input#email2").focus();  
       return false; 
	   
     }  
	  if (email2 != email) {  
      $("label#email3_error").show();  
      $("input#email2").focus();  
       return false; 
	   
     }  
	 
	  password = $("input#passwordx").val();  
        if (password == "") {  
      $("label#password_error").show();  
      $("input#password").focus();  
       return false;  
     }  
	 
	 password2 = $("input#password2").val();  
        if (password2 == "") {  
      $("label#password2_error").show();  
      $("input#password2").focus();  
       return false;  
     } 
	 if (password2 != password) {  
      $("label#password3_error").show();  
      $("input#password2").focus();  
       return false; 
	   
     }  
	
	
    var html = $.ajax({
    type: "POST",
    url: "inc/shop_functions.php",
    data: "action=register&recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
    async: false
    }).responseText;
    
    if(html == "success")
    {
        $("#captchaStatus").html("Success. Submitting form.");
        
		var targetUrl = "inc/shop_functions.php";
		
		
		
		$("#s_middle").load(targetUrl,{firstname : firstname , lastname :lastname , address1:address1, address2:address2, city:city, country:country, pcode : pcode, ship_address1:ship_address1, ship_address2:ship_address2, ship_city :ship_city, ship_country:ship_country, ship_pcode :ship_pcode, email:email, password : password,action: 'register2' },function(){
	
	
	// $("#s_middle").load('inc/shop_functions.php',{ username: email,cat: email, password: password, action: 'login'},function(){
	
	//if (efdfd= dfdf) {
		
	//}
	//});
		
//	$("#s_middle").load('cart_loggedin.ajax.php?user=' + email ,{username: email,cat: email, password: password, action: 'login'},function(){
	
	
	
			   //});	
	
	
			var smid  = $("#s_middle").html();	
			var splitter 	= $("#s_middle").html().split(" ");
		var splitted 			= splitter[0];
 
 //alert(splitted);
	
	if ( splitted != "It") { 
	
	
	//alert("redir");
	
	$('#checkout ').trigger('click',[0]);
	
	}
	
      

	//hide cart in side panel
	$(".update_qtyc").hide();
	$("#slidingTopWrap").hide();
	 $("#yourcart_txt").hide();
	  $("#itemsincart").hide("slow");
					$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
			
			
			
					
	
	 
			
	 
	 
	 
	
				
		
		
		//alert("posting");
        // Uncomment the following line in your application
        //return true; 
		return false;
    }
    else
    {
        $("#captchaStatus").html("Your captcha is incorrect. Please try again");
        Recaptcha.reload();
        return false;
    }
										  
												  
												  
												  
												  
 
		
		 
				
							 });




    //////////////    edit account do ////////////////
	
	
	
	
	
	  $('#editaccount' ).live('click', function(event,update) {
												  
												  
		
	
	    var firstname = $('#firstname').val();
		var lastname = $('#lastname').val();
		var address1 = $('#address1').val();
		var address2 = $('#address2').val();
		var city  = $('#city').val();
		//var country  = $('#country').val();
		var country  = $('#country :selected').text();
		var pcode = $('#pcode').val();
		var ship_address1 = $('#ship_address1').val();
		var ship_address2 = $('#ship_address2').val();
		var ship_city = $('#ship_city').val();
		//var ship_country = $('#ship_country').val();
		var ship_country = $('#ship_country :selected').text();
		var ship_pcode = $('#ship_pcode').val();
		var email = $('#email').val();
		var email2 = $('#email2').val();
		var password = $('#passwordx').val();
		var password2 = $('#password2').val();
		var id = $('#edit_id').val();
		
	
 $('.error').hide();  
        
		firstname = $("input#firstname").val();  
        if (firstname == "") {  
      $("label#firstname_error").show();  
      $("input#firstname").focus();  
       return false;  
     }  
	
    lastname = $("input#lastname").val();  
        if (lastname == "") {  
      $("label#lastname_error").show();  
      $("input#lastname").focus();  
       return false;  
     }  
	 
	 address1 = $("input#address1").val();  
        if (address1 == "") {  
      $("label#address1_error").show();  
      $("input#address1").focus();  
       return false;  
     }  
	 
	  address2 = $("input#address2").val();  
        if (address2 == "") {  
      $("label#address2_error").show();  
      $("input#address2").focus();  
       return false;  
     }  
	 
	 city = $("input#city").val();  
        if (city == "") {  
      $("label#city_error").show();  
      $("input#city").focus();  
       return false;  
     }  
	 
	// country = $("input#country").val();  
       if (country == "Select...") {  
//if (!$("input#country option:selected").length){
    $("label#country_error").show();  
     $("input#country").focus();  
    return false;  
     }  
	 
	  pcode = $("input#pcode").val();  
        if (pcode == "") {  
      $("label#pcode_error").show();  
      $("input#pcode").focus();  
       return false;  
     } 
	 
	  ship_address1 = $("input#address1").val();  
        if (address1 == "") {  
      $("label#ship_address1_error").show();  
      $("input#ship_address1").focus();  
       return false;  
     }  
	 
	  ship_address2 = $("input#ship_address2").val();  
        if (ship_address2 == "") {  
      $("label#ship_address2_error").show();  
      $("input#ship_address2").focus();  
       return false;  
     }  
	 
	 ship_city = $("input#ship_city").val();  
        if (ship_city == "") {  
      $("label#city_error").show();  
      $("input#city").focus();  
       return false;  
     }  
	 
	// ship_country = $("input#ship_country").val();  
        if (ship_country == "Select...") {  
      $("label#ship_country_error").show();  
      $("input#ship_country").focus();  
       return false;  
     }  
	 
	  ship_pcode = $("input#ship_pcode").val();  
        if (ship_pcode == "") {  
      $("label#ship_pcode_error").show();  
      $("input#ship_pcode").focus();  
       return false;  
     }  
	 
	 email = $("input#email").val();  
        if (email == "") {  
      $("label#email_error").show();  
      $("input#email").focus();  
       return false;  
     }  
	 
	 email2 = $("input#email2").val();  
        if (email2 == "") {  
      $("label#email2_error").show();  
      $("input#email2").focus();  
       return false; 
	   
     }  
	  if (email2 != email) {  
      $("label#email3_error").show();  
      $("input#email2").focus();  
       return false; 
	   
     }  
	 
	  password = $("input#passwordx").val();  
        if (password == "") {  
      $("label#password_error").show();  
      $("input#password").focus();  
       return false;  
     }  
	 
	 password2 = $("input#password2").val();  
        if (password2 == "") {  
      $("label#password2_error").show();  
      $("input#password2").focus();  
       return false;  
     }  
        
		var targetUrl = "inc/shop_functions.php";
		
		
		
		$("#s_middle").load(targetUrl,{firstname : firstname , lastname :lastname , address1:address1, address2:address2, city:city, country: country, pcode : pcode, ship_address1:ship_address1, ship_address2:ship_address2, ship_city :ship_city, ship_country:ship_country, ship_pcode :ship_pcode, email:email, password : password,action: 'editaccount', id : id },function(){
	
		
		
      

	//hide cart in side panel
	$(".update_qtyc").hide();
	$("#slidingTopWrap").hide();
	 $("#yourcart_txt").hide();
	  $("#itemsincart").hide("slow");
					$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
			 
			  
			// $('#logintoshop  ').trigger('click',[2]);	
			 //alert("sdfdgd");
			 $('#checkout ').trigger('click',[1]);		
	
	
		//alert("posting");
        // Uncomment the following line in your application
        //return true; 
		return false;
    
	
				
							 });
	
	
	
	
	
	






//////////////// go to checkout function /////////////////////////


 
	  $('#checkout2 ' ).live('click', function(event,update) {
											  
			$('#checkout ').trigger('click',[0]);								  
											  
											  });
	  
	  	





	 
	  $('#checkout ' ).live('click', function(event,update) {
 
	var  cat = $(this).attr("id");
	 loggedin = $('#loggedin').val();
	// shipcunt  = $('#loggedin').val();
	 
	 //if ((loggedin == "") || (loggedin == "undefined")) {  
	 //var targetUrl = "checkout.ajax.php?id=" + cat;
	 //}
	 var def = "def";
	 //if ((loggedin != "") && (loggedin != "undefined")) { 
	 var targetUrl = "cart_loggedin.ajax.php";
	 //}
			
		$("#s_middle").load(targetUrl,{ action : "def"},function(){
	
	
	//hide cart in side panel
	
	 //$(".1").hide();
	 $(".update_qtyc").hide();
	 $("#slidingTopWrap").hide();
	//$("#slidingTopWrap").hide();
	// $("#yourcart_txt").hide();
	 // $("#itemsincart").hide("slow");
					//$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
					
	 
	 return false;
															 
							 });
	  
	  // var targetUrl = "shop_left2.php";
	 ////}
			
		//$("#s_left").load(targetUrl,{ },function(){
															  // });
	 
	 ////////// edit customer goto  //////////
	 
	 
	 
	 $('.editcustbtn ' ).live('click', function(event,update) {
 
	var  id = $(this).attr("id");
	 loggedin = $('#loggedin').val();
	 
	 //if ((loggedin == "") || (loggedin == "undefined")) { 
	 //var targetUrl = "checkout.ajax.php?id=" + cat;
	 //}
	 
	 //if ((loggedin != "") && (loggedin != "undefined")) { 
	 var targetUrl = "edit_customer.ajax.php?id=" + id;
	 //}
			
		$("#s_middle").load(targetUrl,{},function(){
	
	
	//hide cart in side panel
	$(".update_qtyc").hide();
	$("#slidingTopWrap").hide();
	 $("#yourcart_txt").hide();
	  $("#itemsincart").hide("slow");
					$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
				
	 
	 return false;
															 
							 });
	  
	  
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 


/////////////////  add to cart  function //////////////////////

 
 
 
 
 $('.productPriceWrapRight a  ').live('click', function() {
	//$(".productPriceWrapRight a ").click(function() {
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];
 
 
 
 
 topts ="";
 $( "select.prod_opts").each(
 
 //$.each("select .prod_opts ", 
		  function() { 
  
  var opt  = $(this).attr("id");
  opt  = opt.split("_");
  opt  = opt[0];
  var opt_val = $(this).val();
   opts = opt + ":" + opt_val + ", ";						   
    
	if (topts =="") { 
	
	topts = opts;
	} 
	if (topts !="") { 
	
	topts = topts + opts;
	} 
  //alert(opts); 
});

//alert(topts);
		
		if ($("#slidingTopContent").is(":visible")) {

			$("#notificationsLoader").html('<img src="images/loader.gif">');
		
			$.ajax({  
			type: "POST",  
			url: "inc/shop_functions.php",  
			data: { productID: productIDVal, action: "addToBasket", opt_val : topts},  
			success: function(theResponse) {
				
				//var basketIDValSplitter 	= ($("#basketID_" + basketIDVal).id).split("_");
		//var basketIDVal 			= $("#basketID").val();
				
				//alert(basketIDVal);
				
				
				/* if( $("#basketID_" + basketIDVal).length > 0){
					$("#basketID_" + basketIDVal).animate({ opacity: 0 }, 500);
					$("#basketID_" + basketIDVal).before(theResponse).remove();
					$("#basketID_" + basketIDVal).animate({ opacity: 0 }, 500);
					$("#basketID_" + basketIDVal).animate({ opacity: 1 }, 500);
					$("#notificationsLoader").empty();
					
				} else {
					$("#basketItemsWrap li:first").before(theResponse);
					$("#basketItemsWrap li:first").hide();
					$("#basketItemsWrap li:first").show("slow");  
					$("#notificationsLoader").empty();			
				} */
				titems = $("li.cartitem ").size();
				$("#itemsincart").html(titems);	
				
				$("#slidingTopWrap").load("shop_left.ajax.php?#slidingTopWrap",{},function(){
														});
				
			}  
			}); 

		} else {
			
			$("#slidingTopContent").slideToggle("slow", function(){		
																 
				$("#slidingTopFooterLeft").html('<img src="images/arrow-up.png" alt="Hide Basket" /> <a href="aaa.htm" onclick="return false;" id="slidingTopTrigger">Hide Basket</a>');
				$("#notificationsLoader").html('<img src="images/loader.gif">');
			
				$.ajax({  
				type: "POST",  
				url: "inc/shop_functions.php",  
				data: { productID: productIDVal, action: "addToBasket", opt_val : topts},  
				success: function(theResponse) {
				 
				//var basketIDVal 			= $("#basketID").val();

				
				//alert(basketIDVal);
				
				/*	if( $("#productID_" + productIDVal).length > 0){
						$("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
						$("#productID_" + productIDVal).before(theResponse).remove();
						$("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
						$("#productID_" + productIDVal).animate({ opacity: 1 }, 500);
						$("#notificationsLoader").empty();
						
					} else {
						$("#basketItemsWrap li:first").before(theResponse);
						$("#basketItemsWrap li:first").hide();
						$("#basketItemsWrap li:first").show("slow");  
						$("#notificationsLoader").empty();			
					} */
				titems = $("li.cartitem ").size();
				$("#itemsincart").html(titems);		
				
				 //var targetUrl = "shop_left.php#slidingTopWrap";
	        
			
		//$("#slidingTopWrap").load("shop_left.ajax.php?#slidingTopWrap",{},function(){
														//});
				
				} 
				}); 
				
				
				$("#slidingTopTrigger").fadeTo(4000, 1, function(){
					$("#slidingTopContent").slideToggle("slow", function(){
						$("#slidingTopFooterLeft").html('<img src="images/arrow-down.png" alt="Show Basket" /> <a href="aaa.htm" onclick="return false;" id="slidingTopTrigger">Show Basket</a>');												 
					});
					
				});

			});												 
		}
				
	});
	
	
	

	//////// goto security info ////////////
	
	
	  $('#security ' ).live('click', function(event,update) {
 
		
		
		 var targetUrl = "inc/shop_functions.php?action=security";
		
		
		$("#s_middle").load(targetUrl,{action: "security"},function(){
	
	
	
	//hide cart in side panel
	$(".update_qtyc").hide();
	$("#slidingTopWrap").hide();
	 $("#yourcart_txt").hide();
	  $("#itemsincart").hide("slow");
					$("#itemsincart").fadeIn("slow"); 
	   });
		//$("#s_middle").animate({ opacity: 0 }, 000);
					//$("#s_middle").animate({ opacity: 1 }, 1000);
				//alert(update)
				//$("#s_middle").fadeIn("slow");
					if (update != 1) {
					
					$("#s_middle").slideUp();	
					$("#s_middle").slideDown("slow");	
					}
					
	
	 return false;
															 
							 });
	
	
	
	
	
	
	
	
	/////////////////  delete from cart  function //////////////////////
	
	
	
	$("#basketItemsWrap .1").live("click", function(event) { 
		var basketIDValSplitter 	= (this.id).split("_");
		var basketIDVal 			= basketIDValSplitter[1];
		//var productIDVal 			= $('#basketID').val();
	    
		
		//opts                        = $("#options").val();
		 // opts = $('#options_'+productIDVal).val();
		
		//$("#notificationsLoader").html('<img src="images/loader.gif">');
	
		$.ajax({  
		type: "POST",  
		url: "inc/shop_functions.php",  
		data: { basketID: basketIDVal, action: "deleteFromBasket" },  
		success: function(theResponse) {
			
			$("#basketID_" + basketIDVal).hide("slow",  function() {
				$(this).remove();
				
			});
			//$("#notificationsLoader").empty();
			//titems = $("li.cartitem").size()-1;
				//$("#itemsincart").html(titems);	
				//alert(titems);
		$("#slidingTopWrap").load("shop_left.ajax.php?#slidingTopWrap",{},function(){
														});
		}
			
					
		});  	
	 
	});
	
	
	
	
	
	
	
	
	
	
	
	$("#basketItemsWrap2 .2").live("click", function(event) { 
		var basketIDValSplitter 	= (this.id).split("_");
		var basketIDVal 			= basketIDValSplitter[1];
		//var productIDVal 			= $('#basketID').val();
	    
		
		//opts                        = $("#options").val();
		 // opts = $('#options_'+productIDVal).val();
		
		//$("#notificationsLoader").html('<img src="images/loader.gif">');
	
		$.ajax({  
		type: "POST",  
		url: "inc/shop_functions.php",  
		data: { basketID: basketIDVal, action: "deleteFromBasket" },  
		success: function(theResponse) {
			
			$("#basketID2_" + basketIDVal).hide("slow",  function() {
				$(this).remove();
					
			});
			//$("#notificationsLoader").empty();
			//titems = $("li.cartitem").size()-1;
				//$("#itemsincart").html(titems);	
				//alert(titems);
		$('#checkout ').trigger('click',[1]);
		}
			
					
		});  	
	 
	});
	
	
	
	
	
	/////////////////  change quantity  function //////////////////////
	
	
	
	
	$(".quantity_txt").live("keyup", function(event) { 
		
		   var basketIDValSplitter 	= (this.id).split("_");
		var basketIDVal 			= basketIDValSplitter[2];	
		
        var $this = this; // save reference to 'this' so we can use it intimeout function
       setTimeout(function() {
                //search_timeout = undefined;
                // do stuff with $this here
       
	    
	
		var  pID = $('#pID_'+basketIDVal).val();
		var  uq = $('#quantity_txt_'+basketIDVal).val();
	
	//alert(uq) ;
		
		
		$("#notificationsLoader").html('<img src="images/loader.gif">');
	
		$.ajax({  
		type: "POST",  
		url: "inc/shop_functions.php",  
		data: { productID: pID, action: "updateBasket", quantity_txt :uq, basketID: basketIDVal },  
		success: function(theResponse) {
			
			var updtxt = uq + "updateBasket" +  basketIDVal;
			 //$('#checkout ')
			//alert(updtxt ) ;
			var update = 1;
			//$("#productID_" + productIDVal).hide("slow",  function() {
				//$(this).remove();
			$('#checkout ').trigger('click',[1]);		
			//});
			
		
									   
									}
		
					
		});  	
	 
	   
	   
	  }, 500);

		
		
		
		
	});
	
	
	
	
	
	

});

