var bOverMenu = false;
var iMenuStatus = 0;
var objCurrentButton = false;
var aPreloadList = [
	"/images/infobox2.png",
	"/images/nav/active/arts.png",
	"/images/nav/active/music.png",
	"/images/nav/active/fashion.png",
	"/images/nav/active/film.png",
	"/images/nav/active/bestoftoronto.png",
	"/images/nav/active/restaurants.png",
	"/images/nav/active/events.png",
	"/images/nav/active/artistgallery.png",
	"/images/menu-top-1.png",
	"/images/menu-top-2.png",
	"/images/menu-top-3.png",
	"/images/menu-top-4.png",
	"/images/menu-item.png",
	"/images/menu-item-hover.png",
	"/images/menu-item-last.png",
	"/images/menu-bottom-left.png",
	"/images/menu-bottom-center.png",
	"/images/menu-bottom-right.png",
	"/images/comments-tabs-oldest.gif",
	"/images/comments-tabs-newest-on.gif"
];
var aEntries = [];

for(var i=0; i<aPreloadList.length; i++){
	var objImage = new Image();
	objImage.src = aPreloadList[i];
}
	
Effect.Scroll = Class.create();
Object.extend(Object.extend(Effect.Scroll.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
      x:    0,
      y:    0,
      mode: 'absolute'
    } , arguments[1] || {}  );
    this.start(options);
  },
  setup: function() {
    if (this.options.continuous && !this.element._ext ) {
      this.element.cleanWhitespace();
      this.element._ext=true;
      this.element.appendChild(this.element.firstChild);
    }

    this.originalLeft=this.element.scrollLeft;
    this.originalTop=this.element.scrollTop;

    if(this.options.mode == 'absolute') {
      this.options.x -= this.originalLeft;
      this.options.y -= this.originalTop;
    } else {

    }
  },
  update: function(position) {   
    this.element.scrollLeft = this.options.x * position + this.originalLeft;
    this.element.scrollTop  = this.options.y * position + this.originalTop;
  }
});

$j(function(){
	Menu_Activate();
	try{
		Sidebar_LatestReviews_Load();
		Sidebar_Buzz_Load();
	}
	catch(e){}
	try{
		//TorontoLists_Load();
	}
	catch(e){}
	//UpdateRLinks();
	var Link;
	for(i=0; i<document.links.length; i++){
		Link = document.links[i];
		if(Link.href.indexOf("flickr.com") != -1){
			Link.target = "_blank";
		}
	}
	$j("#post_comments .comment:nth-child(even)").addClass("comment-even");
});

$j(window).load(function(){
	var objHeader = $j("#header");
	objHeader.css({backgroundImage: objHeader[0].style.backgroundImage});
});

function Menu_Activate(){
	var aButtons = $$("#nav .items > a");
	for(var i=0; i<aButtons.length; i++){
		var objImage = aButtons[i].childElements()[0];
		if(objImage){
			Event.observe(objImage, "mouseover", Menu_Item_Mouseover);
			Event.observe(objImage, "mouseout", Menu_Item_Mouseout);
		}
	}
	Event.observe($("menu"), "mouseover", function(){
		bOverMenu = true;
		Menu_Item_Mouseover(null, objCurrentButton);
	});
	Event.observe($("page"), "mousemove", function(event){
		if(objCurrentButton != false){
			if(objCurrentButton.src.indexOf("arts.png") != -1){
				if(Event.element(event).id == "page"){
					Menu_Item_Mouseout(null, objCurrentButton);
					$("menu").hide();
				}
			}
		}
	});
	Event.observe($("header"), "mouseover", function(){
		bOverMenu = false;
		Menu_Item_Mouseout(null, objCurrentButton);
	});
	if($("breadcrumb")){
		Event.observe($("breadcrumb"), "mouseover", function(){
			bOverMenu = false;
			Menu_Item_Mouseout(null, objCurrentButton);
		});
	}
	Event.observe($("content"), "mouseover", function(){
		bOverMenu = false;
		Menu_Item_Mouseout(null, objCurrentButton);
	});
}

function Menu_Item_Mouseover(event, objImage){
	var bCalledFromEvent = false;
	var MENU_TOP_TAB_WIDTH = 37;
	
	if(objImage == false) return;
	if(objImage == null){
		bCalledFromEvent = true;
		iMenuStatus = 1;
		objImage = Event.element(event);
		if(objCurrentButton) Menu_Item_Mouseout(null, objCurrentButton);
	}
	else iMenuStatus = 2;
	
	objCurrentButton = objImage;
	bOverMenu = true;
	
	var sImage = objImage.src;
	var aFilename = sImage.match(/\/([a-z]+)\.png$/i);
	if(aFilename){
		var sFilename = aFilename[1];
		sImage = "/images/nav/active/" + sFilename + ".png";
		objImage.src = sImage;
	}
	else return;
	
	if(bCalledFromEvent){
		$("menu").hide();
		if($("items-" + sFilename)){
			var aItems = $$("#items-" + sFilename + " > li");
			$("menu-items").update($("items-" + sFilename).innerHTML);
			for(var i=0; i<aItems.length; i++){
				//$("menu-items").insert({bottom: aItems[i]});
			}
			$("menu").show();
			var iButtonWidth = Element.getWidth(objImage);
			var iContentWidth = Element.getWidth($("menu-items"));
			if(document.all) iContentWidth = iButtonWidth + 50;
			$("menu").setStyle({
				left : (Element.cumulativeOffset(objImage).left) + "px",
				top : ((Element.cumulativeOffset(objImage).top + Element.getHeight(objImage)) - 10) + "px",
				width : (iContentWidth + MENU_TOP_TAB_WIDTH) + "px"
			});
			$("menu-items").setStyle({
				width: iContentWidth + "px"
			});
			$("menu-top-1").setStyle({
				width : (Element.getWidth(objImage) - 2) + "px"
			});
			$("menu-top-3").setStyle({
				width : ((iContentWidth - iButtonWidth) - 18) + "px"
			});
			$("menu-bottom-center").setStyle({
				width : (iContentWidth - 10) + "px"
			});
		}
	}
}

function Menu_Item_Mouseout(event, objImage){
	if(objImage == false) return;
	if(objImage == null){
		objImage = Event.element(event);
		bOverMenu = false;
		if(iMenuStatus == 1) iMenuStatus = 2;
		else if(iMenuStatus == 2) iMenuStatus = 3;
	}
	else if(iMenuStatus == 2) iMenuStatus = 3;
	if(objImage.tagName.toLowerCase() != "img") return;
	var sImage = objImage.src;
	var aFilename = sImage.match(/\/([a-z]+)\.png$/i);
	if(aFilename){
		var sFilename = aFilename[1];
		objImage.src = "/images/nav/" + sFilename + ".png";
	}
	else return;
	if((iMenuStatus == 0 || iMenuStatus == 3)){
		$("menu").hide();
		objCurrentButton = false;
		iMenuStatus = 0;
	}
}

function Toolbox_Toggle(iPostID){
	var objToolbox = $("post_" + iPostID + "_toolbox");
	objToolbox.toggle();
	if(objToolbox.style.display == "none"){
		$("post_" + iPostID + "_tools").style.background = "url('/images/icon-tools-open.gif') no-repeat";
	}
	else{
		$("post_" + iPostID + "_tools").style.background = "url('/images/icon-tools-close.gif') no-repeat";
	}
}

function XMLHttpObject(){
	if(navigator.userAgent.indexOf("Opera") != -1) return false;
	var objXMLHttp = false;
	
	if(window.XMLHttpRequest){
		objXMLHttp = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		try{
			objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
			objXMLHttp.overrideMimeType("text/xml");
		}
		catch(e){
			try{
				objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				objXMLHttp = false;
			}
		}
	}
	return objXMLHttp;
}

var AJAX_ERROR_NOSUPPORT = 0;
var AJAX_ERROR_HTTP = 1;
var AJAX_ERROR_OTHER = 2;

function AJAXRequest(sURL, sMethod, sData, Callback, bErrorAlerts, bXMLParsing){
	if(bXMLParsing == null) bXMLParsing = false;
	//if(bErrorAlerts == null) bErrorAlerts = true;
	bErrorAlerts = false;
	var objXMLHttp = new XMLHttpObject();
	if(!objXMLHttp){
		if(bErrorAlerts) alert("Sorry, in order to use this feature you need to upgrade your browser to the latest version of Internet Explorer, Firefox, or Safari.");
 		if(Callback) Callback(null, [AJAX_ERROR_NOSUPPORT]);
		return;
	}
	objXMLHttp.onreadystatechange = function(){
		if(objXMLHttp.readyState == 4 || objXMLHttp.readyState == "complete"){
			if(objXMLHttp.status == 200){
				if(Callback) Callback((bXMLParsing ? objXMLHttp.responseXML : objXMLHttp.responseText), false);
			}
			else{
				if(bErrorAlerts) alert("We're sorry, there was a problem while trying to process your request. Please try again in a few moments.");
				if(Callback) Callback(null, [AJAX_ERROR_HTTP, objXMLHttp.status]);
			}
		}
	}
	try{
		sMethod = sMethod.toUpperCase();
		objXMLHttp.open(sMethod, sURL + (sMethod == "GET" ? "?" + sData : ""), true);
		if(sMethod == "POST"){
			objXMLHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			objXMLHttp.setRequestHeader("Content-length", sData.length);
			objXMLHttp.setRequestHeader("Connection", "close");
		}
		objXMLHttp.send(sMethod == "POST" ? sData : null);
	}
	catch(Error){
		if(bErrorAlerts) alert("We're sorry, there was a problem while trying to process your request. Please try again in a few moments.");
		if(Callback) Callback(null, [AJAX_ERROR_OTHER, Error.description]);
	}
}

function Go2Category(sCategoryName, sCategoryID){
	var sPage = "";
	if(sCategoryID == "") return;
	if(sCategoryID == "weather"){
		sPage = '/weather/?display=fc';
	}
	if(sCategoryID == "restaurantlistings"){
		sPage = '/restaurants.php';
	}
	else sPage = "/" + escape(sCategoryID);
	window.location = sPage;
	return false;
}

function AuthorSearch(sAuthor){
	if(sAuthor == "") return;
	window.location = "/author/" + sAuthor.toLowerCase();
}

function BookmarkPage(sURL, sTitle){
	if(sURL == null){
		sURL = window.location.href;
		sTitle = document.title;
	}
	if(document.all){
		window.external.AddFavorite(sURL, sTitle);
	}
	else{
		alert("Sorry, automatic adding of this page to your favorites is not supported by your web browser.\n\nTo add this page to your favorites, just use the \"Bookmarks\" menu in your browser."); 
	}
	return false;
}

function PrintEntry(iEntryID){
	var sPage = "/print/" + iEntryID;
	var iHeight = 500;
	var iWidth = 700;
	var iLeft = Math.round(screen.width / 2) - Math.round(iWidth / 2);
	var iTop = Math.round(screen.height / 2) - Math.round(iHeight / 2);
	var Popup = window.open(sPage, "", "left=" + iLeft + ",top=" + iTop + ",height=" + iHeight + ",width=" + iWidth + ",scrollbars=1");
	return false;
}

function ToggleDisplay(sLayerID){
	var Layer = document.getElementById(sLayerID);
	if(Layer.style.display == "none"){
		Layer.style.display = "block";
	}
	else{
		Layer.style.display = "none";
	}
}

function Trim(sText){
	return sText.replace(/^\s*|\s*$/g, "");
}

function IsEmail(sAddress){
	if(sAddress == "") return false;
	var objRegExp = new RegExp("^[a-z0-9_.\-]{3,}@[a-z0-9.\-]{3,}\.[a-z]{2,3}$", "i");
	return objRegExp.test(sAddress);
}

function EmailEntry(Form){
	var sTo = Form.ToEmail.value;
	var sFrom = Form.FromEmail.value;
	var sMessage = Form.Message.value;
	
	if(!IsEmail(sTo)){
		alert("Please enter a valid receiver email address");
		Form.ToEmail.focus();
		Form.ToEmail.select();
		return false;
	}
	if(!IsEmail(sFrom)){
		alert("Please enter a valid sender email address");
		Form.FromEmail.focus();
		Form.FromEmail.select();
		return false;
	}
	if(Trim(Form.captcha.value) == ""){
		alert("Please enter the code shown on the image");
		Form.captcha.focus();
		return false;
	}
	
	var sData = "to=" + escape(sTo) + "&from=" + escape(sFrom) + "&message=" + escape(sMessage) + "&captcha=" + escape(Form.captcha.value) + "&title=" + escape(document.title) + "&url=" + escape("http://" + location.host + location.pathname);
	AJAXRequest("/include/emailentry.php", "POST", sData, function(sResponse, aError){
		if(!aError){ 
			if(sResponse == "success"){
				Form.reset();
				alert("This entry has been succesfully sent to your friend's email address");
			}
			else if(sResponse.indexOf("error:") == 0){
				aResponse = sResponse.split(":");
				alert(aResponse[1]);
			}
			else{
				alert("Sorry, we found a problem while trying to send this entry to your friend. Please try again in a few minutes.");
			}
		}
		else{
			alert("Sorry, we found a problem while trying to send this entry to your friend. Please try again in a few minutes.");
		}
	}, false);
	return false;
}

function CurrentDateTime(){
	var dNow = new Date();
	var iDay = dNow.getDate();
	var iMonth = dNow.getMonth();
	var aMonths = new Array();
	aMonths[0] = "January";
	aMonths[1] = "February";
	aMonths[2] = "March";
	aMonths[3] = "April";
	aMonths[4] = "May";
	aMonths[5] = "June";
	aMonths[6] = "July";
	aMonths[7] = "August";
	aMonths[8] = "September";
	aMonths[9] = "October";
	aMonths[10] = "November";
	aMonths[11] = "December";
	var iYear = dNow.getFullYear();
	var iHour = dNow.getHours();
	if (iHour >= 12) sTime = "PM";
	else sTime = "AM";
	if (iHour > 12) iHour -= 12;
	if (iHour == 0) iHour = 12;
	var iMinutes = dNow.getMinutes();
	if (iMinutes < 10) iMinutes = "0" + iMinutes;
	return aMonths[iMonth] + " " + iDay + ", " + iYear + " " + iHour + ":" + iMinutes + " " + sTime;
}

function PostComment(){
	var Form = document.forms.comments_form;
	if(bTypeKeyUser){
		Form.submit();
		return;
	}
	if(Trim(Form.author.value) == ""){
		alert("Please enter your name");
		Form.author.focus();
		return;
	}
	if(!IsEmail(Trim(Form.email.value))){
		alert("Please enter a valid email address");
		Form.email.focus();
		Form.email.select();
		return;
	}
	if(Trim(Form.text.value) == ""){
		alert("Please enter your comment");
		Form.text.focus();
		return;
	}
	if(Trim(Form.captcha.value) == ""){
		alert("Please enter the code shown on the image");
		Form.captcha.focus();
		return;
	}
	Form.post.value = "Posting comment, please wait...";
	Form.post.disabled = true;
	var sPage = window.location.pathname;
	sData = "page=" + escape(sPage) + "&entry_id=" + Form.entry_id.value + "&author=" + escape(Form.author.value) + "&email=" + escape(Form.email.value) +
			"&url=" + escape(Form.url.value) + "&text=" + escape(Form.text.value) + "&captcha=" + escape(Form.captcha.value);
	AJAXRequest("/template_include/postcomment.php", "POST", sData, function(sResponse, aError){
		if(!aError){
			if(sResponse == "success"){
				var PreviewLayer = document.getElementById("CommentPreview");
				var sAuthor = Form.author.value;
				if(Form.url.value != "") sAuthor = '<a href="' + Form.url.value + '">' + sAuthor + '</a>';
				PreviewLayer.innerHTML = '<div class="commentbox_wrapper">' + Form.text.value + '<p class="commentbox_posted">Posted by: ' + sAuthor + ' at ' + CurrentDateTime() + '</p></div><div class="commentbox_bottom"></div>';
				Form.post.value = "Posted!";
				Form.post.disabled = false;
				Form.reset();
				if(Form.bakecookie[0].checked) rememberMe(Form);
			}
			else{
				Form.post.value = "Post comment";
				Form.post.disabled = false;
				alert(sResponse);
			}
		}
		else{
			Form.post.value = "Post comment";
			Form.post.disabled = false; 
			alert(aError);
		}
	});
}

function RecommendThis(iEntryID){
	var Layer = document.getElementById("RecommendThis_" + iEntryID);
	Layer.innerHTML = "<img src=\"/site/images/recommendthis.jpg\" align=\"absmiddle\" /> One moment...";
	var sData = "id=" + iEntryID;
	AJAXRequest("/include/recommend.php", "POST", sData, function(sResponse, aError){
		if(!aError){
			Layer.innerHTML = "<img src=\"/site/images/recommendthis.jpg\" align=\"absmiddle\" /> " + sResponse;
		}
	});
	return false;
}

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") +
        (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function rememberMe(){
}

function UpdateRLinks(){
	try{
		var sData = "cmd=get-erc&entries=" + escape(aEntries.join(","));
		AJAXRequest("/include/mostrecommended.php", "POST", sData, function(sResponse, aError){
			if(!aError){
				var aCount = new Array();
				eval(sResponse);
				for(i=0; i<aEntries.length; i++){
					Layer = document.getElementById("RecommendThis_" + aEntries[i]);
					iCount = aCount["entry_" + aEntries[i]];
					if(!iCount) iCount = 0;
					Layer.innerHTML = '<a href="#" onclick="return RecommendThis(' + aEntries[i] + ');"><img src="/site/images/recommendthis.jpg" width="14" height="15" align="absmiddle" /> Recommend This (' + iCount + ')</a>';
				}
			}
		}, false, false);
	}
	catch(e){}
}

function ToggleDisplay(sLayerID){
	var Layer = document.getElementById(sLayerID);
	if(Layer.style.display == "none"){
		Layer.style.display = "block";
	}
	else{
		Layer.style.display = "none";
	}
}

function PreloadImage(sFile){
	var objImage = new Image();
	objImage.src = sFile;
}

function SwapImage(objImage, sNewImage){
	if(document.images){
		objImage.src = sNewImage;
	}
}

function ToggleEntryTools(iEntryID){
	ToggleDisplay("entry_tools_" + iEntryID);
	var Button = document.images["entry_tools_" + iEntryID + "_button"];
	var sImage = Button.src;
	if(sImage.indexOf("tools.jpg") != -1){
		Button.src = "/site/images/tools-hide.jpg";
	}
	else{
		Button.src = "/site/images/tools.jpg";
	}
	return false;
}

function Sidebar_Links_Category_Change(){
	var Form = document.forms.frmSidebarLinks;
	var objLayer = document.getElementById("Sidebar_Links_Layer");
	if(Form.Category.value != ""){
		objLayer.innerHTML = "<img src=\"/site/images/ajax-loader2.gif\" align=\"absmiddle\" /><strong> Loading...</strong>";
		sData = "cmd=getlinks&category=" + Form.Category.value;
		AJAXRequest("/include/ajax.php", "POST", sData, function(sResponse, aError){
			if(!aError){
				objLayer.innerHTML = sResponse;
			}
		});
	}
	else{
		objLayer.innerHTML = "";
	}
}

function Sidebar_Links_List_Change(sURL){
	if(sURL != ""){
		window.open(sURL);
	}
}

var objBuzzItems;
var iBuzzListSize = 10;
var sBuzzTab = "mostcommented";

function Sidebar_Buzz_ChangeType(sType){
	var sFolder = "/site/images/buzz/";
	var sMostCommentedMode = "off";
	var sMostRecommendedMode = "off";
	var sMostViewedMode = "off";
	sBuzzTab = sType;
	if(sType == "mostcommented") sMostCommentedMode = "on";
	if(sType == "mostrecommended") sMostRecommendedMode = "on";
	if(sType == "mostviewed") sMostViewedMode = "on";
	document.images.imgSidebarBuzz_MostCommented.src = sFolder + "mostcommented-" + sMostCommentedMode + ".jpg";
	document.images.imgSidebarBuzz_MostRecommended.src = sFolder + "mostrecommended-" + sMostRecommendedMode + ".jpg";
	document.images.imgSidebarBuzz_MostViewed.src = sFolder + "mostviewed-" + sMostViewedMode + ".jpg";
	Sidebar_Buzz_Display();
}

function Sidebar_Buzz_Load(){
	var Form = document.forms.frmSidebarBuzz;
	var Layer = document.getElementById("Sidebar_Buzz_Results");
	Layer.innerHTML = "<img src=\"/site/images/ajax-loader2.gif\" align=\"absmiddle\" style=\"margin-right: 5px;\"><strong>Loading...</strong>";
	var sData = "cmd=getbuzz&post_age=" + Form.PostAge.value;
	AJAXRequest("/include/ajax.php", "POST", sData, function(sResponse, aError){
		if(!aError){
			objBuzzItems = eval(sResponse);
			Sidebar_Buzz_Display();
		}
	});
}

function Sidebar_Buzz_Display(){
	var sHTML = "";
	if(sBuzzTab == "mostcommented"){
		objList = objBuzzItems.mostcommented;
	}
	else if(sBuzzTab == "mostrecommended"){
		objList = objBuzzItems.mostrecommended;
	}
	else if(sBuzzTab == "mostviewed"){
		objList = objBuzzItems.mostviewed;
	}
	iListItems = iBuzzListSize;
	if(iListItems > objList.length) iListItems = objList.length;
	for(i=0; i<iListItems; i++){
		sHTML += "<p><a href=\"" + objList[i].url + "\">" + unescape(objList[i].title) + "</a></p><div class=\"line\"></div>";
	}
	var Layer = document.getElementById("Sidebar_Buzz_Results");
	Layer.innerHTML = sHTML;
}

function Sidebar_Buzz_Size(){
	if(iBuzzListSize == 10){
		iBuzzListSize = 20;
		document.getElementById("Sidebar_Buzz_SizeLink").innerHTML = "Less";
	}
	else{
		iBuzzListSize = 10;
		document.getElementById("Sidebar_Buzz_SizeLink").innerHTML = "Expand";
	}
	Sidebar_Buzz_Display();
}

function Sidebar_LatestReviews_Load(){
	var Form = document.forms.frmSidebarLatestReviews;
	var Layer = document.getElementById("Sidebar_LatestReviews_Results");
	var aListingTypes = [];
	for(i=0; i<Form.ListingTypes.length; i++){
		if(Form.ListingTypes[i].checked) aListingTypes.push(Form.ListingTypes[i].value);
	}
	Layer.innerHTML = "<div style=\"margin: 10px;\"><img src=\"/site/images/ajax-loader2.gif\" align=\"absmiddle\" style=\"margin-right: 5px;\"><strong>Loading...</strong></div>";
	var sData = "cmd=load-latest-reviews&types=" + aListingTypes.join(",");
	AJAXRequest("/include/ajax.php", "POST", sData, function(sResponse, aError){
		if(!aError){
			Layer.innerHTML = sResponse;
		}
	});
}

function Sidebar_LatestReviews_ToggleListingTypes(){
	var Form = document.forms.frmSidebarLatestReviews;
	for(i=0; i<Form.ListingTypes.length; i++){
		Form.ListingTypes[i].checked = Form.ToggleListingTypes.checked;
	}
	Sidebar_LatestReviews_Load();
}

function BookmarkPage(sURL, sTitle){
	if(sURL == null){
		sURL = window.location.href;
		sTitle = document.title;
	}
	if(document.all){
		window.external.AddFavorite(sURL, sTitle);
	}
	else{
		alert("Sorry, automatic adding of this page to your favorites is not supported by your web browser.\n\nTo add this page to your favorites, just use the \"Bookmarks\" menu in your browser."); 
	}
	return false;
}

function PrintEntry(iEntryID){
	var sPage = "/print/" + iEntryID;
	var iHeight = 500;
	var iWidth = 700;
	var iLeft = Math.round(screen.width / 2) - Math.round(iWidth / 2);
	var iTop = Math.round(screen.height / 2) - Math.round(iHeight / 2);
	var Popup = window.open(sPage, "", "left=" + iLeft + ",top=" + iTop + ",height=" + iHeight + ",width=" + iWidth + ",scrollbars=1");
	return false;
}

function Sidebar_Links_Category_Change(){
	var Form = $("frmSidebarLinks");
	var objLayer = document.getElementById("Sidebar_Links_Layer");
	if(Form.Category.value != ""){
		objLayer.innerHTML = "<img src=\"/site/images/ajax-loader2.gif\" align=\"absmiddle\" /><strong> Loading...</strong>";
		sData = "cmd=getlinks&category=" + Form.Category.value;
		AJAXRequest("/include/ajax.php", "POST", sData, function(sResponse, aError){
			if(!aError){
				objLayer.innerHTML = sResponse;
			}
		});
	}
	else{
		objLayer.innerHTML = "";
	}
}

function Sidebar_Links_List_Change(sURL){
	if(sURL != ""){
		window.open(sURL);
	}
}

var RecentComments_ItemsPerPage = 3;
var RecentComments_Page = 1;

var MostCommented_ItemsPerPage = 3;
var MostCommented_Page = 1;

function RecentComments_Scroll(iDirection){
	if($$("#recentcomments ul li").length == 0) return;
	RecentComments_Page += iDirection;
	if(RecentComments_Page < 1){
		RecentComments_Page = 1;
		return;
	}
	else if(RecentComments_Page > ($$("#recentcomments ul li").length / RecentComments_ItemsPerPage)){
		RecentComments_Page = 1;
	}
	Position.prepare();
	var iContainerY = Position.cumulativeOffset($("recentcomments"))[1];
	var iPositionY = Position.cumulativeOffset($$("#recentcomments ul li:nth-child(" + (((RecentComments_Page - 1) * RecentComments_ItemsPerPage) + 1) + ")")[0]).top - iContainerY;
	new Effect.Scroll($("recentcomments"), {x:0, y:iPositionY});
}

function MostCommented_Scroll(iDirection){
	if($$("#mostcommented ul li").length == 0) return;
	MostCommented_Page += iDirection;
	if(MostCommented_Page < 1){
		MostCommented_Page = 1;
		return;
	}
	else if(MostCommented_Page > ($$("#mostcommented ul li").length / MostCommented_ItemsPerPage)){
		MostCommented_Page = 1;
	}
	Position.prepare();
	var iContainerY = Position.cumulativeOffset($("mostcommented"))[1];
	var iPositionY = Position.cumulativeOffset($$("#mostcommented ul li:nth-child(" + (((MostCommented_Page - 1) * MostCommented_ItemsPerPage) + 1) + ")")[0]).top - iContainerY;
	new Effect.Scroll($("mostcommented"), {x:0, y:iPositionY});
}

var sCommentOrder = "oldest";

function Entry_Comments_Order(sOrder){
	if(sOrder == sCommentOrder) return;
	if(sOrder == "newest"){
		$("commentorder_oldest").src = "/images/comments-tabs-oldest.gif";
		$("commentorder_newest").src = "/images/comments-tabs-newest-on.gif";
	}
	else if(sOrder == "oldest"){
		$("commentorder_oldest").src = "/images/comments-tabs-oldest-on.gif";
		$("commentorder_newest").src = "/images/comments-tabs-newest.gif";
	}
	sCommentOrder = sOrder;
	if($$("#post_comments .comment").length == 0) return;
	var aComments = $$("#post_comments .comment");
	aComments.reverse();
	var objContainer = document.createElement("div");
	objContainer.id = "post_comments";
	objContainer.className = "container comments";
	for(var i=0; i<aComments.length; i++){
		objContainer.insert($(aComments[i]));
	}
	$("post_comments").replace(objContainer);	
}