
$(document).ready(

	function() {
		
        var _f = true;
        
        var debug = "";
        
        $('#navbar ul#procat-0 ul').each(
        	function() {
        		if( !$(this).parent().hasClass('active') )
            		$(this).hide();
        	}
        );

        $('#navbar li').click(
			function(e)
			{
				if( e.pageX - $(this).offset().left > $(this).width() - 40 )
				{
					if( _f ) {
						_f = false;
						if( !$(this).is('.active') ) {
							resetNodes($(this));
							$(this).addClass('active');
							$(this).children('ul').slideDown(400);
						}
						else {
							resetNodes($(this));
							$(this).removeClass('active');
							$(this).children('ul').slideUp(400);
						}
						setTimeout(function(){_f = true;}, 400);
					}
					return false;
				}
			}
		);
		
        function resetNodes(_this) {
            $(_this).parent().find('li').each(function(){
                if(this != _this){
                    $(this).removeClass('active');
                    $(this).find('ul').slideUp(400);
                }
            });
        }
        
        
	}
);


function WBM_displayProductGallery(_cid)
{
	$('#product-gallery li').removeClass('active')
	
	$.get('../includes/product_action.php', {action: 'display_product_gallery', cid: _cid},
		function(html) {
			$("#product-gallery").html(html);
		}
	);
}

function WBM_displayProductDetails(_pid, _index)
{
	$('#product-gallery li').removeClass('active')
	$('#product-gallery li').eq(_index).addClass('active');
	
	$.get('../includes/product_action.php', {action: 'display_product_details', pid: _pid},
		function( html ) {
			$("#product-details").html(html);
			$("a.fancy-thumb").fancybox();
		}
	);
}

function WBM_displayPressArticleGallery()
{
	$('#press-article-gallery li').removeClass('active')
	
	$.get('../includes/press_article_action.php', {action: 'display_press_article_gallery'},
		function(html) {
			$("#press-article-gallery").html(html);
		}
	);
}

function WBM_displayPressArticleDetails(_aid, _index)
{
	$('#press-article-gallery li').removeClass('active')
	$('#press-article-gallery li').eq(_index).addClass('active');
	
	$.get('../includes/press_article_action.php', {action: 'display_press_article_details', aid: _aid},
		function( html ) {
			$("#press-article-details").html(html);
			$("a.fancy-thumb").fancybox();
		}
	);

}

var moveupvar = null;
var movedownvar = null;
var WBM_scroller = 
{	
	moveup: function(_id)
	{
		var _speed = 5;
		var _content = "scroller-content" + (_id ? "-" + _id : "");
		
		if(document.getElementById(_content))
		{
			var _obj = document.getElementById(_content);
		}
		
		if(_obj)
		{
			if(parseInt(_obj.style.top) <= 0)
			{
				_obj.style.top = (parseInt(_obj.style.top) + _speed) + "px";
			}
			moveupvar = setTimeout("WBM_scroller.moveup()", 50);
		}
	},
	
	movedown: function(_id)
	{
		var _speed = 5;
		var _content = "scroller-content" + (_id ? "-" + _id : "");
		
		if(document.getElementById(_content))
		{
			var _obj = document.getElementById(_content);
		}
		
		if(_obj)
		{
			var contentHeight = _obj.offsetHeight;
			
			if(parseInt(_obj.style.top) >= (contentHeight * (-1) + 411))
			{
				_obj.style.top = (parseInt(_obj.style.top) - _speed) + "px";
			}
			movedownvar = setTimeout("WBM_scroller.movedown()", 50);
		}
	}, 
	
	reset: function(_type)
	{
		if(_type == "up")
		{
			clearTimeout(moveupvar);
		}
		if(_type == "down")
		{
			clearTimeout(movedownvar);
		}
	}
}
