

jQuery(document).ready(function() {

	jQuery("#marcas-dropdown").hide();
	jQuery("#marcas-btn").click(function(){
		jQuery(this).addClass("click");
		jQuery("#marcas-dropdown").toggle(100, function(){
			jQuery("#marcas-btn").removeClass("click");
		});
	});
	
	
	// marca a navegacao activa
	jQuery("#navigation li").each(function(){
		if (location.pathname == jQuery("a", this).attr("href")){
			jQuery(this).addClass("active");
		}
	});
	
	
	var searchStringDefault = jQuery("#searchstring").attr("value");
	jQuery("#searchstring").focus(function(){
		if (jQuery("#searchstring").attr("value") == searchStringDefault){
			jQuery("#searchstring").attr("value","");
		}
	}).blur(function(){
		if (jQuery("#searchstring").attr("value") == ""){
			jQuery("#searchstring").attr("value",searchStringDefault);
		}
	})
	
	
	var topVendasClone = jQuery("#top-vendas .content")
		.clone(true)
		.attr("id", "top-vendas-clone")
		.hide();
	jQuery("#top-vendas")
		.append(topVendasClone)
		.hover(
			function(){
				jQuery("#top-vendas-clone").show();
				jQuery("#top-vendas-clone li").show();
			},
			function(){
				jQuery("#top-vendas-clone").hide();
			}
		);
		
	
	jQuery(".hndl_proceed_checkout").colorbox({
		iframe: true,
		width: 760,
		height: 400,
		href: "/?view=noframe&ukey=cart"
	});
	
	
	jQuery("#login-links .login").colorbox({
		iframe: true,
		width: 360,
		height: 300,
		href: "/?view=noframe&ukey=auth"
	});
	
	jQuery("#login-links .myaccount").colorbox({
		iframe: true,
		width: 360,
		height: 300,
		href: "/myaccount/?view=noframe"
	})
	
	jQuery("#login-links .register").colorbox({
		iframe: true,
		width: 360,
		height: 400,
		href: "/?view=noframe&ukey=register"
	});
	
	
	jQuery(".add2cart_handler").click(function(){
		var objForm = getFormByElem(this);
		if (!objForm) return true;

		var r_productParam = jQuery('.product_option', objForm);

		var query = '';
		for (var i = r_productParam.length - 1; i >= 0; i--) {

			if (!parseInt(r_productParam[i].value))	continue;

			if (r_productParam[i].name)
				query += '&' + r_productParam[i].name + '='
						+ parseInt(r_productParam[i].value);
		}

		var r_productQty = jQuery('.product_qty', objForm);
		if (r_productQty) {
			r_productQty = parseInt(jQuery(r_productQty).attr("value"));
			if (r_productQty > 1) {
				query += '&product_qty=' + r_productQty;
			}
		}

		var url = ORIG_LANG_URL
				+ set_query('?ukey=cart&view=noframe&action=add_product&'
				+ query + '&productID='
				+ objForm.getAttribute('rel'), '');
		//openFadeIFrame(url);
		//alert(url)
		jQuery.fn.colorbox({
			iframe: true,
			open: true,
			width: 700,
			height: 400,
			href: url
		})
		return false;
	});
})
