$(document).ready(function () {
	$(".proditem").each(function (j) {
		$(this).find("a.prodbutton").eq(0).click(function () {
			var pr = $(this).parent("div.proditem").find("img").eq(0);
			$.post('/index.php?route=module/cart/callback',{product_id:$(this).next("input").eq(0).val(),quantity:'1',justone:'true'},function (html) {

				var image = $(pr).offset();
				var cart  = $('span.cartnumm').offset();
				var l = image.left;
				$("div.outer").before('<img src="' + $(pr).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;z-index:2000" />');
				var params = {top : cart.top + 'px',left : cart.left + 'px',opacity: 0.0,width : $('span.cartnumm').width(),height : $('span.cartnumm').height()};
				$('#temp').animate(params, 'slow',false,function () {$("#temp").remove();});

        			    var str = html.split("<>");
		        	    var s = $('span.cartnumm').html()*1 + 1;
				$('span.cartnumm').html(s).next("span").html("items &#163;" + trim(str[1]));
				var w = 120 - $('span.cartnumm').width()*1;
				w = (w <= 90)?w:90;
				$('span.cartnumm').next('span').css("width",w+"px");
			});
		});
	});
});
$(".centralright").ready(function () {
	$(this).find("a.add").each(function (k) {
		$(this).click(function () {
			var pr = $(this).parent("p").find("img").eq(0);
			$.post('/index.php?route=module/cart/callback',{product_id:$(this).next("input").eq(0).val(),quantity:'1',justone:'true'},function (html) {

				var image = $(pr).offset();
				var cart  = $('span.cartnumm').offset();
				var l = image.left;
				$("div.outer").before('<img src="' + $(pr).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;z-index:2000" />');
				var params = {top : cart.top + 'px',left : cart.left + 'px',opacity: 0.0,width : $('span.cartnumm').width(),height : $('span.cartnumm').height()};
				$('#temp').animate(params, 'slow',false,function () {$("#temp").remove();});

        		    var str = html.split("<>");
		            var s = $('span.cartnumm').html()*1 + 1;
				$('span.cartnumm').html(s).next("span").html("items &#163;" + trim(str[1]));
				var w = 120 - $('span.cartnumm').width()*1;
				w = (w <= 90)?w:90;
				$('span.cartnumm').next('span').css("width",w+"px");
			});
		return false;
		});
	});
});


function changetopcat(subs) {
    var cattop = $("#topcat").val()*1;
    
    var d = new Date();
    
    if (subs == 1) {
        /** showing sub categories so get the secondary categories **/
        $.post("/?route=module/searchdropdown/seconds",{d:d.getTime(),catid:cattop},function (data) {
            if (data == '') {
            
                $("#secondcat").html("").attr("disabled","disabled");
            
                /** see if there are any products within this category **/
                $.post("/?route=module/searchdropdown/products",{d:d.getTime(),catid:cattop},function (prods) {
                
                    if (prods !== '') {
                    
                        $("#prodcat").html(prods).removeAttr("disabled");
                        
                    
                    }
                
                })
            } else {
                $("#secondcat").html(data).removeAttr("disabled");
                $("#prodcat").html("").attr("disabled","disabled");
            }
        });
    } else {
        /** only showing one level of drill down **/
        /** see if there are any products within this category **/
        $.post("/?route=module/searchdropdown/products",{d:d.getTime(),catid:cattop},function (prods) {
                
             if (prods !== '') {
                    
                 $("#prodcat").html(prods).removeAttr("disabled");
                        
                    
             } else {
                $("#prodcat").html("").attr("disabled","disabled");
             }
                
         });
    }
    
    
    
}

function changesecondcat() {
    var secondcat = $("#secondcat").val()*1;
    var d = new Date();
    $.post("/?route=module/searchdropdown/products",{d:d.getTime(),catid:secondcat},function (prods) {

             if (prods !== '') {
                    
                 $("#prodcat").html(prods).removeAttr("disabled");
                        
                    
             } else {
                $("#prodcat").html("").attr("disabled","disabled");
             }
    });
}

function productfinder() {
    if ($("#topcat")) {
        var cattop = $("#topcat").val();
    } else {
        var cattop = -1;
    }

    if ($("#secondcat")) {
        var secondcat = $("#secondcat").val();
    } else {
        var secondcat = -1;
    }
    
    if ($("#prodcat")) {
        var prodcat = $("#prodcat").val();
    } else {
        var prodcat = -1;
    }

    if (carttop > -1) {

        if (secondcat > -1) {
        
        }

        /** now we need to post the selected items to get the product results **/
        var d = new Date();
        $.post("/?route=module/searchdropdown/callback",{d:d.getTime(),topcat:cattop,secondcat:secondcat,prod:prodcat},function (data) {alert(data);});


    }
}
