<!--//--><%
//=============================================================================
// Jocys.com JavaScript.NET Classes               (In C# Object Oriented Style)
// Created by Evaldas Jocys <evaldas@jocys.com>
//-----------------------------------------------------------------------------
// You can include this script on both sides - server and client:
// Server: <!-- #INCLUDE FILE="ScriptFile.js" -->
// Client: <script type="text/javascript" src="ScriptFile.js"></script>
//-----------------------------------------------------------------------------
// Warning: Be careful about what code you include in such way. Since the  code
// will be passed to the client side as simple text, your code can be  seen  by
// anyone who wants. Never do this with  scripts  which  contain  any  kind  of
// passwords, database connection strings, or SQL queries.
//=============================================================================
// Namespaces
//-----------------------------------------------------------------------------
//alert(2);
//alert(typeof(System.Type));
//debugger;

if (System.Type){
	System.Type.RegisterNamespace("Satan.EditLink");
}else{
	var Satan = Satan ? Satan : {};
	Satan.EditLink = Satan.EditLink ? Satan.EditLink : {};
}
//-----------------------------------------------------------------------------

Satan.EditLink.Menu = null;
Satan.EditLink.MenuItems = new Array();
Satan.EditLink.Anot = null;
Satan.EditLink.AnotItems = new Array();

Satan.EditLink.Player = null;
Satan.EditLink.TrackSwitcher = null;

Satan.EditLink.InitPage = function(){
    // Fill all anotations.
	//var ic = document.getElementById("ctl00_PageContentPlaceHolder_AnotationsList1_AnotationsListView_itemPlaceholderContainer");
	var ic = document.getElementById("ctl00_PageMenuPlaceHolder_AnotationsList1_AnotationsListView_itemPlaceholderContainer");
	if (ic == null) return;
	Satan.EditLink.Anot = ic;
	Satan.EditLink.Menu = document.getElementById("PageMenuDiv");
	var items = ic.childNodes;
	// Hide all items.
	var length = items.length;
	var item;
	for	(var i = 0; i < length; i++){
		item = items[i];
		// ContentsMenuItem_cbe942ad-35d6-472c-8006-06aab1f66f3f
		if (item.tagName == "DIV"){
			Satan.EditLink.AnotItems.push(item);
		}
	}
	length = Satan.EditLink.AnotItems.length
	for	(var i = 0; i < length; i++){
		item = Satan.EditLink.AnotItems[i];
		var menuId = item.id.replace("ContentsAnotItem_", "ContentsMenuItem_");
		var menuItem = document.getElementById(menuId);
		if (menuItem){
			Satan.EditLink.MenuItems.push(menuItem);
			//var me = this;
			//Sys.UI.DomEvent.addHandler(menuItem, "mouseover", function(){ Satan.EditLink.MenuItem_MouseOver(menuItem, arguments[0] || window.event); });
			//Sys.UI.DomEvent.addHandler(menuItem.parentNode, "mouseout", function(e){ Satan.EditLink.MenuItem_MouseOver(menuItem.parentNode, arguments[0] || window.event); });

			Events.Add(menuItem, "mouseover", new System.EventHandler(this, Satan.EditLink.MenuItem_MouseOver), false);
			Events.Add(menuItem.parentNode, "mouseout", new System.EventHandler(this, Satan.EditLink.MenuItem_MouseOut), false);
		}
		
		//var e = arguments[0] || window.event;
		//var sender = e.target || e.srcElement;

		
		//item.style.display = "none";
		//alert(Satan.EditLink.MenuItems.length);
	}
	Satan.EditLink.SetAnotationsPosition();
	// Setup background audio.
	var track = document.getElementById("CategoryMenuAudioBackgroundInput").value;
	if (track.length > 0){
		var player = document.getElementById("BgAudioPlayerWmpObject");
		var pType = System.Audio.PlayerType.WMP;
		if (player == null){
			player = document.getElementById("BgAudioPlayerObject");
			pType = System.Audio.PlayerType.XSPF;
		}
		if (player != null){
			Satan.EditLink.Player = new System.Audio.Player(System.Audio.PlayerType.WMP, player.id);
			Satan.EditLink.TrackSwitcher = new System.Audio.TrackSwitcher(Satan.EditLink.Player);
			Satan.EditLink.TrackSwitcher.VolumeMaxDefault = 100;
			Satan.EditLink.TrackSwitcher.VolumeStepIncrease = 1;
			Satan.EditLink.TrackSwitcher.VolumeStepDecrease = 2;
			Satan.EditLink.TrackSwitcher.currentDelay = 500;
			Satan.EditLink.TrackSwitcher.RescheduleWhenVolumeZero = false;
			Satan.EditLink.TrackSwitcher.SheduleTrackChange({title: track, href: track}, false);
			//Satan.EditLink.Player.ChangeTrack("/Main/Audios/MID/candy.mid");
		}
	}
}

Satan.EditLink.AnotItemPrevious = null;
Satan.EditLink.AnotItemCurrent = null;
Satan.EditLink.AnotItemRequest = null;
Satan.EditLink.AnotMenuTimerId = 0;

Satan.EditLink.MenuItem_MouseOver = function(sender, e){
	var tr = System.Web.UI.HtmlControls.FindParentElement(sender, "TR")
	var anotId = tr.id.replace("ContentsMenuItem_", "ContentsAnotItem_");
	var aItem = document.getElementById(anotId);
	if (aItem != Satan.EditLink.AnotItemPrevious){
		Satan.EditLink.StartAnotTimeout(aItem);
	}
}

Satan.EditLink.MenuItem_MouseOut = function(sender, e){
	Satan.EditLink.StopAnotTimeout();
	Satan.EditLink.StartAnotTimeout(null);
}

Satan.EditLink.StopAnotTimeout = function(){
	if (Satan.EditLink.AnotMenuTimerId > 0) window.clearTimeout(Satan.EditLink.AnotMenuTimerId);
}

Satan.EditLink.StartAnotTimeout = function(aItem){
	Satan.EditLink.StopAnotTimeout();
	var span = 200;
	Satan.EditLink.AnotMenuTimerId = window.setTimeout(function(){
		if (Satan.EditLink.AnotItemPrevious) Satan.EditLink.AnotItemPrevious.style.display = "none";
		if (aItem){
			aItem.style.display = "";
			// increase sound here.
			if (Satan.EditLink.TrackSwitcher) Satan.EditLink.TrackSwitcher.IncreaseSound();
		}else{
			// decrease sound here.
			if (Satan.EditLink.TrackSwitcher) Satan.EditLink.TrackSwitcher.DecreaseSound();
		}
		Satan.EditLink.AnotItemPrevious = aItem;
	}, span);
}

Satan.EditLink.SetAnotationsPosition = function(){
	var m = Satan.EditLink.Menu;
	var a = Satan.EditLink.AnotItems;
	var addSpace = -11;
	var addWidth = 0;
	var t = m.offsetTop;
	var l = m.offsetLeft;
	var w = m.offsetWidth;
	// minus padding and borders
	var h = m.offsetHeight - 20 -2;
	//alert(t+" "+l+" "+w+" "+h);
	// Position of anotations background.
//	divAnotationsBack.style.width = w + addWidth;
//	divAnotationsBack.style.height = h;
//	divAnotationsBack.style.top = t;
//	divAnotationsBack.style.left = l - w - addSpace - addWidth;
//	// Position of anotations shadow.
//	divAnotationsShadow.style.width = w + addWidth;
//	divAnotationsShadow.style.height = h ;
//	divAnotationsShadow.style.top = t;
//	divAnotationsShadow.style.left = l - w - addSpace - addWidth;
	// Position of all anotations.
	for (var i = 0; i < a.length; i++){
		var item = a[i];
		item.style.display = "none";
		item.style.top = (t)+"px";
		item.style.left = (l + w + addSpace)+"px";
		item.style.width = (w + addWidth)+"px";
		item.style.height = h+"px";
	}
 }

//==============================================================================
// END
//------------------------------------------------------------------------------
//%>
