
/********************************************
 *
 * Copyright (c) 2003-2010 XML-INTL Ltd.
 *
 * All Rights Reserved
 *
 ********************************************/

var defaultSelectedModuleName = 'Workbench';

$(document).ready(function()
{
	// Make home page navigation link bold
	initializeHomePageLink();

	// Fill XTM Suite panel
	fillModulesSelect();
	
	initializeModulesSelect();
	
	initializeSelect("xtmsuiteSelect", "modules-select");

	//resizeLogo(".comment-logo");
	adjustCommentLogoPosition();
	
	BottomTextAnimator.animate();
	HeaderAnimator.start();
});

function initializeHomePageLink()
{
	$('.item_1 a').addClass('selected');//css({'color' : '#ffffff', 'font-weight' : 'bold'});
}

var BottomTextAnimator =
{
	currentIndex : 0,
	
    animate : function()
    {
    	if ($("#editModeOn").length == 0)
    	{
    		if ($("#bottom-texts tr").length > 0)
    		{
	    		$("#bottom-texts tr").hide();
	    		
	    		$("#bottom-texts tr:eq(0)").show();
	    		
	    		if ($("#bottom-texts tr").length > 1)
	    		{
	    		     //BottomTextAnimator.showNext();
	    			setTimeout('BottomTextAnimator.showNext()', 15000);
	    		}
    		}
    	}
    },
    showNext : function()
    { 
    	$("#bottom-texts tr:visible").fadeOut('slow').queue(function()
    	{
    		BottomTextAnimator.currentIndex++;
    		if ($("#bottom-texts tr").length <= BottomTextAnimator.currentIndex)
    		{
    			BottomTextAnimator.currentIndex = 0;
    		}

    		$("#bottom-texts tr:eq(" + BottomTextAnimator.currentIndex + ")").fadeIn();
    		
    		notloadedImagesList.push($("#bottom-texts tr:eq(" + BottomTextAnimator.currentIndex + ")").children(".bottom-texts-left img"));
    		
    		ImageResizer.resizeNotLoadedImages();
    		adjustCommentLogoPosition();
            $(this).dequeue();		
    	});
    	
    	setTimeout('BottomTextAnimator.showNext()', 15000);
    }	
};

function hideIE6warning()
{
	$('#ie6-warning-box').hide('slow');
}

function adjustCommentLogoPosition()
{
	$('.bottom-texts-left').each(function()
	{
		if($(this).outerHeight() - 44 >= $(this).find("img").outerHeight())
		{
			if($(this).children(".comment-logo").css('padding-top') == '0px')
			{
				var $marginTop = ($(this).outerHeight() - $(this).find("img").outerHeight() - 44)/2;//children(".comment-logo").height() - 44)/2;
				
				$(this).children(".comment-logo").css('padding-top', $marginTop+'px');
				$(this).children(".comment-logo").css('padding-bottom', $marginTop+5+'px');
			}
		}
		else
		{
			//$(this).height($(this).find("img").height() + 44);
		}
		
		var heightDifference = $(this).outerHeight() - ($(this).children(".comment-logo").outerHeight() + $(this).children(".comment-logo-top").outerHeight() + $(this).children(".comment-logo-bottom").outerHeight());
		if(heightDifference > 0)
		{
			var currentPaddingTop = parseFloat($(this).children(".comment-logo").css('padding-top'));
			var currentPaddingBottom = parseFloat($(this).children(".comment-logo").css('padding-bottom'));

			$(this).children(".comment-logo").css('padding-top', currentPaddingTop + (heightDifference*0.75) +'px');
			$(this).children(".comment-logo").css('padding-bottom', currentPaddingBottom + (heightDifference*0.25) +'px');
		}
	});
}


function initializeModulesSelect()
{
	$('#xtmsuiteSelect option').each(function(index){
			
		var currentValue = $(this).attr('value');
		
		if(currentValue.indexOf(defaultSelectedModuleName) >= 0)
		{
			try
			{
				$('#xtmsuiteSelect').val(currentValue);
			}
			catch(ex)	// Catch exception thrown by IE6
			{
				setTimeout("$('#xtmsuiteSelect').val('" + currentValue + "');",1);
			}
			
			loadModule();
			
			return false;
		}
	});
}

