jQuery.noConflict();

function initMenu() {
	
  jQuery('#menu ul').hide();
  jQuery('#menu li ul li.active').parent().show();
  jQuery('#menu li ul li.active').parent().parent().addClass('active-tab');
  
  //clicking menu links
  jQuery('#menu li a').click(
    function() {
    	
 			var e = jQuery(this);
      var checkElement = jQuery(this).next();
      
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        return false;
        
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        jQuery('#menu ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
        
        jQuery("#menu li").removeClass('active-tab');	
    		e.parent().addClass('active-tab');
       
        return false;
        }
      }
    );
  }

jQuery(document).ready(function() {
	
	/*************** showing log in form in 	 ***************/	
	 jQuery('#login_toggle').click(function() {
	 	  jQuery(this).addClass('active');
	 		jQuery('.header .boxContent').slideToggle(100);
	 });
	
	 jQuery('#login-mini').click(function(){
			 	  jQuery('.header .boxContent').hide(500);			
		 
	 });
	 /*************** END***************/
	
	jQuery(function() {

		jQuery('a.lightbox').lightBox(); // Select all links that contains lightbox in the attribute rel
	});

	
  /*************** category left menu	 ***************/
		initMenu();
	/*************** END***************/
			 
  /*************** making an id to cart row as a basis for calculatio in ajax. 	 ***************/	 

 	 jQuery('#shopping-cart-table tbody tr').each(function(i){
	 		 jQuery(this).attr('id','row-' + i );

	 	})
	 
	 //submitting form in ajax
		jQuery('#cart_form').submit(function(){
	 
	 		 //loader scripts
	 		 jQuery('#loader').show(300);	 		 	 		
	 		 var eHeight = jQuery('#shopping-cart-table').height();	
	 		 jQuery('#waiting').css('height', eHeight/2).css('margin-top', eHeight/2);
	 	
	 	   //serialize the form data
	 		 data =jQuery("#cart_form").serialize();
			 	
			 	
			 	
			 jQuery.ajax({
					  type:'POST',
					  url: "http://www.wearpact.com/checkout/cart/updatePost",
					  data: data,
					  dataType:	"html",
					  success:function (data) { 
					  		jQuery('#loader').hide(300);		
					  		
					  			var totals_firt = jQuery('#shopping-cart-totals-table .price').html().substr(1);
	
	
									threshold(totals_firt);	
					
					
					  }					 
				});
				
				function threshold(totals){
					var diff_value = 0.00;
					var threshold_val = 75.00;
					
					if(totals <= threshold_val ){
					  diff_value = threshold_val - totals;
					  jQuery('#threshold').html('Almost there! $'+ diff_value.toFixed(2) + ' away from FREE standard US shipping')	;
					}else{
						 jQuery('#threshold').html('')	;
					}
				}
				
	 	 		return false;
		 });
	 		/*************** END***************/
	 
	 /*************** calculation of the cart sub totals ***************/
	 jQuery('.btn-upate-qty').click(function(){
	
	  //get the parent row id 
	 	var price = jQuery(this).parent().parent().parent().attr('id');
    
    //declare price, subtotal and quantity variable 
    var cartSubTotal 	= jQuery("#"+ price + " td.cart-subtotal .price");
	 	var unitPrice 		= parseFloat(jQuery("#"+ price + " td.cart-unit-price .price").html().substr(1));
	 	var qty 					= parseInt(jQuery("#"+ price + " td.cart-quantity .qty").val());
	  
	 	
	 	//calculation process
	 	var total = unitPrice * qty;
	 		  cartSubTotal.html('$'+ total.toFixed(2));
		
		var subTotalFinal = 0.00;
		
		jQuery("#shopping-cart-table tbody tr .cart-subtotal .price").each(function(i){
					 
					var a = parseFloat(jQuery(this).html().substr(1));
					subTotalFinal = parseFloat(subTotalFinal) + a;
				//	alert(subTotalFinal);
				
		});		
		
		 //displaying the total sub totals 
			jQuery(".cart-collaterals .cart-subTotal-final .price").html('$'+ subTotalFinal.toFixed(2));
		 			

	 });
	 	

		// increase the default animation speed to exaggerate the effect
			//jQuery.fx.speeds._default = 1000;
			jQuery(function() {
				jQuery( "#dialog" ).dialog({
					autoOpen: false,
					show: "blind",
					hide: "explode"
				});
		
				jQuery( "#opener" ).click(function() {
					jQuery( "#dialog" ).dialog( "open" );
					return false;
				});
				
				jQuery( "#close-btn" ).click(function() {
						jQuery( "#dialog" ).dialog( "close" );
				});
				
		});
		
		// increase the default animation speed to exaggerate the effect
		//jQuery.fx.speeds._default = 1000;
		// for the coupon code
		
	 jQuery(function() {
				jQuery( ".onestepcheckout-coupons" ).dialog({
					autoOpen: false,
					show: "blind",
					hide: "drop"
				});
		
				jQuery( "#coupon-opener" ).click(function() {
					jQuery( ".onestepcheckout-coupons" ).dialog( "open" );
					return false;
				});
				
				jQuery( "#close-coupon" ).click(function() {
					jQuery( ".onestepcheckout-coupons" ).dialog( "close" );
					return false;
				});
		});
		

		
		jQuery('.shortText .textSwitcher').click(function(){
				jQuery(this).parent().parent().next('.longText').slideToggle(500);
				jQuery(this).css('display','none')
		});
		
		jQuery('.longText .textSwitcher').click(function(){
				jQuery(this).parent().parent().prev().children().children().css('display','inline');
				jQuery(this).parent().parent().slideToggle(500);
				
		});

		
		//image hover for back images
		
		jQuery('.product-image-wrapper').hover(
			  function () {	
			  		jQuery(this).children('a').children('img:last-child').css('z-index','1'); 
			  }, 
			  function () {
			   		jQuery(this).children('a').children('img:last-child').css('z-index','0'); 
			  }
		);
		
		jQuery('.product-image-parent .small-image-wrapper').hover(
			function(){	
			 		jQuery(this).children('a').children('img:last-child').css({'z-index':'1','display':'block'}); 
			},
			function(){
			 		jQuery(this).children('a').children('img:last-child').css({'z-index':'0','display':'none'}); 
			});	
		
});

function changeImage(hrefImage){
		jQuery('.image').click( function(){
			var class_id = jQuery(this).attr("id");
			if(class_id == "small-img-0"){
				jQuery("#image-1").fadeOut(1200);	
				jQuery("#image-0").fadeIn(800);
			}
			else{
				jQuery("#image-1").fadeIn(1200);	
				jQuery("#image-0").fadeOut(800);
			}	
		});
	}
	

