function showCategory(category_id) {
	_inBusiness=0;
	_inAccessory=0;
	jQuery(document).ready(function(){
		if(category_id==_accessoryCat){
			_inAccessory=1;
		}
		if(category_id==_businessCat){
			_inBusiness=1;
		}
		jQuery.get("/_ajax/shop/items.get.ajax.php",{'cat':category_id},function(data){
			eval("_itemsArr="+data);
			_totalCatPages = _itemsArr.length;
			_totalCatItems = 0;
			_curPage = 0;
			if(_totalCatPages>1) { 
				_totalCatItems = _totalCatPages*4; 
				jQuery("#next4").css("display","block");
			} 
			if(_totalCatItems>0) {
				_totalCatItems += _itemsArr[(_totalCatPages-1)].length;
			} 
			showPage(0);
			jQuery(".mitem-sel").attr("class","mitem");
			if(category_id==_accessoryCat) {
				jQuery("a[id='cat-"+category_id+"'] > img").attr("src","/_media/images/shop/accessories_selected.png");
			} else {
				jQuery("a[id='cat-"+_accessoryCat+"'] > img").attr("src","/_media/images/shop/accessories.png");
				jQuery("a[id='cat-"+category_id+"']").attr("class","mitem-sel");
			}
		});
	})
}

function showPage(diff) {
	if(_totalCatPages==0) {
		jQuery("#next4").css("display","none");
		jQuery("#prev4").css("display","none");
	} else {
		//jQuery(".frame-hover").attr("class","frame").css("background-image","url(/_media/images/shop/p-frame-small.png)");
		if(diff==0) { _curPage = 0; }
		else { _curPage += diff; }
		if(_curPage==0) { jQuery("#prev4").css("display","none"); } else { jQuery("#prev4").css("display","block"); }
		if((_curPage+1)==_totalCatPages) { jQuery("#next4").css("display","none"); } else { jQuery("#next4").css("display","block"); }
		for(var i=0;i<4;i++) {
			if(_itemsArr[_curPage]==undefined) {
				jQuery("div[id='item"+i+"']").css("display","none");
			} else {
				if(_itemsArr[_curPage][i]) {
					jQuery("div[id='item"+i+"']").find(".img > img").attr("src","/_media/items/"+_itemsArr[_curPage][i]['id']+"-thumb."+_itemsArr[_curPage][i]['img_ext_order']);
					jQuery("div[id='item"+i+"']").attr("title",_itemsArr[_curPage][i]['title']).css("display","block");
				} else {
					jQuery("div[id='item"+i+"']").css("display","none");
				}
			}
		}
		jQuery(document).ready(function(){
			showItem(null,0);
		});
	}
}

function toggleBottomCourse(main) {
	var extra_chk_items = "";
	var chk_items = "";
	var sel_items = "";
	var _total_chks = 0;
	var item_cook_level = 'no';
	var _total_props_for_item = main!="" ? _deals[465]['properties'][main].length : 0;
	
	jQuery("#bottom-course").hide();
	
	if(main=="1") {
		$("#bottom-course").show();
		item_cook_level='yes';
	} else if(main=="2") {
		$("#bottom-course").show();
	}

	if(item_cook_level=='yes') {
		sel_items = '<div style="float:right; width:190px;">מידת עשייה: &nbsp;';
		sel_items += '<select name="properties[1]">';
		jQuery.each(_cookLevel,function(index, value) { 
				sel_items += '<option value="'+index+'">'+value+'</option>';
		});
		sel_items += '</select><br /><br /></div>';
	}
	
	for(var i = 0;i<_total_props_for_item;i++) {
		var prop_id=_deals[465]['properties'][main][i];
		var prop_type=_propertiesArr[_deals[465]['properties'][main][i]].property_type;
		var prop_title=_propertiesArr[_deals[465]['properties'][main][i]].title;
		var prop_options=_propertiesArr[_deals[465]['properties'][main][i]].options;
		var prop_price=_propertiesArr[_deals[465]['properties'][main][i]].price;
		if(prop_type==1) {
			if(prop_price) {
				var new_chk = '<div style="float:right; width:110px;"><input name="properties['+prop_id+']" type="checkbox" value="1" id="chk'+i+'" />';	
				new_chk += '<label for="chk'+i+'">'+prop_title;
				new_chk += ' ('+prop_price+' &#8362;)';
				new_chk += '</label></div>';
			} else {
				var new_chk = '<div style="float:right; width:90px;"><input name="properties['+prop_id+']" type="checkbox" value="1" id="chk'+i+'" checked="checked" />';	
				new_chk += '<label for="chk'+i+'">'+prop_title+'</label></div>';
			}

			if(prop_price=="") {
				chk_items += new_chk
			} else {
				extra_chk_items += new_chk
			}
			_total_chks++;						
		} else if(prop_type==2) {
			sel_items += '<div style="float:right; width:230px;">'+prop_title+'&nbsp;';
			sel_items += '<select name="properties['+prop_id+']">';
			for(var x = 0;x<prop_options.length;x++) {
				sel_items += '<option value="'+prop_options[x]+'">'+prop_options[x]+'</option>';
			}
			sel_items += '</select></div>';
		}
	}
	jQuery("#chk_props").html(chk_items);
	jQuery("#sel_props").html(sel_items+extra_chk_items);
	jQuery("#additions_btn").css("visibility","visible");
	jQuery("#order_btn").css("visibility","hidden");
	jQuery("#bottom-course").show();
}




function showItem(obj,item) {
	if(_itemsArr[_curPage]==undefined) return false;
	var item_id = _itemsArr[_curPage][item]['id'];
	var item_title = _itemsArr[_curPage][item]['title'];
	var item_cat = _itemsArr[_curPage][item]['category_id'];
	var item_desc = _itemsArr[_curPage][item]['description'];
	var item_price = _itemsArr[_curPage][item]['price'];
	var item_price_friend = _itemsArr[_curPage][item]['price_friends'];
	var item_cook_level = _itemsArr[_curPage][item]['cook_level'];
	var item_business = _itemsArr[_curPage][item]['business'];
	var item_custom_add = _itemsArr[_curPage][item]['custom_additions'];
	var item_accessory = _inAccessory;
	var _total_props_for_item = _itemsArr[_curPage][item].properties.length;
	var _item_price_length = Object.size(item_price);
	
	jQuery(".frame-cur").attr("class","frame").css("background-image","url(/_media/images/shop/p-frame-small.png)");
	
	if(obj) {
		jQuery(obj).find(".frame").attr("class","frame-cur");
	} else {
		jQuery("#item0").find(".frame").attr("class","frame-cur").css("background-image","url(/_media/images/shop/p-frame-small-hover.png)");
	}
	
	jQuery("#add_item").find("input[name='id']").val(item_id);				// update form 
	jQuery("#add_item").find("input[name='title']").val(item_title);		// update form 
	jQuery("#add_item").find("input[name='accessory']").val(_inAccessory);	// update form 
	jQuery("#p").attr("title",item_title);									// update title for div
	jQuery("#p-img > img").attr({
		"src":"/_media/items/"+item_id+"-preview."+_itemsArr[_curPage][item]['img_ext_order'],
		"title":item_title,
		"alt":item_title
	});																		// update image
	jQuery("#pinfo > div > p").text(item_desc);								// update description
	jQuery("#pinfo > div > h3").text(_itemsArr[_curPage][item]['title']);	// update title
	jQuery("#pinfo2 > div > h3").text(_itemsArr[_curPage][item]['title']);	// update title
	
	if(item_business=='yes'&&_inBusiness==1) {	//fixed price
		jQuery("#add_item").find("input[name='business']").val('1');		// update form 
		
		
		$("#bottom-course").show();
		$("#additions_btn").attr("src","/_media/images/shop/btn-choose-add.png");
		
		var drinks_combo = '<select name="drink" id="drink">';
		drinks_combo += '<option value="">בחר שתייה</option>'+"\n";
		jQuery.each(_businessDrinks,function(index,value){
			drinks_combo += '<option value="'+value['id']+'">'+value['title']+'</option>'+"\n";
		});
		drinks_combo += '</select><br />';
		var addons_combo = "";

		addons_combo += '<select name="addon" id="addon">';
		addons_combo += '<option value="">בחר תוספת</option>'+"\n";
		jQuery.each(_businessAddons,function(index,value){
			addons_combo += '<option value="'+value['id']+'">'+value['title']+'</option>'+"\n";
		});
		addons_combo += '</select><br />';
		
		jQuery("#pinfo2 > div > p").html(item_desc+'<br /><br />'+addons_combo+'<br />'+drinks_combo);
		
		jQuery.each(item_price, function(index, value) { 
			prc = index;
			prc_desc = value;
		});
		jQuery("#p_price").html( prc + " &#8362;" );
		jQuery("#p_price_2").html( prc + " &#8362;" );
		jQuery("#add_item").find("input[name='price']").val(prc);
		jQuery("#add_item").find("input[name='price_desc']").val(prc+" &#8362;");
		jQuery("#pinfo2 > div > h3").html(item_title + " - "+prc+" &#8362;");
		jQuery("#price_div").hide();
	} else {
		jQuery("#pinfo2 > div > p").text(item_desc);
		jQuery("#add_item").find("input[name='business']").val('0');		// update form 
		
		$("#bottom-course").show();
		$("#additions_btn").attr("src","/_media/images/shop/btn-choose-add.png");
		if(item_custom_add=='yes') {
			var drinks_combo = "";
			/*
			// mondeal
			if(item_id==465) {
				var addons_combo = '<select name="deal" id="deal-combo" onchange="toggleBottomCourse(this.value);">';
				addons_combo += '<option value="">בחר מנה עיקרית</option>'+"\n";
				addons_combo += '<option value="1">מינימי</option>'+"\n";
				addons_combo += '<option value="2">נקניקיה</option>'+"\n";
				addons_combo += '</select>&nbsp;';
				$("#bottom-course").hide();
				$("#additions_btn").attr("src","/_media/images/shop/btn-choose-main.png");
				
				addons_combo += '<select name="addon" id="addon">';
				addons_combo += '<option value="">בחר תוספת</option>'+"\n";
				jQuery.each(_businessAddons,function(index,value){
					addons_combo += '<option value="'+value['id']+'">'+value['title']+'</option>'+"\n";
				});
				addons_combo += '</select><br />';
				jQuery("#pinfo2 > div > p").html(item_desc+'<br /><br />'+addons_combo+'<br />'+drinks_combo);
			}
			*/
			
		}
		
		
		if(_item_price_length > 1){
			temp_html = '<select onchange="updatePrice();">';
			var i=0;
			jQuery.each(item_price, function(key, value) { 
				temp_html += '<option value="'+key+'">'+value+ " &#8362;" +'</option>';
				if(i==0) {
					jQuery("#add_item").find("input[name='price']").val(key);
					jQuery("#add_item").find("input[name='price_desc']").val(value + " &#8362;");
				}
				i++;
			});
			temp_html += '</select>';
			jQuery("#p_price").html( temp_html );
			jQuery("#p_price_2").html( temp_html );
		} else {
			var prc = 0;
			var prc_desc = "";
			var prc_frnd = 0;
			var prc_frnd_desc = "";
			
			jQuery.each(item_price, function(index, value) { 
				if(_inAccessory==1) {
					for(var key in item_price_friend) {
						prc_frnd = key;
						prc_frnd_desc = item_price_friend[key];
					}
				} else {
					prc_frnd = 0;
					prc_frnd_desc = "";
				}
				prc = index;
				prc_desc = value;
			});
			
			if(_inAccessory==1) {
				jQuery("#p_price").html( prc + " &#8362;, מחיר מועדון: "+prc_frnd+" &#8362;" );
			} else {
				jQuery("#p_price").html( prc + " &#8362;" );
			}
			
			jQuery("#p_price_2").html( prc + " &#8362;" );
			jQuery("#add_item").find("input[name='price']").val(prc);
			jQuery("#add_item").find("input[name='price_desc']").val(prc + " &#8362;");
			
			jQuery("#add_item").find("input[name='price_frnd']").val(prc_frnd);
			jQuery("#add_item").find("input[name='price_frnd_desc']").val(prc_frnd + " &#8362;");
			
		}
		jQuery("#price_div").show();
	}
	
	
	
	if(_total_props_for_item>0) {
		var extra_chk_items = "";
		var chk_items = "";
		var sel_items = "";
		var _total_chks = 0;
		if(item_cook_level=='yes') {
			sel_items = '<div style="float:right; width:190px;">מידת עשייה: &nbsp;';
			sel_items += '<select name="properties[1]">';
			jQuery.each(_cookLevel,function(index, value) { 
  				sel_items += '<option value="'+index+'">'+value+'</option>';
			});
			sel_items += '</select><br /><br /></div>';
		}
		
		for(var i = 0;i<_total_props_for_item;i++) {
			var prop_id=_itemsArr[_curPage][item]['properties'][i];
			var prop_type=_propertiesArr[_itemsArr[_curPage][item]['properties'][i]].property_type;
			var prop_title=_propertiesArr[_itemsArr[_curPage][item]['properties'][i]].title;
			var prop_options=_propertiesArr[_itemsArr[_curPage][item]['properties'][i]].options;
			var prop_price=_propertiesArr[_itemsArr[_curPage][item]['properties'][i]].price;
			if(prop_type==1) {
				if(prop_price) {
					var new_chk = '<div style="float:right; width:110px;"><input name="properties['+prop_id+']" type="checkbox" value="1" id="chk'+i+'" />';	
					new_chk += '<label for="chk'+i+'">'+prop_title;
					new_chk += ' ('+prop_price+' &#8362;)';
					new_chk += '</label></div>';
				} else {
					var new_chk = '<div style="float:right; width:90px;"><input name="properties['+prop_id+']" type="checkbox" value="1" id="chk'+i+'" checked="checked" />';	
					new_chk += '<label for="chk'+i+'">'+prop_title+'</label></div>';
				}

				if(prop_price=="") {
					chk_items += new_chk
				} else {
					extra_chk_items += new_chk
				}
				_total_chks++;						
			} else if(prop_type==2) {
				sel_items += '<div style="float:right; width:230px;">'+prop_title+'&nbsp;';
				sel_items += '<select name="properties['+prop_id+']">';
				for(var x = 0;x<prop_options.length;x++) {
					sel_items += '<option value="'+prop_options[x]+'">'+prop_options[x]+'</option>';
				}
				sel_items += '</select></div>';
			}
		}
		jQuery("#chk_props").html(chk_items);
		jQuery("#sel_props").html(sel_items+extra_chk_items);
		jQuery("#additions_btn").css("visibility","visible");
		jQuery("#order_btn").css("visibility","hidden");
	} else {
		if(item_custom_add=='yes') {
			
			var addons_combo = '<select name="addon" id="addon">';
			addons_combo += '<option value="">בחר תוספת</option>'+"\n";
			jQuery.each(_businessAddons,function(index,value){
				addons_combo += '<option value="'+value['id']+'">'+value['title']+'</option>'+"\n";
			});
			addons_combo += '</select><br />';
			jQuery("#pinfo2 > div > p").html(item_desc+'<br /><br />'+addons_combo);
			jQuery("#chk_props").html("");
			jQuery("#sel_props").html("");
			jQuery("#additions_btn").css("visibility","visible");
			jQuery("#order_btn").css("visibility","hidden");
		} else {
			jQuery("#chk_props").html("");
			jQuery("#sel_props").html("");
			jQuery("#additions_btn").css("visibility","hidden");
			jQuery("#order_btn").css("visibility","visible");
		}
	}
	_curItem = item;
}

function updatePrice(obj) {
	var opt = jQuery(obj).find("option:selected");
	jQuery("#add_item").find("input[name='price']").val(opt.val());
	jQuery("#add_item").find("input[name='price_desc']").val(opt.html());
	jQuery("#p_price_2 > select").val(opt.val());
}


function addItem2Order() {
	if(_inBusiness) {
		if(_canOrderBiz=='0') {
			alert("מנה עסקית ניתן להזמין בימים א-ה בין 11:00 ל - 17:00 בימים א' עד ה'."); 
			return false;
		}
		if(_itemsArr[_curPage][_curItem]['custom_additions']=='yes' ) {
			if(jQuery("#deal-combo").val()==''||jQuery("#addon").val()=='') {
				alert("עליך לבחור מנה ותוספת.");	
				return false;
			}
		} else {
			if(jQuery("#drink").val()==''||jQuery("#addon").val()=='') {
				alert("עליך לבחור שתיה ותוספת למנה.");	
				return false;
			}
		}
	}
	if(_itemsArr[_curPage][_curItem]['custom_additions']=='yes' ) {
		if(jQuery("#addon").val()=='') {
			alert("עליך לבחור תוספת");
			return false;
		}
	}
	
	hideAdditions();
	jQuery.post("/_ajax/shop/cart.item.add.ajax.php", jQuery("#add_item").serialize(),function(cart){
		//eval('var cart='+data);
		cart_item_html = '<tr><td>'+cart.item.ttl+'</td><td class="itemprice">'+cart.item.prc_xtra+' &#8362;</td><td class="delitem"><img src="/_media/images/shop/del-cart.gif" onclick="removeFromCart(this,\''+cart.skey+'\');" class="pointer"></td></tr>'+"\n";
		jQuery("#cart-items > table").append(cart_item_html);
		jQuery("#cart-items").animate({scrollTop: jQuery('#cart-items')[0].scrollHeight});
		jQuery("#cart_total").html('סה"כ '+cart.ttl+' &#8362;');
		jQuery("#finish_btn").show();
		jQuery("#discount").html("הנחת חברי מועדון 10% :&nbsp;&nbsp;&nbsp;&nbsp; ₪ "+cart.discount+"");
		_cartItems++;
		showPage(0);
	},"json");
}

jQuery(document).ready(function(){
	showItem(null,0);
	if(_cartItems > 0) {
		jQuery("#finish_btn").show();
	}
});