$(document).ready(function() {
	
	//transição de página

	$("#container").css("display", "none");

    $("#container").fadeIn(1000);
    
	$("a.transition").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$("#container").fadeOut(500, redirectPage);		
	});
		
	function redirectPage() {
		window.location = linkLocation;
	}

//fim	
	
	/* Search */
	$('.button-search').bind('click', function() {
		url = 'index.php?route=product/search';
		 
		var filter_name = $('input[name=\'filter_name\']').attr('value')
		
		if (filter_name) {
			url += '&filter_name=' + encodeURIComponent(filter_name);
		}
		
		location = url;
	});
	
	$('#header input[name=\'filter_name\']').keydown(function(e) {
		if (e.keyCode == 13) {
			url = 'index.php?route=product/search';
			 
			var filter_name = $('input[name=\'filter_name\']').attr('value')
			
			if (filter_name) {
				url += '&filter_name=' + encodeURIComponent(filter_name);
			}
			
			location = url;
		}
	});
	
	/* Ajax Cart */
/*	
	$('#cart > .heading a').bind('click', function() {
		$('#cart').addClass('active');
		
		$.ajax({
			url: 'index.php?route=checkout/cart/update',
			dataType: 'json',
			success: function(json) {
				if (json['output']) {
					$('#cart .content').html(json['output']);
				}
			}
		});			
		
		$('#cart').bind('mouseleave', function() {
			$(this).removeClass('active');
		});
	});
	
*/
	$("#cart").hover(
  function () {
   	$('#cart').addClass('active');
		
		$.ajax({
			url: 'index.php?route=checkout/cart/update',
			dataType: 'json',
			success: function(json) {
				if (json['output']) {
					$('#cart .content').html(json['output']);
				}
			}
		});	
  },
  function () {
  $('#cart').removeClass('active');
  }
);
	
	
	/* Mega Menu */
	$('#menu ul > li > a + div').each(function(index, element) {
		// IE6 & IE7 Fixes
		if ($.browser.msie && ($.browser.version == 7 || $.browser.version == 6)) {
			var category = $(element).find('a');
			var columns = $(element).find('ul').length;
			
			$(element).css('width', (columns * 143) + 'px');
			$(element).find('ul').css('float', 'left');
		}		
		
		var menu = $('#menu').offset();
		var dropdown = $(this).parent().offset();
		
		i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth());
		
		if (i > 0) {
			$(this).css('margin-left', '-' + (i + 5) + 'px');
		}
	});

	// IE6 & IE7 Fixes
	if ($.browser.msie) {
		if ($.browser.version <= 6) {
			$('#column-left + #column-right + #content, #column-left + #content').css('margin-left', '195px');
			
			$('#column-right + #content').css('margin-right', '195px');
		
			$('.box-category ul li a.active + ul').css('display', 'block');	
		}
		
		if ($.browser.version <= 7) {
			$('#menu > ul > li').bind('mouseover', function() {
				$(this).addClass('active');
			});
				
			$('#menu > ul > li').bind('mouseout', function() {
				$(this).removeClass('active');
			});	
		}
	}
});

$('.success img, .warning img, .attention img, .information img').live('click', function() {
	$(this).parent().fadeOut('slow', function() {
		$(this).remove();
	});
});

function addToCart(product_id) {
	$.ajax({
		url: 'index.php?route=checkout/cart/update',
		type: 'post',
		data: 'product_id=' + product_id,
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, .information, .error').remove();
			
			if (json['redirect']) {
				location = json['redirect'];
			}
			
			if (json['error']) {
				if (json['error']['warning']) {
					$('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/ligchopp/image/close.png" alt="" class="close" /></div>');
				}
			}	 
						
			if (json['success']) {
				$('#notification').html('<div class="attention" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/ligchopp/image/close.png" alt="" class="close" /></div>');
				
				$('.attention').fadeIn('slow');
				
				$('#cart_total').html(json['total']);
				
				$('html, body').animate({ scrollTop: 0 }, 'slow'); 
				/*add cart sucess*/
			
				$('#cart-success').after('<div class="success2" style="display: none;">' + json['success'] + '</div>');

				$('.success2').fadeIn(1000).delay(2000).fadeOut(1500);

			$('#cart_total').html(json['total']);
/*fim added card sucess*/
			}	
		}
	});
}

function removeCart(key) {
	$.ajax({
		url: 'index.php?route=checkout/cart/update',
		type: 'post',
		data: 'remove=' + key,
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, .information').remove();
			
			if (json['output']) {
				$('#cart_total').html(json['total']);
				
				$('#cart .content').html(json['output']);
			}			
		}
	});
}

function removeVoucher(key) {
	$.ajax({
		url: 'index.php?route=checkout/cart/update',
		type: 'post',
		data: 'voucher=' + key,
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, .information').remove();
			
			if (json['output']) {
				$('#cart_total').html(json['total']);
				
				$('#cart .content').html(json['output']);
			}			
		}
	});
}

function addToWishList(product_id) {
	$.ajax({
		url: 'index.php?route=account/wishlist/update',
		type: 'post',
		data: 'product_id=' + product_id,
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, .information').remove();
						
			if (json['success']) {
				$('#notification').html('<div class="attention" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/ligchopp/image/close.png" alt="" class="close" /></div>');
				
				$('.attention').fadeIn('slow');
				
				$('#wishlist_total').html(json['total']);
				
				$('html, body').animate({ scrollTop: 0 }, 'slow'); 	
				/*add sucess*/
				$('#cart-success').after('<div class="success2" style="display: none;">' + json['success'] + '</div>');
				
				$('.success2').fadeIn(1000).delay(3000).fadeOut(1500);
				
				$('#wishlist_total').html(json['total']);
/*fim add sucess*/
			
			}	
		}
	});
}

function addToCompare(product_id) { 
	$.ajax({
		url: 'index.php?route=product/compare/update',
		type: 'post',
		data: 'product_id=' + product_id,
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, .information').remove();
						
			if (json['success']) {
				$('#notification').html('<div class="attention" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/ligchopp/image/close.png" alt="" class="close" /></div>');
				
				$('.attention').fadeIn('slow');
				
				$('#compare_total').html(json['total']);
				
				$('html, body').animate({ scrollTop: 0 }, 'slow'); 
				/*add sucess*/
				$('#cart-success').after('<div class="success2" style="display: none;">' + json['success'] + '</div>');
				
				$('.success2').fadeIn(1000).delay(3000).fadeOut(1500);
				
				$('#compare_total').html(json['total']);
/*fim added sucess*/
			}	
		}
	});
}

/* exibir parcelas Pagamento digital pag. produtos */

$('#iframe').css('display', 'none');
$('#preload').css('display', 'block');

$(document).ready(function() {
$('iframe').load(function() {
$('#iframe').css('display', 'block');
$('#preload').css('display', 'none');
});
});






$(document).ready(function(){
$(".product_container").hover(function() {
$(this).find(".product_hidden").stop()
.animate({top: "0"}, "fast")
.css("display","block");

$(this).find(".n_price").animate({
	left: "-100"
  }, 500, function() {
    // Animation complete.
});

$(this).find(".s_price").animate({
	left: "-100"
  }, 500, function() {
    // Animation complete.
});


}, function() {
$(this).find(".product_hidden").stop()
.animate({top: "260"}, "medium");


$(this).find(".n_price").animate({
	left: "10"
  }, 500, function() {
    // Animation complete.
});

$(this).find(".s_price").animate({
	left: "10"
  }, 500, function() {
    // Animation complete.
});


});

/*-
/* IMAGE HOVER
/*-*/
jQuery(function() {

jQuery("#product_top img").hover(function () {
jQuery(this).stop().animate({ opacity: 0.5 }, "medium"); },
function () {
jQuery(this).stop().animate({ opacity: 1.0 }, "slow");
});
});



jQuery(function() {
jQuery("#column_left ul li a").hover(function () {
jQuery(this).stop().animate({ left: "5" }, "fast"); },
function () {
jQuery(this).stop().animate({ left: "0" }, "medium");
});
});






$(".box-product > div").hover(
function () {
$(this).siblings().stop().animate({
opacity: .6
}, 500)
},
function () {
$(this).siblings().stop().animate({
opacity: 1
}, 500)
}
);
$(".product-grid > div").hover(
function () {
$(this).siblings().stop().animate({
opacity: .6
}, 500)
},
function () {
$(this).siblings().stop().animate({
opacity: 1
}, 500)
}
);
$(".box-category > ul > li > a").hover(function () {
$(this).stop().animate({ left: "5" }, "fast"); },
function () {
$(this).stop().animate({ left: "0" }, "medium");
});


	// Animation for the languages and currency dropdown
$('.switcher').hover(function() {
$(this).find('.option').stop(true, true).slideDown(300);
},function() {
$(this).find('.option').stop(true, true).slideUp(150);
}); 



    /* formulario pessoa fisica e juridica 
	addClass para carregar java form.js validação cpf cnpj e validação "req"
	*/

     $(document).ready(function() {

        if ($("#fisica").is(':checked')) {
            $('.pessoa_fisica').show();
            $('.pessoa_juridica').hide(); 
			$("#cpf").addClass("cpf");   
        }
        if ($("#juridica").is(':checked')) {
            $('.pessoa_fisica').hide();
            $('.pessoa_juridica').show();
			$("#cnpj").addClass("cnpj");
			$("#razao_social").addClass("req");
			  
        }
        $('#juridica').click( function() {
            $("#cpf").val("");
			$("#rg").val("");
			$("#cnpj").addClass("cnpj");
			$("#razao_social").addClass("req");
			$("#cpf").removeClass("cpf");
	    $('.pessoa_fisica').hide();
            $('.pessoa_juridica').show();    
	});
        $('#fisica').click( function() {
            $("#cnpj").val("");
			$("#razao_social").val("");
			$("#inscricaoe").val("");
			$("#cpf").addClass("cpf");
			$("#cnpj").removeClass("cnpj");
			$("#razao_social").removeClass("req");
	    $('.pessoa_fisica').show();
            $('.pessoa_juridica').hide();
	}); 
    });
	    
 // fim   
// class select nos menus pegando url
function getURLVar(urlVarName) {
	var urlHalves = String(document.location).toLowerCase().split('?');
	var urlVarValue = '';
	
	if (urlHalves[1]) {
		var urlVars = urlHalves[1].split('&');

		for (var i = 0; i <= (urlVars.length); i++) {
			if (urlVars[i]) {
				var urlVarPair = urlVars[i].split('=');
				
				if (urlVarPair[0] && urlVarPair[0] == urlVarName.toLowerCase()) {
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	
	return urlVarValue;
} 


route = getURLVar('route');
	
	if (!route) {
		$('#tabe_home').addClass('selected');
	} else {
		part = route.split('/');
		
		if (route == 'common/home') {
			$('#tabe_home').addClass('selected');
		} else if (route == 'account/wishlist') {
			$('#wishlist_total').addClass('selected');
		} else if (route == 'information/contact') {
			$('#tabe_contato').addClass('selected');
		} else if (part[0] == 'account') {
			$('#tabe_account').addClass('selected');
		} else if (route == 'checkout/cart') {
			$('#tabe_cart').addClass('selected');
		} else if (part[0] == 'checkout') {
			$('#tabe_checkout').addClass('selected');
		} else if (route == '') {
			$('tabe_home').addClass('selected');	
		}
	}
	
// fim class menu pegando url	


//inicio tipsy 
//$('#foo').tipsy({gravity: 'n'});
// nw | n | ne | w | e | sw | s | se

//$.fn.tipsy.defaults = {
//    delayIn: 0,      // delay before showing tooltip (ms)
//    delayOut: 0,     // delay before hiding tooltip (ms)
//    fade: false,     // fade tooltips in/out?
//    fallback: '',    // fallback text to use when no tooltip text
//    gravity: 'n',    // gravity
//    html: false,     // is tooltip content HTML?
//    live: false,     // use live event support?
//    offset: 0,       // pixel offset of tooltip from element
//    opacity: 0.8,    // opacity of tooltip
//    title: 'title',  // attribute/callback containing tooltip text
//    trigger: 'hover' // how tooltip is triggered - hover | focus | manual
//};
	$('a.prod_compare, a.prod_wish, #button-cart').tipsy({
	gravity: 'n',
	opacity: 0.8, 
	delayOut: 1000,
	delayIn: 6000,
	fade: true
	});

	$('#topcontrol').tipsy({
	gravity: 'e',
	opacity: 0.8, 
	delayOut: 500,
	delayIn: 500,
	fade: true
	});
	
	$(' .correios').tipsy({
	gravity: 'w',
	opacity: 0.8, 
	delayOut: 500,
	delayIn: 500,
	fade: true
	});
//
//$(document).ready(function(){
//	$('a.prod_compare, a.prod_wish').tipsy({gravity: 's', fade: true, 
//	title: function() { 
//	return this.getAttribute('original-title').toUpperCase(); 
//	}
//	});
//});
// fim tipsy

	

});


