/* 
function historyChange(newLocation, historyData) 
{
	if (historyData)
	{
		Navigate.geth(historyData, true);
	}
	else
	{
		//(location.href, true);
		location.href = location.href;
	}
}
	
function historyInit()
{
//	window.historyStorage.init();
//	window.dhtmlHistory.create();
	// -
	dhtmlHistory.initialize();
	dhtmlHistory.addListener(historyChange);

}
*/
var img = new Image();
img.src="/shop/skins/skin_7/i/shtora_full.jpg";
function historyCall(hash, sl) 
{
//	if(hash=="")
//		hash = "index";

	if(hash) 
	{
		// restore ajax loaded state
		if (!sl) 
		{
			if (hash == 'fc')
			{
				hash = $.cookie('last_url');
			}

			hash = hash.replace(/\:\:\:/gi, '=');
			hash = hash.replace(/\:\:/gi, '?');
			hash = hash.replace(/\:/gi, '/');

			Navigate.geth(hash, true);
		}

	} else 
	{
		// start page
		location.reload();
	}
}

var Navigate = {
	url : null,
	html:null,
	blocked: false,
	html:"",
	cache : [],
	
	geth : function(url, noHistory)
	{
		if(Shtora.done==0)
			return;
		this.url		= url;
		this.html	= null;
		if(Navigate.blocked)
			return;
		Navigate.blocked = true;
		Navigate.loadHtml(url, noHistory);
	},
	
	loadHtml : function(url, noHistory)
	{
		Shtora.show();
		Navigate.html="";
		if (!noHistory) this.historyAdd(url);

		var url = url;
		$.ajax({
			url: "/shop/"+url,
			cache: false,
			dataType: "text",
			success: function(html){
				Navigate.html = html;
				if(Shtora.done == 1)
				{
					$("#shtorkaCont").animate({top:"900px"}, 1000, function()
						{
							$("#shtorka").hide();
							Shtora.done=1;
						}
					);
					Navigate._refresh(Navigate.html);
					Shtora.hide();
				}
			}
		});
	},

	_refresh : function(html)
	{
		/*
		var reg = new RegExp("AddToCartForm_[\\w]+_[\\w]+_Validator", "gi");
		html = html.replace(reg, '');
		*/

		$("#__content").html(html);
		$('#scrollPane').jScrollPane({showArrows:true});
		Navigate.blocked = false;
	},

	goCustom : function(url)
	{
		if(Navigate.blocked)
			return;
		if(typeof(url) == "undefined")
			return;
		switch(url)
		{
			case "link1":
				// Menu.render(4);
				this.geth("x-entity.choco.boxes.aspx?CategoryID=87");
				break;
			case "link2":
				this.geth("x-entity.choco.boxes.aspx?CategoryID=87");
//				this.geth("x-choco.content.aspx?Topic=ChocolateHistory");
				break;
			case "link3":
				// Menu.render(3);
				this.geth("x-entity.choco.grid.aspx?CategoryID=98");
				break;
			case "link4":
				this.geth("x-entity.choco.grid.aspx?CategoryID=98");
//				this.geth("x-choco.content.aspx?Topic=ChocolateTypes");
				break;
//			case "x-entity.choco.boxes.aspx?CategoryID=87":
//				Sweets.init();
//				break;
		}
		Navigate.blocked = false;
	},

	historyAdd : function(url)
	{
		// dhtmlHistory.add('h' + Math.round(Math.random()*1000), url);

		url = url.replace(/\//gi, ':');
		url = url.replace(/\?/gi, '::');
		url = url.replace(/\=/gi, ':::');

		if (url != 'fc')
		{
			$.cookie('last_url', url, {path: '/'});
		}			
		
		$.historyLoad(url, true);
	}

};

var Shtora = {
	height:0,
	count:0,
	done:1,
	filled:0,

	show : function(withoutContent)
	{
		Shtora.withoutContent = withoutContent==true;
		Shtora.done=0;
		var cnt = 16;
		Shtora.filled=0;
		$("#shtorkaCont").html("");
		$("#shtorkaCont").css({top:0})
		$("#shtorka").show();
		for(var i=0;i<cnt;i++)
		{
			setTimeout("Shtora.insertItem()", 100*i+50);
		}
		setTimeout("Shtora.hide()", 100*i+500);
	},

	insertItem : function()
	{
		$("#shtorkaCont").createAppend(
			'img', {width:952,height:57,src:"/shop/skins/skin_7/i/shtora_full.jpg"}
			);
	},

	hide : function()
	{
		Shtora.done=1;
		if(Navigate.html != "" || Shtora.withoutContent)
		{
			$("#shtorkaCont").animate({top:"900px"}, 1000, function()
				{
					$("#shtorka").hide();
					Shtora.done=1;
				}
			);
			Navigate._refresh(Navigate.html);
			Navigate.goCustom();
		}
	}
}

function rollflash (id)
{
	try
	{
		document.getElementById(id).rolldown();
		setTimeout("document.getElementById('"+id+"').rollup();", 400);
	}
	catch(e)
	{

	}
}