startList = function()
{
	if (document.all&&document.getElementById)
	{
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++)
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI")
			{
				node.onmouseover=function()
				{
					this.className+=" over";
			  	}
			  	node.onmouseout=function()
			  	{
			  		this.className=this.className.replace(" over", "");
			   	}
			   	
			   	for(i2=0; i2<node.childNodes.length; i2++)
			   	{
					if(node.childNodes[i2].nodeName=="UL")
					{
						liNode = node.childNodes[i2];
						
						for (a=0; a< liNode.childNodes.length; a++)
						{
							subNode = liNode.childNodes[a];
							if (subNode.nodeName=="LI")
							{
								subNode.onmouseover=function()
								{
									this.className+=" over";
							  	}
							  	subNode.onmouseout=function()
							  	{
							  		this.className=this.className.replace(" over", "");
							   	}
							}
						}
					}
				}
			}
		}
	}
}
window.onload=startList;


var purchased=new Array();
var totalprice=0;



function addlist(param, bSave)
{
    
    $.ajax({
    type: "POST",
    url: "/cart.php?action=add&save=" + bSave,
    data: 'id='+encodeURIComponent(param),
    
    dataType: 'json',
    beforeSend: function(x){$('#ajax-loader').css('visibility','visible');},
   
    
    success: function(msg)
    {                       
        
        $('#ajax-loader').css('visibility','hidden');
        if(parseInt(msg.status)!=1)
        {
            return false;
        }
        
        else
        {
           
            var check=false;
            var cnt = false;
            
            for(var i=0; i<purchased.length;i++)
            {
                if(purchased[i].id==msg.id)
                {
                    check=true;
                    cnt=purchased[i].cnt;
                    
                    break;
                }
            }
            
            if(!cnt)
                $('#item-list').append(msg.txt);
                
            totalprice+=msg.price;
            update_total();

        }
        
        $('.tooltip').hide();
        $('.vase-product').cornerz({radius:5})    
        $('.vase-remove').cornerz({radius:5,corners: "tl"})    
    },
    error: function(xml_req, txt_status, error_thrown)
    {
        //alert('fout!');
    }
    
    });
}

function findpos(id)
{
    for(var i=0; i<purchased.length;i++)
    {
        if(purchased[i].id==id)
            return i;
    }
    
    return false;
}

function remove(id)
{
    $('#vase'+id).remove();
    $.ajax({
    type: "POST",
    url: "/cart.php?action=remove",
    data: 'id='+encodeURIComponent(id),
    dataType: 'json',
    success: function(msg){
        
        }
    });
    
    
}

function change(id)
{
    var i=findpos(id);
    
    totalprice+=(parseInt($('#'+id+'_cnt').val())-purchased[i].cnt)*purchased[i].price;
    
    purchased[i].cnt=parseInt($('#'+id+'_cnt').val());
    update_total();
}

function update_total()
{
    if(totalprice)
    {
        $('#total').html('total: $'+totalprice);
        $('a.button').css('display','block');
    }
    else
    {
        $('#total').html('');
        $('a.button').hide();
    }
}
