//open banners in new window
$(document).ready(function(){  

$('#cartUpdated').fadeOut(2000);

$('.bannerNewWindow').click(function(){
	window.open(this.href);
	return false;
});

//if aadress1 == aadress2
aCheck();

$('#addressForm1 input').each(function(){ 
	
	$(this).keyup(function(){ 
		
		aCheck(); }) 
	
});

$('#sameaddress').click(function(){ 

	if ($('#sameaddress').is(":checked")){

		aCheck();
		
	} else {
	
		$('#ucompany2').val("");
		$('#firstname2').val("");
		$('#lastname2').val("");
		$('#email2').val("");
		$('#phone2').val("");
		$('#city2').val("");
		$('#state2').val("");
		$('#address2').val("");
		$('#postalcode2').val("");
	}


});

});

//if aadress1 == aadress2
var aCheck = function(){

	if ($('#sameaddress').is(":checked")){
	
		$('#ucompany2').val($('#ucompany').val());
		$('#firstname2').val($('#firstname').val());
		$('#lastname2').val($('#lastname').val());
		$('#email2').val($('#email').val());
		$('#phone2').val($('#phone').val());
		$('#city2').val($('#city').val());
		$('#state2').val($('#state').val());
		$('#address2').val($('#address').val());
		$('#postalcode2').val($('#postalcode').val());
	
	}

}

//Acordion tree
$(document).ready(function() {

	$('.level1subitems').hide();
	$('.level2subitems').hide();
	
	$('.level1Header').click(function(){
	
		$(this).find('span').toggleClass("openTree1");
		$(this).siblings('.level1subitems').slideToggle("fast");
	
	});	
	
	$('.level2Header').click(function(){
	
		$(this).find('span').toggleClass("openTree2");
		$(this).siblings('.level2subitems').slideToggle("fast");
	
	});
	
	var activeItem = $('.activeCategory').closest('.menuTree');
	
	activeItem.find('.level1Header span').addClass('openTree1');
	activeItem.find('.level1subitems').show();
	
	$('.activeCategory').closest('.level1subitems').find('.level2Header span').addClass('openTree2');
	$('.activeCategory').closest('.level2subitems').show();

});

//Acordion tree
$(document).ready(function(){

	$('.qPlus,.qMinus').click(function(){
	
		var currentItem = $(this).siblings('.productQuantity');
		var currentValue = parseInt(currentItem.val());
		
			if ($(this).attr('class') == "qPlus"){
			
				currentItem.attr("value",currentValue+1);
			}	

		if (currentValue > 1){		
			
			if ($(this).attr('class') == "qMinus"){
			
				currentItem.attr("value",currentValue-1);
			}
		
		}
		
		return false;
	});

});

/*
$(document).ready(function(){

	var orgImg = $('.productImage').find('img').attr('src');

	$('.smallProductImage').hover(function(){
	
		var imgSrc = $(this).find('img').attr('src');
		
		$('.productImage').find('img').attr('src',imgSrc);
	
	},
	
	function(){
			
			$('.productImage').find('img').attr('src',orgImg);
			
			}
	
	)

});
*/

//Clear input on click
$(document).ready(function() {
	$('.clear_field').click(function() {
	var orig_value = $(this).val();
	$(this).val("");
	$(this).blur(function () {
	     if ($(this).val()==""){
         $(this).val(orig_value);
		 }
    });
	});
});

