/**
 * Copyright (c) 2008 Logisoft Szymon Sawicki
 *
 * All rights reserved
 *
 */
var Logishop = 
{
	indicatorId : 'indicator',
	
	/*********************
	* POKAZ INDICATOR *
	*********************/
	showIndicator: function(msg, overlay)
	{
		var indicator = $('#'+Logishop.indicatorId);
    
        var indicator_msg = $('#indicator_msg');
		
        indicator_msg.html('Proszę czekać - trwa '+msg);

		win_center = Logishop.winSize();
		pg_offset = Logishop.scrollSize();
		//alert(pg_offset[0]+' '+pg_offset[1]);
		indicator.css('left', (win_center[0]/2-272+pg_offset[0])+'px');
		indicator.css('top', (win_center[1]/2-150+pg_offset[1])+'px');
        if(indicator.css('visibility') == 'hidden')
          indicator.css('visibility', 'visible');
		
		$('#indicator_spinner').show();
        $('#indicator_cart_link').hide();
        $('#indicator_close_link').show();
        indicator.show();
        
        if(overlay)
        	Logishop.showOverlay();	
		
	}, // showIndicator()
	
	
		/*********************
		 * SCHOWAJ INDICATOR *
		 *********************/
	hideIndicator : function ()
	{
		if($('#'+Logishop.indicatorId))
		{
			$('#'+Logishop.indicatorId).hide();
			Logishop.hideOverlay();
		}
		return false;
	}, // hideIndicator()
	
	

	/*********************
	* POKAZ PODSUMOWANIE W INDICATOR (dodawanie do koszyka) *
	*********************/
	showCompleteIndicator: function(msg, type)
	{
		var indicator = $("#"+Logishop.indicatorId);
		indicator.stop();
    
        var indicator_msg = $('#indicator_msg');
        
        if(!msg)
        	 msg = 'Wybrany produkt został dodany do koszyka.<div style="height:10px;"></div>';

		
        indicator_msg.html('<br/>'+msg);

		win_center = Logishop.winSize();
		pg_offset = Logishop.scrollSize();
		//alert(pg_offset[0]+' '+pg_offset[1]);
		indicator.css('left', (win_center[0]/2-272+pg_offset[0])+'px');
		indicator.css('top', (win_center[1]/2-150+pg_offset[1])+'px');
        if(indicator.css('visibility') == 'hidden')
          indicator.css('visibility', 'visible');

        $('#indicator_cart_link').show();
		$('#indicator_spinner').hide();
		$('#indicator_close_link').hide();
		indicator.show();
		
		if(type=='l')
		{
			$('#indicator_later_button').show();
			$('#indicator_cart_button').hide();
		}
		else
		{
			$('#indicator_later_button').hide();
			$('#indicator_cart_button').show();
		}
		
		Logishop.showOverlay();
	}, // showCompleteIndicator()
	

	/**
	 * pokaż overlay
	 */
	showOverlay : function()
	{
		$('embed, object, select').css({ 'visibility' : 'hidden' });
		var objOverlay = document.getElementById('overlay');
		var pageSize = Logishop.pageSize();
		
		if(!objOverlay)
		{
			var objBody = document.getElementsByTagName("body").item(0);
			var objOverlay = document.createElement("div");
			objOverlay.setAttribute('id','overlay');
			objOverlay.onclick = function () {Logishop.hideIndicator(); return false;}
			objOverlay.style.display = 'none';
			objOverlay.style.position = 'absolute';
			objOverlay.style.top = '0';
			objOverlay.style.left = '0';
			objOverlay.style.zIndex = '10000';
		 	objOverlay.style.width = '100%';
		 	objOverlay.style.backgroundColor = '#666';
		 	objOverlay.style.opacity = '0.7';
			objBody.insertBefore(objOverlay, objBody.firstChild);
		}
		
		objOverlay.style.height = (pageSize[1] + 'px');
		$(objOverlay).css({
			backgroundColor:	'#666',
			opacity:			'0.7'
		}).show();

	}, // showOverlay()
	
	/**
	 * ukryj overlay
	 */
	hideOverlay : function()
	{
		var objOverlay = document.getElementById('overlay');
		if(objOverlay)
			objOverlay.style.display = 'none';
	}, // hideOverlay()
	
	
	//------------------------------------

	winSize : function () {
		var x,y;
		// wszystko poza IE
		if (window.innerHeight) {
			x = window.innerWidth;
			y = window.innerHeight;
		}
		// IE 6 Strict Mode
		else if (document.documentElement && document.documentElement.clientHeight) {
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		}
		// pozostale IE
		else if (document.body) {
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}
		return new Array (x, y);
	},

	scrollSize : function  () {
		var x,y;
		// wszystko poza IE
		if (self.pageYOffset || self.pageXOffset) {
			x = self.pageXOffset;
			y = self.pageYOffset;
		}
		// IE 6 Strict
		else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		}
		// pozostale IE
		else if (document.body) {
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		}
		return new Array (x, y);
	},	
		
	viewSize : function  ()
	{
		var x,y;
		// wszystko poza IE
		if (self.innerHeight) {
			x = self.innerWidth;
			y = self.innerHeight;
		}
		// IE 6 Strict Mode
		else if (document.documentElement && document.documentElement.clientHeight) {
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		}
		// pozostale IE
		else if (document.body) {
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}
		return new Array (x, y);
	},
	

	pageSize : function() 
	{
		
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}


		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
		
	}, // pageSize()

	popUp : function(url, name, left, top, width, height, scrollbars) 
	{
	    window.open(url, name, "left="+left+",top="+top+",width="+width+",height="+height+",scrollbars="+scrollbars);
	    return false;		
	},
	
	updateAssortmentData : function (url, editor_id, target_area, type)
	{
		new Ajax.Request(
			url, 
			{
				asynchronous:true, 
				evalScripts:true, 
				onComplete:function(request, json)
				{
					try
					{
						tinyMCE.execInstanceCommand(editor_id, 'mceSetContent', false, request.responseText);
						Logishop.hideIndicator();
						new Effect.Highlight(target_area, {});
					}
					catch(e)
					{
						alert(e);
					}
				}, 
				onLoading:function(request, json)
				{
					Logishop.showIndicator('Pobieranie opisu z asortymentu ...');
				}, 
				parameters:'assortment_id=' + $('#product_assortment_id').value + '&type='+type
			}
		);
	},

	printContent : function(url, _w, _h)
	{
		var h=700;
		var w=800;
		if(_h)
		{
			h = _h;
		}
		if(_w)
		{
			w = _w;
		}
		window.open(url,  "printable_window", "scrollbars=1, left=100, top=100, width="+w+", height="+h);
	},
	
	toggleElement: function(element_id, duration)
	{
    	if(!duration)
    		duration = 500;
  		$('#'+element_id).slideToggle(duration);
	  	return false;
	},
	
	fancySubmit: function(select)
	{
		value = select.options[select.selectedIndex].value;
		form = select.form;
		
		//form.action += value;
		this.showIndicator('przekierowanie do producenta');
		window.location=form.action + value;
		//form.submit();
	},
	
	// wyczyść firmę z formularza
	clearFirm: function()
	{
		firm_check = $('#profile_register_firm');
		if(firm_check && !firm_check.checked)
		{
			$('#profile_firm').val(''); 
			$('#profile_nip').val(''); 
		} 
	},
	
	// wyczyść dane dostawy z formularza
	clearAddressDelivery: function()
	{
		address_delivery_check = $('#profile_register_address_delivery');
		if(address_delivery_check && !address_delivery_check.checked)
		{
			$('#profile_street_name_delivery').val('');
			$('#profile_street_no_delivery').val(''); 
			$('#profile_home_no_delivery').val(''); 
			$('#profile_postal_code_delivery').val(''); 
			$('#profile_city_delivery').val(''); 
		} 
	},
	
	calculatePrice: function(ob, netto_field, brutto_field, tax_rate)
	{
		var price_netto = $('#'+netto_field).val(); 
		var price_brutto = $('#'+brutto_field).val(); 

		if(ob.id==netto_field)
	    {
		    if(isNaN(price_netto.replace(",", ".")))
		    {
		    	$('#'+brutto_field).val(0);
		    }
		    else
		    {
				$('#'+brutto_field).val(Math.round(price_netto.replace(",", ".") * (100+parseInt(tax_rate))) / 100);
		    } 
	    }
	    else
	    {
		    if(isNaN(price_brutto.replace(",", ".")))
		    {
		    	$('#'+brutto_field).val(0);
		    }
		    else
		    {
				$('#'+netto_field).val( Math.round(price_brutto.replace(",", ".")*100000 / (100+parseInt(tax_rate)))/1000);
		    } 
		}
	}
	
} // end Logishop


/**
 * 
 * klasa do zdarzeń związanych z asortymentem
 * 
 */
var LgsAssortment = 
{
	imageFader: null,	

		/******************************************
		 * zamiana aktywnego obrazka (micro->midi)
		 ******************************************/
		 
	switchImage: function (no)
	{
		var i=0;

		while(image_div = document.getElementById('assortment_image_'+i))
		{
			image_div.style.display = 'none';
			i++;
		}
		document.getElementById('assortment_image_'+no).style.display = 'block';

		j = 0;
		while($('#gallery_thumb_'+j).get(0))
		{
			$('#gallery_thumb_'+j).attr('class', '');
			j++;
		}
		
		var i=0;

		while(image_div = document.getElementById('assortment_image_'+i))
		{
			image_div.style.display = 'none';
			i++;
		}
		document.getElementById('assortment_image_'+no).style.display = 'block';

	},
	
		/************************************
		 * przelaczanie zakladek w produkcie
		 ************************************/
		 
	switchTab : function (container_id, tab, object)
	{
		tabs = $('#assortment_tabs').get(0).getElementsByTagName('a');
			
		for(i=0; tabs[i]; i++)
			tabs[i].className = '';
		$(object).get(0).className = 'on';
		$(object).get(0).blur();
		
		divs = $(".assortment_tab_content");
		for(i=0; divs[i]; i++)
			$(divs[i]).hide();
		$('#tab_'+tab).show();
	},
	
			/***************************************
			 * czyszczenie filtru wyszukiwania
			 ***************************************/
	
	clearFilter: function()
	{
		$('filter_price_from').value = '';
		$('filter_price_to').value = '';
		$('filter_name').value = '';
		params = $('filter_content').getElementsByTagName('select');
		for(i=0; params[i]; i++)
		{
			options = params[i].getElementsByTagName('option');
			for(j=0; options[j]; j++)
				options[j].selected = '';
			options[0].selected = 'selected';
		}
	} // end clearFilter()
	
} // LgsAssortment


/**
 * AssortmentScore
 * Copyright (c) 2008 Logisoft Szymon Sawicki
 *
 * All rights reserved
 *
 */

  imgExt = '.png';
  var STARS_RATING_IMG = '/images/stars/star_full'+imgExt;
  var STARS_RATING_IMG_HALF = '/images/stars/star_half_19x19'+imgExt;
  var STARS_RATING_IMG_BG = '/images/stars/star_empty'+imgExt;


var AssortmentScore = function(maxStars, objectName, ratingMessageId)
{
    this.maxStars = maxStars;
    this.objectName = objectName;
    this.ratingMessageId = ratingMessageId
    this.messages = new Array("Oceń produkt!", "Beznadziejny", "Słaby", "Przyzwoity", "Warto kupić", "Bardzo dobry", "Fantastyczny");
  
    this.starTimer = null;
    this.starCount = 0;
  
    // pre-fetch image
    (new Image()).src = STARS_RATING_IMG;
    (new Image()).src = STARS_RATING_IMG_HALF;
  
    function showStars(starNum, skipMessageUpdate)
    {
      this.clearStarTimer();
      this.greyStars();
      this.colorStars(starNum);
      if(!skipMessageUpdate)
        this.setMessage(starNum, this.messages);
    }
  
    function setMessage(starNum)
    {
      document.getElementById(this.ratingMessageId).innerHTML = this.messages[starNum];
    }
  
    function colorStars(starNum)
    {
      for (var i=0; i < starNum; i++) {
        document.getElementById('star__' + (i+1)).src = STARS_RATING_IMG;
      }
    }
  
    function greyStars()
    {
      for (var i=0; i < this.maxStars; i++)
        if (i <= this.starCount) {
          document.getElementById('star__'  + (i+1)).src = STARS_RATING_IMG_BG;
        }
        else
        {
          document.getElementById('star__'  + (i+1)).src = STARS_RATING_IMG_BG;
        }
    }
  
    function setStars(starNum)
    {
      this.starCount = starNum;
      this.drawStars(starNum);
    }
  
  
    function drawStars(starNum, skipMessageUpdate)
    {
      this.starCount=starNum;
      this.showStars(starNum, skipMessageUpdate);
    }
  
    function clearStars()
    {
      this.starTimer = setTimeout(this.objectName + ".resetStars()", 300);
    }
  
    function resetStars()
    {
      this.clearStarTimer();
      if (this.starCount)
        this.drawStars(this.starCount);
      else
        this.greyStars();
      this.setMessage(0);
    }
  
    function clearStarTimer()
    {
      if (this.starTimer) {
        clearTimeout(this.starTimer);
        this.starTimer = null;
      }
    }
  
    this.clearStars = clearStars;
    this.clearStarTimer = clearStarTimer;
    this.greyStars = greyStars;
    this.colorStars = colorStars;
    this.resetStars = resetStars;
    this.setStars = setStars;
    this.drawStars = drawStars;
    this.showStars = showStars;
    this.setMessage = setMessage;
} // end AssortmentScore


PromoCounter = function init(dateId, endMsg) 
{
	var interval, h, m, s;
	this.endMsg = endMsg;
	this.dateEnd = new Date();
	this.dateElement = document.getElementById(dateId);
	if ((interval = $(this.dateElement).html())) {
		interval = interval.split(':');
		if (interval.length >= 3) {
			this.dateEnd.setSeconds(this.dateEnd.getSeconds() + parseInt(interval[2], 10));
			this.dateEnd.setMinutes(this.dateEnd.getMinutes() + parseInt(interval[1], 10));
			this.dateEnd.setHours(this.dateEnd.getHours() + parseInt(interval[0], 10));
		}
		this.update();
		this.intervalId = window.setInterval(dateId+'.update()', 1000);
	}
};

PromoCounter.prototype.update = function () 
{
	var delta, n, days, interval = [0, 0, 0], dateNow = new Date();
	delta = this.dateEnd.getTime() - dateNow.getTime(); //ilość milisekund
	if (delta > 0) {
		delta /= 1000;
		n = Math.floor(delta) % 60;
		interval[2] = (n > 9 ? String(n) : '0' + n); //ilość sekund
		delta /= 60;
		n = Math.floor(delta) % 60;
		interval[1] = (n > 9 ? String(n) : '0' + n); //ilość minut
		delta /= 60;
		interval[0] = Math.floor(delta); //ilość godzin
		days = Math.floor(interval[0] / 24); //ilość dni
		if (days > 1) {
			this.dateElement.firstChild.nodeValue = days + ' dni';
		} else if (days > 0) {
			this.dateElement.firstChild.nodeValue = '1 dzień';
		} else {
			this.dateElement.firstChild.nodeValue = interval.join(':');
		}
	} else {
		this.dateElement.firstChild.nodeValue = this.endMsg;
		clearInterval(this.intervalId);
	}
	this.dateElement.style.display = 'inline-block';
}





/**
 * menu_front.js
 * Copyright (c) 2008 Logisoft Szymon Sawicki
 *
 * All rights reserved
 *
 */
 
window.Menu = {};

/**
 * klasa Menu
 * @param idOrElement - root ul.id
 * @param name
 * @param customConfigFunction
 * @return
 */
Menu = function init(idOrElement, name, customConfigFunction)
{
	this.name = name;
	this.type = "menu";
	this.closeDelayTimer = null;
	this.closingMenuItem = null;
//alert(name);
	this.config();
	if (typeof customConfigFunction == "function") {
		this.customConfig = customConfigFunction;
		this.customConfig();
	}
	this.rootContainer = new MenuContainer(idOrElement, this);
}

Menu.prototype.config = function()
{
	  this.collapseBorders = true;
	  this.quickCollapse = true;
	  this.closeDelayTime = 400;
};


/**
 * klasa MenuContainer
 * @param idOrElement
 * @param parent
 * @return
 */
window.MenuContainer = {};

MenuContainer = function initialize(idOrElement, parent)
{
	this.type = "menuContainer";
	this.menuItems = [];
	this.init(idOrElement, parent);
}

MenuContainer.prototype.init = function(idOrElement, parent)
{
	 if(!$(idOrElement))
	  	return;
	  this.element = $(idOrElement);
	  this.parent = parent;
	  this.parentMenu = (this.type == "menuContainer") ? ((parent) ? parent.parent : null) : parent;
	  this.root = parent instanceof Menu ? parent : parent.root;
	  this.id = this.element.attr("id");

	  if (this.type == "menuContainer") 
	  {
	  	if (this.element.hasClass("level1")) this.menuType = "dropdown";
		else if (this.element.hasClass("level2")) this.menuType = "flyout";
		else this.menuType = "flyout";

	    if (this.menuType == "flyout" /*|| this.menuType == "dropdown"*/)
	    {
	      this.isOpen = false;
		  this.element.css({"position": "absolute", "top": "0px", "left": "0px", "visibility": "hidden"});
	    }
	    else 
	    {
	      this.isOpen = true;
	    }
	  } 
	  else 
	  {
	    this.isOpen = this.parentMenu.isOpen;
	  }

	  var childNodes = this.element.children();
	  if (childNodes == null) return;

	  for (var i = 0; i < childNodes.length; i++) 
	  {
	    var node = childNodes[i];
	    
	    if (node.nodeType == 1) 
	    {
	      if (this.type == "menuContainer")
	      {
	        if (node.tagName.toLowerCase() == "li")
	        {
	          this.menuItems.push(new MenuItem(node, this));
	        }
	      } 
	      else
	      {
	        if (node.tagName.toLowerCase() == "ul") 
	        {
	          this.subMenu = new MenuContainer(node, this);
	        }
	      }
	    }

	  }
	  
} // MenuContainer.init()

MenuContainer.prototype.getBorders = function(element) {
	  var ltrb = ["Left","Top","Right","Bottom"];
	  var result = {};
	  dom_element = this.element.get(0);

	  for (var i = 0; i < ltrb.length; ++i) 
	  {
	    if (dom_element.currentStyle)
	      var value = parseInt(dom_element.currentStyle["border"+ltrb[i]+"Width"]);
	    else if (window.getComputedStyle)
	      var value = parseInt(window.getComputedStyle(dom_element, "").getPropertyValue("border-"+ltrb[i].toLowerCase()+"-width"));
	    else
	      var value = parseInt(dom_element.style["border"+ltrb[i]]);
	    result[ltrb[i].toLowerCase()] = isNaN(value) ? 0 : value;
	  };
	  return result;
} // MenuContainer.getBorders()


MenuContainer.prototype.open = function() {
	  if (this.root.closeDelayTimer) window.clearTimeout(this.root.closeDelayTimer);
	  this.parentMenu.closeAll(this);
	  this.isOpen = true;
	  
	  if (this.menuType == "dropdown")
	  {
		  // TODO
//	  	this.element.css({
//			"left": (this.parent.element.position().left) + "px",
//			"top": (this.parent.element.position().top + Element.getHeight(this.parent.element)) + "px"
//		});

	  } 
	  else if (this.menuType == "flyout")
	  {
	    var parentMenuBorders = this.parentMenu ? this.parentMenu.getBorders() : new Object();
	    var thisBorders = this.getBorders();
	    
	    if($(this.element).attr('class') == 'vert')
	    {
	    	dx = -18;
	    }	    	
	    else
	    {
	    	dx = -10;
	    }
	    
	    dx = 0;
	    if(navigator.appName=='Opera')
	    	dx += 1;
	    else
	    	dx += 0;

		$(this.parent.element).find('.level1_parent').attr('class', 'level1_parent_hover');

		if (
	      (this.parentMenu.element.position().left + this.parentMenu.element.width() + this.element.width() + 20) >
	      (window.innerWidth ? window.innerWidth : document.body.offsetWidth)
	    ) 
	    {
			this.element.css({
	      		"left": (- this.element.width() - (this.root.collapseBorders ?  0 : parentMenuBorders["left"])) + "px"
			});
	    } 
	    else
	    {
	    	this.element.css({
	    		"left": (this.parentMenu.element.width() - parentMenuBorders["left"] - (this.root.collapseBorders ?  Math.min(parentMenuBorders["right"], thisBorders["left"]) : 0) + dx) + "px"
			});
	    }
		this.element.css({
	    	"top": (this.parent.element.position().top - parentMenuBorders["top"] - this.menuItems[0].element.position().top) + "px"
		});
	  }
	  this.element.css({"visibility": "visible"});
	  if($('#results'))
	  	$('#results').hide();

} //  MenuContainer.open()

MenuContainer.prototype.close = function() {
	this.element.css({"visibility": "hidden"});
	this.isOpen = false;
	if($('#results'))
		$('#results').show();
	this.closeAll();
	$(this.parent.element).find('.level1_parent_hover').attr('class', 'level1_parent');
} // MenuContainer.close()

MenuContainer.prototype.closeAll = function(trigger) {
	for (var i = 0; i < this.menuItems.length; ++i) {
		this.menuItems[i].closeItem(trigger);
	}
}

/**
 * klasa MenuItem
 */
window.MenuItem = {};

MenuItem = function initialize(idOrElement, parent) 
{
	var menuItem = this;
	this.type = "menuItem";
	this.subMenu;
	this.init(idOrElement, parent);
	if (this.subMenu) 
	{
		this.element.mouseover(function() {
			menuItem.subMenu.open();
		})
	} 
	else 
	{
		if (this.root.quickCollapse) 
		{
		  this.element.mouseover(function() {
			menuItem.parentMenu.closeAll();
		  })
		}
	 }
	  var linkTag = this.element.children("a")[0];
	  if (linkTag) 
	  {
		 /*linkTag.focus(function(){
			 this.element.trigger('mouseover');
		 	}
		 );*/
		 this.link = linkTag;
		 this.text = linkTag.text;
	  }
	  if (this.subMenu) {
		this.element.mouseout(function() 
		{
		  if (menuItem.root.openDelayTimer) window.clearTimeout(menuItem.root.openDelayTimer);
		  if (menuItem.root.closeDelayTimer) window.clearTimeout(menuItem.root.closeDelayTimer);
		  eval(menuItem.root.name + ".closingMenuItem = menuItem");	  
		  menuItem.root.closeDelayTimer = window.setTimeout(menuItem.root.name + ".closingMenuItem.subMenu.close()", menuItem.root.closeDelayTime);
		})
	  }
} // MenuItem.initialize()

MenuItem.prototype.init = MenuContainer.prototype.init;
MenuItem.prototype.getBorders = MenuContainer.prototype.getBorders;
MenuItem.prototype.open = MenuContainer.prototype.open;
MenuItem.prototype.close = MenuContainer.prototype.close;
MenuItem.prototype.closeAll = MenuContainer.prototype.closeAll;

MenuItem.prototype.openItem = function() {
	  this.isOpen = true;
	  if (this.subMenu) { this.subMenu.open(); }
}

MenuItem.prototype.closeItem = function(trigger) {
	  this.isOpen = false;
	  if (this.subMenu) {
	    if (this.subMenu != trigger) this.subMenu.close();
	  }
}


/**
 * inicjalizacja menu obiektów oraz menu
 **/

var menu;


function configMenu() {
  this.closeDelayTime = 900;
}

function initMenu() {
  menu = new Menu('#root', 'menu', configMenu);
}


$(document).ready(initMenu);
