	var args = []; 
	var personalizationProperties;
	var cUpdateIntervalSec = 10;
	var secondsPerDay = 86400;
	var secondsPerHour = 3600;
	var secondsPerMinute = 60;
	var lastTabClicked = "";

 	function processAudienceManagerProfile(profile) { $(window).trigger('generateMBoxes', profile); }
		
	$(document).bind( 'touchmove', function(e) { e.preventDefault(); } );
	
	function jsonDataReceiver(jsonData)
	{
		if(jsonData != undefined && jsonData != "" && jsonData != null)
		{
			personalizationProperties = JSON.parse(jsonData);
		}
		else
		{
            alert( "AdobeHello: Unable to get data from host application" );
		}
						
		loadDefaultLanguage();							
	}	
	
    $(document).ready(function ()
     {
		onLoaded();
		
		// create the hello control object
		if (!window.__adobe_hello) {
			// we pass in the CSXS ID here because we are not running in CEP mode
			window.__adobe_hello = new AdobeHello('DRWV');
		}

		// get the hello product interface
		var productInterface = window.__adobe_hello.getProductInterface();

		if (!productInterface) {
			alert("AdobeHello: product interface is not initialized");
			return;
		}
		
		productInterface.getUserJsonData(jsonDataReceiver);

	});	
	
	function loadDefaultLanguage()
	{
		LangStringSet = personalizationProperties["language"];
		if(LangStringSet.length == 0) LangStringSet = "en_US";
		
		$.get("language/"+LangStringSet+".xml", {}, function(xml) {		
			var visitCounter = "";
			$(xml).find("string").each(function()
			  {									

				if($(this).attr("counter") == "true")
				{visitCounter += $(this).attr("name")+'Counter,'+$(this).attr("name")+'LUpdate,';}
				
				if($(this).attr("align")=="left")
				{
					if(personalizationProperties["accountType"]=="trial" && $(this).attr("name") == "specialoffer")
					{
						$(".shell_nav ul").append('<li name="'+$(this).attr("name")+'" data-url="'+$(this).attr("data-url")+'" counter="'+$(this).attr("counter")+'"><span id="tDaysLeft"></span>'+$(this).text()+'</li>');	
						loadTrialDaysRemaining();					
					}				
					else if($(this).attr("name") != "specialoffer") 
					{
						$(".shell_nav ul").append('<li name="'+$(this).attr("name")+'" data-url="'+$(this).attr("data-url")+'" counter="'+$(this).attr("counter")+'">'+$(this).text()+'</li>');
					}					
				}
				else if($(this).attr("align")=="right")
				{
					if(personalizationProperties["accountType"]=="trial" && $(this).attr("name") == "specialoffer")
					{
						$(".shell_nav ul").append('<li name="'+$(this).attr("name")+'" style="float:right;" data-url="'+$(this).attr("data-url")+'" counter="'+$(this).attr("counter")+'"><span id="tDaysLeft"></span> '+$(this).text()+'</li>');
						loadTrialDaysRemaining();
					}				
					else if($(this).attr("name") != "specialoffer") 
					{
						$(".shell_nav ul").append('<li name="'+$(this).attr("name")+'" style="float:right;" data-url="'+$(this).attr("data-url")+'" counter="'+$(this).attr("counter")+'">'+$(this).text()+'</li>');
					}
				}	
								
			  });
				
			$('.shell_nav ul li').on('click', function(){
				var liName	= $(this).attr('name');	
				$("body").removeAttr( "style" );							
				$(this).addClass('active').siblings().removeClass('active');		
				$('#shell_wrapper').stop().fadeOut(300, function() {
					loadContentPages(liName);				
				});
			});			

			if(checkCookie('lastTabClicked') != 1)
			{
				$(".shell_nav ul li[name=create]").trigger( "click" );
			}
			else
			{	
				lastTabClickedCookie = getCookie('lastTabClicked').split("=");
				lastTabClicked = lastTabClickedCookie[1];
				
				if(lastTabClicked == "" || lastTabClicked == undefined || lastTabClicked == "none")
				{
					$(".shell_nav ul li[name=create]").trigger( "click" );
				}
				else 
				{

					$(".shell_nav ul li[name="+lastTabClicked+"]").trigger( "click" );
				}	
			}
											
			
		}, "xml");
	}
	
	
	function loadContentPages(liName)
	{
		$("#shell_content" ).load($(".shell_nav ul li[name="+liName+"]").attr('data-url'), function() {
			setCookie('lastTabClicked',liName,365);
			$('#shell_wrapper').fadeIn(300);	
            if(liName.indexOf("create")!=-1){LoadCreateContent();}
			else{
				if(personalizationProperties["lastError"] != undefined && personalizationProperties["lastError"] != "" && personalizationProperties["lastError"] != null)
				{$(".offline_error_title").html(personalizationProperties["lastError"]);}
				else
				{$(".offline_error_title").html("Internet Connection Was Lost");}								
			}
		});
	}
			
	function LoadCreateContent()
    {
        var productInterface = window.__adobe_hello.getProductInterface();
		var recentFiles      = parent.personalizationProperties["recentFiles"];

		if(recentFiles.length == undefined || recentFiles.length == null || recentFiles.length == "" || recentFiles.length < 2)
		{
            var createTabBackgroundImage = productInterface.ui.create.initialImage;
            var createTabBackgroundColor = productInterface.ui.create.backgroundColor;

			$(".create_base_wrapper").css("display","none");
			$("body").attr("style", "background:url('"+createTabBackgroundImage+"') no-repeat;background-position:0px 45px;background-color:"+createTabBackgroundColor+";");
			$(".create_base_wrapper_new").removeAttr( "style" );	
		}
		else
		{
			$(".create_base_wrapper_new").css("display","none");
			$(".create_base_wrapper").removeAttr( "style" );	
			$("body").removeAttr( "style" );	
	
			var newDocTypes = parent.personalizationProperties["newDocTypes"];		
							
			for ( i=0;i<newDocTypes.length;i++)
            {
				var docType     = newDocTypes[i]["docType"];
				var docTypeName =  newDocTypes[i]["name"];
                var docTypeTip  =  newDocTypes[i]["tip"];
				$("#createNewContainer").append( '<a class="new_site_button" title="'+docTypeTip+'" onClick="processNewDocClick(event,\'' + docType + '\')"><img src="images/' + newDocTypes[i]["icon"] + '.png"/><p> ' + docTypeName + '</p></a>');
				
			}	

            /**
             * Ellipsis a text string in the middle based on a certain pixel width.
             *
             * @param str               string object to ellipsize
             * @param maxPxWidth        width to clip the string to in pixel units
             * @return A string object containing the ellipsized string.
             */
            var middleEllipsis = function( str, maxPxWidth )
            {
                var ellipsisStr = "";

                if ((typeof str !== "undefined" && typeof maxPxWidth !== "undefined")
                    && (( str.length > 1 ) && ( maxPxWidth > 0 )))
                {
                    /**
                     * Determine the pixel width of a string object on the current page.  This
                     * method requires the 'pxtextruler' tag object in the page to be setup
                     * with the proper font face and point size before the results will be
                     * accurate.
                     *
                     * @param str               string object to measure width in pixel units
                     * @return Integer value indicatating the width of the string in pixel units.
                     */
                    var strPixelLength = function( str )
                    {
                        var ruler = document.getElementById("pxtextruler");

                        if ( (typeof ruler === "undefined") || (typeof str === "undefined") ) { return 0; }

                        ruler.innerHTML = str;

                        return ruler.offsetWidth;
                    }
                    var pxWidth  = strPixelLength( str );
                    ellipsisStr  = str;

                    if ( pxWidth > maxPxWidth )
                    {
                        var middle      = Math.ceil( ellipsisStr.length / 2 );
                        var remainder   = ellipsisStr.length - middle;
                        var subLeft     = ellipsisStr.substring( 0, remainder );
                        var subRight    = ellipsisStr.substring( middle );

                        for ( var i = 0; i < remainder; i++ )
                        {
                            ellipsisStr = subLeft + "..." + subRight;
                            pxWidth     = strPixelLength( ellipsisStr );

                            if ( pxWidth > maxPxWidth )
                            {
                                subLeft  = subLeft.substring( 0, subLeft.length - 1 );
                                subRight = subRight.substring( 1 );
                            }
                            else { break; }
                        }

                    }
                }
                return ellipsisStr;
            }

            var containerWidth = $("#openRecentContainer").width() - 20; // magic cookie 15px is the width of the icon + 5 for padding (eyeballing)

			for ( j=0;j<recentFiles.length;j++)
            {
				var fileName =  middleEllipsis(recentFiles[j]["name"], containerWidth);
				var fileTip  =  recentFiles[j]["tip"];

                var element = $('<a class="new_site_button" title="'+fileTip+"bbb"+'" onClick="processRecentDocClick(event,' + j + ')"><img src="images/' + recentFiles[j]["icon"] + '.png" /><p>' + fileName + '</p></a>');
				$("#openRecentContainer").append( element );
			}

			var templateTypes = parent.personalizationProperties["templateTypes"];

            containerWidth = $("#starterTemplateContainer").width() - 20; // magic cookie 15px is the width of the icon + 5 for padding (eyeballing)
			for ( k=0;k<templateTypes.length;k++)
            {
				var templateType     = templateTypes[k]["docType"];
				var templateTypeName = middleEllipsis(templateTypes[k]["name"], containerWidth);
                var templateTypeTip  = templateTypes[k]["tip"];

				$("#starterTemplateContainer").append( '<a class="new_site_button" title="'+templateTypeTip+'" onClick="processNewDocClick(event,\'' + templateType + '\')"><img src="images/' + templateTypes[k]["icon"] + '.png"/><p> ' + templateTypeName + '</p></a>');

			}
		}
        
		setTimeout($('#shell_wrapper').fadeIn(300),9000);
		
		loadOffineFooter("create");
				
	}
		 
		
	function processNewDocClick( e, docType ) {		
		var doSuppressUI = e.altKey;
		window.projectHello.hostAppCreateNewDoc( docType, doSuppressUI );
	}
	
	
	function processRecentDocClick( e, docPath ) {
		window.projectHello.hostAppOpenDoc( docPath );
	}

	function handleNewDocumentClick( e )
	{
        var doSuppressUI = e.altKey;
		var newDocTypes  = parent.personalizationProperties["newDocTypes"];
		var docType      = newDocTypes[0]["docType"];
        
		window.projectHello.hostAppCreateNewDoc( docType, doSuppressUI );
	}	

	function loadTrialDaysRemaining() {
				
		var secondsPerDay = 86400;
		var appTrialTime = 0;
		var appStartTime = 0;
		var sysCurrentTime = parseInt((new Date()).getTime()/1000);
		var elapsedTime = 0;
		var remainingTime = 0;
		var remainingDays = 0;
		
		appTrialTime = parseInt(personalizationProperties["secondsLeftInTrial"]);		
		appStartTime = parseInt(personalizationProperties["appStartClockTime"]);
		elapsedTime = parseInt((sysCurrentTime - appStartTime));
		remainingTime = parseInt(appTrialTime - elapsedTime);		
		
		if ( remainingTime < 0 ) remainingTime = 0;		
		remainingDays = Math.round(remainingTime / secondsPerDay);		
		$('#tDaysLeft').html(remainingDays)
	}
	
	function setCookie(cname,cvalue,exdays)
	{
		var d = new Date();
		d.setTime(d.getTime()+(exdays*24*60*60*1000));
		var expires = "expires="+d.toGMTString();
		document.cookie = cname + "=" + cvalue + "; " + expires;
	}
	
	function getCookie(cname)
	{
		var name = cname + "=";
		var ca = document.cookie.split(';');
		for(var i=0; i<ca.length; i++)
		{
			var c = ca[i].trim();
			if (c.indexOf(name)==0) return c;
		}
		return "";
	}
	
	function checkCookie(cname)
	{
		var coname = getCookie(cname);
		if (coname!="" && coname!=null && coname!=undefined)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
