$(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");
	
	// initialize categories tree structure
	if ($(".tree").length > 0)
	{
		$(".tree").treeview({
			collapsed: true,
			animated: "medium",
			persist: "location"
		});
	}

	//init product tabs
	if ($("body").hasClass("page-product"))
	{
		if ($(".product-page-blocks").hasClass("product-page-blocks-tabs"))
		{
			var html = '<ul>';
			var blockCounter = 0;
			var checkRefresh = false;
			$(".product-page-blocks .product-page-block").each(function(){
				//check is there header
				if ($(this).find(".product-page-block-header").length > 0)
				{
					//check is block already transformed
					if ($(".product-page-blocks ul li a[href='#product-page-block-" + blockCounter + "']").length > 0)
					{
						$(".product-page-blocks ul li a[href='#product-page-block-" + blockCounter + "']").html(
							$(this).find(".product-page-block-header:first").html()	
						); 
						checkRefresh = true;
					}
					else
					{
						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++;
			});
			html = html + '</ul>';
			$(".product-page-blocks .product-page-block .product-page-block-header").remove();
			if (html != '<ul></ul>') $(".product-page-blocks").prepend(html).tabs();
			
			if (checkRefresh)
			{
				if (confirm("Some of changes you just made require page refresh.\nDo you want to do it now?"))
				{
					document.location.reload();
				}
			}
		}
	}

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