﻿/**
@class A class which represents the current configuration of the application.
*/
var Configuration = {};

Configuration.GetServerPath = function()
{
	if (window.location.href.indexOf('http://localhost:8080') == 0)
	{
		return "http://localhost:8080/";
	}
	else if (window.location.href.indexOf('http://lior.gotdns.com:8080') == 0)
	{
		return "http://lior.gotdns.com:8080/";
	}
	else
	{
		return window.location.protocol + "//" + window.location.host + "/"
		//return "http://app.imcreator.com/";
	}
}

/**
 * Get the external (SEO) operational URL for the specified page.
 * e.g. http://i-m.co/user/website/mypage    or    http://www.userwebsite.com/mypage
 * Called in edit mode from ImJuicer
 */ 
Configuration.GetPageExternalUrl = function(page)
{
	var website = CurrentWebsite();
	if (website.vmDomain == website.noDomain){	
		console.log(Configuration.GetTestDriveUrlForCurrentFile()+"#"+Viewer.GetUrlSlugForPage(page));
		return Configuration.GetTestDriveUrlForCurrentFile()+"#"+Viewer.GetUrlSlugForPage(page)
	} else {
		return Configuration.GetOperationalUrlForCurrentWebsite() + '/' + Viewer.GetUrlSlugForPage(page);
	}
		

	
}

/**
 * Get the internal (hash) operational URL for the specified page.
 * e.g. http://i-m.co/user/website#mypage    or    http://www.userwebsite.com#mypage
 * Called in view mode from viewer Page Change
 */ 
Configuration.GetPageInternalUrl = function(page)
{
	return Configuration.GetWebsiteUrlInViewMode() + '#' + Viewer.GetUrlSlugForPage(page);
}

/**
 * Get the page name to display, from the path.
 * This would return 'mypage' for  http://i-m.co/user/website/mypage
 * This would return an emptry string, if there is no page or if using a hash 
 */
Configuration.GetPageNameFromPathNotHash = function()
{
	var url = window.location.href;
	
	//var url = "http://www.jeremytarian.com/collection#campaign";
		
	var slashCount = 3; // http://www.userwebsite.com/page
	if (url.indexOf('i-m.co')!=-1) slashCount = 5; //  http://www.i-m.co/user/website/page
	if (url.indexOf('?vbid=')!=-1) slashCount = 4; //  http://app.imcreator.com/view?vbid=1234/page
	var startIndex = 0;
	for (i=0; i<slashCount; i++)
	{
		var index = url.indexOf('/', startIndex)
		startIndex = index + 1;
	}
	var page = (index == -1) ? '' : url.substring(index+1);
	
	var hashPosition = page.indexOf('#');
	if (hashPosition != -1)
	{
		page = page.substring(0, hashPosition);
	}
	
	if (window.location.href.indexOf('dbg-seo=1') != -1) console.log("GetPageNameFromPathNotHash for '" + url +"' returned '" + page + "'");
	return page;	
}

/**
 * Get the test drive URL for the current website.
 */
Configuration.GetTestDriveUrlForCurrentFile = function()
{
	// Return URL on i-m.co
	var filename_friendly = $.cookie("filename");
	if (filename_friendly == null || $.trim(filename_friendly) == "")
	{
		return "http://www.imcreator.com";
	}
	filename_friendly = filename_friendly.replace(" ", "%20");
	var url = "";
	if (usernameNew != ""){
		url = "http://i-m.co/" + usernameNew + "/" + filename_friendly;
	} else {
		url = "http://i-m.co/" + username + "/" + filename_friendly;
	}
	
	return url;
}

/**
 * Get the operational URL for the current website. This is the real website domain, or the test-drive URL as a fallback.
 */
Configuration.GetOperationalUrlForCurrentWebsite = function()
{
	var website = CurrentWebsite();
	if (website.vmDomain == website.noDomain)
		return Configuration.GetTestDriveUrlForCurrentFile(); // The best "operational" URL we can get
	
	// Return URL on user's domain
	var url = "http://www." + website.vmDomain;
	return url;
}



/**
 * Get the operational URL for the current website. This is the real website domain, or the test-drive URL as a fallback.
 */
Configuration.GetWebsiteUrlInViewMode = function()
{
	var url = window.location.href;
	var slashCount = (url.indexOf('i-m.co')!=-1) ? 5 : 3;
	var startIndex = 0;
	for (i=0; i<slashCount; i++)
	{
		var index = url.indexOf('/', startIndex)
		startIndex = index + 1;
	}
	var page = (index == -1) ? '' : url.substring(0, index);
	
	console.log("------------------", page);
	return page;
}

Configuration.GetEditorPathToLoadVbid = function(vbid)
{
	return Configuration.GetServerPath() + 'edit?vbid=' + vbid;
}

Configuration.GetEditorPathToDeleteVbid = function()
{
	return Configuration.GetServerPath() + 'delete_box?vbid=' + vbid;
}

Configuration.GetDemoPathToLoadVbid = function (vbid)
{
	return Configuration.GetServerPath() + 'preview?vbid=' + vbid;
}

Configuration.GetVisualBoxUploaderPath = function()
{
	return Configuration.GetServerPath() + 'new_box';
}


Configuration.GetPublishPath = function()
{
	return Configuration.GetServerPath() + 'publish';
}

Configuration.GetPublishPartitionPath = function()
{
	return Configuration.GetServerPath() + 'new_partition';
}

Configuration.GetActivatePath = function()
{
	return Configuration.GetServerPath() + 'activate';
}

Configuration.GetLikedPath = function()
{
	return Configuration.GetServerPath() + 'liked';
}

Configuration.GetCheckLikedPath = function()
{
	return Configuration.GetServerPath() + 'check_liked';
}

Configuration.GetStaticPagePath = function()
{
	return Configuration.GetServerPath() + 'static_page';
}

Configuration.GetServeUrlPath = function()
{
	return Configuration.GetServerPath() + 'create_pic_serve';
}


Configuration.GetServeUrlUploadPath = function()
{
	return Configuration.GetServerPath() + 'create_pic_serve_upload';
}

Configuration.GetStaticImageResized = function(url, width, height)
{
	var largest = Math.ceil( Math.max(width, height) );
	if(largest > 1600){
		largest = 1590;
	}
	return url + '=s' + largest;
}


Configuration.GetDownsizeImageScriptPath = function()
{
	var server = Configuration.GetServerPath()
	if ( (window.location.href.indexOf('http://localhost:8080') == 0) || (window.location.href.indexOf('http://lior.gotdns.com:8080') == 0) )
	{ 
		server = "http://fast.im-creator.appspot.com/";
	}
	return server + 'fetch_pic';
}


Configuration.GetVisualBoxListPath = function()
{
	return Configuration.GetServerPath() + 'list_boxes_json';
}


Configuration.GetElementsListPath = function()
{
	return Configuration.GetServerPath() + 'list_elements';
}

Configuration.GetSitesByUserPath = function()
{
	return Configuration.GetServerPath() + 'list_user';
}

Configuration.GetSitesByCategoryPath = function(categoryId)
{
	return Configuration.GetServerPath() + 'list_category?cat=' + categoryId;
}

Configuration.GetSitesByCategoryTagPath = function(categoryId)
{
	return Configuration.GetServerPath() + 'list_category_tag?cat=' + categoryId;
}

Configuration.GetVisualBoxByVbidPath = function(vbid)
{
	return Configuration.GetServerPath() + 'get_box?key='+vbid;
}

Configuration.GetViewVisualBoxByVbidPath = function(vbid)
{
	return Configuration.GetServerPath() + 'view_box?key='+vbid;
}

Configuration.GetPublishedVisualBoxByVbidPath = function(vbid)
{
	return Configuration.GetServerPath() + 'get_published_box?key='+vbid;
}

Configuration.EditVisualBoxByVbidPath = function(vbid)
{
	return Configuration.GetServerPath() + 'edit_box?key='+vbid;
}


Configuration.HostImageOnAmazon = function()
{
	return true;
}

Configuration.EditorUsesStaticImages = function()
{
	return true;
}

Configuration.GetAmazonS3PictureUploaderPath = function()
{
	return 'http://imcreatorassets.s3.amazonaws.com/';
}
Configuration.GetAmazonS3PictureUrl = function(filename)
{
	return 'http://d1g45wfosh779p.cloudfront.net/' + filename;
}



Configuration.GetAmazonS3UserFilesUploaderPath = function()
{
	return 'http://imcreatoruserfiles.s3.amazonaws.com/';
}
Configuration.GetAmazonS3UserFilesUrl = function(filename)
{
	return 'http://d284f45nftegze.cloudfront.net/' + filename;
}



Configuration.GetAmazonS3MusicUploaderPath = function()
{
	return 'http://imcreatormusicfiles.s3.amazonaws.com/';
}
Configuration.GetAmazonS3MusicUrl = function(filename)
{
	return 'http://d2p7g6n46wxikk.cloudfront.net/' + filename;
}




Configuration.GetGoogleAppEnginePictureUploaderPath = function()
{
	return Configuration.GetServerPath() + 'upload_pic';
}



Configuration.GetGoogleAppEnginePictureUrl = function(pictureId)
{
	return Configuration.GetServerPath() + 'get_pic?img_id='+pictureId;
}

Configuration.GetLoginPostPath = function()
{
	return Configuration.GetServerPath() + 'login';
}


Configuration.GetRegisterPostPath = function()
{
	return Configuration.GetServerPath() + 'new_user';
}

Configuration.GetForgotPostPath = function()
{
	return Configuration.GetServerPath() + 'forgot';
}

Configuration.IsUsingPayPal = function ()
{
	return false;
}


Configuration.GetPaypalSuccessCallbackUrl = function(redirect)
{
	return Configuration.GetServerPath() + 'success';
}


Configuration.GetPaypalSuccessDomainCallbackUrl = function(redirect)
{
	return Configuration.GetServerPath() + 'success_domain';
}


Configuration.GetPaypalCancelCallbackUrl = function(redirect)
{
	return Configuration.GetServerPath() + 'cancel';
}

Configuration.GetConnectDomainPath = function()
{
	return Configuration.GetServerPath() + 'connect_domain';
}


Configuration.GetCheckDomainPath = function()
{
	return Configuration.GetServerPath() + 'check_domain';
}

Configuration.GetCheckDomainNamePath = function()
{
	return Configuration.GetServerPath() + 'check_domain_name';
}



