function topOfElement(elementId)
{
    var obj = document.getElementById(elementId);
    if (!obj)
	{
		return 0;
	}
	var offset =0;
    while (obj.offsetParent)
    {
        offset+= obj.offsetTop;
        obj = obj.offsetParent;
    }

    return (offset);
}

var BlogDisplay = {
    "ScrollToArchives" : function BlogDisplay_ScrollToArchives()
    {
        scrollTo(0, topOfElement('archivesTop') - 10);
    },
    "toggleArchive" : function toggleArchive(premiumBlogID, year, month)
    {
        var id;
		var imageId;
        if (!!month)
        {
            id = year + '_' + month + '_postList';
			imageId = year+'_' +month+'_imageTag';
        }
        else
        {
            id = year + '_postList';
			imageId = year+'_imageTag';
        }
        var ele = document.getElementById(id);
        if (!!ele)
        {
            if (ele.style.display == 'none')
            {
			    var image = document.getElementById(imageId);
                if (!!month && ele.innerHTML === '')
                {
			        var params = {};
			        params['pblogid'] = premiumBlogID;
			        params['year'] = year;
			        params['month'] = month;
    			    
                    new Ajax.Updater(id, 'ArchiveBlogListHandler.ashx',
                        {
                            "method" : "post",
                            "parameters" : params,
                            "onSuccess" : function(){ele.style.display = 'block'; image.className="icon_arrow_blue_down";}
                        });
                }
                else
                {
                    ele.style.display = 'block';
					if (image)
					{
						image.className="icon_arrow_blue_down";
					}
                }
            }
            else
            {
                ele.style.display = 'none';
				var image = document.getElementById(imageId);
				if (image)
				{
					image.className="icon_arrow_blue_up";
				}
            }
        }
    },
	"scrollToPreview" : function scrollToPreview(element)
	{
		window.scrollTo(0,topOfElement(element));
	},
	"scrollToMogu" : function()
	{
		if (typeof isPOPopped != "undefined" && !!isPOPopped)
		{
			AnimObject.startAnim();
		}
		else
		{
			window.scrollTo(0,topOfElement('PurchasingOpportunity'));
		}
	},
	"GoToSA" : function GoToSA(url)
	{
		window.location = url;
		parent.browser.bringToFocus();
	},
	"CloseBlog" : function BlogDisplay_CloseBlog()
	{
		if(window == window.top)
		{
			window.location = "http://www.fanbox.com/socnet/Desktop.aspx?skipSplash=1&opg=http%3A%2F%2Fprofile.fanbox.com%2FPremiumBlogs%2FAPB_SA.aspx";
		}
		else
		{
			var windowID = BlogDisplay.GetCurrentWindowID();
			if(!(isNaN(windowID)))
			{
				window.parent.WindowManager.GetWindowByWindowID(windowID).Close();
			}
			else
			{
				var problem = new Error();
				problem.message = "The window cannot be closed because the window ID is absent.";
				throw problem;
			}
		}
	},
	"GetCurrentWindowID" : function BlogDisplay_GetCurrentWindowID()
	{
		var windowName = window.name;
		var windowIndex = windowName.indexOf("frm");
		if(windowIndex !== -1)
		{
			return parseInt(windowName.substr(windowIndex + 3), 10);
		}
		else
		{
			return NaN;
		}
	},
	"UpdateDesktopWindowTitleBar" : function BlogDisplay_UpdateDesktopWindowTitleBar(title)
	{
		if(window != window.top)
		{
			var windowID = BlogDisplay.GetCurrentWindowID();
			if(!(isNaN(windowID)))
			{
				window.parent.WindowManager.GetWindowByWindowID(windowID).SetTitle(title);
			}
			else
			{
				var problem = new Error();
				problem.message = "The window title cannot be changed because the window ID is absent.";
				throw problem;
			}
		}
	},
	"ShowPosts" : function BlogDisplay_ShowPosts()
	{
		window.document.getElementById("BlogPostsSection").style.display = "block";
		window.document.getElementById("ShopperBlogPreviewShowSection").style.display = "none";
		window.document.getElementById("ShopperBlogPreviewHideSection").style.display = "block";
		window.document.getElementById("showPreview").style.display = "none";
		window.document.getElementById("hidePreview").style.display = "block";
		window.document.getElementById("BlogTagSection").style.display = "block";
		window.document.getElementById("ArchiveContainer").style.display = "block";
		window.document.getElementById("BlogPostsVisibleLandmark").nextSibling.checked = true;
		return false;
	},
	"HidePosts" : function BlogDisplay_HidePosts()
	{
		window.document.getElementById("BlogPostsSection").style.display = "none";
		window.document.getElementById("ShopperBlogPreviewShowSection").style.display = "block";
		window.document.getElementById("ShopperBlogPreviewHideSection").style.display = "none";
		window.document.getElementById("showPreview").style.display = "block";
		window.document.getElementById("hidePreview").style.display = "none";
		window.document.getElementById("BlogTagSection").style.display = "none";
		window.document.getElementById("ArchiveContainer").style.display = "none";
		window.document.getElementById("BlogPostsVisibleLandmark").nextSibling.checked = false;
		return false;
	},
	"ShowRatingDiv" : function BlogDisplay_ShowRatingDiv()
	{
		var currentRating = parseInt(window.document.getElementById("ParticipantBlogPersonalRatingCurrentScore").value, 10);
		if(currentRating === 0)
		{
			window.document.getElementById("ParticipantBlogPersonalRatingNewIntroduction").style.display = "block";
			window.document.getElementById("ParticipantPersonalBlogRatingNewLabel").style.display = "inline";
			window.document.getElementById("ParticipantBlogPersonalRatingExistingIntroduction").style.display = "none";
			window.document.getElementById("ParticipantBlogPersonalRatingExistingInstruction").style.visibility = "hidden";
		}
		else
		{
			window.document.getElementById("ParticipantBlogPersonalRatingNewIntroduction").style.display = "none";
			window.document.getElementById("ParticipantPersonalBlogRatingNewLabel").style.display = "none";
			window.document.getElementById("ParticipantBlogPersonalRatingExistingIntroduction").style.display = "block";
			window.document.getElementById("ParticipantBlogPersonalRatingExistingInstruction").style.visibility = "visible";
		}
		window.document.getElementById("ParticipantBlogPersonalReviewSection").style.display = "none";
		if(window.document.getElementById("ParticipantBlogPersonalRatingReviewAllowed").value === "1")
		{
			window.document.getElementById("ParticipantBlogPersonalReviewInvitationLink").style.display = "block";
			window.document.getElementById("ParticipantBlogPersonalReviewClosedMessage").style.display = "none";
		}
		else
		{
			window.document.getElementById("ParticipantBlogPersonalReviewInvitationLink").style.display = "none";
			window.document.getElementById("ParticipantBlogPersonalReviewClosedMessage").style.display = "block";
		}
		window.document.getElementById("ParticipantBlogPersonalReview").value = "";
		window.document.getElementById("ParticipantBlogPersonalReviewFeedback").firstChild.data = "";
		window.document.getElementById("ParticipantBlogPersonalRatingCurtainBackdrop").style.height = "162px";
		this.ChooseRating(currentRating);
		var dialog = window.document.getElementById("ParticipantBlogPersonalRatingChild").parentNode;
		dialog.style.display = "block";
		this.ShowModalCurtain();
		return false;
	},
	"HideRatingDiv" : function BlogDisplay_HideRatingDiv()
	{
		var dialog = window.document.getElementById("ParticipantBlogPersonalRatingChild").parentNode;
		dialog.style.display = "none";
		this.HideModalCurtain();
		return false;
	},
	"ShowReadReviewDiv" : function BlogDisplay_ShowReadReviewDiv()
	{
	    var dialog = window.document.getElementById("reviewCollectionDiv");
		dialog.style.display = "block";				
		window.document.getElementById("reviewCollectionIframe").src= "/ReviewCollection.aspx?pbid="+blogId+"&page="+page+"&link="+link+"&src="+src+"&pageno=1";
		this.ShowModalCurtain();
		return false;
	},	
	"HideReadReviewDiv" : function BlogDisplay_HideReadReviewDiv()
	{
		var dialog = window.document.getElementById("reviewCollectionDiv");
		dialog.style.display = "none";
		window.document.getElementById("reviewCollectionIframe").src="about:blank";
		this.HideModalCurtain();
		return false;
	},
	"SetDefaultRating" : function BlogDisplay_SetDefaultRating(rating)
	{
		window.document.getElementById("ParticipantBlogPersonalRatingExistingMeterFilling").style.width = (Math.round(rating * 100 / 5)).toString() + "%";
	},
	"ChooseRating" : function BlogDisplay_ChooseRating(rating)
	{
		window.document.getElementById("ParticipantBlogPersonalRatingNewScore").value = rating.toString();
		this.SetDefaultRating(rating);
		return false;
	},
	"SaveRating" : function BlogDisplay_SaveRating(premiumBlogID, rating, review, formToken, successFunction, failureFunction)
	{
		var ratingProvided = (rating > 0);
		var reviewProvided = (review.length !== 0);
		var transportPlacebo = {"responseText" : ""};
		if(ratingProvided)
		{
			new Ajax.Request("BlogDisplay.ashx",
			{
				"method" : "post",
				"parameters" : "action=rate&pbid=" + encodeURIComponent(premiumBlogID.toString()) + "&rating=" + encodeURIComponent(rating.toString()) + "&review=" + encodeURIComponent(review) + "&token=" + encodeURIComponent(formToken),
				"onSuccess" : successFunction,
				"onFailure" : failureFunction
			});
		}
		else
		{
			if(reviewProvided)
			{
				transportPlacebo.responseText = "You must enter a rating with your review.";
			}
		}
		if(!!failureFunction)
		{
			failureFunction(transportPlacebo);
		}
	},
	"ShowPersonalReviewSection" : function BlogDisplay_ShowPersonalReviewSection()
	{
		window.document.getElementById("ParticipantBlogPersonalRatingCurtainBackdrop").style.height = "278px";
		window.document.getElementById("ParticipantBlogPersonalReviewSection").style.display = "block";
		window.document.getElementById("ParticipantBlogPersonalReviewInvitationLink").style.display = "none";
		window.document.getElementById("ParticipantBlogPersonalReview").focus();
		return false;
	},
	"ShowModalCurtain" : function BlogDisplay_ShowModalCurtain()
	{

		var ele= window.document.getElementById("reviewCollectionDiv");
		if (ele != null)
		{
			window.document.body.appendChild(ele);
		}

	    
		var curtain = window.document.getElementById("ModalCurtain");
		curtain.style.display = "block";
		if(curtain.offsetHeight < 20)
		{
			curtain.style.height = Math.max(window.document.documentElement.scrollHeight, window.document.documentElement.offsetHeight) + "px";
			curtain.style.width = Math.max(window.document.documentElement.scrollWidth, window.document.documentElement.clientWidth) + "px";
		}

		/* Lure the caret away from framed text boxes in Internet Explorer to prevent its blinking from lingering. */
		var frames = window.document.getElementsByName("mogubox");
		if(frames.length !== 0)
		{
			var field = window.document.createElement("INPUT");
			field.className = "offscreen";
			window.document.body.appendChild(field);
			field.focus();
			window.document.body.removeChild(field);
		}
		HideClipboards();
	},
	"HideModalCurtain" : function BlogDisplay_HideModalCurtain()
	{
		window.document.getElementById("ModalCurtain").style.display = "none";
		ShowClipboards();
	},
	/* Displays an activation dialog for authors intending to publish a post.  Optional parameters (NaN, null) specify the blog ID and profile page URL to open if the author signs in to a different account. */
	"ShowActivationDialog" : function BlogDisplay_ShowActivationDialog(blogID, profileURL)
	{
		window.top.PrepareDesktop(function() {ShowActivationDialog_Loaded(blogID, profileURL);});
		return false;
	}
	
};

function ShowActivationDialog_Loaded(blogID, profileURL)
{
	window.top.FanBox.Registration.SetPremiumBlogsAuthorScenario(blogID, profileURL);
	window.top.FanBox.Registration.ShowMogu();
}

/* Imitates the actual PBlogs object for the desktop (PBlogs.js).  Please synchronize. */
var PBlogs = {
	"ShowShareDiv" : function PBlogs_ShowShareDiv()
	{
		BlogDisplay.ShowModalCurtain();
		try
		{
			if(window != window.top)
			{
				window.top.coverPageWithDarkness();
			}
		}
		catch(problem)
		{
		}

		if (!PBlogs._shareDiv)
		{
			var ifr = document.createElement('script');
			ifr.type = 'text/javascript';
			ifr.src = 'http://files.fbstatic.com/' + $('MasterVersion').value + '/socnet/ajaxdivs/pblog_ShareDiv.js';
			document.getElementsByTagName('head')[0].appendChild(ifr);
		}
		if (!!PBlogs._shareDiv)
		{
			PBlogs._finishShareDiv();
		}
	},
	"_finishShareDiv" : function PBlogs_FinishShareDiv()
	{
		PBlogs._uniqueURLInput.value = $("BlogDisplayURL").value;
		PBlogs._shareDiv.style.visibility = 'visible';
		PBlogs._shareDiv.style.zIndex = 100000;
	},
	"HideShareDiv" : function()
	{
		BlogDisplay.HideModalCurtain();
		try
		{
			if(window != window.top)
			{
				if(!!window.top.uncoverPageFromDarkness)
				{
					window.top.uncoverPageFromDarkness()
				}
			}
		}
		catch(problem)
		{
		}

		PBlogs._shareDiv.style.visibility = 'hidden';
	}
};

function tagClicked(tagName, tagId, blogId)
{
    var params = {};
    params['blogid'] = blogId;
    params['tagid'] = tagId;
    params['source'] = 'BlogCanvas';
    new Ajax.Request('PBlogTagStatHandler.ashx', 
        {
            'method' : 'post',
            'parameters' : params
        }
    );
    var url = 'http://profile.fanbox.com/PremiumBlogs/APB_SA.aspx?TagName=' + encodeURIComponent(tagName) + '&jump=1';
    ProfileLink_Click(url);
}

function hideAboutDiv()
{
	var show = document.getElementById('blogDescriptionTrunc');
	var hide = document.getElementById('blogDescriptionFull');
	if (!!hide && !!show)
	{
		hide.style.display='none';
		show.style.display='block';
	}
}
function showAboutDiv()
{
	var hide = document.getElementById('blogDescriptionTrunc');
	var show = document.getElementById('blogDescriptionFull');
	if (!!hide && !!show)
	{
		show.style.display='block';
		hide.style.display='none';
	}
}

function ProfileLink_Click(url)
{
    var link = false;
    if (!url)
    {
        url = this.href;
        link = true;
    }
	var browser;
	try
	{
		browser = window.top.browser;
	}
	catch(problem)
	{
	}

	if(!!browser)
	{
		browser.openBrowser(url);
		browser.bringToFocus();
		return false;
	}
	else if (link)
	{
		this.href = "http://www.fanbox.com/socnet/Desktop.aspx?skipSplash=1&opg=" + encodeURIComponent(url);
		this.target = "_top";
		return true;
	}
	else
	{
	    top.window.location = "http://www.fanbox.com/socnet/Desktop.aspx?skipSplash=1&opg=" + encodeURIComponent(url);
	}
}

function RatingFormSaveButton_Click()
{
	var blogID = parseInt(window.document.getElementById("ParticipantBlogPersonalRatingBlogID").value, 10);
	var rating = parseInt(window.document.getElementById("ParticipantBlogPersonalRatingNewScore").value, 10);
	var review = window.document.getElementById("ParticipantBlogPersonalReview").value;
	var token = window.document.getElementById("ParticipantBlogPersonalRatingFormToken").value;
	this.disabled = true;
	var feedbackTextNode = window.document.getElementById("ParticipantBlogPersonalReviewFeedback").firstChild;
	feedbackTextNode.data = "";
	BlogDisplay.SaveRating(blogID, rating, review, token, RatingFormSave_Succeeded, RatingFormSave_Failed);
}

function RatingFormSave_Succeeded(transport)
{
	window.document.getElementById("ParticipantBlogPersonalRatingCurrentScore").value = transport.responseText;
	var review = window.document.getElementById("ParticipantBlogPersonalReview").value;

	BlogDisplay.HideRatingDiv();
	EnableRatingForm();

	if (review != "")
	{
		window.document.getElementById("ParticipantBlogPersonalRatingReviewAllowed").value = "0";
	    BlogDisplay.ShowReadReviewDiv();
	}
}

function RatingFormSave_Failed(transport)
{
	var feedbackTextNode = window.document.getElementById("ParticipantBlogPersonalReviewFeedback").firstChild;
	feedbackTextNode.data = transport.responseText;
	EnableRatingForm();
}

function EnableRatingForm()
{
	window.document.getElementById("ParticipantBlogPersonalReviewSaveButton").disabled = false;
}

function RepaintBlogRatingIE6()
{
	this.style.display = "none";
	this.style.display = "inline-block";
}

function ConfigureBlogRatingRepaintingIE6()
{
	if((window.navigator.appName === "Microsoft Internet Explorer") && (window.navigator.appVersion.indexOf("MSIE 6.") !== -1))
	{
		var links = window.document.links;
		for(var index = 0;  index < links.length;  index++)
		{
			var link = links[index];
			if(link.className.indexOf("BlogRating") !== -1)
			{
				link.onmouseout = link.onblur = RepaintBlogRatingIE6;
			}
		}
	}
}

var Clipboards = [];
function ConfigureExportToClipboardButtons()
{
	var exportLandmarks = window.document.getElementsByName("BlogPostExportLandmark");
	if(exportLandmarks.length !== 0)
	{
		if(!!window.addEventListener)
		{
			window.addEventListener("resize", ResizeClipboards, false);
		}
		else if(!!window.attachEvent)
		{
			window.attachEvent("onresize", ResizeClipboards);
		}

		for(var buttonIndex = 0;  buttonIndex < exportLandmarks.length;  buttonIndex++)
		{
			var exportLandmark = exportLandmarks[buttonIndex];
			var exportButton = exportLandmark.nextSibling;
			var exportTextHolder = exportButton.nextSibling;

			var clipboard = new ZeroClipboard.Client();
			Clipboards.push(clipboard);
			clipboard.BlogDiplayTargetID = exportButton.id;
			clipboard.setText(exportTextHolder.value);
			clipboard.addEventListener("onLoad", Clipboard_Loaded);
			clipboard.addEventListener("onComplete", Clipboard_Copied);
			clipboard.glue(BuildDecoyElementForClipboard(exportButton));
		}
	}
}

function BuildDecoyElementForClipboard(element)
{
	return {
		"id" : element.id,
		"className" : element.className,
		"style" : {
			"zIndex" : element.zIndex
		},
		"width" : element.offsetWidth,
		"height" : element.offsetHeight,
		"offsetLeft" : element.offsetLeft,
		"offsetTop" : element.offsetTop,
		"offsetParent" : element.offsetParent
	};
}

function Clipboard_Loaded(clipboard)
{
	var exportButton = window.document.getElementById(clipboard.BlogDiplayTargetID);
	exportButton.disabled = false;
	exportButton.title = "";
}

function Clipboard_Copied(clipboard)
{
	window.document.getElementById(clipboard.BlogDiplayTargetID).click();
}

function ResizeClipboards()
{
	for(var clipboardIndex = 0;  clipboardIndex < Clipboards.length;  clipboardIndex++)
	{
		var clipboard = Clipboards[clipboardIndex];
		var exportButton = window.document.getElementById(clipboard.BlogDiplayTargetID);
		clipboard.reposition(BuildDecoyElementForClipboard(exportButton));
	}
}

function HideClipboards()
{
	for(var clipboardIndex = 0;  clipboardIndex < Clipboards.length;  clipboardIndex++)
	{
		var clipboard = Clipboards[clipboardIndex];
		clipboard.hide();
	}
}

function ShowClipboards()
{
	for(var clipboardIndex = 0;  clipboardIndex < Clipboards.length;  clipboardIndex++)
	{
		var clipboard = Clipboards[clipboardIndex];
		clipboard.show();
	}
}

function ConfigureDesktopWindowFocus()
{
	if(window != window.top)
	{
		if(!!window.addEventListener)
		{
			window.document.documentElement.addEventListener("mousedown", FocusDesktopWindow, false);
		}
		else if(!!window.attachEvent)
		{
			window.document.documentElement.attachEvent("onmousedown", FocusDesktopWindow);
		}
	}
}

function FocusDesktopWindow()
{
	var windowID = BlogDisplay.GetCurrentWindowID();
	if(!(isNaN(windowID)))
	{
		window.parent.WindowManager.GetWindowByWindowID(windowID).BringToFront();
	}
}

function BlogDisplayPageLoad()
{
	ConfigureExportToClipboardButtons();
	var ratingMeter = window.document.getElementById("BlogRatingMeter");
	if(ratingMeter !== null)
	{
		ConnectInlineHTMLTooltipTargetEvents(ratingMeter);
	}
	ratingMeter = window.document.getElementById("PurchasingBlogRatingMeter");
	if(ratingMeter !== null)
	{
		ConnectInlineHTMLTooltipTargetEvents(ratingMeter);
	}
	ConfigureDesktopWindowFocus();
	WrapComments();
	if(!!window.ScrollToComments && typeof(ScrollToComments) === 'function')
	{
		window.ScrollToComments();
	}
	var qstring = window.location.search;
	if (qstring.indexOf('&comment=') > -1)
	{
		qstring = qstring.substring(qstring.indexOf('&comment=')+9);
		if (qstring.indexOf('new') == 0)
		{
			BlogDisplay.scrollToPreview('pb_blogcomment_textarea');
		}
		else if (qstring.indexOf('view') == 0)
		{
			BlogDisplay.scrollToPreview('pb_blogcomments_header');
		}
	}
	ConfigureBlogRatingRepaintingIE6();
	if (typeof isPOPopped != "undefined" && !!isPOPopped)
	{
		window.AnimObject = new OptDivAnimator();
		window.setTimeout(function() { AnimObject.startAnim(); },1000);
		
		document.getElementById('optinboxWin').onclick = function() { window.optinDivClicked=true; };
		
		if(!!window.document.addEventListener)
		{
			window.addEventListener("click",
				function() 
				{
					if (AnimObject.optinShowFlag && typeof(window.optinDivClicked) != 'undefined' && !window.optinDivClicked) 
					{
						AnimObject.startAnim(); 
					}
					window.optinDivClicked = false;
				}, 
				false
				);
			window.addEventListener("scroll",
				function()
				{
					if (AnimObject.optinShowFlag)
					{
						AnimObject.scrollWithWindow();
					}
				},
				false
				);
		}
		else if(!!window.attachEvent)
		{
			window.document.attachEvent("onclick",
				function() 
				{
					if (AnimObject.optinShowFlag && (typeof window.optinDivClicked == 'undefined' || (typeof window.optinDivClicked != 'undefined' && !window.optinDivClicked)))
					{
						AnimObject.startAnim(); 
					}
					window.optinDivClicked = false;
				}
				);
			window.attachEvent("onscroll",
				function()
				{
					if (AnimObject.optinShowFlag)
					{
						AnimObject.scrollWithWindow();
					}
				}
				);
		}
	}
}

if(!!window.addEventListener)
{
	window.addEventListener("load", BlogDisplayPageLoad, false);
}
else if(!!window.attachEvent)
{
	window.attachEvent("onload", BlogDisplayPageLoad);
}

function ResizeModalCurtain()
{
	var curtain = window.document.getElementById("curtain");
	var curtainBacking = window.document.getElementById("curtainBacking");

	curtain.style.display = "none";
	curtainBacking.style.display = "none";

	var fullWidth = window.document.documentElement.scrollWidth;
	var fullHeight = window.document.documentElement.scrollHeight;

	curtain.style.display = "block";
	curtainBacking.style.display = "block";

	curtain.style.width = fullWidth + "px";
	curtain.style.height = fullHeight + "px";
	curtainBacking.style.width = fullWidth + "px";
	curtainBacking.style.height = fullHeight + "px";
}

var FeatureManager={
updateFeature:function(featureId,isEnabled){
    if (window.document.getElementById('donotshowagain').checked)
    {
        var isEnabledParam=isEnabled?1:0;
        var rn=Math.random()*10000000;        
        var tempscript = document.createElement("script");
        tempscript.src='http://www.fanbox.com/socnet/handlers/FeatureHandler.ashx?fid='+featureId+'&stts='+isEnabledParam+'&r='+rn;
        window.document.body.appendChild(tempscript);
    }
    }
}


function ShowModalCurtain()
{
	var curtain = window.document.getElementById("curtain");
	curtain.style.display = "block";
	var curtainBacking = window.document.getElementById("curtainBacking");
	curtainBacking.style.display = "block";

	ResizeModalCurtain();
}

function HideModalCurtain()
{
	var curtain = window.document.getElementById("curtain");
	curtain.style.display = "none";
	curtain.style.width = "100%";
	curtain.style.height = "100%";
	var curtainBacking = window.document.getElementById("curtainBacking");
	curtainBacking.style.display = "none";
	curtainBacking.style.width = "100%";
	curtainBacking.style.height = "100%";
}

function showNewBlogDiv()
{
	var createdDivShow = document.getElementById("newBlogDiv");
	createdDivShow.style.display = "";
}

function hideNewBlogDiv()
{
	var createdDivShow = document.getElementById("newBlogDiv");
	createdDivShow.style.display = "none";
}

function hideReminder()
{
	FeatureManager.updateFeature(10, 0);
	var shoutoutreminder = document.getElementById("ShoutoutReminder");
	shoutoutreminder.style.display = "none";	
	HideModalCurtain();
}

function hideReminderShout(prodId)
{
    var rn=Math.random()*10000000;        
    var tempscript = document.createElement("script");
    tempscript.src='http://www.fanbox.com/socnet/handlers/FeatureHandler.ashx?fid=10&stts=0&r='+rn;
    window.document.body.appendChild(tempscript);
	window.open('http://developer.fanbox.com/WidgetWizard/Shoutout/Manage.aspx?appid=' + prodId + '', '_blank');
	var shoutoutreminder = document.getElementById("ShoutoutReminder");
	shoutoutreminder.style.display = "none";
	DeveloperAction.RecordStat(2, 37, -1);
    HideModalCurtain();	
}

var LastTextArea = null;
var LastTextAreaLimit = NaN;
var TextAreaTimer = NaN;
function LimitedTextArea_KeyPress()
{
	var checkNow;
	if(isNaN(TextAreaTimer))
	{
		checkNow = true;
	}
	else if(LastTextArea !== this)
	{
		window.clearTimeout(TextAreaTimer);
		TextAreaTimer = NaN;
		TrimLastLimitedTextAreaToLength();
		checkNow = true;
	}
	else
	{
		checkNow = false;
	}
	if(checkNow)
	{
		LastTextAreaLimit = parseInt(this.attributes["maxlength"].value, 10);
		LastTextArea = this;
		if(this.value.length < LastTextAreaLimit)
		{
			TextAreaTimer = window.setTimeout(TrimLastLimitedTextAreaToLength, 250);
		}
		else
		{
			TextAreaTimer = window.setTimeout(TrimLastLimitedTextAreaToLength, 0);
		}
	}
}

function LimitedTextArea_Change()
{
	LastTextAreaLimit = parseInt(this.attributes["maxlength"].value, 10);
	LastTextArea = this;
	TrimLastLimitedTextAreaToLength();
}

function TrimLastLimitedTextAreaToLength()
{
	var currentValue = LastTextArea.value;
	if(currentValue.length > LastTextAreaLimit)
	{
		LastTextArea.value = currentValue.substr(0, LastTextAreaLimit);
	}
	TextAreaTimer = NaN;
}

function ResizePhotos()
{
	var images = [window.document.getElementById("ParticipantBlogAuthorPhoto")];
	for(var imageIndex = 0;  imageIndex < images.length;  imageIndex++)
	{
		var image = images[imageIndex];
		if(image !== null)
		{
			ResizePhoto(image, parseInt(image.maxWidth, 10), parseInt(image.maxHeight, 10));
		}
	}
}

function ResizePhoto(imgRef, maxWidth, maxHeight)
{
	if(imgRef)
	{
		if(imgRef.width)
		{
			if(imgRef.width > maxWidth || imgRef.height > maxHeight)
			{
				var maxRatio = maxWidth / maxHeight;
				var imgRatio = imgRef.width / imgRef.height;

				if(maxRatio < imgRatio)
				{
					var temph = Math.round(((maxWidth)/imgRef.width) * imgRef.height);
					if(temph > 2)
					{
						imgRef.height = temph;
						imgRef.width = maxWidth;
					}
				}
				else
				{
					var tempw = Math.round(((maxHeight)/imgRef.height) * imgRef.width);
					if(tempw > 2)
					{
						imgRef.width = tempw;
						imgRef.height = maxHeight;
					}
				}
			}
		}
		else
		{
			imgRef.height = maxHeight;
		}
	}
	imgRef.style.visibility = "visible";
}

function WrapComments()
{
	var elementIDs = window.commentBodyClientIDs;
	if(!!elementIDs)
	{
		for(i = 0; i < elementIDs.length; i++)
		{
			var elementID = elementIDs[i];
			var commentContainer = window.document.getElementById(elementID);
			if(commentContainer.offsetWidth > 518)
			{
				var textNodes = [];
				for(var cursor = commentContainer.firstChild;  cursor !== null;  cursor = cursor.nextSibling)
				{
					if(cursor.nodeType === 3)
					{
						textNodes.push(cursor);
					}
				}
				for(var textNodeIndex = 0;  textNodeIndex < textNodes.length;  textNodeIndex++)
				{
					WordBreakDisplayTextWidth(commentContainer, 450, textNodes[textNodeIndex]);
				}
			}
		}
	}
}
var DeveloperAction = DeveloperAction || {};

DeveloperAction.RecordStat = function(action, eventLocationId, assocIntData)
{
    var args = {
        vlsid : -1,
        ac : action,
        elid : eventLocationId,
        aid : assocIntData};
    new Ajax.Request
	('DeveloperActionStat.ashx',
    {
        method: 'post',
		parameters: args
	});
}

function GetScrollTop()
{
	if (typeof document.documentElement.scrollTop !== 'undefined')
	{
		return document.documentElement.scrollTop;
	}
	if (typeof window.pageYOffset !== 'undefined')
	{
		return window.pageYOffset;
	}
	else
	{
		return document.body.scrollTop;
	}
}

var AnimObject;
function OptDivAnimator()
{	
	//Variables used across the different functions
	this.optinwinmaxwid = 560;
	this.optinwinmaxhgt = 320;
	this.optinwincontentmaxhgt = 320;
	this.optinShowFlag = false;
	this.optinwin = null;
	this.optinwincontent = null;
	this.optinwin = document.getElementById('optinboxWin');
	this.optinwincontent = document.getElementById('optinboxWinContent');
	this.optincon = document.getElementById('optinContent');

	//Determine window size values
	this.windowmaxwid = window.document.body.clientWidth;
	this.windowmaxhgt = window.document.body.clientHeight;
	this.offsetleftmax = (this.windowmaxwid/2) - 280;
	this.offsettopmax = (this.windowmaxhgt/2) - 160;
	this.intervalhgt = this.optinwinmaxhgt / 6;
	this.intervalwid = this.optinwinmaxwid / 6;
	this.intervalcontenthgt = this.optinwincontentmaxhgt / 6;
	
	this.regularStepIncrement = 75;
	this.lastStepTime = null;
	
	this.alreadyOpted = false;
	
	//Initializes animation sequences
	this.startAnim = function()
	{
		if (this.alreadyOpted === true && this.optinShowFlag === false)
		{
			return;
		}
		
		if (this.optinShowFlag)
		{
			this.stepDown();
		}
		else
		{
			this.stepSlide();
		}
	};
	
	this.scrollWithWindow = function()
	{
		this.optinwin.style.marginTop = (-1*(parseInt(this.optinwin.style.height) / 2) + GetScrollTop()) + "px";
	};
	
	//Maximizes the Profile window
	this.stepSlide = function()
	{
		if(this.optinShowFlag === false)
		{
			this.lastStepTime = null;
		}
		
		var stepIncrement = this.setStep();
		if(parseInt(this.optinwin.style.bottom) >= 40) 
		{
			this.optinwin.style.marginBottom = '';
			this.optinwin.style.bottom = "";
			this.optinwin.style.top = "50%";
			this.optinwin.style.left = "50%";
			this.optinwin.style.height = "347px";
			this.optinwincontent.style.height = "327px";
			this.optinwin.style.width = "560px";
			this.optinwin.style.marginLeft = "-" + (parseInt(this.optinwin.style.width) / 2) + "px";
			this.optinwin.style.marginTop = (-1*(parseInt(this.optinwin.style.height) / 2) + GetScrollTop()) + "px";
			if (this.optinShowFlag === false)
			{
				this.showOptin();
			}
		}
		else 
		{
			this.optinwin.style.top = "";
			this.optinwin.style.marginTop = "";
			this.optinwin.style.width = (parseInt(this.optinwin.style.width) + (stepIncrement * this.intervalwid)) + "px";
			this.optinwin.style.height = (parseInt(this.optinwin.style.height) + (stepIncrement * this.intervalhgt)) + "px";
			this.optinwincontent.style.height = ((parseInt(this.optinwincontent.style.height) + (stepIncrement * this.intervalcontenthgt)) - 10) + "px";
			this.optinwin.style.bottom = (parseInt(this.optinwin.style.bottom) + (stepIncrement * 10)) + "%";
			this.optinwin.style.marginLeft = "-" + (parseInt(this.optinwin.style.width) / 2) + "px";
			this.optinwin.style.marginBottom = "-" + ((parseInt(this.optinwin.style.height) / 2) + GetScrollTop() ) + "px";
			window.setTimeout(function() { AnimObject.stepSlide(); }, 75);
		}
	};
	
	//Minimizes the profile window
	this.stepDown = function() 
	{
		if(this.optinShowFlag === true)
		{
			this.showOptin();
		}
	
		var stepIncrement = this.setStep();
		if(parseInt(this.optinwin.style.bottom) <= 10) {
			this.optinwin.style.top = "";
			this.optinwin.style.marginTop = "";
			this.optinwin.style.bottom = "-10%";
			this.optinwin.style.left = "50%";
			this.optinwin.style.height = "0";
			this.optinwincontent.style.height = "0";
			this.optinwin.style.width = "0";
			this.optinwin.style.marginLeft = "-" + (parseInt(this.optinwin.style.width) / 2) + "px";
			this.optinwin.style.marginBottom = "-" + ((parseInt(this.optinwin.style.height) / 2) + GetScrollTop() ) + "px";
		}
		else {
			//just catch every error and completely hide, I dont want to check if each operation is going to go negative
			try
			{
				this.optinwin.style.top = "";
				this.optinwin.style.marginTop = "";
				this.optinwin.style.width = (parseInt(this.optinwin.style.width) - (stepIncrement * this.intervalwid)) + "px";
				this.optinwin.style.height = (parseInt(this.optinwin.style.height) - (stepIncrement * this.intervalhgt)) + "px";
				this.optinwincontent.style.height = ((parseInt(this.optinwincontent.style.height) - (stepIncrement * this.intervalcontenthgt)) - 10) + "px";
				if(isNaN(parseInt(this.optinwin.style.bottom,10)))
				{
					this.optinwin.style.bottom = '50%';
				}
				this.optinwin.style.bottom = (parseInt(this.optinwin.style.bottom) - (stepIncrement * 10)) + "%";
				this.optinwin.style.marginLeft = "-" + (parseInt(this.optinwin.style.width) / 2) + "px";
				this.optinwin.style.marginBottom = "-" + ((parseInt(this.optinwin.style.height) / 2) + GetScrollTop() ) + "px";
			}
			catch(e)
			{
				//make it less than 10px so next time this method gets called it is completely hidden
				this.optinwin.style.bottom = "9px";
			}
			window.setTimeout(function() { AnimObject.stepDown(); }, 75);
		}
	};
	
	//Fades out the profile window content
	this.showOptin = function() 
	{	
		this.lastStepTime = null;
		if(this.optincon.style.visibility == "hidden") 
		{
			this.optincon.style.visibility = "visible";
			this.optinShowFlag = true;
		}
		else 
		{
			this.optincon.style.visibility = "hidden";
			this.optinShowFlag = false;
		}
	};
	
	//Sets the last step time and returns the ratio of regular step time over real step time
	this.setStep = function()
	{
		if(!this.lastStepTime)
		{
			//keep normal increment, nothing has happened yet
			this.lastStepTime = new Date();
			return 1;
		}
		else
		{
			//set new increment depending on how long it's been
			var tempTime = new Date();
			//get total milliseconds
			var ms = (tempTime.getTime() - this.lastStepTime.getTime());
			
			this.lastStepTime = tempTime;
			return ms/this.regularStepIncrement;
		}
	}
}
