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;

$(document).ready(function(){
    
    $('.drag_product').simpletip({
          
        offset:[40,10],
        content:'<img src="/vase/img/ajax_load.gif" alt="loading" style="margin:10px;" />',
        onShow: function(){
            
            var param = this.getParent().find('img').attr('id');
            
            if($.browser.msie && $.browser.version=='6.0')
            {
                param = this.getParent().find('img').attr('style').match(/src=\"([^\"]+)\"/);
                param = param[1];
            }
            
            this.load('/ajax/tips.php',{id:param});
        } 

    });
    
    $(".drag_product img").draggable({
    
    containment: 'document',
    opacity: 0.6,
    revert: 'invalid',
    helper: 'clone',
    zIndex: 100
    
    });

    $("div.content.drop-here").droppable({
    
            drop:
                    function(e, ui)
                    {
                        var param = $(ui.draggable).attr('id');
                        
                        if($.browser.msie && $.browser.version=='6.0')
                        {
                            param = $(ui.draggable).attr('style').match(/src=\"([^\"]+)\"/);
                            param = param[1];
                            
                        }
                        addlist(param, 1);
                    }
    
    });       

});

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();
    
    },
    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)
{
    $('#table_'+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();
    }
}

