// JavaScript Document
$(document).ready(function() {
	$("#categoryTree>ul>li>ul>li>ul, #categoryTree>ul>li>ul>li>ul>li>ul").hide();
	$('#categoryTree>ul>li>ul>li, #categoryTree>ul>li>ul>li>ul>li').click(function(){
        //event.preventDefault();
        if ($('#categoryTree ul:animated').size() == 0) {
            $heading = $(this);
            $expandedSiblings = $heading.siblings().find('ul:visible');
            if ($expandedSiblings.size() > 0) {
                $expandedSiblings.slideUp(200, function(){
                    $heading.find('ul:first').slideDown(500);
                });
            }
            else {
                $heading.find('ul:first').slideDown(200);
            }
        }
    });		
	$('#categoryTree .liCurrent').parents().show();	
	$("#categoryTree").show();
	
	modifyCart(0,0,0, 'cartMini');
	modifyCart(0,0,0, 'cartMaxi');
	modifyList(0,0, 'alisverisListesi');
});

function modifyCart(productID,action,qty,target) {
	$.get("sepet.php?" + target, { a: action, q: qty, pID: productID }, function(data){ $('#' + target).html(data) } );
	$.get("sepet.php?adet", function(data){ $('#minsepet').find('span').html(data) });
};

function modifyList(productID,action,target) {
	$.get("includes/liste.php?" + target, { a: action, pID: productID }, function(data){ $('#' + target).html(data) } );
};

function transferItem(urunID, action) {
	if (action == "toList") {
		// Geleni sepetten sil, listeye ekle.
		modifyCart(urunID, 'remove', '', 'cartMaxi');
		modifyList(urunID, 'add', 'alisverisListesi');
		}
	else if (action == "toCart") {
		// Geleni listeden sil, sepete ekle.
		modifyCart(urunID, 'add', '1', 'cartMaxi');	
		modifyList(urunID, 'remove', 'alisverisListesi');				
		}
	}
	
(function(d){d.each(["backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","color","outlineColor"],function(f,e){d.fx.step[e]=function(g){if(!g.colorInit){g.start=c(g.elem,e);g.end=b(g.end);g.colorInit=true}g.elem.style[e]="rgb("+[Math.max(Math.min(parseInt((g.pos*(g.end[0]-g.start[0]))+g.start[0]),255),0),Math.max(Math.min(parseInt((g.pos*(g.end[1]-g.start[1]))+g.start[1]),255),0),Math.max(Math.min(parseInt((g.pos*(g.end[2]-g.start[2]))+g.start[2]),255),0)].join(",")+")"}});function b(f){var e;if(f&&f.constructor==Array&&f.length==3){return f}if(e=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(f)){return[parseInt(e[1]),parseInt(e[2]),parseInt(e[3])]}if(e=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(f)){return[parseFloat(e[1])*2.55,parseFloat(e[2])*2.55,parseFloat(e[3])*2.55]}if(e=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(f)){return[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)]}if(e=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(f)){return[parseInt(e[1]+e[1],16),parseInt(e[2]+e[2],16),parseInt(e[3]+e[3],16)]}if(e=/rgba\(0, 0, 0, 0\)/.exec(f)){return a.transparent}return a[d.trim(f).toLowerCase()]}function c(g,e){var f;do{f=d.curCSS(g,e);if(f!=""&&f!="transparent"||d.nodeName(g,"body")){break}e="backgroundColor"}while(g=g.parentNode);return b(f)}var a={violet:[128,0,128],red:[255,0,0],white:[255,255,255],yellow:[255,255,0],transparent:[255,255,255]}})(jQuery);
