﻿function browser_IsIE() {
	return (jQuery.browser.msie);
}
function opacityRemove(oObjRemoveFilter) {
	if (browser_IsIE()) {
		oObjRemoveFilter.get(0).style.removeAttribute('filter');
	}
}
function useGifOverPng() {
	return (browser_IsIE() && jQuery.browser.version < 7);
}
function validateField(oField, sDefault, onSuccessNextValidate) {
	var sVal = oField.val();
	var isValid = (jQuery.trim(sVal).length > 0 && sDefault != sVal);

	if (!isValid) {
		oField.next().html('required').css({ display: 'block' });
	}
	else {
		if (onSuccessNextValidate)
			isValid = onSuccessNextValidate();
		else
			oField.next().css({ display: 'none' });
	}

	return isValid;
}
function validateIsEmail(oField) {
	var isValid = jQuery.trim(oField.val()).match(/^[a-zA-Z0-9].+\@.+\.[a-zA-Z0-9]{2,3}$/);
	if (!isValid) {
		oField.next().html('invalid').css({ display: 'block' });
	}
	else {
		oField.next().css({ display: 'none' });
	}
	return isValid;
}


function initNewsLetterSignup(sEmailId, sPathToRoot, sDefaultText) {
	//jQuery('#social_net_newsletter .input').css({ opacity: 1 });
	jQuery('#social_net_newsletter .ajax_loading').css({ opacity: 0, display: 'none' });
	jQuery('#social_net_newsletter .thanks').css({ display: 'none', opacity: 0, 'background-color': '#FFF' });

	jQuery('#social_net_newsletter .input p a').click(function () {
		submitNewsLetterSignup(sEmailId, sPathToRoot, sDefaultText);
	});
}
function submitNewsLetterSignup(iEmailId, sPathToRoot, sDefaultText) {
	var oEmailField = jQuery('#' + iEmailId);
	if (validateField(oEmailField, sDefaultText, function () { return validateIsEmail(oEmailField); })) {
		jQuery('#social_net_newsletter .input').animate({ opacity: 0 }, { duration: 300, complete: function () {
			jQuery(this).css({ display: 'none' });
			jQuery('#social_net_newsletter .ajax_loading').css({ display: 'block' }).animate({ opacity: 1 }, { duration: 300, complete: function () {
				opacityRemove(jQuery(this));
				var bCanFinish = false;
				setTimeout(function () { bCanFinish = true; }, 1000);

				jQuery.post(sPathToRoot + 'pub/service/newsletter-signup.ashx', { email: oEmailField.val() }, function (data) {
					function finishProcessing() {
						jQuery('#social_net_newsletter .input').animate(
						{ 'margin-right': '-200px' },
						{ duration: 1100, complete: function () {
							jQuery(this).css('display', 'none');
						}
						});

						jQuery('#social_net_newsletter .ajax_loading').animate({ opacity: 0 }, { duration: 300, complete: function () {
							jQuery('#social_net_newsletter .thanks').css({ display: 'block' }).animate({ opacity: 1 }, { duration: 300, complete: function () { opacityRemove(jQuery(this)); } });
							jQuery(this).css({ display: 'none' });
						}
						});
						jQuery('#social_net_newsletter').animate({ 'width': '68px' }, { duration: 900 });
					}


					if (bCanFinish) {
						finishProcessing();
					}
					else {
						setTimeout(function () { finishProcessing(); }, 1000);
					}

				});
			}
			});
		}
		});
	}
	else {
		//Invalid
	}

	
}
function submitContactForm(sPathToRoot, sEmailId, sNameId, sMessageId) {
	var oEmail = jQuery('#' + sEmailId);
	var oName = jQuery('#' + sNameId);
	var oMessage = jQuery('#' + sMessageId);

	var isValid = true;
	if (!validateField(oEmail, '', function () { return validateIsEmail(oEmail); }))
		isValid = false;
	if (!validateField(oName))
		isValid = false;
	if (!validateField(oMessage))
		isValid = false;


	if (isValid) {
		jQuery.post(sPathToRoot + 'pub/service/contact_request.ashx', { email: oEmail.val(), name: oName.val(), message: oMessage.val() }, function (data) {
			jQuery('#contact_column .contact_column').animate(
			{ height: '35px' },
			{ duration: 1100 });
			jQuery('#contact_column .contact_column .contact_input').animate(
			{ opacity: 0 },
			{ duration: 1100, complete: function () {
				jQuery(this).css('display', 'none');
				jQuery('#contact_thanks').css({ display: 'block', opacity: 0 }).animate({ opacity: 1 }, { duration: 1100, complete: function () { opacityRemove(jQuery(this)); } });
			}
			});
		});
	}
	else {
		//Invalid
	}
}
function submitStarbucksForm(sPathToRoot, sOrderId, sNameId, sEmailId, sOrderDefault, sNameDefault, sEmailDefault) {
	var oEmail = jQuery('#' + sEmailId);
	var oName = jQuery('#' + sNameId);
	var oOrder = jQuery('#' + sOrderId);

	var isValid = true;
	if (!validateField(oEmail, sEmailDefault, function () { return validateIsEmail(oEmail); }))
		isValid = false;
	if (!validateField(oName, sNameDefault))
		isValid = false;
	if (!validateField(oOrder, sOrderDefault))
		isValid = false;

	if (isValid) {
		var oThanks = jQuery('#starbucks_thanks').css({ opacity: 0 });
		jQuery('#starbucks fieldset .ajax_loading').css({ display: 'block', opacity: 0 }).animate({ opacity: 1 }, { duration: 300, complete: function () {
			opacityRemove(jQuery(this));
			jQuery.post(sPathToRoot + 'pub/service/starbucks_request.ashx', { order: jQuery('#' + sOrderId).val(), name: jQuery('#' + sNameId).val(), email: jQuery('#' + sEmailId).val() }, function (data) {
				//jQuery('#starbucks fieldset .ajax_loading').css({ display: 'none' });

				jQuery('#starbucks .star_input fieldset *').css({ opacity: 1 }).stop().animate({ opacity: 0 }, { duration: 800, complete: function () {
					oThanks.css({ display: 'block' }).stop().animate({ opacity: 1 }, { duration: 800, complete: function () { opacityRemove(jQuery(this)); } });
				}
				});
			});
		}
		});
	}
}


//Expand SubNav
function slideOutSubNavBox(fnOnComplete) {
	slideOutSubNavInState(fnOnComplete, jQuery('#left_navigation .sub_nav').stop());
}
function slideOutSubNavInState(fnOnComplete, oSubNavInState, altDuration) {

	if (!altDuration)
		altDuration = 600;
	
	if (!jQuery('#left_navigation').hasClass('still_new_load')) {
		oSubNavInState.animate(
			{ width: '400px' },
			{ duration: altDuration, complete: function () { fadeInSubNav(jQuery('#left_navigation .sub_nav .sub_sub_nav ul.current')); } }
		);
	}
}
//Collapse SubNav
function slideInSubNavBox() {
	//Remove all selections
	jQuery('#left_navigation .sub_nav ul.mainlist li').removeClass('hover');
	jQuery('#left_navigation .sub_nav ul.mainlist li.on_ph').removeClass('on_ph').addClass('on');

	var fnOnCompleteExec = function () {
		jQuery('#left_navigation').children('.sub_nav').stop().animate(
			{ width: '203px' },
			{ duration: 500 }
		);
	};

	//When collapsing, all subnavs must be disappeared first
	fadeOutSubNavs(function () { return fnOnCompleteExec(); });
}
//Fade In SubNavList
function fadeInSubNav(sSubNavToFadeInId) {
	var fOnCompleteExec = function () {
		sSubNavToFadeInId.addClass('current').parent().css({ opacity: 0, display: 'block' }).stop().animate(
			{ opacity: 1 },
			{ duration: 100, complete: function () { opacityRemove(jQuery(this)); } }
		);
	};

	//Before fading in, the subnav box must be expanded
	//slideOutSubNavBox(function () { return fOnCompleteExec() });
	fOnCompleteExec();
}
//Fade Out Sub Nav List
function fadeOutSubNavs(fnOnComplete) {
	jQuery('#left_navigation .sub_nav .sub_sub_nav').stop().animate(
		{ opacity: 0 },
		{ duration: 100, complete: function () { jQuery(this).children('ul').removeClass('current'); if (fnOnComplete) { fnOnComplete(); } } }
	);
}
//Register RollOver
function regSubNavRollOver(sListItemId, sSubNavListId) {
	var fnSelectLeftItem = function () {
		jQuery('#left_navigation .sub_nav ul li').removeClass('hover');
		jQuery('#left_navigation .sub_nav ul.mainlist li.on').removeClass('on').addClass('on_ph');
		jQuery('#' + sListItemId).addClass('hover');
	}
	var fnOnHoverComplete = function () {
		//fnSelectLeftItem();
		if (sSubNavListId) {
			jQuery('#' + sSubNavListId).addClass('current');
			//fadeInSubNav(jQuery('#' + sSubNavListId));
		}

	};


	jQuery('#' + sListItemId).hover(
		function () {
			//fnOnHoverComplete();
			if (!jQuery('#left_navigation').hasClass('still_new_load') && !jQuery('#left_navigation').hasClass('on_load_hover')) {
				fnSelectLeftItem();
				fadeOutSubNavs(function () {
					fnOnHoverComplete();
					slideOutSubNavInState(null, jQuery('#left_navigation .sub_nav'), 1);
				});
			}
		},
		function () {
			//
			//fadeOutSubNavs();
		}
	);
}

// Rotating Divs
function initContentRotatingDivs(sMainContainerId) {
	var oContainerDiv = jQuery('#' + sMainContainerId);
	var oStartDiv = oContainerDiv.children('.starton');
	var iStartHeight = oStartDiv.css('height');
	if (!iStartHeight)
		iStartHeight = oStartDiv.height() + 'px';
	oContainerDiv.css({ height: iStartHeight });
	

	oStartDiv.css({ opacity: 1, display: 'block' });
	registerContentRotatingDiv(oStartDiv, oContainerDiv);

	jQuery.each(oStartDiv.siblings(), function () {
		jQuery(this).css({ display: 'none', opacity: 0 });
		registerContentRotatingDiv(jQuery(this), oContainerDiv);
		
	});

	function registerContentRotatingDiv(oRotatingDiv, oContainerDiv) {
		//jQuery('#content_page_1').css({ opacity: 1, display: 'block' });
		var sRotateId = oRotatingDiv.attr('id');
		oRotatingDiv.find('.link_continue a, #preview_click_win').click(function () {
			//jQuery(this).css({ display: 'none' });
			//if (jQuery(this).parent().hasClass('link_continue'))
				oRotatingDiv.find('.link_continue a').css({ display: 'none' });

			var oNextDiv = oRotatingDiv.next();
			if (oNextDiv.attr('id') == null) {
				oNextDiv = oRotatingDiv.siblings('.starton');
			}

			var iChangeHeight = oNextDiv.css('height');
			if (!iChangeHeight)
				iChangeHeight = oNextDiv.height() + 'px';

			oRotatingDiv.stop().animate({ opacity: 0 }, { duration: 1100, complete: function () {
				oContainerDiv.stop().animate({ height: iChangeHeight }, { duration: 1100, complete: function () {
					oRotatingDiv.css({ display: 'none' });
					//jQuery('#link_page_2').css({ display: 'block' });

					oNextDiv.css({ display: 'block' }).stop().animate({ opacity: 1 }, { duration: 1100 }).find('.link_continue a').css({ display: 'block' });
				}
				});
			}
			});
		});
	}
}

//Link_Button RollOvers
function initLinkButtonRollovers() {
	jQuery.each(jQuery("div.link_button"), function () {
		var oDivLink = jQuery(this); //.css({ width: '150px', height: '20px' });
		if (oDivLink.css('position').toLowerCase() != 'absolute')
			oDivLink.css('position', 'relative');
		var oImg = oDivLink.find('img'); //.css({ position: 'absolute', display: 'block' });

		if (oImg.attr('src')) {
			//Src
			var sImgSrc = oImg.attr("src");
			var sRollSrc = sImgSrc.replace(/\_off\.gif$/i, "_on.gif");
			sRollSrc = sRollSrc.replace(/\_off\.jpg$/i, "_on.jpg");

			//Alt
			var sAlt = oImg.attr("alt");

			//Add Hover Image
			var oImgRoll = jQuery(document.createElement("img")).addClass("hoverimg").attr("src", sRollSrc).attr("alt", sAlt).css({ position: 'absolute', top: '0px', left: '0px', opacity: 0 });
			//oDivLink.css({ width: oImgRoll.attr('width') + 'px', height: oImgRoll.attr('height') + 'px' });

			//oDivLink.append('<img style="position: absolute; top: 0px; left: 0px;" src="' + sRollSrc + '" alt="' + sAlt + '" />');
			//oDivLink.append(oImgRoll);
			oImg.parent().append(oImgRoll);

			oDivLink.hover(
			function () {
				oImgRoll.stop().animate({ opacity: 1 }, { duration: 500, complete: function () { opacityRemove(jQuery(this)); } });
			}, function () {
				oImgRoll.stop().animate({ opacity: 0 }, { duration: 500 });
			}
		);
		}
	});
}

//Case Study Expand
function regCaseStudyExpand(sLinkid) {
	var oCaseDiv = jQuery('#cast_study_expand').css({ display: 'none', opacity: 0 });
	//oCaseDiv.css({ display: 'block', opacity: 1 });
	var iDefaultHeight = oCaseDiv.height();
	//oCaseDiv.css();
	jQuery('#' + sLinkid).click(function () {

		jQuery(this).parent().stop().animate({ opacity: 0 }, { duration: 300, complete: function () { jQuery(this).css({ display: 'none' }); } });
		var bExpanded = (oCaseDiv.css('display') == 'block');

		if (bExpanded) {
			//			oCaseDiv.stop().animate({ opacity: (bExpanded) ? 0 : 1 }, { duration: 1100, complete: function () {
			//				oCaseDiv.animate({ height: '1px' }, { duration: 1100, complete: function () {
			//					oCaseDiv.css({ display: 'none' });
			//				} 
			//				});
			//			} 
			//			});
		}
		else {
			oCaseDiv.css({ height: '1px', display: 'block' }).stop().animate({ height: iDefaultHeight + 'px' }, { duration: 1100, complete: function () {
				oCaseDiv.animate({ opacity: (bExpanded) ? 0 : 1 }, { duration: 1100, complete: function () {
					if (!bExpanded)
						opacityRemove(jQuery(this));
				}
				});
			}
			});
		}
	});

}

//Register Client Roll Overs
function initClientRollOvers(sBgColor, sBgHoverColor) {
	if (!sBgColor)
		sBgColor = '#d9f3fb';
	if (!sBgHoverColor)
		sBgHoverColor = '#FFF';

	var oDivContainer = jQuery('#client_logo_banner');

	oDivContainer.find('div.logo div.link_button').css({ opacity: 0 });

	oDivContainer.find('div.logo').hover(function () {
		jQuery(this).find('div.link_button').stop().animate({ opacity: 1 }, { duration: 300 });
		jQuery(this).stop().animate({ 'background-color': sBgHoverColor }, { duration: 100, complete: function () {
			//jQuery(this).find('div.link_button').stop().animate({ opacity: 1 }, { duration: 300 });
		}
		});
	}, function () {
		
		jQuery(this).stop().find('div.link_button').stop().animate({ opacity: 0 }, { duration: 300, complete: function () {
			//oDivContainer.find('div.logo').animate({ 'background-color': '#d9f3fb' }, { duration: 300 });
		}
		});
		oDivContainer.find('div.logo').stop().animate({ 'background-color': sBgColor }, { duration: 300 });
	});
}

//Reg Expanding News
//function regNewsExpander(sExpandingDivId, sClickerId, sCollapseClickerId, iPrefHeight) {
//	
//	sExpandingDivId = '#' + sExpandingDivId;
//	sClickerId = '#' + sClickerId;
//	sCollapseClickerId = '#' + sCollapseClickerId;

//	jQuery(sCollapseClickerId).css({ display: 'none' });

//	if (!iPrefHeight)
//		iPrefHeight = 100;

//	var iOriginalHeight = jQuery(sExpandingDivId).height();
//	if (iOriginalHeight > iPrefHeight) {
//		jQuery(sClickerId).click(function () {
//			jQuery(this).css({ visibility: 'hidden' });
//			jQuery(sExpandingDivId).stop().animate({ height: iOriginalHeight + 'px' }, { duration: 1100, complete: function () {
//				jQuery(sCollapseClickerId).css({ display: 'block' }); 
//			} });
//		});
//		jQuery(sExpandingDivId).css({ height: '100px' });
//		jQuery(sCollapseClickerId).click(function () {
//			jQuery(this).css({ display: 'none' });
//			jQuery(sExpandingDivId).stop().animate({ height: iPrefHeight }, { duration: 1100, complete: function () {
//				jQuery(sClickerId).css({ visibility: 'visible' });
//			} });
//		});
//	}
//	else {
//		jQuery(sClickerId).css({ visibility: 'hidden' });
//	}
//}
//Reg Expanding News Items In Container
function regNewsExpander(sNewsContainerId, iPrefHeight, onFadeIn, sOuterContainerId, sScrollKey) {
	
	var oNewsContainer = jQuery('#' + sNewsContainerId);
	if (sOuterContainerId)
		oNewsContainer = jQuery('#' + sOuterContainerId);

	//Loading
	oNewsContainer.find('.page_ajax_loading').css({ opacity: 1, height: oNewsContainer.height() + 'px' });

	if (!iPrefHeight)
		iPrefHeight = 100;

	var iCountEntries = jQuery('#' + sNewsContainerId + ' div.entry').length;
	var arrLoadings = [];

	var bNone = true;
	
	function checkImagesLoaded(oImageContainerToCheck) {
		var bLoaded = true;
		jQuery.each(oImageContainerToCheck.find('img'), function (index, value) {
			if (!value.complete)
				bLoaded = false;
		});
		return bLoaded;
	}
	var bNone = true;
	jQuery.each(jQuery('#' + sNewsContainerId + ' div.entry'), function (index, value) {
		var oExpandingDiv = jQuery(this).find('div.expanding');
		var oClicker = jQuery(this).find('a.expander');
		var oCollpaser = jQuery(this).find('a.collapser');

		function setTimedImageCheck(oImageContainerToChec, iPrefHeight, oClicker, oLinks, oCollpaser, oNewsContainer) {
			setTimeout(function () {
				if (checkImagesLoaded(oImageContainerToChec)) {
					processExpansion(oImageContainerToChec, iPrefHeight, oClicker, oLinks, oCollpaser, oNewsContainer);
				}
				else
					setTimedImageCheck(oImageContainerToChec, iPrefHeight, oClicker, oLinks, oCollpaser, oNewsContainer);
			}, 500);
		}

		var oLinks = jQuery(this).find('.links');
		if (!checkImagesLoaded(oExpandingDiv)) {
			bNone = false;
			setTimedImageCheck(oExpandingDiv, iPrefHeight, oClicker, oLinks, oCollpaser, oNewsContainer);
		}
		else {
			if (!processExpansion(oExpandingDiv, iPrefHeight, oClicker, oLinks, oCollpaser, oNewsContainer))
				bNone = false;
		}
	});
	if (sScrollKey) {
		var oScrollTo = jQuery(sScrollKey);
		if (oScrollTo.length) {
			//alert(oScrollTo.scrollTop());
			//alert(oScrollTo.scrollTop());
			jQuery('html').scrollTop(oScrollTo.offset().top);
			oScrollTo.find('a.expander').trigger('click');
		}
	}
	if (bNone)
		setTimeout(function () { finishLoadingAndDisplay(oNewsContainer, true, sScrollKey); }, 1000);
	else {
		setTimeout(function () { finishLoadingAndDisplay(oNewsContainer, true, sScrollKey); }, 5000);
		//Fail safe
	}
}
//News Final Display
function finishLoadingAndDisplay(oNewsContainer, bForce, sScrollKey) {
	var bGoodToGo = true;
	var iCount = 0;
//	jQuery.each(arrLoadings, function (index, value) {
//		if (!value) {
//			bGoodToGo = false;
//		}
//		iCount++;
//	});
	//if (bGoodToGo && iCount >= iCountEntries || bForce) {
	if (bGoodToGo) {
		if (oNewsContainer.find('.page_ajax_loading').css('opacity') == 1) {
			oNewsContainer.find('.loading').css({ visibility: 'visible' });
			oNewsContainer.find('.page_ajax_loading').stop().animate({ opacity: 0 }, { duration: 800, complete: function () { jQuery(this).css({ display: 'none' }); } });
		}
	}
}
// Actual Expander Registration
function processExpansion(oExpandingDiv, iPrefHeight, oClicker, oLinks, oCollpaser, oNewsContainer) {
		var iOriginalHeight = oExpandingDiv.height();
		var bSmall = iOriginalHeight <= iPrefHeight;
		
		if (!bSmall) {	
	//*****************************
		oClicker.click(function () {
			jQuery(this).css({ display: 'none' });
			if (oLinks)
				oLinks.css({ display: 'none' });
			oExpandingDiv.stop().animate({ height: iOriginalHeight + 'px' }, { duration: 1100, complete: function () {
				oCollpaser.css({ display: 'block' });
				if (oLinks)
					oLinks.css({ display: 'block' });
			}
			});
		});
		oExpandingDiv.stop().animate({ height: iPrefHeight + 'px' }, { duration: 1300, complete: function () {
			//arrLoadings[index] = true;
			finishLoadingAndDisplay(oNewsContainer);
//			setTimeout(function () { finishLoadingAndDisplay(true); }, 5000);
//								oNewsContainer.find('.loading').css({ visibility: 'visible' });
//								oNewsContainer.find('.page_ajax_loading, .page_ajax_loading *').stop().animate({ opacity: 0 }, { duration: 800, complete: function() { jQuery(this).css({ display: 'none' }); } });
//								if (onFadeIn)
//									onFadeIn();
		}
		});
		oCollpaser.click(function () {
			jQuery(this).css({ display: 'none' });
			if (oLinks)
				oLinks.css({ display: 'none' });
			oExpandingDiv.stop().animate({ height: iPrefHeight }, { duration: 1100, complete: function () {
				oClicker.css({ display: 'block' });
				if (oLinks)
					oLinks.css({ display: 'block' });
			}
			});
	});
		}
		else
			oClicker.css({ visibility: 'hidden' });
	return bSmall;
}


//Reg Blog Share/Tweet Links
function regSocialMediaLinks(sContainerSearchPattern, sUrlToUse) {
	jQuery(sContainerSearchPattern).each(function () {
		var sTitle = jQuery(this).find('h2 a').text();
		var sUrl = jQuery(this).find('h2 a').attr('href');
		//Facebook
		jQuery(this).find('a.fb').attr('target', '_blank').attr('href', 'http://www.facebook.com/sharer.php?u=' + jQuery.URLEncode(sUrl) + '&t=' + jQuery.URLEncode(sTitle));
		jQuery(this).find('a.tw').attr('target', '_blank').attr('href', 'http://twitter.com/share?url=' + jQuery.URLEncode(sUrl) + '&via=ink_la&text=' + jQuery.URLEncode(sTitle));
	});
}

//Get News List
function getNewsList(sResourceFeed, sDivToAddItemsTo, iPageNumber, iItemsPerPage, sPathToRoot, sOuterLoadingId, iPrefHeight, onFinishLoading, sScrollKey) {
	var oDivToAddItemsTo = jQuery('#' + sDivToAddItemsTo);

	jQuery.post(sResourceFeed, { 'iPageIndex': iPageNumber - 1, iItemCount: iItemsPerPage }, function (data) {
		var sHtml = setPathToRoot(data, sPathToRoot);
		//alert(sHtml.substr(0, 100));
		function fadeIn() {
			oDivToAddItemsTo.parent().stop().animate({ opacity: 1 }, { duration: 600, complete: function () {
				opacityRemove(jQuery(this));
			}
			});
		}
		oDivToAddItemsTo.html(sHtml);
		initLinkButtonRollovers();
		if (onFinishLoading)
			onFinishLoading(oDivToAddItemsTo, sPathToRoot);



		//oDivToAddItemsTo.parent().stop().animate({ opacity: 1 }, { duration: 600, complete: function () { ; regNewsExpander(sDivToAddItemsTo); } });
		regNewsExpander(sDivToAddItemsTo, iPrefHeight, function () {
			//fadeIn();  
		}, sOuterLoadingId, sScrollKey);
	});
}
//function FinishLoadingBlogs(oContainer, sPathToRoot) {

//}


//Get Blog List -- just use normal use
//function getBlogList(sResourceFeed, sDivToAddItemsTo, iPageNumber, iItemsPerPage, sPathToRoot, sOuterLoadingId) {
//	var oDivToAddItemsTo = jQuery('#' + sDivToAddItemsTo);
//	
//	jQuery.post(sResourceFeed, { 'iPageIndex': iPageNumber - 1, iItemCount: iItemsPerPage, PathToRoot: sPathToRoot }, function (data) {
//		var sHtml = setPathToRoot(data, sPathToRoot);
//		function fadeIn() {
//			oDivToAddItemsTo.parent().stop().animate({ opacity: 1 }, { duration: 600, complete: function () { opacityRemove(jQuery(this)) } });
//		}
//		oDivToAddItemsTo.html(sHtml);
//		//oDivToAddItemsTo.parent().stop().animate({ opacity: 1 }, { duration: 600, complete: function () { ; regNewsExpander(sDivToAddItemsTo); } });
//		regNewsExpander(sDivToAddItemsTo, 60, function () {
//			//fadeIn(); 
//		}, sOuterLoadingId);
//	});
//}

//Register Pager
function regPager(sResourceFeed, sDivToAddItemsTo, iItemsPerPage, sPathToRoot, sOuterContainerId, iPrefHeight, onFinishLoadingEntry) {
	var oPagerList = jQuery('div.list_pager ul');

	jQuery.each(oPagerList.children('li'), function (index, value) {
		jQuery(this).hover(
			function () {
				if (!jQuery(this).hasClass('on')) {
					jQuery(this).stop().animate({ 'background-color': '#00bce4', color: '#FFF' }, { duration: 300 });
				}
			},
			function () {
				if (!jQuery(this).hasClass('on')) {
					jQuery(this).stop().animate({ 'background-color': '#d9f3fb', color: '#00bce4' }, { duration: 300 });
				}
			}).click(function () {
				if (!jQuery(this).hasClass('on')) {
					jQuery(this).siblings('li.on').removeClass('on').stop().animate({ 'background-color': '#d9f3fb', color: '#00bce4' }, { duration: 300 });

					jQuery(this).addClass('on');

					//Fade Out Current News
					var oCurrNews = jQuery('#' + sDivToAddItemsTo);
					var oCurrListItem = jQuery(this);
					var iPageChangeIndex = oCurrListItem.html();
					//alert(iPageChangeIndex);
					//oCurrNews.parent().stop().animate({ opacity: 0 }, { duration: 600, complete: function () {
					jQuery('html').stop().animate({ scrollTop: '1px' }, { duration: 600, complete: function () {
						jQuery(window).scrollTop('1px');
						jQuery('#' + sOuterContainerId + ' .page_ajax_loading').css({ display: 'block' }).stop().animate({ opacity: 1 }, { duration: 600, complete: function () {
							getNewsList(sResourceFeed, sDivToAddItemsTo, iPageChangeIndex, iItemsPerPage, sPathToRoot, sOuterContainerId, iPrefHeight, onFinishLoadingEntry);
						}
						});
					}
					});


				}
			});
	});
}

//Anchor Checker
function regTextLineLength(sAnchorId) {
	var oAnchor = jQuery('#' + sAnchorId);
	var sStartText = oAnchor.text();
	var sNewText = '';

	var iIndex = 0;
	var iBuffer = 60;
	var iRemaining = sStartText.length;
	while (iRemaining > iBuffer) {
		sNewText += sStartText.substr(iIndex, iBuffer);
		sNewText += ' ';
		iRemaining -= iBuffer;
		iIndex += iBuffer;
	}
	if (iRemaining > 0) {
		sNewText += sStartText.substr(iIndex, iRemaining);
	}

	oAnchor.text(sNewText);
}

//Banner Rotator
function initBannerRotator(sContainerId) {
	var oBannerContainer = jQuery('#' + sContainerId);

	var sHideDirection = 'margin-top';
	var sShowDirection = 'margin-bottom';

	var iNumBanners = oBannerContainer.children('.rotating').css({ display: 'none', width: '687px', 'margin-top': '687px' }).length;

	//Auto Rotate
	function autoSlide() {
		var aPlayer = jQuery('.flowplayer');
		if (!aPlayer.length || !aPlayer.hasClass('playing')) {
			//Fade Current
			oBannerContainer.children('.selected').animate({ 'margin-top': '-687px' }, { duration: 800, complete: function () {
				var oNextSib = jQuery(this).removeClass('selected').css({ display: 'none' }).next();
				if (!oNextSib.is('.rotating'))
					oNextSib = oBannerContainer.children(':first-child');
				oNextSib.css({ 'margin-top': '687px', display: 'block' }).addClass('selected').animate({ 'margin-top': 0 }, { duration: 800 });
			}
			});
		}

		setTimeout(autoSlide, 5000);
	};
	autoSlide();
	oBannerContainer.children(':first-child').addClass('selected').css({ display: 'block', 'margin-top': 0, 'margin-bottom': 0 });

	//Make Pager
}
//Banner Scroller
function initBannerScroller(sContainerId) {
	var oBannerContainer = jQuery('#' + sContainerId);
	var oScrollingContainer = oBannerContainer.children('.scroller');

	var iHeight = '418px';
	var iWidth = '687px';
	var iAnimationSpeed = 1100;
	var iDelay = 8000;

	var iNumBanners = oScrollingContainer.children('.rotating').css({ display: 'block', height: 'iHeight', width: '687px', 'margin-top': 0 }).length;
	var oPagerList = oBannerContainer.children('div.pager').children('ul');

	//Auto Rotate
	function autoSlide() {
		//Slide Scroller
		var aPlayer = jQuery('.flowplayer');
		if (true && (!aPlayer.length || !aPlayer.hasClass('playing'))) {
			oScrollingContainer.stop().animate({ 'margin-top': '-' + iHeight }, { duration: iAnimationSpeed, complete: function () {
				//			//Scroller Moved Up -- Push item to bottom, reset margin-top
				//			var oNextSib = jQuery(this).children('.selected').removeClass('selected').css({ display: 'none', 'margin-top': iHeight }).next();
				//			if (!oNextSib.is('.rotating'))
				//				oNextSib = oScrollingContainer.children(':first-child');
				//			//oNextSib.css({ 'margin-top': '687px', display: 'block' }).addClass('selected').animate({ 'margin-top': 0 }, { duration: 800 });
				//			oNextSib.css({ display: 'block' }).addClass('selected').animate({ 'margin-top': 0 }, { duration: 800 });

				var oCurrent = jQuery(this).css({ 'margin-top': 0 }).children('.selected');
				var oNextSib = oCurrent.next().addClass('selected');
				//			if (!oNextSib.is('.rotating'))
				//				oNextSib = oScrollingContainer.children(':first-child');

				oCurrent.removeClass('selected').appendTo(jQuery(this)).css({ display: 'block' });
			}
			});

			//Advance Pager
			var oNextPage = oPagerList.children('li.on').removeClass('on').prev();
			if (!oNextPage.is('li'))
				oNextPage = oPagerList.children(':last-child');
			oNextPage.addClass('on');
		}

		setTimeout(autoSlide, iDelay);
	};

	//Make Pager
	for (var iPage = 0; iPage < iNumBanners; iPage++) {
		var oPageLI = jQuery(document.createElement('li')).html('.');
		if (iPage == 0)
			oPageLI.addClass('on');

		oPagerList.prepend(oPageLI);
	}

	//autoSlide();
	setTimeout(autoSlide, iDelay);
	oScrollingContainer.children(':first-child').addClass('selected').css({ display: 'block', 'margin-top': 0, 'margin-bottom': 0 });


}

function regEmailThisPageAnchor(sSubject, sBody) {
	jQuery('a.email_this_link').attr('href', 'mailto:?subject=' + sSubject + '&body=' + sBody);
}
function regSingleEmailThisPageAnchor(sClientId, sSubject, sBody, sTo) {
	jQuery('#' + sClientId).attr('href', 'mailto:' + sTo + '?subject=' + sSubject + '&body=' + sBody);
}

function getLightBoxConfigSettings(sPathToRoot) {
	return (
	{
		overlayBgColor: '#CCC',
		overlayOpacity: 0.6,
		imageLoading: sPathToRoot + 'ui/image/lightbox/loading.gif',
		imageBtnClose: sPathToRoot + 'ui/image/lightbox/close.gif',
		imageBtnPrev: sPathToRoot + 'ui/image/lightbox/prev.gif',
		imageBtnNext: sPathToRoot + 'ui/image/lightbox/next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Image',
		txtOf: 'of'
   });
}

//Expand Comments
function regCommentExpander(sId, sPathToRoot) {
	var oCommContainer = jQuery('#blog_' + sId);

	//Set Fields
	var oEmail = oCommContainer.find('.txtEmail');
	var sEmailDefault = oEmail.val();
	var oName = oCommContainer.find('.txtName');
	var sNameDefault = oName.val();
	var oComments = oCommContainer.find('.txtComments');
	var sCommentsDefault = oComments.val();
	setDefaultTextBoxToggle(oEmail, function () { validateIsEmail(oEmail); });
	setDefaultTextBoxToggle(oName);
	setDefaultTextBoxToggle(oComments);

	//Reg Submission Click
	oCommContainer.find('.link_button a').click(function () {
		//Validation
		var isValid = true;
		if (!validateField(oEmail, sEmailDefault, function () { return validateIsEmail(oEmail); }))
			isValid = false;
		if (!validateField(oName, sNameDefault))
			isValid = false;
		if (!validateField(oComments, sCommentsDefault))
			isValid = false;
		if (isValid) {

			oCommContainer.find('.ajax_loading').css({ display: 'block', opacity: 0 }).stop().animate({ opacity: 1 }, { duration: 300, complete: function () {
				opacityRemove(jQuery(this));
				jQuery.post(sPathToRoot + 'pub/service/blog_comment.ashx', { email: oEmail.val(), name: oName.val(), comments: oComments.val(), key: sId }, function (data) {

					oCommContainer.find('fieldset *').css({ opacity: 1 }).stop().animate({ opacity: 0 }, { duration: 400, complete: function () {


					}
					});
					oCommContainer.find('.comment_thanks').css({ opacity: 0, display: 'block' }).stop().animate({ opacity: 1 }, { duration: 700, complete: function () { opacityRemove(jQuery(this)); } });
				});
			}
			});
		}
	});
	//End Reg Click

	//Set Click Expand
	var sOriginalHeight = oCommContainer.height() + 'px';
	oCommContainer.css({ height: '1px' });
	jQuery('#comm_' + sId).click(function () {
		oCommContainer.css({ display: 'block' }).animate({ height: sOriginalHeight }, { duration: 800 });
	});
}


//Text replace
function setTextBoxToggle(sBoxId, sDefaultValue, onBlurValidate) {
	jQuery('#' + sBoxId).focus(function () {
		if (sDefaultValue && sDefaultValue.length > 0)
			if (jQuery(this).val() == sDefaultValue) { jQuery(this).val(''); }
		var oError = jQuery(this).next();
		if (oError)
			oError.css({ display: 'none' });
	}).blur(function () {
		if (jQuery(this).val() == '') { jQuery(this).val(sDefaultValue); }
		else {
			if (onBlurValidate)
				onBlurValidate();
		}
	});
}
function setDefaultTextBoxToggle(oBoxObject, onBlurValidate) {
	var sDefaultValue = oBoxObject.val();
	oBoxObject.focus(function () {
		if (sDefaultValue && sDefaultValue.length > 0)
			if (jQuery(this).val() == sDefaultValue) { jQuery(this).val(''); }
		var oError = jQuery(this).next();
		if (oError)
			oError.css({ display: 'none' });
	}).blur(function () {
		if (jQuery(this).val() == '') { jQuery(this).val(sDefaultValue); }
		else {
			if (onBlurValidate)
				onBlurValidate();
		}
	});
}

//Clean Root
function setPathToRoot(sInput, sPathToRoot) {
	//%%PATH_TO_ROOT%%
	return sInput.replace(/\%\%PATH\_TO\_ROOT\%\%/gi, sPathToRoot);
}
