$('html').addClass('js');
//log message to console (instead of alert).  works in Firebug
function logItem(msg)
{
	if ( window.console )
	{
		try
		{
			console.log(msg);
		}
		catch(cErr) {}
	}
}

//simple little "SJAX" function.  should be switched over to jQuery when able
function getFile(url) 
{
	if (window.XMLHttpRequest) {
		AJAX=new XMLHttpRequest();
	} else {
		AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX) {
		AJAX.open("GET", url, false);
		AJAX.send(null);	
		return AJAX.responseText;
	} else {
		return false;  
	}
}

function playerEvent( evntid )
{
	logItem("playerEvent() called with: " + evntid);
	if ( $.jqm  )
	{
		$('.tomCWrapper').jqmHide();
	}
}

function flashLink(pageCode)
{
	if (pageCode)
	{
		var flashLinkPage = "#";
		var bNewWindow = false;
		var eventCode = "/event/flash";
		switch(pageCode)
		{
			case 'SS':  //================================================================= SS  = Style Series
					flashLinkPage = '/styleseries/?ref=rd';
					eventCode += '/callout/TO/styleseries';
					break;
			case 'SL':  //================================================================= SL  = Show Your Love
					flashLinkPage = '/reddress/get-involved/show-your-love.jsp';
					eventCode += '/can/TO/showlove';
					break;
			case 'SW':  //================================================================= SW  = Spread the Word
					flashLinkPage = '/reddress/get-involved/spread-the-word.jsp';
					eventCode += '/can/TO/spreadword';
					break;
			case 'MCR': //================================================================= MCR = My Coke Rewards
					bNewWindow = true;
					flashLinkPage = 'http://www.mycokerewards.com/index.jsp?WT.mc_id=SOURCEREG:DIETCOKE&adParam=1#windowType:brand/id:2';
					eventCode += '/heart/TO/supportCampaign';
					break;
			case 'CS':  //================================================================= CS  = Charmed Sweeps
					flashLinkPage = '/reddress/sweepstakes/';
					eventCode += '/can/TO/charmsweeps';
					break;
		}
		
		trackEvent(eventCode);
		
		if (bNewWindow) {
			window.open(flashLinkPage);
		} else {	
			location.href = flashLinkPage;
		}
	}
		
}

//called from Flash for any event that somebody wants tracked...
//for DKO WebTrends and SearchRev "search pixels" and SMG Floodlight tags and...
function trackEvent(eventid)
{
	try
	{
		if (eventid)
		{
			//first, call internal (for DKO) WebTrends tracking
			dcsMultiTrack("DCS.dcssip", DCS.dcssip, "DCS.dcsuri", window.location.pathname+eventid, "WT.ti", eventid);
	
			/*		
			//following code is for dynaically firing DoubleClick Floodlight tags and SearchRev pixels.
			var catID  = null;
			var srPage = null;
			var srAmnt = 0;
			var type   = "dietc255";  //default
			var rndOrd = Math.floor(Math.random()*100000000);
			switch(eventid)
			{
				case 'watch_tab_clicked':         catID = "dietc547"; srAmnt = "1"; srPage = "StyleSeriesWatch";  break; // 1 = watch
				case 'invite_form_initiated':     catID = "dietc339"; srAmnt = "2"; srPage = "StyleSeriesInvite"; break; // 2 = invite
				case 'main_share_button_clicked': catID = "style037"; srAmnt = "3"; srPage = "StyleSeriesShare";  break; // 3 = share
				case 'invite_email_sent':         catID = "style974"; break; // 4 = invite success
				case 'more_panel_opened':         catID = "dietc724"; break; // 5 = more		
			}	
			
			if (srPage)
			{
				var searchRevTag = new Image();
				searchRevTag.src = "http://s1.srtk.net/www/delivery/ti.php?trackerid=517&cb=42229&_sr_amount=" + 
						srAmnt + "&_sr_page=" + srPage + "&ord=" + rndOrd;
			}
			*/
		}
		
		logItem("trackEvent called for Event ID:=" + eventid);
	}
	catch(Err) {}
}


/* Copyright (c) 2006-2007 Mathias Bank (http://www.mathias-bank.de)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Version 2.1
 */
jQuery.fn.extend({
/**
* Returns get parameters.
* If the desired param does not exist, null will be returned
* To get the document params:
* @example value = $(document).getUrlParam("paramName");
* To get the params of a html-attribut (uses src attribute)
* @example value = $('#imgLink').getUrlParam("paramName");
*/ 
 getUrlParam: function(strParamName){
	  strParamName = escape(unescape(strParamName));
	  
	  var returnVal = new Array();
	  var qString = null;
	  
	  if ($(this).attr("nodeName")=="#document") {
	  	//document-handler
		
		if (window.location.search.search(strParamName) > -1 ){
			
			qString = window.location.search.substr(1,window.location.search.length).split("&");
		}
			
	  } else if ($(this).attr("src")) {
	  	
	  	var strHref = $(this).attr("src")
	  	if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	  		qString = strQueryString.split("&");
	  	}
	  } else if ($(this).attr("href")) {
	  	
	  	var strHref = $(this).attr("href")
	  	if ( strHref.indexOf("?") > -1 ){
	    	var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	  		qString = strQueryString.split("&");
	  	}
	  } else {
	  	return null;
	  }

	  if (qString==null) return null;
	  
	  for (var i=0;i<qString.length; i++){
			if (escape(unescape(qString[i].split("=")[0])) == strParamName){
				returnVal.push(qString[i].split("=")[1]);
			}		
	  }	  
	  if (returnVal.length==0) return null;
	  else if (returnVal.length==1) return returnVal[0];
	  else return returnVal;
	}
});

$().ready(function() {

	if ($.jqm) {
	
		var myClose = function(hash) {
			hash.w.hide();
			hash.o.hide();
	 		$('div#iframeForms').hide();
		};

		var myOpen = function(hash) {
			hash.w.show();
			hash.o.show();
	 		$('div#iframeForms').show();
		};

		$('.jqmWindow,#contact-us,#share-it').jqm({onShow:myOpen,onHide:myClose});
	
		$('a#ftrSM').click(function() {
			$('.jqmWindow div').html('');
			$('.jqmWindow div').load('/inc/jsp/sitemap.jsp');
			$('.jqmWindow').jqmShow();
			return false;
		});	
	
		$('a#ftrToU').click(function() {
			$('.jqmWindow div').html('');
			$('.jqmWindow div').load('/inc/jsp/terms-of-use.jsp');
			$('.jqmWindow').jqmShow();
			return false;
		});	
	
		$('a#ftrPP, a#ssPPFormLink').click(function() {
			$('.jqmWindow div').html('');
			$('.jqmWindow div').load('/inc/jsp/privacy-policy.jsp');
			$('.jqmWindow').jqmShow();
			return false;
		});	
	
		$('a#calendarNav').click(function() {			
			$('.jqmWindow div').html('');
			$('.jqmWindow div').load('/inc/jsp/calendar-of-events.jsp');
			$('.jqmWindow').jqmShow();
			return false;
		});
		
		$('a#smartEatingTips').click(function() {			
			$('.jqmWindow div').html('');
			$('.jqmWindow div').load('/inc/jsp/smart-eating-tips.jsp');
			$('.jqmWindow').jqmShow();
			return false;
		});
		
		$('a#ftrCU').click(function() {	
			//The "loc" variable is set in the page-layout.jsp page								
			document.getElementById("contact-us").src= loc + "/ssldocs/contact-us.jsp";
			$('div#iframeForms p#closeBtn').show();
			$('iframe#contact-us').jqmShow();
			return false;
		});	

		$('a#shareIt').click(function() {
			document.getElementById("share-it").src="/share-it.jsp";
			$('iframe#share-it').jqmShow();
			$('div#iframeForms p#closeBtn').show();
			return false;
		});
		
		$('div#iframeForms p#closeBtn').click(function() {
			$('iframe#share-it, iframe#contact-us, .jqmWindow').jqmHide();
		});
	}

});