$(document).ready(function(){
	removeEmptyZones();
	setContentWidth();
	setTimeout('setContentWidth();', 1000);
	$(window).resize(function(){
		setContentWidth();
		setTimeout('setContentWidth();', 1000);
	});

	init();
});

/**
 * Init user site
 */
function init()
{
	$("body").css("display", "block");
	
	// init top menu
	if (topMenu == "YES")
	{
		$("#menu ul").dropDownMenu({});
	}
	
	// initialize categories tree structure
	if (sideMenuStyle == "tree" || $(".tree").length > 0)
	{
		$(".tree").treeview({collapsed: true, animated: "medium", persist: "location"});
	}
	
	// or, alternativelly, initialize categories drop-down structure
	if (sideMenuStyle == "drop-down" || $(".drop-down-menu-vertical").length > 0)
	{
		$(".drop-down-menu-vertical").parent(".panel .content").each(function(){$(this).css("padding", "0px").css("margin", "0px");});
		$(".drop-down-menu-vertical .current").parents('li').each(function(){$(this).addClass('current');});
		$(".drop-down-menu-vertical").dropDownMenu({
			layout : 'vertical',
			onBeforeShow: function()
			{
				var w = $(this).parent().parent().width();
				$(this).css("left", w + "px").css("width", w + "px");
			}
		}); 
	}
	
	//ini cataog navigation
	if ($("body").hasClass("page-catalog"))
	{
		var currentSortItem = $("#catalog-navigation-menu-sort ul li a.current");
		if (currentSortItem.length > 0)
		{
			var a = $("#catalog-navigation-menu-sort a:first");
			$(a).html($(a).html() + ': ' + $(currentSortItem).html());
		}
		var currentViewItem = $("#catalog-navigation-menu-view ul li a.current");
		if (currentViewItem.length > 0)
		{
			var a = $("#catalog-navigation-menu-view a:first");
			$(a).html($(a).html() + ': ' + $(currentViewItem).html());
		}
		$("#catalog-navigation-menu").dropDownMenu({subMenuWidth:'100%', menuMinWidth:'100px', arrowCode:'&nbsp; &darr;'});
	}
	
	if ($(".catalog-view-flexible").length > 0)
	{
		setCatalogViewFlexible();
		setTimeout('setCatalogViewFlexible();', 500);
		$(window).resize(function(){
			setCatalogViewFlexible();
			setTimeout('setCatalogViewFlexible();', 500);
		});
	}
	
	
	
	//add product rate
	$(".product-rating-small").each(function(){
		$(this).rater({
			'curvalue': this.title,
			'style': 'small',
			'disable': true
		});
	});

	//init product tabs
	if ($("body").hasClass("page-product"))
	{
		if ($(".product-page-blocks").hasClass("product-page-blocks-tabs"))
		{
			var html = '';
			var blockCounter = 0;
			$(".product-page-blocks .product-page-block").each(function(){
				//check is there header
				if ($(this).find(".product-page-block-header").length > 0)
				{
					var blockId = $(this).attr("id") != '' ? $(this).attr("id") : 'product-page-block-' + blockCounter;
					$(this).attr("id", blockId);
					var title = $(this).find(".product-page-block-header:first").html();
					html = html + '<li><a href="#' + blockId + '">' + title + '</a></li>';
				}
				blockCounter++;
			});
			$(".product-page-blocks .product-page-block .product-page-block-header").remove();
			if (html != '') $(".product-page-blocks").prepend('<ul>' + html + '</ul>').tabs();
		}
	}

	/**
	$('object').each(function(){
		$(this).prepend('<param name="wmode" value="opaque" />');
	});
	$('embed').each(function(){
		$(this).attr('wmode', 'opaque');
		alert($(this).attr('wmode'));
	});
	**/
}