var showcart = 0;
function ShowCartTooltip()
{
	showcart = showcart+1;
	if (showcart > 1)
	{
		return false;
	}
	if ($('tooltip'))
	{
		var showing = 0;
		
		function hide_tooltip()
		{
			if (effect_show)
			{
				effect_show.stop();
			}
				
			effect_hide = new Fx.Style($('tooltip'), 'opacity', {duration: 400, onComplete: function() { $('tooltip').setStyle('visibility', 'hidden'); $('tooltip').setStyle('display', 'none'); }});
			effect_hide.start(1, 0);
		};
	
		var effect_show;
		var effect_hide;
		$('tooltip').setStyle('height',  $('tooltip').offsetHeight);
		$('tooltip').setStyle('display', 'none');

		
		$$('.tip').each(function(el)
		{ 
			el.addEvent('mouseenter', function(e)
			{
				
				showing++;
				if (showing == 1)
				{
					
					(function() {
						if (showing == 1)
						{
							if (effect_hide)
							{
								effect_hide.stop();
							}
							
							
							
							
							$('tooltip').setStyle('display', 'block');
							
							
							effect_show = new Fx.Style($('tooltip'), 'opacity', {duration: 400, onStart: function() { }});
							effect_show.start(0, 1);
							$$('#tooltip .tooltip-body p').setHTML(el.getAttribute('alt'));
							showing = 0;
						}
						}).delay(500);
				}
				
				
			
			});
			el.addEvent('mouseleave', function(e)
			{
				showing = 0;
				hide_tooltip();
				
			});
			el.addEvent('mousemove', function(e)
			{
				e = new Event(e);
				
				if (this.hasClass('left-tip')) // tooltip with left arrow
				{
					$('tooltip').setStyle('left', e.page.x+this.offsetWidth-90); // -80 - move a tooltip more to left
					$('tooltip').setStyle('top',e.page.y-30);
				}
				else // tooltip with right arrow
				{
					$('tooltip').setStyle('left', e.page.x-this.offsetWidth-60); // -70 - move a tooltip more to right
					$('tooltip').setStyle('top',e.page.y-30);
				}
			});
		});
	}
}
function common_functions()
{
	/* top menu animations */

	$$('#nav-content ul li').each(function(element)
	{
		
		var top = parseInt(element.getChildren()[0].getChildren().getStyle('margin-top'));
		if (isNaN(top))
		{
			var el = element.getChildren()[0];
			top = 3;
		}
		else
		{
			var el = element.getChildren()[0].getChildren()[0];
		}
		element.addEvent('mouseenter', function()
		{
			effect = new Fx.Style(el, 'margin-top', {duration: 1800, transition: Fx.Transitions.Elastic.easeOut});
			effect.start(top+8, top-2);
		
		});
		element.addEvent('mouseleave', function()
		{
		 try {
			effect.stop();
			el.setStyle('margin-top', top);
			}
		catch (e) {
		}
		});
	});
	/* end top menu animations */


	/* shopping cart sliding */

	/*if ($('shopping-cart') && $('wrapper-right'))
	{
	
		var topen = 0;
		var slideEffect = new Fx.Style('shopping-cart', 'margin-top', {wait:false, duration:800, transition:Fx.Transitions.circOut});
	 
		var top = $('shopping-cart').getPosition().y -10;
		window.addEvent('scroll', function(){
			if ((($('wrapper-right').offsetHeight) > $('main-content').offsetHeight))
			{
				 if (topen > window.getScrollTop() - top)
				 {
					 slideEffect.start.delay(600, slideEffect, Math.max(0, window.getScrollTop() - top));
				 }

			}
			else
			{
				slideEffect.start.delay(600, slideEffect, Math.max(0, window.getScrollTop() - top));
			}
			topen = window.getScrollTop() - top;
		});
	 
		new SmoothScroll({duration:700, transition:Fx.Transitions.circOut});
	}*/

	/* end shopping cart sliding */

/*
	$$('.checkout-dialog').each(function(el)
	{
		
		el.addEvent('click', function(e)
		{
			if (window.ie)
			{
				$$('select').each(function(select)
				{
					select.setStyle('visibility', 'hidden');
				});
			}
			var body = $$('body')[0];
			var dialog = new Element('div', {
						'id': 'dialog'
						});
						var div = new Element('div', {
						'id': 'dialog-container'

						});
			dialog_content = '<div id="dialog-content"><div id="dialog-top"></div><div id="dialog-body"><div id="dialog-text">sdsads</div><div id="dialog-checkouts"><a href="'+el.firstChild.getAttribute('href')+'" id="dialog-checkout"></a> <a href="#goback" id="dialog-goback"></a></div></div><div id="dialog-bottom"></div></div>';
			
			body.insertBefore(dialog, body.firstChild);
			
			body.insertBefore(div, body.firstChild);
			div.setHTML(dialog_content);

			dialog.setStyle('height', window.getScrollHeight());
			
			$('dialog-content').setStyle('top', (window.getHeight()/2)-100);
			$('dialog-content').setStyle('left', ((window.getWidth()-303)/2));

			$('dialog-goback').addEvent('click', function(e)
			{
				e = new Event(e);
				e.stop();
				dialog.remove();
				$('dialog-container').remove();
			});

			$('dialog-text').setText(el.firstChild.getAttribute('title'));
			if (window.ie6)
			{
				window.addEvent('scroll', function(e)
				{
					if ($('dialog-content'))
					{
						$('dialog-content').setStyle('top', (window.getScrollTop()+window.getHeight()/2)-100);
						new SmoothScroll({duration:700, transition:Fx.Transitions.circOut});
					}
					
				});
			}
			e = new Event(e);
			e.stop();
			return false;
		});
	});
*/
	/* tooltip */
    ShowCartTooltip();
	/* end tooltip */

	/* add/buy items */

	$$('.buy a').addEvent('click', function(e)
	{	
		var self = this;
		var effect = new Fx.Style(this, 'margin-top', {duration: 500, transition: Fx.Transitions.Elastic.easeOut, onComplete: function() { 	 $(self).fx = $(self).effect('opacity', {duration: 1000}).start(0); $(self).fx = $(self).getParent().getPrevious().effect('opacity', {duration: 1000}).start(1); }});
		effect.start(5, 10);
		(function() { $(self).fx = $(self).effect('opacity', {duration: 1000}).start(1); $(self).fx = $(self).getParent().getPrevious().effect('opacity', {duration: 1000}).start(0);}).delay(5000); 
		this.removeEvent('click');
		e = new Event(e);
		e.stop();
		return false;
	});

	$$('.show-details a').addEvent('click', function(e)
	{
		e = new Event(e);
		e.stop();
		show_item(this);
		return false;
	});

	
	$$('.hide-details a').addEvent('click', function(e)
	{
		e = new Event(e);
		e.stop();
		hide_item(this);
	});
	$$('.product .product-img div p a').addEvent('click', function(e)
	{
		e = new Event(e);
		e.stop();
		show_item(this);
	});
	$$('.hide-item a').addEvent('click', function(e)
	{
		e = new Event(e);
		e.stop();
		hide_item(this);
	});
	$$('.product-expand .product-expand-img a').addEvent('click', function(e)
	{
		e = new Event(e);
		e.stop();
		hide_item(this);
	});
	$$('.expand-item a').addEvent('click', function(e)
	{
		e = new Event(e);
		e.stop();
		show_item(this);
	});
	
	/* end add/buy items */

	/* edit account credit card focus */
        /*
	$$('#credit-card-container input, #credit-card-container select').each(function(element)
	{
		element.addEvent('focus', function(e)
		{
			$('credit-card-container').setStyle('border', '1px solid #FFBB51');
		});
		element.addEvent('blur', function(e)
		{
			$('credit-card-container').setStyle('border', '');
		});
		
	});
        */
	$$('.popup').each(function(element)
	{
		element.addEvent('click', function(e)
		{
			var e = new Event(e);
			e.stop();
			window.open(element.getProperty('href'),'popup', 'width=600,height=676,menubar=yes,status=yes, location=yes,toolbar=yes,scrollbars=yes');
		});
	});
	
	$$('.popup-invoice').each(function(element)
	{
		element.addEvent('click', function(e)
		{
			var e = new Event(e);
			e.stop();
			window.open(element.getProperty('href'),'popup', 'width=720,height=676,menubar=yes,status=yes, location=yes,toolbar=yes,scrollbars=yes');
		});
	});
}