$('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 flashEvent( eventtype, assetname, swfname )
{
	/*
	logItem('  ev: ' + eventtype + 
			', an: ' + assetname +
			', sn: ' + swfname); */
	trackEvent('/event/flash/' + eventtype.toUpperCase() + assetname);
}



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 = DKO.mcrdkolbe;
					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)
		{
			//call internal (for DKO) WebTrends tracking
			dcsMultiTrack("DCS.dcssip", DCS.dcssip, "DCS.dcsuri", window.location.pathname+eventid, "WT.ti", eventid);
		}
	}
	catch(err0) 
	{
		try
		{
			if ( console )
			{
				console.error("track EVENT:=" + eventid + "FAILED!!! - " + err0);
			}
		}
		catch(err0a) {}
	}
	
	try
	{
		if ( console )
		{
			console.log("trackEvent called for Event ID:=" + eventid);
		}
	}
	catch(err1) {}
	
	
}


/* 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;
	}
});

$(document).ready(function () 
{

	//BEGIN - initialize click tracking
	$('#content a').click( function(evt) {
		var $t = $(this);
		var evtType = ($t.hasClass('button')||$t.hasClass('reimg') ? 'button' 
							: ($t.hasClass('callout') ?  'callout' 
							: ($t.hasClass('trkoffsite') ?  'OFFSITE' 
							: ($t.hasClass('trkdownload') ? 'DOWNLOAD' 
							: 'link'))));
							
		var targId = $t.closest('[id]').attr('id');
		trackEvent('/event/html/' + evtType + '/TO/' + targId);
	});
	
	$('#navContent a.link, #navContent #navControl a, #navContent li li a').click( function(evt) {
		var $t = $(this);
		var evtType = 'navigation';
		var targId = $t.closest('[id]').attr('id');
		trackEvent('/event/html/' + evtType + '/TO/' + targId);
	});
	
	$('#footer a').click( function(evt) {
		trackEvent('/event/html/footer/TO/' + $(this).attr('id'));
	});
	
	//E=N=D - initialize click tracking



	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 "oNavInfo.sslLocation" variable is set in html-head.jsp								
			document.getElementById("contact-us").src = oNavInfo.sslLocation + "/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();
		});
	}

});