/**
 * DrPepper.Site
 *
 * Global functionality for Dr Pepper site.
 *
 * Author:	Silvan Reinhold
 * Date:	2009-03-03
 **/

var DrPepper = DrPepper || {};

DrPepper.Site = {};

DrPepper.Site.LINKTYPE_NONE			= -1;
DrPepper.Site.LINKTYPE_SELF			=  0;
DrPepper.Site.LINKTYPE_NEWWINDOW	=  1;
DrPepper.Site.LINKTYPE_POPUP		=  2;
DrPepper.Site.LINKTYPE_DOWNLOAD		=  3;
DrPepper.Site.LINKTYPE_VIDEO		=  4;

/**
 * Performs an action for the given link, according to the specified LINKTYPE
 *
 * @param	p_xParams	Parameter hash (specific parameters depend on link type)
 */
DrPepper.Site.performLinkAction = function(p_xParams)
{
	switch (p_xParams.linkType)
	{
		// LINKTYPE_VIDEO shows a video on the Video page. Parameters:
		//
		// applicationUrl
		// url
		// stillUrl
		// title
		// addedDate
		//
		case DrPepper.Site.LINKTYPE_VIDEO:
			// Scroll to top and play video
			//
			$(document).scrollTo(
				0,
				500,
				{
					onAfter: function()
					{
						DrPepper.VideoController.playVideo(
							"#videoplayer-container",
							"#videoplayer-info",
							DrPepper.Util.urlDecode(p_xParams.applicationUrl),
							DrPepper.Util.urlDecode(p_xParams.url),
							DrPepper.Util.urlDecode(p_xParams.stillUrl),
							DrPepper.Util.urlDecode(p_xParams.categoryTitle),
							DrPepper.Util.urlDecode(p_xParams.title),
							DrPepper.Util.urlDecode(p_xParams.addedDate)
						); 
					} 
				}
			);			
			break;

		// LINKTYPE_POPUP opens link in popup window. Parameters:
		//
		// url
		// params	popup window parameters (optional)
		//
		case DrPepper.Site.LINKTYPE_POPUP:
			var l_sWindowParameters = p_xParams.params;
			if (!l_sWindowParameters) {
				l_sWindowParameters = "menubar=0,toolbar=0,location=0,status=0,scrollbars=0";
			}
			var l_xPopup = window.open(DrPepper.Util.urlDecode(p_xParams.url), "drpepperpopup", l_sWindowParameters);
			try {
				if (l_xPopup && l_xPopup.moveTo) {
					l_xPopup.moveTo(32, 32);
				}
			}
			catch (e) {}
			break;
			
		// LINKTYPE_DOWNLOAD and LINKTYPE_NEWWINDOW open link in new window. Parameters:
		//
		// url
		//
		case DrPepper.Site.LINKTYPE_DOWNLOAD:
		case DrPepper.Site.LINKTYPE_NEWWINDOW:
			window.open(DrPepper.Util.urlDecode(p_xParams.url));
			break;
		
		// LINKTYPE_SELF opens link in current window/tab. Parameters:
		//
		// url
		//
		case DrPepper.Site.LINKTYPE_SELF:
		default:
			document.location.href = DrPepper.Util.urlDecode(p_xParams.url)
			break;
	}
}
