var MainJS = 
{
	FixHeightElements : new Array(),
	
	SetTwoColumnLayout : false,
	
	AddFixHeightElement : function(id)
	{
		this.FixHeightElements[this.FixHeightElements.length] = id;
	},
	
	FixHeights : function()
	{
		var iLoop;
		for(iLoop = 0; iLoop < this.FixHeightElements.length; iLoop++)
		{
			//alert($("#" + this.FixHeightElements[iLoop]).height() + " - " + $("#" + this.FixHeightElements[iLoop]).parent().height());
			$("#" + this.FixHeightElements[iLoop]).height($("#" + this.FixHeightElements[iLoop]).parent().height());
		}
	},
	
	Tab_Click : function(TabID, TabCount, Prefix_Tab)
	{
        var i = 0;
        for (i = 1; i <= TabCount; i++)
        {
            document.getElementById(Prefix_Tab + i + '_Details').style.display = "none";
            document.getElementById('TabLink_' + i).className = "";
        }
        document.getElementById(Prefix_Tab + TabID + "_Details").style.display = "block";
		document.getElementById('TabLink_' + TabID).className = "Hover";
	},

	IndexSlideShow : function()
	{
		jQuery(function($) {
			
			$('.IndexGallery_unstyled').addClass('IndexGallery'); // adds new class name to maintain degradability
			
			$('ul.IndexGallery').galleria({
				history   : false, // activates the history object for bookmarking, back-button etc.
				clickNext : false, // helper for making the image clickable
				insert    : '#main_image', // the containing selector for our main image
				onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
					
					// fade in the image & caption
					if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
						image.css('display','none').fadeIn(1000);
					}
					caption.css('display','none').fadeIn(1000);
					
					// fetch the thumbnail container
					var _li = thumb.parents('li');
					
					// fade out inactive thumbnail
					_li.siblings().children('img.selected').fadeTo(500,1);
					_li.siblings().children('img.selected').parents('li').css("top", "auto");
					
					// fade in active thumbnail
					thumb.fadeTo('fast',1).addClass('selected');
					thumb.parents('li').css("top", "-4px");
					// add a title for the clickable image
					//image.attr('title','Next image >>');
					var arrDetails = thumb.attr("id").split("_");
					var pID = arrDetails[1];
					if (arrDetails[2] == "G")
					{
						image.click(function(){window.location="/portal/boxx/modules/gadgets/gadget.asp?GadgetID=" + pID;});
					}
					else
					{
						image.click(function(){window.location="/portal/boxx/modules/resources/resource-main.asp?ResourceID=" + pID;});
					}
					image.css('cursor', 'pointer');
				},
				onThumb : function(thumb) { // thumbnail effects goes here
					
					// fetch the thumbnail container
					var _li = thumb.parents('li');
					
					// if thumbnail is active, fade all the way.
					var _fadeTo = _li.is('.active') ? '1' : '1';
					
					// fade in the thumbnail when finnished loading
					thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
					
					// hover effects
					thumb.hover(
						function() { $.galleria.activate(thumb.attr('rel')); },
						function() { thumb.fadeTo('fast',1); },
						function() { _li.not('.active').children('img').fadeTo('fast',1); } // don't fade out if the parent is active
					)
				}
			});
		});
	},
	
	ToggleElements : function(sCurrent, sNew)
	{
		$('#' + sCurrent).hide();
		$('#' + sNew).fadeIn(500);
	},
		
	Do_SetTwoColumnLayout : function()
	{
		$("#TableRight").hide();
		$("#TableRight").parent().width(0);
		//$("#TableCenter").width($("#TableCenter").width() + $("#TableRight").width());
	},
	
	init : function()
	{
		MainJS.AddFixHeightElement("TableLeft");
		MainJS.AddFixHeightElement("TableCenter");
		MainJS.AddFixHeightElement("TableRight");
		MainJS.FixHeights();
		MainJS.IndexSlideShow();
if(this.SetTwoColumnLayout == true)
		{
			MainJS.Do_SetTwoColumnLayout();
		}
	},
	
	ArchivesByDate_Toggle : function()
		{
			var obj = document.getElementById("DivArchivesByDate");
			if(obj != null)
			{
				if(obj.style.display == "none")
				{
					obj.style.display = "block";
				}
				else
				{
					obj.style.display = "none";
				}
			}
		}

}