var MSLO = {};

/* getDay, genGuid, S4, getGUID are added for tracking purpose */
function getDay()
{
	var currentTime = new Date() ;
	var mm = currentTime.getMonth() + 1 ;
	var dd   = currentTime.getDate() ;
	var yyyy  = currentTime.getFullYear() ;	
	return ( yyyy+''+mm+''+dd );
}

function S4() 
{
    return (((1+Math.random())*128)|0).toString(16);
}

function genGuid()
{        
    return  (S4()+S4()+S4()+S4()+S4()+S4()+S4()+S4()).toUpperCase();
}

// yyyymmdd + 16 digit HEX numbers
function getGUID()
{
    return getDay()+''+genGuid(); 
}



/* addLoadEvent for multiple onload functions */

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

MSLO.toggleContent = Class.create();

MSLO.toggleContent.prototype = {
	initialize: function(elem) {
		this.elem = elem;
		this.anchors = $(this.elem).getElementsByTagName('a');
		this.old = 0;
		this.hrefs = [];
		for(var i=0; i<this.anchors.length; i++) {
			Event.observe(this.anchors[i], 'click', this.toggle.bind(this,i), false);
			var href = this.anchors[i].getAttribute('href').split('#')[1];
			this.hrefs.push(href);
		}
	},
	toggle: function(elem,e) {
		Event.stop(e);
		if(this.old == elem) return; 
		$(this.hrefs[elem]).addClassName('current');
		this.anchors[elem].ancestors()[0].addClassName('active');
		$(this.hrefs[this.old]).removeClassName('current');
		this.anchors[this.old].ancestors()[0].removeClassName('active');
		this.old = elem;
	}
}

Event.observe(window, 'load', function() { 
	if($('related_list_nav'))
	new MSLO.toggleContent('related_list_nav'); 
});

MSLO.collageModule = Class.create();
MSLO.collageModule.prototype = {
	initialize: function(elem) {
		this.elem = elem;
		this.imgs = $$('#' + this.elem + ' img'.toString());
		this.destitation = $$('#' + this.elem + ' .collageTitle p'.toString())[0];
		this.imgs.each(function(s) {
			Event.observe(s,'mouseover',this.show.bind(s,this.destitation));
			Event.observe(s,'mouseout',this.hide.bind(s,this.destitation));										
		}.bind(this));
	},
	show: function(destitation) {
		destitation.update(this.title);
		this.addClassName('hover');
	},
	hide: function(destitation) {
		this.removeClassName('hover');
		destitation.update('&nbsp\;');
	}
};

function collageModuleInit() {
	var collage = $$('.collage');
	if(!collage) return;
	collage.each(function(s,index) {
		var collageId = function() {
			collage[index].id = 'collage'+index;
			return collage[index].id;
		}();
		new MSLO.collageModule(collageId);
	});
}

MSLO.dropdown = function() {
	var eventName = (window.attachEvent) ?
		['mouseenter','mouseleave'] : ['mouseover','mouseout'];
	var dropwdown = $$('.dropdown')[0]; // improves speed
	var list = $$('.dropdown .inner')[0]; // improves speed
	var container = $$('.dropdown .list_container')[0];
	var dimensions = list.getDimensions();
	[list,container].each(function(s) {
		s.setStyle({ width: dimensions.width + 'px' });
	});
	$$('.dropdown div')[0].observe(eventName[0], function() {
		list.addClassName('hover');
	});
	$$('.dropdown div')[0].observe(eventName[1], function() {
		list.removeClassName('hover');
	});
};

function photoGallery(dir) {	 
if(photoGallery != 0) {

	//move left
	if(dir != 0) {
		if(photoGalleryCounter == 0) { $('ms-global-img-mover2').style.left = photoGalleryWidth }
		//reset the photo containers and the counter 
		if(photoGalleryCounter == (photoGalleryTotal-(photoGalleryTotal*2))) { 
			$('ms-global-img-mover1').style.left = '0px'; 
			$('ms-global-img-mover2').style.left = photoGalleryWidth;
			photoGalleryCounter = 0}	
				photoGalleryCounter = photoGalleryCounter -1;
				Effect.MoveBy( 'ms-global-img-mover1', 0, -142, { 
				beforeStart: function() { disablepGalleryBtns(0); }, afterFinish: function() { disablepGalleryBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'ms-global-img-mover2', 0, -142, {duration:1} );
							
		} else { 
		
		//move right
		if(photoGalleryCounter == 0) { $('ms-global-img-mover2').style.left = photoGalleryWidthRight; }
		//reset the photo containers and the counter 
		if(photoGalleryCounter == photoGalleryTotal) { 
			$('ms-global-img-mover1').style.left = '0px'; 
			$('ms-global-img-mover2').style.left = photoGalleryWidthRight;
			photoGalleryCounter = 0}
				photoGalleryCounter = photoGalleryCounter +1;
				Effect.MoveBy( 'ms-global-img-mover1', 0, 142, { 
				beforeStart: function() { disablepGalleryBtns(0); }, afterFinish: function() { disablepGalleryBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'ms-global-img-mover2', 0, 142, {duration:1} ); 
		}
	}
}	

//this function deactivates button while photo gallery is moving
function disablepGalleryBtns(active) {	
	if(active == 0) { 
		$('ms-col2-img-container').style.width = '422px';
		$('ms-col2-img-container').style.clip = 'rect(auto auto auto 5px)';
		$('ms-global-pGalleryBtn-right').onclick =  null;
		$('ms-global-pGalleryBtn-left').onclick =  null }
	if(active == 1) { 
		$('ms-col2-img-container').style.width = '427px';
		$('ms-col2-img-container').style.clip = 'rect(auto auto auto auto)';
		$('ms-global-pGalleryBtn-right').onclick =  photoGallery;
		$('ms-global-pGalleryBtn-left').onclick =  new Function("photoGallery("+0+")");
		}
}

//community module - column 2

var oldComm = 1;
function changeComm(comm) {
	previousComm = "community-boards-content"+oldComm
	selectedComm = "community-boards-content"+comm;	
	$(previousComm).style.display = 'none';
	$(selectedComm).style.display = 'block';
	$('community-board'+comm).className = "community-boards-numbers-on";
	$('community-board'+oldComm).className = "";
	//set new visible as current
	oldComm = comm;
}

//these functions handle rollover effect for community module
function ieRoll(selectedTR,selectedID) {
	if(selectedID != oldComm) {
	selectedTR.className = 'community-boards-numbers-hover'; }
}

function ieRollOut(selectedTR,selectedID) {
	if(selectedID != oldComm) {
	selectedTR.className = '';}
}

//more like this module - column 3

function moreThis(dir) {	 
if(moreThis != 0) {

	//move left
	if(dir != 0) { 
		if(moreThisCounter == 0) { $('ms-col3-morethis-mover2').style.left = moreThisWidth }
		//reset the photo containers and the counter 
		if(moreThisCounter == (moreThisTotal-(moreThisTotal*2))) { 
			$('ms-col3-morethis-mover1').style.left = '0px'; 
			$('ms-col3-morethis-mover2').style.left = moreThisWidth;
			moreThisCounter = 0}	
				moreThisCounter = moreThisCounter -1;
				Effect.MoveBy( 'ms-col3-morethis-mover1', 0, -83, { 
				beforeStart: function() { disablemoreThisBtns(0); }, afterFinish: function() { disablemoreThisBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'ms-col3-morethis-mover2', 0, -83, {duration:1} );
							
		} else { 
		
		//move right
		if(moreThisCounter == 0) { $('ms-col3-morethis-mover2').style.left = moreThisWidthRight; }
		//reset the photo containers and the counter 
		if(moreThisCounter == moreThisTotal) { 
			$('ms-col3-morethis-mover1').style.left = '0px'; 
			$('ms-col3-morethis-mover2').style.left = moreThisWidthRight;
			moreThisCounter = 0}
				moreThisCounter = moreThisCounter +1;
				Effect.MoveBy( 'ms-col3-morethis-mover1', 0, 83, { 
				beforeStart: function() { disablemoreThisBtns(0); }, afterFinish: function() { disablemoreThisBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'ms-col3-morethis-mover2', 0, 83, {duration:1} ); 
		}
	}
}	

//this function deactivates button while photo gallery is moving
function disablemoreThisBtns(active) {	
	if(active == 0) { 
		$('ms-col3-morethis-container').style.width = '250px';
		$('ms-col3-morethis-container').style.clip = 'rect(auto 245px auto 5px)';
		$('ms-global-morethisBtn-right').onclick = null;
		$('ms-global-morethisBtn-left').onclick = null; }
	if(active == 1) { 
		$('ms-col3-morethis-container').style.width = '250px';
		$('ms-col3-morethis-container').style.clip = 'rect(auto auto auto auto)';
		$('ms-global-morethisBtn-right').onclick =  moreThis;
		$('ms-global-morethisBtn-left').onclick =  new Function("moreThis("+0+")");
		}
}


//browse menu module - column 2

function menuBrowser(dir) {	 
if(menuBrowser != 0) {

	//move left
	if(dir == 0) { 
		if(menuBrowserCounter == 0) { $('ms-col2-menuBrowser-mover2').style.left = menuBrowserWidth }
		//reset the photo containers and the counter 
		if(menuBrowserCounter == (menuBrowserTotal-(menuBrowserTotal*2))) { 
			$('ms-col2-menuBrowser-mover1').style.left = '0px'; 
			$('ms-col2-menuBrowser-mover2').style.left = menuBrowserWidth;
			menuBrowserCounter = 0}	
				menuBrowserCounter = menuBrowserCounter -1;
				Effect.MoveBy( 'ms-col2-menuBrowser-mover1', 0, -100, { 
				beforeStart: function() { disablemenuBrowserBtns(0); }, afterFinish: function() { disablemenuBrowserBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'ms-col2-menuBrowser-mover2', 0, -100, {duration:1} );
							
		} else { 
		
		//move right
		if(menuBrowserCounter == 0) { $('ms-col2-menuBrowser-mover2').style.left = menuBrowserWidthRight; }
		//reset the photo containers and the counter 
		if(menuBrowserCounter == menuBrowserTotal) { 
			$('ms-col2-menuBrowser-mover1').style.left = '0px';
			$('ms-col2-menuBrowser-mover2').style.left = menuBrowserWidthRight;
			menuBrowserCounter = 0}
				menuBrowserCounter = menuBrowserCounter +1;
				Effect.MoveBy( 'ms-col2-menuBrowser-mover1', 0, 100, { 
				beforeStart: function() { disablemenuBrowserBtns(0); }, afterFinish: function() { disablemenuBrowserBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'ms-col2-menuBrowser-mover2', 0, 100, {duration:1} ); 
		}
	}
}	

//this function deactivates button while photo gallery is moving
function disablemenuBrowserBtns(active) {	
	if(active == 0) { 
		$('ms-col2-menu-module-items-container').style.width = '379px';
		$('ms-col2-menuBrowser-leftBtn').style.backgroundColor = '#D6F29F';
		$('ms-global-menuBrowseBtn-right').onclick =  null;
		$('ms-global-menuBrowseBtn-left').onclick =  null }
	if(active == 1) { 
		$('ms-col2-menu-module-items-container').style.width = '385px';
		$('ms-col2-menuBrowser-leftBtn').style.backgroundColor = ''
		$('ms-global-menuBrowseBtn-right').onclick =  menuBrowser;
		$('ms-global-menuBrowseBtn-left').onclick =  new Function("menuBrowser("+0+")");
		}
}

//swaps text & video container on article pages

function videoSwap(tab) {
	if(tab == 1) {
		$('ms-col2-stepbystep-txt').style.display = 'block';
		$('ms-col2-stepbystep-video').style.display = 'none';
		$('recipe-tab').className = 'here';
		$('video-tab').className = '';
		} else {
		$('ms-col2-stepbystep-txt').style.display = 'none';
		$('ms-col2-stepbystep-video').style.display = 'block';
		$('recipe-tab').className = '';
		$('video-tab').className = 'here';					
		}
}

//swaps text & video container on article pages

function articleVideoSwap(tab) {
	if(tab == 1) {
		$('ms-col2-article-container').style.display = 'block';
		$('ms-col2-stepbystep-video').style.display = 'none';
		$('article-tab').className = 'here';
		$('video-tab').className = '';
		} else {
		$('ms-col2-article-container').style.display = 'none';
		$('ms-col2-stepbystep-video').style.display = 'block';
		$('article-tab').className = '';
		$('video-tab').className = 'here';					
		}
}


// pop up

var newWin;
function openBrWindow(theURL,winName,features) { 
  newWin = window.open(theURL,winName,features);
  newWin.focus();
}


//poll text changes

function pollTxtChanges() {
	//hide question
	Element.hide('ms-col3-poll-question-container');
	
	//show resulting poll 
	Element.show('ms-col3-poll-results-container');
	
	//show "total votes" text at bottom
	Element.show('ms-col3-poll-bottom-container');
}

// new poll - used on microsites

function showPollResults() {
	$("col3-poll-options").style.display = "none";
	$("col3-poll-result-container").style.display = "block";
}

/* brand tray */

function brandTray(dir) {	 
if(brandTray != 0) {

	//move left
	if(dir != 0) {
		if(brandTrayCounter == 0) { $('brandLogosGroup2').style.left = brandTrayWidth }
		//reset the photo containers and the counter 
		if(brandTrayCounter == (brandTrayTotal-(brandTrayTotal*2))) { 
			$('brandLogosGroup1').style.left = '0px'; 
			$('brandLogosGroup2').style.left = brandTrayWidth;
			brandTrayCounter = 0}	
				brandTrayCounter = brandTrayCounter -1;
				Effect.MoveBy( 'brandLogosGroup1', 0, -115, { 
				beforeStart: function() { disableBrandTrayBtns(0); }, afterFinish: function() { disableBrandTrayBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'brandLogosGroup2', 0, -115, {duration:1} );
							
		} else { 
		
		//move right
		if(brandTrayCounter == 0) { $('brandLogosGroup2').style.left = brandTrayWidthRight; }
		//reset the photo containers and the counter 
		if(brandTrayCounter == brandTrayTotal) { 
			$('brandLogosGroup1').style.left = '0px'; 
			$('brandLogosGroup2').style.left = brandTrayWidthRight;
			brandTrayCounter = 0}
				brandTrayCounter = brandTrayCounter +1;
				Effect.MoveBy( 'brandLogosGroup1', 0, 115, { 
				beforeStart: function() { disableBrandTrayBtns(0); }, afterFinish: function() { disableBrandTrayBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'brandLogosGroup2', 0, 115, {duration:1} ); 
		}
	}
}	

//this function deactivates button while photo gallery is moving
function disableBrandTrayBtns(active) {	
	if(active == 0) { 
		$('next').onclick =  null;
		$('prev').onclick =  null;
	  }
	if(active == 1) { 
		$('next').onclick =  brandTray;
		$('prev').onclick =  new Function("brandTray("+0+")");
		}
}


/* make marthastewart.com your homepage */

function setMarthaAsHomePage(obj, url) {
	var browserName=navigator.appName; 

	// tracking
	var s=s_gi(s_account); 
	s.linkTrackVars='eVar1,prop8'; 
	s.linkTrackEvents='None'; 
	s.eVar1='homepage_bookmark'; 
	s.prop8='homepage_bookmark'; 
	s.tl(this,'o','Homepage Bookmark');

	// set home page, if possible
	if (browserName=="Microsoft Internet Explorer") {
		obj.style.behavior='url(#default#homepage)';
		obj.setHomePage('http://www.marthastewart.com');
	} else { 
		// can't set homepage with current browser - show instructions instead	
		openBrWindow(url,'setHomePageWindow','status=no,scrollbars=yes,width=550,height=600');
	}
}

/* showCollageTitles replaced by the collageModule class
showCollageTitles = function() {

	if (!document.getElementById('collage')) return false;
		
	var collage = document.getElementById('collage');
	var collageImgs = collage.getElementsByTagName("img");
	
	for(var i=0; i<collageImgs.length; i++) {
		var collageTitles = document.getElementById('collageTitle');
		collageImgs[i].onmouseover = function() {
			getCollageTitle = this.getAttribute("title");
			collageTitles.style.visibility = "visible";
			collageTitles.innerHTML = '<p>'+getCollageTitle+'</p>';
			this.className = "img_hover";
		}
			collageImgs[i].onmouseout = function() {
			collageTitles.innerHTML = '<p>&nbsp;</p>';
			this.className = "";
		}
	}
}
addLoadEvent(showCollageTitles);*/

showAlsoTryTitles = function() {

	if (!document.getElementById('also_try')) return false;
		
	var alsoTry = document.getElementById('also_try');
	var alsoTryImgs = alsoTry.getElementsByTagName("img");

	for(var i=0; i<alsoTryImgs.length; i++) {
			var alsoTryTitles = document.getElementById('alsoTryTitleDiv');
			alsoTryImgs[i].onmouseover = function() {
			getAlsoTryTitle = this.getAttribute("title");
			alsoTryTitles.style.visibility = "visible";
			alsoTryTitles.innerHTML = '<p>'+getAlsoTryTitle+'</p>';
			this.className = "img_hover";
		}
			alsoTryImgs[i].onmouseout = function() {
			alsoTryTitles.innerHTML = '<p>&nbsp;</p>';
			this.className = "";
		}		
	}
}

addLoadEvent(showAlsoTryTitles);

/* col3: Also Try... */

function alsoTry(dir) {	 
if(alsoTry != 0) {

	//move left
	if(dir != 0) {
		if(alsoTryCounter == 0) { $('also_try_images_group2').style.left = alsoTryWidth }
		//reset the photo containers and the counter 
		if(alsoTryCounter == (alsoTryTotal-(alsoTryTotal*2))) { 
			$('also_try_images_group1').style.left = '0px'; 
			$('also_try_images_group2').style.left = alsoTryWidth;
			alsoTryCounter = 0}	
				alsoTryCounter = alsoTryCounter -1;
				Effect.MoveBy( 'also_try_images_group1', 0, -81, { 
				beforeStart: function() { disableAlsoTryBtns(0); }, afterFinish: function() { disableAlsoTryBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'also_try_images_group2', 0, -81, {duration:1} );
							
		} else { 
		
		//move right
		if(alsoTryCounter == 0) { $('also_try_images_group2').style.left = alsoTryWidthRight; }
		//reset the photo containers and the counter 
		if(alsoTryCounter == alsoTryTotal) { 
			$('also_try_images_group1').style.left = '0px'; 
			$('also_try_images_group2').style.left = alsoTryWidthRight;
			alsoTryCounter = 0}
				alsoTryCounter = alsoTryCounter +1;
				Effect.MoveBy( 'also_try_images_group1', 0, 81, { 
				beforeStart: function() { disableAlsoTryBtns(0); }, afterFinish: function() { disableAlsoTryBtns(1); }, duration:1} ); 
				Effect.MoveBy( 'also_try_images_group2', 0, 81, {duration:1} ); 
		}
	}
}

//this function deactivates button while photo gallery is moving
function disableAlsoTryBtns(active) {	
	if(active == 0) { 
		$('also_try_images').style.width = '239px';
		$('also_try_images').style.clip = 'rect(auto, auto, auto, 3px)';
		$('also_try_prev').onclick =  null;
		$('also_try_next').onclick =  null }
	if(active == 1) { 
		$('also_try_images').style.width = '243px';
		$('also_try_images').style.clip = 'rect(auto auto auto auto)';
		$('also_try_prev').onclick =  alsoTry;
		$('also_try_next').onclick =  new Function("alsoTry("+0+")");
		}
}


/* show archive functions */

showArchiveFunctions = function() {
	if (!document.getElementById('show-archive')) return false;
	var showArchiveTrs = $('show-archive').getElementsByTagName("tr");
	if (!window.XMLHttpRequest) {
		$('show-archive-dropdown').onmouseover = function() {
			$('show-archive-select').style.backgroundPosition = '0px -29px';
			$('show-archive-dates').style.display='block';
		}
		$('show-archive-dropdown').onmouseout = function() {
			$('show-archive-select').style.backgroundPosition = 'top left';
			$('show-archive-dates').style.display='none';
		}		
		for (var i=0; i<showArchiveTrs.length; i++) {
			showArchiveTrs[i].onmouseover = function() {
				if (this.className != 'table-headers') {
					if(this.className == 'shaded') {
						this.className = "ieHover";
						this.onmouseout = function() { this.className = 'shaded'; }
					} else {
						this.className = "ieHover";
						this.onmouseout = function() { this.className = ''; }		
					}
				}
			}
		}
	}
}

addLoadEvent(showArchiveFunctions);

top7Sort = function() {

			if (!document.getElementById('top7')) return false;
		
			var top7List = document.getElementById("top7_dropdown").getElementsByTagName("li");

			// show dropdown
			$('top7_select').onmouseover = function() {
				$('top7_nest').style.height = "auto";
				$('top7_nest').style.visibility = "visible";
			}
			// hide dropdown (onmouseout)
			$('top7_select').onmouseout = function() {
				$('top7_nest').style.height = "0";
				$('top7_nest').style.visibility = "hidden";
			}
			// hide dropdown (onclick)
			for (var i=0; i<top7List.length; i++) {
				top7List[i].onclick=function() {
					$('top7_nest').style.height = "0px";
					$('top7_nest').style.visibility = "hidden";
				}
			}
				
			var getTop7Lnks = $('top7_dropdown').getElementsByTagName("a");
			
			for(var i=0; i<getTop7Lnks.length; i++) {
		
			// hide all lists
			getTop7Lnks[i].onclick = function() {
			var allTop7 = $('top7_sort1','top7_sort2','top7_sort3');
			for(var j=0; j<allTop7.length; j++) {
				if($(allTop7[j])) {
				allTop7[j].style.display = "none";
				}
			}

			// hid all hdrs
			var allTop7Hdrs = $('top7_hdr1', 'top7_hdr2', 'top7_hdr3');
			for(var k=0; k<allTop7Hdrs.length; k++) {
				if($(allTop7Hdrs[k])) {
				allTop7Hdrs[k].className = "invisibleHdr";
				}
			}

			var top7Lnks = this.getAttribute("href").split("#")[1];
			
			var top7Hdr = this.parentNode.parentNode.parentNode.className = top7Lnks;
			
			// show appropriate list
			$(top7Lnks).style.display = "block";

			// show appropriate hdr
			if (top7Lnks == "top7_sort1") {
				$('top7_hdr1').className = "visibleHdr";
			}
			if (top7Lnks == "top7_sort2") {
				$('top7_hdr2').className = "visibleHdr";
			}
			if (top7Lnks == "top7_sort3") {
				$('top7_hdr3').className = "visibleHdr";
			}
			return false;	
		}
	}
}

addLoadEvent(top7Sort);

homeTop7Sort = function() {

			if (!document.getElementById('top7_home')) return false;
		
			var top7HomeList = document.getElementById("top7_home_dropdown").getElementsByTagName("li");

			// show dropdown
			$('top7_home_select').onmouseover = function() {
				$('top7_home_nest').style.height = "auto";
				$('top7_home_nest').style.visibility = "visible";
			}
			// hide dropdown (onmouseout)
			$('top7_home_select').onmouseout = function() {
				$('top7_home_nest').style.height = "0px";
				$('top7_home_nest').style.visibility = "hidden";
			}
			// hide dropdown (onclick)
			for (var i=0; i<top7HomeList.length; i++) {
				top7HomeList[i].onclick=function() {
					$('top7_home_nest').style.height = "0px";
					$('top7_home_nest').style.visibility = "hidden";
				}
			}
				
			var getTop7HomeLnks = $('top7_home_dropdown').getElementsByTagName("a");
			
			for(var i=0; i<getTop7HomeLnks.length; i++) {
		
			// hide all lists
			getTop7HomeLnks[i].onclick = function() {
			var allHomeTop7 = $('top7_home_sort1','top7_home_sort2','top7_home_sort3');
			for(var j=0; j<allHomeTop7.length; j++) {
				if($(allHomeTop7[j])) {
					allHomeTop7[j].style.display = "none";
				}
			}

			// hid all hdrs
			var allTop7Hdrs = $('top7_home_hdr1', 'top7_home_hdr2', 'top7_home_hdr3');
			for(var k=0; k<allTop7Hdrs.length; k++) {
				if($(allTop7Hdrs[k])) {
				allTop7Hdrs[k].className = "invisibleHdr";
				}
			}

			var top7HomeLnks = this.getAttribute("href").split("#")[1];
			
			// show appropriate list
			$(top7HomeLnks).style.display = "block";

			// show appropriate hdr
			if (top7HomeLnks == "top7_home_sort1") {
				$('top7_home_hdr1').className = "visibleHdr";
			}
			if (top7HomeLnks == "top7_home_sort2") {
				$('top7_home_hdr2').className = "visibleHdr";
			}
			if (top7HomeLnks == "top7_home_sort3") {
				$('top7_home_hdr3').className = "visibleHdr";
			}
			return false;
		}
	}
}

addLoadEvent(homeTop7Sort);

function homepageLoginHover() {
	if(!$('sign_up_now') || !$('sign_in_arrow')) return false;
	$('sign_up_now').onmouseover = function() {
		$('sign_up_now').style.backgroundPosition = "bottom left";
		$('sign_in_arrow').style.backgroundPosition = "bottom left";
	}
	$('sign_up_now').onmouseout = function() {
		$('sign_up_now').style.backgroundPosition = "top left";
		$('sign_in_arrow').style.backgroundPosition = "top left";
	}
	$('sign_in_arrow').onmouseover = function() {
		$('sign_up_now').style.backgroundPosition = "bottom left";
		$('sign_in_arrow').style.backgroundPosition = "bottom left";
	}
	$('sign_in_arrow').onmouseout = function() {
		$('sign_up_now').style.backgroundPosition = "top left";
		$('sign_in_arrow').style.backgroundPosition = "top left";
	}
}

addLoadEvent(homepageLoginHover);			


// hint framework
hintOpen = "<div class='reg_hint'><div class='reg_message_outer'><div class='reg_message_inner'><div>";
hintClose = "</div></div></div></div>";

bio_question1_hint = "How are you feeling? Happy? Stressed? Excited?";
bio_question2_hint = "Here's Martha's: &ldquo;Family instilled love of home and work-I took it from there!&ldquo;";
bio_question3_hint = "We love this one that a Contributor submitted: &ldquo;It doesn't have to be perfect.&ldquo;";
bio_question4_hint = "Anyone from Ghandi to your granddaughter.";
bio_question5_hint = "When we're looking for experts from the Community Table, we'll know you're one of them.";
bio_question8a_hint = "A little mood-making music for your trip?";
bio_question8b_hint = "Maybe it's the one that always laugh or cry-or both.";
bio_question8c_hint = "There's no &ldquo;right&rdquo; answer.";
bio_question8d_hint = "Soon, you'll also be able to upload that photo.";
bio_question8e_hint = "Do tell...";
bio_question9_hint = "Any room that's not listed above.";
bio_question10_hint = "Soon you will be able to submit your recipes, so others can try them out.";
bio_question11_hint = "Dream big!";
bio_question12_hint = "This is also a perfect spot to leave a personal note for visitors to Your Place.";

//keyword_search_hint = "Separate multiple ingredients or keywords with commas";


function fieldHint() {
	var getAllHints = document.getElementsByClassName("hintBubble");
	for(var i=0; i<getAllHints.length; i++) {
		getAllHints[i].onfocus = function() {
			var getId = this.getAttribute("id");
      this.style.backgroundColor = '#EDF7F7';
			$(getId + "-M").innerHTML =  hintOpen + eval(getId + "_hint") + hintClose;
			if(!$(getId).hasClassName("required")) {
				$(getId).onblur = function() {
					$(getId + "-M").innerHTML = "";
					$(getId).style.background = "";
				}
			}
		}	
	}
}

addLoadEvent (fieldHint);


var today = new Date() // this is used in both TipData and TipSidebar

var TipData = { days: ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday"],
				months: ["January", "February", "March","April","May","June","July","August","September","October","November","December"],
				month: today.getMonth(),
				day: today.getDate(),
				year: today.getYear(),
				current_tip: 0,
				hide_cookies: false,
				cookie_icon_s: "http://images.marthastewart.com/images/assets/channel/cookie_of_the_day/ms_cookie_icon.jpg",
				init: function() {
					//$('tips_of_day_inner').style.visibility = 'hidden'
					//TipData.month = 10
					//TipData.day = 5
					for (i=0;i<7;i++) {
						var d = tips[i].date.split("-")
						tips[i].month = TipData.months[d[0] - 1]
						tips[i].day = d[1]
						if (TipData.month == d[0] - 1)
							if (d[1] == TipData.day) {
								TipData.current_tip = i
								TipData.hide_cookies = true
							  }
					}
					TipData.is_week_in_future()
					var calendar = document.getElementById('tips_week')
					calendar.innerHTML = ""
					for (i=0;i<7;i++) {
						calendar.appendChild(TipData.output_calendar_item(i,tips[i]))
					}
					calendar = null
					TipData.show_recipe(TipData.current_tip)
					$('tips_of_day_inner').style.visibility = "visible"
				},
				
			 is_week_in_future: function() {
			     if (TipData.hide_cookies == false && TipData.current_tip == 0) {
			      var p = tips[6].date.split("-")
			      if (p[0] >= TipData.month - 1) {
			       if (p[1] >= TipData.day) {
			        TipData.hide_cookies = false
			       }
			      } else {
			       TipData.hide_cookies = true
			      }
			     } else {
			       TipData.is_future_week = false
			     }
	    	},
	    				
				output_calendar_item: function(day_of_week,item) {
	                if ((TipData.is_future_week) || (TipData.hide_cookies && (day_of_week > TipData.current_tip))) {
						html = "<h2>" + TipData.days[day_of_week] + "<span>" + item.day + "</span></h2>"
						html += "<img src=\"" + TipData.cookie_icon_s + "\" />"
		                html +="<span>" + item.teaser + "</span>"
					} else {
						html = "<h2>" + TipData.days[day_of_week] + "<span>" + item.day + "</span></h2>"
	                	html +="<a href=\"#\" onclick=\"return TipData.switch_recipe(" + day_of_week + ",'" + tips[day_of_week].date + "', this)\">"
						html +="<img src=\"" + item.thumb + "\" />"
	                	html +="<span>" + item.short_title + "</span></a>"
					}
	              	elm = document.createElement("li")
					if (day_of_week == TipData.current_tip)
						$('tips_week').className = "day_" + day_of_week
					elm.innerHTML = html
					return elm
				},
				
				switch_recipe: function(day,date,obj) {
					if (obj) {
					  	//items = $('tips_week').getElementsByTagName('li')
						//for (i=0;i<items.length;i++) 
						//	items[i].className = ""
						//items = null
						$('tips_week').className = "day_" + day
					}
					TipData.show_recipe(day);
					setTimeout( 'TipData.track(\''+date+'\')',500);
					return false;
				},
				
				show_recipe: function(day) {
					$('tip_month').innerHTML = tips[day].month
					$('tip_day').innerHTML = tips[day].day
					$('tip_dayofweek').innerHTML = TipData.days[day]
					$('tip_title').innerHTML = tips[day].title
					$('tip_description').innerHTML = tips[day].description

	      //  if ((TipData.is_future_week ) || (TipData.hide_cookies && (day > TipData.current_tip))) {
	      //					$('tip_img_large').src = "http://images.marthastewart.com/images/assets/channel/cookie_of_the_day/ms_cookie_icon_l.jpg"
		//				Element.hide('tip_url')
		//			} else {
						Element.show('tip_url')
						//$('tip_url').href = tips[day].url
						$('tip_url').setAttribute("href",tips[day].url);
						$('tip_img_large').src = tips[day].image
		//			}
					
					$('tips_of_day_inner').style.visibility = 'visible'
				},

				track: function(date) {
					var s=s_gi(s_account);
					s.linkTrackVars='eVar1,prop8';
					s.linkTrackEvents='None';
					try {
					  if($('cookie-day')) {
					  	var prefix = "cod_";
					  	}
					  if($('craft-day')) {
					  	var prefix = "craftcod_";
					  	}	
					  if($('organizing-day')) {
					  	var prefix = "ood_";
					  	}
					 }
					catch(e) {}
					s.eVar1 = s.prop8 = prefix + date.replace('-','_').replace('-','_');
					s.tl(this,'o','of the day');
				}
				
				//,
				
			//	flash_replace: function() {
					//flash replace

			//		if(typeof sIFR == "function"){	
			//			sIFR.bHideBrowserText = true;
			//		    sIFR.replaceElement("div.global_module_hdr h1", named({sFlashSrc: "http://images.marthastewart.com/images/assets/flash/fonts/archer.swf", sColor: "#cc6633", sWmode: "transparent", sFlashVars:"underline=true"}));    
			//		    sIFR.replaceElement("#bottom_module h2", named({sFlashSrc: "http://images.marthastewart.com/images/assets/flash/fonts/archer.swf", sColor: "#cc6633", sWmode: "transparent", sFlashVars:"underline=true"}));    
			//		}

					
			//	}
			
				
				}
				
//TipData.flash_replace()
TipSidebar = {
	month: today.getMonth(),
	day: today.getDate(),
	year: today.getYear(),
	current_tip: 0,
	init: function() {
		//TipSidebar.month = 10
		//TipSidebar.day = 5
		for (i=0;i<sidetips.length;i++) {
			try {
			var d = sidetips[i].date.split("-")
			if (TipSidebar.month == d[0] - 1)
				if (d[1] == TipSidebar.day) {
					TipSidebar.current_tip = i
				  }
			} catch(e) {}
		}
		try {
		  if($('cookie-day')) {
		  	var url = "/craft-of-the-day";
		  	var linktext = "See Today's Craft";
		  	}
		  if($('craft-day')) {
		  	var url = "/cookie-of-the-day";
		  	var linktext = "See Today's Recipe";
		  	}	
		  if($('organizing-day')) {
		  	var url = "/craft-of-the-day";
		  	var linktext = "See Today's Craft";
		  	}	
		 }
		catch(e) {}
		var img = document.createElement("img")
		img.src = sidetips[TipSidebar.current_tip].image
		var h2 = document.createElement("h2")
		h2.innerHTML = sidetips[TipSidebar.current_tip].title
		var a = document.createElement("a")
		a.href = url
		a.innerHTML = linktext
		//a.href = "#"
		//a.innerHTML = "See a month of crafts."
		var module = $('tips_sidebar')
		module.innerHTML = ''
		module.appendChild(img)
		module.appendChild(h2)
		module.appendChild(a)
		img = h2 = a = null
	}	
	
}

//Rating Script for Crowdfactory
function select_rating(rating, containerID) {
	switch(rating){
		case '1':
			width = '-15';
			break;
		case '2':
			width = '-30';
			break;
		case '3':
			width = '-45';
			break;
		case '4':
			width = '-60';
			break;
		case '5':
			width = '-75';
			break;
		default: 
			width = '0';
			break;
			
	}
	$(containerID).style.backgroundPosition = '0px ' + width + 'px';
}


article_video_toggle = {
	init: function() {
		if(!$('article_video')) return false;
		var div = document.createElement('div');
		div.setAttribute("id", "play_video");
		Event.observe(div, 'click', function() { article_video_toggle.show() });
		$('ms-col2-article-img-shadow-inner').appendChild(div);
		Event.observe("article_video_close", 'click', function() { article_video_toggle.hide() });
		article_video_toggle.check_auto_load();
	},
	check_auto_load: function() {
		if($('article_video') && autoplay == 'Y') {
			article_video_toggle.show();
		}
	},
	show: function() {
		initPlayer();
		if($('ms-col2-stepbystep-txt')) {
				$('ms-col2-stepbystep-txt').hide();
				$('article_video').show();
		} else if ($('ms-col2-article-container')) {
				$('ms-col2-article-container').hide();
				$('article_video').show();
		}
	},
	hide: function() {
		$('videoPlayer').remove();
		if($('ms-col2-stepbystep-txt')) {
				$('ms-col2-stepbystep-txt').show();
				$('article_video').hide();
		} else if ($('ms-col2-article-container')) {
				$('ms-col2-article-container').show();
				$('article_video').hide();
		}
	}
}

Event.observe(window, 'load', article_video_toggle.init);



menu_tabs = {
	current_info: "menu_tab_info",
	old_tab: "menu_tab",
	init: function() {
		if(!$("menu_details_tabs")) return false;
		var li = $("menu_details_tabs").getElementsByTagName("li");
		for(var i=0; i<li.length; i++) {
			li[i].onclick = function() { menu_tabs.toggle(this); return false; };
		}
	},
	toggle: function(obj) {
		var id = obj.getAttribute("id");
		var tab = id + '_info';
		if(menu_tabs.old_tab != id) {
			$(tab).show();
			obj.className = "here";
			$(menu_tabs.current_info).hide();
			menu_tabs.current_info = tab;
			$(menu_tabs.old_tab).className = "";
			menu_tabs.old_tab = id;
		}
	}
}

Event.observe(window,'load',menu_tabs.init);

contest_accept = {
	validate: function() {
		if(!$('contest_accept_validate')) return false;
		$('contest_accept_validate').onclick = function() {
			if(!$('contest_accept_checkbox').checked) {
				$('contest_accept_error').style.visibility = 'visible';
				return false;
			}
		}
		$('contest_accept_checkbox').onclick = function() {
				$('contest_accept_error').style.visibility = 'hidden';
		}
	}
}

Event.observe(window,'load', contest_accept.validate);



function doTrackAction(action)
{


	var events = '';

	var evar22 = '';

	if(action=='save')

	{

		events = 'event8,event13';

		evar22 = 'save';

	}

	else if(action=='noteandtag')

	{

		events = 'event6,event13';

		evar22 = 'tag_save';

	}
	else if(action=='noteandtagtab')

	{

		events = 'event27,event13';

		evar22 = 'tag_open';

	}

	else if(action=='ratetab')

	{

		events = 'event28,event13';

		evar22 = 'rate_open';

	}

	else if(action=='rate' || action=='oneClickRecommend' || action=='recommend')

	{

		events = 'event7,event13';

		evar22 = 'rate_save';

	}



	else if(action=='addcomment')

	{

		events = 'event29,event13';

		evar22 = 'comment_open';

	}
	

	else if(action=='comments')

	{

		events = 'event9,event13';

		evar22 = 'comment_save';

	}
	else if(action=='email')
	{
		events = 'event11,event13';

		evar22 = 'email';

	}
	else if(action=='print')
	{

		events = 'event12,event13';

		evar22 = 'print';

	}
	else if(action.indexOf('contest')>-1)
	{
		var contest_id = action.substring(action.indexOf('_')+1);
		events = 'event33';
		evar22 = 'upc_'+contest_id;
	
	}
	
	else if (action.indexOf('share_')>-1) {
		events = 'event10,event13';
		evar22 = action;
	}
	
	
	if(action!='login')
	{

		var s=s_gi(s_account);

		s.linkTrackVars='eVar22,evar28,events';

		s.linkTrackEvents=events;

		s.events=events;

		s.eVar22=evar22;
		s.evar28='registered';

		s.tl(this,'o','Community Event');
	}
	else
	{
		var s=s_gi(s_account);
		s.linkTrackVars='prop27,prop28';
		s.prop27='logged in';
		s.prop28='li:'+omniturePageName;



	}
}


function trackAction(action, formname) {

	setTimeout( 'doTrackAction(\''+action+'\')',500);

	if (action.indexOf('contest')>-1) {
		var contest_id = action.substring(action.indexOf('_')+1);
		window.location.href='/portalext/gallery/photo-terms?galleryId='+contest_id;
	}
}


/*Wedding Wire Module stuff*/
function searchBy(tosearch) {
	switch (tosearch) {
		case 'category':
			$('catSearch').style.display = 'block';
			$('busSearch').style.display = 'none';
			break;
		case 'business':
			$('catSearch').style.display = 'none';
			$('busSearch').style.display = 'block';
			break;
	}
}
function submitForm(){
		if(document.getElementById("catId").value == "999") window.location = "https://www.missnowmrs.com/weddingwire.htm?ref=main";
		else{
			$("form1cid").value = $("catId").value;
			$("form1geo").value = $("geoID").value;
			document.forms.CatalogForm.submit();
		}
	}
/* onBlur event function for text fields - restores the default message*/
function setDefault(el,txt) {
	if (el.value.length == 0 || el.value == txt) {
		el.style.color = "gray";
		el.value = txt;
	} else {
		el.style.color = "";
	}
}
function clearDefault(el,txt) {
	if (el.value == txt) {
		el.value = "";
	}
	el.style.color = "";
}	


function submitForm1() {
	document.CatalogForm1.cid.value=document.CatalogForm1.catId.value;
	document.CatalogForm1.geo.value=document.CatalogForm1.geoID.value;
	document.forms.CatalogForm1.submit();
}

// function appendAd() {
// 	if(document.getElementById('ad') && document.getElementById('ms-article-hdr-ad')) {
// 		var ad_container = document.getElementById('ms-article-hdr-ad');
// 		var generated_ad = document.getElementById('ad').innerHTML;
// 		ad_container.innerHTML = generated_ad;
// 	}
// }
// 
// addLoadEvent(appendAd);

function Querystring(qs) {

	this.params = new Object()
	this.get=Querystring_get
		
	if (qs == null)
		qs=location.search.substring(1,location.search.length)
	
		if (qs.length == 0) return
		
		qs = qs.replace(/\+/g, ' ')
		var args = qs.split('&')
		
		for (var i=0;i<args.length;i++) {
			var value;
			var pair = args[i].split('=')
			var name = unescape(pair[0])
	
			if (pair.length == 2)
				value = unescape(pair[1])
			else
				value = name
			
			this.params[name] = value
		}
	}
	
	function Querystring_get(key, default_) {
		if (default_ == null) default_ = null;
		
		var value=this.params[key]
		if (value==null) value=default_;
		
		return value
	}
  
  
/*Groups
change_group_state
state - int - (1: initial "join now"    2: login & errors   3: congrats)
        the state to change the group-opt-in module to
msg - optional string
        the message to display if there is an error*/
function change_group_state(state, msg) {
  ['state1', 'state2', 'state3'].each(function(s) {
     //hide each of the states
    $(s).style.display = 'none';
  });
  //display the requested state
  $('state'+state).style.display = 'block';
  //if we are on the login page and there is an error
  if (state == 2) {
	starturl = window.location.href;
	if (starturl.indexOf('grprslt') > -1)
		starturl = starturl.substring(0, starturl.indexOf('grprslt') - 1);
    document.subscribe_form.grpurl.value = starturl;
    if (msg!=null) { 
      //insert the error
      $('state2msg').innerHTML = msg;
    }
  }
  else {
    //otherwise blank out the error field
    $('state2msg').innerHTML = '';
  }
  //prevent a link from being followed if event generated from anchor
  return false;
}

/*toggle_join_button
Toggles visibility of the join button.  
Really just a case-specific wrapper for prototype's toggle()
*/
function toggle_join_button() {
  $('joinbtn').toggle();
  //prevent a link from being followed if event generated from anchor
  return false;
}

/* decide what msg/state to show for group join module */
function examine_group_join_results() {
	rsltIndex = document.location.href.indexOf('grprslt');
	if (rsltIndex > -1) {
		rslt = document.location.href.substr(rsltIndex + 8, 1);
		if (rslt > 0 && rslt < 5) {
			change_group_state(2, 'Please try again.');
		} else if (rslt == 5) {  
			parent.change_group_state(3);
		} else {
			parent.change_group_state(2, 'Unable to complete request. Please try again later.');
		}
	}

}


Event.observe(window,'load', examine_group_join_results);




/*set omniture for modules begin*/
omniture_submitted_flag = false;
omnitureVarforMod = {            
            /*
            isDLModule:'',           
            setOmnitureVarforMod: function(){
                 omnitureVarforMod.isDLModule='false';                 
                 
                 if($('dl-flag')){
                 	omnitureVarforMod.isDLModule='true';                 	
                 }
                 
                 if(omnitureVarforMod.isDLModule == 'false'){                    
                    if(document.getElementById('navi-flag')){                                                                  
                        s.prop4="MSLO-NAVIGATION";
                        s.eVar29=s.prop4;
                    }
                    
                    if(document.getElementById('taxonomy-flag')){                                                                 
                        	s.prop4="MSLO-COLLECTION";
                        	s.eVar29=s.prop4;
                        
                    }
                    
                    if(typeof submitOmnitureFromSP == 'function'){ 
	                 	submitOmnitureFromSP();
	                 	omniture_submitted_flag = true;
                 	}
                 }
                  
                                               
            }*/
};
/*set omniture for modules end*/



/*quick newsletter opt-in*/
quicknews = {

			//the error message for when the password submitted is wrong
			passworderror: 'Sorry, we don\'t recognize that account. If you\'ve '+
			'forgotten your password, click the "Forgot Password" link below.',			
			notfilledinerror: 'Sorry, you must enter your email address and select at least one newsletter to subscribe to.',                
			tmphtml: '',
			activetab: 1,
			replaceCheckedFlag: 0,
			closeflag: '',
			loadflag: 'true',
			outdoneflag: 'false',
			indoneflag: '',
			invalidPwd: '',
			loginflag: '',			
			finalcloseflag:'false',
			closePWDMod:'false',
			checkedForm:'false',
			//loggedinstatus = 'in' or 'out'
			//emailaddress = if logged in, the users email to auto-populate the form
			init: function(loggedinstatus, emailaddress){
			    			    
				if(document.getElementById('newsletter_quick')){					
					$('emailaddr').value = (nopt_gup('emailhub'));					
					this.tmphtml = $('newsletter_quick').innerHTML;
					quicknews.indoneflag = 'false';
					quicknews.outdoneflag = 'false';
										
					switch (loggedinstatus){
						case 'in':	
						    //quicknews.indoneflag = 'false';						
							quicknews.loginflag = 'true';							
							quicknews.invalidPwd='false';
							
							Event.observe($('state1anxt'), 'click', function(){
							   quicknews.indoneflag = 'true'; 
							   
							   /*
								quicknews.setOmniture('emailbtn');
							   if(typeof submitOmnitureFromSP == 'function') 
								{
								    submitOmnitureFromSP();
								}
								*/
								
							   quicknews.changestate('loggedinstate1b', quicknews.notfilledinerror);
							   							   
							   }
							);
							
							if(quicknews.indoneflag == 'false'){
							   							   								
								if(quicknews.loadflag == 'true'){					    
							       quicknews.hideall();											
								   $('loggedinstate1a').show();
								}
								
							}														
							$('emailaddr').value = emailaddress;
							$('username').value= emailaddress;						
							
														
							break;
						case 'out':
							    
						    quicknews.loginflag = 'false';						    
					        //quicknews.outdoneflag = 'false';
					        quicknews.checkedForm = 'false'
	        					        					        
					        var useremail = $('emailaddrloggedout').value;
					        
							Event.observe($('loggedoutstate1anxt'), 'click', function() { 
							    quicknews.outdoneflag = 'true';																	
								var checkflag = quicknews.checkform();								
								quicknews.checkedForm = checkflag;
																							
								if(checkflag == 'true') {
								     newsletterhub.subscribNewsletters();	
								}    			          
								           								
								
								if(checkflag == 'false'){
									quicknews.changestate('loggedoutstate1a', quicknews.notfilledinerror);
								}							
								
							});							
							
							
							if(quicknews.outdoneflag == 'false'){															
								 quicknews.hideall();
								//$('state1').show();	
								$('loggedoutstate1a').show();								
							}							
																		
							break;
					}//end switch (loggedinstatus)
					
					Event.observe($('tab1_hdr'), 'click', function(){
					    if(quicknews.loadflag == 'false'){
					        quicknews.changestate('thanksfinal','');
					    }
					    
						quicknews.switch_tab('1')
					
					});		
					
					Event.observe($('tab2_hdr'), 'click', function(){
					    if(quicknews.loadflag == 'false'){
					        quicknews.hideall();
					        $('newsquicktab2').show();
					    }
					    
						quicknews.switch_tab('2')
					
					});					
					
					Event.observe($('state1bnxt'), 'click', function() { quicknews.submitsignup() });
					
					Event.observe($('enterpwd'), 'focus', function() { $('enterpwd').value=''; $('enterpwd').type='password'});
									
					
					//determine if we are after they have submitted					
					var pagestate = nopt_gup('pwdpass');
                    var logout = nopt_gup('logout');
                    
                    if(logout != 'true')
                    logout = 'false';								
										
					if(pagestate == 'undefined' || pagestate == null || logout == 'true' || quicknews.closePWDMod == 'true')
					 {
					       pagestate = '';
					       
					       if(quicknews.closePWDMod == 'true')
					       {quicknews.replaceCheckedFlag = 0;}
					       	 
					 }
					 
									

//alert("quicknews.loginflag : "+quicknews.loginflag+":pagestate : "+pagestate+":quicknews.closeflag : "+quicknews.closeflag+":quicknews.loadflag:"+quicknews.loadflag);					
					switch(pagestate) {					   
						case 'Y':
						
						    						    
						    if((quicknews.closeflag == 'false' || quicknews.closeflag == '' || quicknews.closeflag == null) && (quicknews.loadflag == 'false' || quicknews.loadflag == 'true')) {
								 
								  if(quicknews.finalcloseflag != 'true')quicknews.setOmniture('pwdbtn');	
								  	  			   						    							
								  																						
							}		
							
							if((quicknews.closeflag == 'false' || quicknews.closeflag == '' || quicknews.closeflag == null) && quicknews.loadflag == 'true') {
								  	   						    							
								  quicknews.changestate('thankyou','');																							
							}	
													
							
							if(quicknews.closeflag == 'true' && quicknews.loadflag == 'true'){
							
							    quicknews.closeflag = 'false';								    				    
							    $('state1').show();											
								$('loggedinstate1a').show();
								//quicknews.changestate('loggedinstate1a', '');							    
							
							    
							}
							
							if(quicknews.loadflag == 'false'){
							
							   quicknews.changestate('thanksfinal','');
							}				
							
						break;
								
						default:						
						//alert("init:case : default :");							
							if (pagestate > '' && pagestate != 'Y') {							
															
								els2 = $$('input.newsopt');
								for (i = 0; i < els2.length; i++) {
									els2[i].checked = false ;
								}
								
								elstosplit = nopt_gup('pwdpass').split("|");
								if (elstosplit.length > 0) {
									
									/*********									
									IF THEY SUBMITTED THE WRONG PASSWORD									
									********/
																		
									elstosplit.each(function(s) {
										if(s > '') {
											$(s).checked=true;
											
										}
									});
									
								}
								
								quicknews.replaceCheckedFlag = 0;
								//alert("::: Invalid pwd :::");
								quicknews.invalidPwd = 'true';			
								quicknews.changestate('loggedinstate1b', quicknews.passworderror);
								
																
															   
							}
							
																			
							if(pagestate =='' && quicknews.loadflag == 'true' && quicknews.loginflag == 'false'){						    

								 quicknews.hideall();
								$('state1').show();																						
								$('loggedoutstate1a').show();
										
							}
							
						
							if(pagestate =='' && quicknews.loadflag == 'false' && quicknews.loginflag == 'true'){							   					   
								   quicknews.changestate('thanksfinal','');													
							}
							
							if(pagestate =='' && quicknews.loadflag == 'true' && quicknews.loginflag == 'true'){
								 //quicknews.closePWDMod = 'false'
							     quicknews.replaceCheckedFlag = 0;							   							
							   	 quicknews.hideall();						   
								$('state1').show();									 											
								$('loggedinstate1a').show();
																	
							}											
																				
							break;
					}
					//alert('after_pagestate_switch');
				}//end if document.getElementById('newsletter_quick')
			},
			submitsignup: function() {
				//This is where the ajax call to submit the newsletter opt-in should go
				//newsletter_form is the name of the form that contains the user's 
				//login, password, and the newsletter checkbox options	
			    
				newsletterhub.subscribNewsletters();						

			},
			
			check_is_user: function(useremail) {			
				//This is where the ajax call to check if a user exists should go
				//set ajaxresult to true if they exist and false if they dont
				//passes thie email they submitted:    useremail
				//ajaxresult = true/false;
							 								                
                if(newsletterhub.newsletterhub_email == 'true'){                               
                    $('email_inline_container').innerHTML = useremail;                    
                    $('username').value=useremail;            
                    
                	quicknews.hideall();
                	/*quicknews.setOmniture('emailbtn');*/
					quicknews.changestate('loggedinstate1b','');
					
					/*
if(typeof submitOmnitureFromSP == 'function') 
					{
					    
					    submitOmnitureFromSP();
					}
*/
					
                }else{   
                 	
					quicknews.changestate('notsignedup','');
                }
                           		
			},
			waitValue: function(loops){
			     	var countIt = 0;
				     while(countIt<=loops){
				        if(newsletterhub.newsletterhub_email != '')break;
				        countIt++;
				        if(newsletterhub.newsletterhub_email == 'false' || newsletterhub.newsletterhub_email == 'true')break;	        
				        
				     }
			},
			
			//switches tabs between newsletter and blogs
			switch_tab: function(toswitchto) {
				if(toswitchto != quicknews.activetab) {
					switch(toswitchto) {
						case '1':
							$('newsquicktab2').hide();
							$('newsquicktab1').show();
							break;
						case '2':
							$('newsquicktab1').hide();
							$('newsquicktab2').show();
							break;
					}
					if ($('newsletterhdr').hasClassName('alt_tab')) {
						$('newsletterhdr').removeClassName('alt_tab');
					}
					else {
						$('newsletterhdr').addClassName('alt_tab');
					}
					quicknews.activetab = toswitchto;
				}
			},
			//switches the different states of the newsletter
			changestate: function(state,errormsg) {
			    //quicknews.closePWDMod = 'false';
				switch(state) {
					case 'loggedinstate1a':
						this.hideall();
						$('loggedinstate1a').show();
						break;
					case 'loggedinstate1b':					    
										
						var checkflag_2 = '';
						
						if(quicknews.outdoneflag == 'true'){
						   checkflag_2 = quicknews.checkedForm;
						}else{
						   checkflag_2 = quicknews.checkform();
						}
	                    
						if (checkflag_2 == 'true'){						
						    $("_source2").innerHTML = 'password';
						    if($('emailaddr').getValue() !=null && $('emailaddr').getValue() !='')
								 $('email_inline_container').innerHTML = $('emailaddr').getValue();
							else $('email_inline_container').innerHTML = $('emailaddrloggedout').getValue();
								 $('username').value=$('email_inline_container').innerHTML;
																												
							if(quicknews.replaceCheckedFlag == 1) {							
							
							
							}
							else {
							    var count = 0;
							    
								els = $$('input.newsopt');
								els.each(function(s) { 
								
								    if(count == 0){									   
									   	   new Insertion.Before(s.ancestors()[0],'<p><a class="close_btn" href="javascript:quicknews.setClosePWDMod();">Close</a></p>');
									   	   count++;
									 }
									 
									if (s.getValue() > '') {
									   	s.hide();									   	
										new Insertion.Before(s.ancestors()[0], '<ul><li><\/li><\/ul>');
									}
									else {
										s.ancestors()[0].hide();
									}
								});
								quicknews.replaceCheckedFlag = 1;
								
								
							}	
							
							quicknews.hideall();
							$('loggedinstate1b').show();
													
							
							if(quicknews.invalidPwd == 'true'){
							  if(errormsg != null && errormsg != '')
							  $('errorcontainer').innerHTML = errormsg;
							  $('errorcontainer').show();
							}
												 

							$('sent_to_container').show();							
							

														
						}
						else {
							quicknews.changestate('loggedinstate1a', quicknews.notfilledinerror);						
						}
											
						break;
					case 'notsignedup':					     
						 $('state1').hide();
					     quicknews.hideall();	
						$('notsignedup').show();
						break;
					case 'thankyou':					    
						$('state1').hide();
						quicknews.hideall();
						$('thanksdone').show();
						break;
					case 'thanksfinal':	
					    quicknews.finalcloseflag='true';
					    quicknews.setOmniture('pwdbtn');				   
					    $('state1').hide();
					    quicknews.hideall();												
						$('thanksfinal').show();
						break;
					}
				//if(errormsg!=null) {$('errorcontainer').innerHTML = errormsg;}
			},
			//hides all states, called between state changes and onload.
			hideall: function() {
				$('loggedinstate1a').hide();
				$('loggedinstate1b').hide();
				$('loggedoutstate1a').hide();
				$('sent_to_container').hide();				
				$('thanksdone').hide();
				$('thanksfinal').hide(); 
				$('notsignedup').hide();
				
			},
			checkform: function() {
			
				var checkflag_3 = 'false';
				els2 = $$('input.newsopt');
				for (i = 0; i < els2.length; i++) {
					if(els2[i].checked == true) {
						checkflag_3 = 'true';						
						if(checkflag_3 == 'true')break;
					}
				}
			
				if(quicknews.outdoneflag =='true' && checkflag_3 == 'true'){				  
				   if(($("emailaddrloggedout").value == '') || ($("emailaddrloggedout").value == 'Enter Email Address'))
				    checkflag_3 = 'false'; 
				   
				}		
				
				$('errorcontainer').innerHTML = quicknews.notfilledinerror;

				if(checkflag_3 == 'true'){				  
				    $('errorcontainer').innerHTML ='';				    	
				    $('errorcontainer').hide();	
	            }else{
	                $('errorcontainer').show();
	            }

	            
				return checkflag_3;
			},
			setClosePWDMod: function(){
			    quicknews.closePWDMod = 'true';
			    closeMsg();
			},
			setOmniture: function(btn){
			    /*
			    if(btn == 'emailbtn'){
			        var s=s_gi(s_account); 
			        s.linkTrackVars='eVar22, events';
			        s.linkTrackEvents='event43'; 
			        
			        if(quicknews.loginflag =='false')
			         s.eVar22='NL_loggedout'; 
			        if(quicknews.loginflag =='true')
			         s.eVar22='NL_loggedin'; 
			         
			        s.events='event43'; 			         
			        s.tl(this,'o','NL Module Link');
			    }
			    
			    if(btn == 'pwdbtn'){
			    
			       var s=s_gi(s_account); 
			       s.linkTrackVars='eVar22, events';
			       s.linkTrackEvents='event44'; 			       
			       		       
			       s.eVar22='NL_loggedin';		      		       		        
			       s.events='event44'; 
			       s.tl(this,'o','NL Module Link');
			    }*/
			}
		};



MSLO.collageModule = Class.create();
MSLO.collageModule.prototype = {
	initialize: function(elem) {
		this.elem = elem;
		this.imgs = $$('#' + this.elem + ' img'.toString());
		this.destitation = $$('#' + this.elem + ' .collageTitle p'.toString())[0];
		this.imgs.each(function(s) {
			Event.observe(s,'mouseover',this.show.bind(s,this.destitation));
			Event.observe(s,'mouseout',this.hide.bind(s,this.destitation));										
		}.bind(this));
	},
	show: function(destitation) {
		destitation.update(this.title);
		this.addClassName('hover');
	},
	hide: function(destitation) {
		this.removeClassName('hover');
		destitation.update('&nbsp\;');
	}
};

function collageModuleInit() {
	var collage = $$('.collage');
	if(!collage) return;
	collage.each(function(s,index) {
		var collageId = function() {
			collage[index].id = 'collage'+index;
			return collage[index].id;
		}();
		new MSLO.collageModule(collageId);
	});
}

MSLO.dropdown = function() {
	var eventName = (window.attachEvent) ?
		['mouseenter','mouseleave'] : ['mouseover','mouseout'];
	var dropwdown = $$('.dropdown')[0]; // improves speed
	var list = $$('.dropdown .inner')[0]; // improves speed
	var container = $$('.dropdown .list_container')[0];
	var dimensions = list.getDimensions();
	[list,container].each(function(s) {
		s.setStyle({ width: dimensions.width + 'px' });
	});
	$$('.dropdown div')[0].observe(eventName[0], function() {
		list.addClassName('hover');
	});
	$$('.dropdown div')[0].observe(eventName[1], function() {
		list.removeClassName('hover');
	});
};

function nopt_gup(name) {
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return results[1];
	}

//of the day monthly view tool tip

ofDayToolTip = {
	day : "",
		
	initDay: function() {
		if(!$("weeks-in-month")) return false;
	
		ofDayToolTip.day = $("weeks-in-month").getElementsByTagName("li");
		for(var i=0; i<ofDayToolTip.day.length; i++) {
			//Event.observe(ofDayToolTip.day[i], "click", function() { ofDayToolTip.showDay(this); return false; });
			ofDayToolTip.day[i].onclick = function() { ofDayToolTip.showDay(this); return false; };
		}
		Event.observe("close-tip", "click", ofDayToolTip.hideDay);
	},
	
	showDay: function(obj) {
		//close tip if opened
		ofDayToolTip.hideDay(this);
		
		//position tip
		var liPos = Position.positionedOffset(obj);
		var posLeft = liPos[0]-21;
		var pointLeft = liPos[0]+66;
		var posTop = liPos[1]-157;
		var pointTop = liPos[1]+110;
		var point = "url(http://images.marthastewart.com/images/assets/module/cookie_of_the_day/of-the-day-tooltip-pointer-flip.png)";
		var pointFlip = "url(http://images.marthastewart.com/images/assets/module/cookie_of_the_day/of-the-day-tooltip-pointer.png)";

		//get info this from list item
		var getImgs = obj.getElementsBySelector("img")[0];
		var getDesc = obj.getElementsByClassName("tip-desc")[0];
		var getTheMonth = obj.getElementsByClassName("tip-month")[0];
		var getTheDate = obj.getElementsByClassName("tip-date")[0];
		var getTheDay = obj.getElementsByClassName("tip-day")[0];
		var getTheLink = obj.getElementsByClassName("tip-link")[0];
		
		var attTitle = getImgs.getAttribute("title");
		var attRel = getImgs.getAttribute("rel");
		var makeImg = "<a href=" + getTheLink.innerHTML + "><img src=" + attRel + " class=\"ms-global-shadow-large-thumb\" title=" + attTitle +"  /></a>";
		
		//place list item info into tip
		document.getElementById('tool-tip-title').innerHTML = attTitle;
		document.getElementById('tool-tip-description').innerHTML = getDesc.innerHTML;
		document.getElementById('tool-tip-img').innerHTML = makeImg;
		document.getElementById('cal-month').innerHTML = getTheMonth.innerHTML;
		document.getElementById('cal-date').innerHTML = getTheDate.innerHTML;
		document.getElementById('cal-day').innerHTML = getTheDay.innerHTML;
		document.getElementById("tool-tip-title").href = getTheLink.innerHTML
		document.getElementById("tool-tip-url").href = getTheLink.innerHTML
				
		Element.setStyle("tool-tip-pointer", { background:point });
		
		//position tip depending on list item position
		if(posLeft == 82) {
			var posLeft = posLeft-22;
			var pointLeft = posLeft+104;
			Element.setStyle("tool-tip-pointer", { background:point });
		} if(posLeft == 171) {
			var posLeft = posLeft-85;
			var pointLeft = posLeft+170;
			Element.setStyle("tool-tip-pointer", { background:point });
		} if(posLeft == 260) {
			var posLeft = posLeft-126;
			var pointLeft = posLeft+215;
			Element.setStyle("tool-tip-pointer", { background:point });
		} if(posLeft == 349) {
			var posLeft = posLeft-172;
			var pointLeft = posLeft+165;
			Element.setStyle("tool-tip-pointer", { background:pointFlip });
		} if(posLeft == 438) {
			var posLeft = posLeft-234;
			var pointLeft = posLeft+225;
			Element.setStyle("tool-tip-pointer", { background:pointFlip });
		} if(posLeft == 527) {
			var posLeft = posLeft-265;
			var pointLeft = posLeft+253;
			Element.setStyle("tool-tip-pointer", { background:pointFlip });
		} 
						
		$("tips-month-tooltip").show();
		$("tool-tip-pointer").show();
		Element.setStyle("tips-month-tooltip", { position:"absolute", top:posTop+"px", left:posLeft+"px" });
		Element.setStyle("tool-tip-pointer", { position:"absolute", top:pointTop+"px", left:pointLeft+"px" });
		
		obj.addClassName("highlight");
	},
	
	hideDay: function() {
		$("tips-month-tooltip").hide();
		$("tool-tip-pointer").hide();
		
		for(var i=0; i<ofDayToolTip.day.length; i++) {
			$(ofDayToolTip.day[i]).removeClassName("highlight");
		}
	}
	
};

Event.observe(window, 'load', ofDayToolTip.initDay);


function fixIESelect() {
	if (document.getElementById("filter_block")) {
		$("filter_topic").onfocus = function() {
			this.addClassName("ie_sel_focus");
		}
		$("filter_topic").onblur = function() {
			this.removeClassName("ie_sel_focus");
		}

		$("filter_celebration").onfocus = function() {
			this.addClassName("ie_sel_focus");
		}
		$("filter_celebration").onblur = function() {
			this.removeClassName("ie_sel_focus");
		}

		$("filter_source").onfocus = function() {
			this.addClassName("ie_sel_focus");
		}
		$("filter_source").onblur = function() {
			this.removeClassName("ie_sel_focus");
		}

		$("filter_type").onfocus = function() {
			this.addClassName("ie_sel_focus");
		}
		$("filter_type").onblur = function() {
			this.removeClassName("ie_sel_focus");
		}
	}
}

// if (document.all) {
// 	Event.observe(window, 'load', fixIESelect);
// }


// temporary fix to most-active-posts module
/*
function addGroupIdToPostLinks() {

	postSections = $$('div.recent_posts');
	if (postSections.length > 0) {
		var groupId;
		anchors = postSections[0].getElementsByTagName('a')
		for (i = 0; i < anchors.length; i++ ) {
			beginIndex = anchors[i].href.indexOf("groupId=");
			if (beginIndex > -1) {
				groupId = anchors[i].href.substring(beginIndex + 8);
				break;
			}		
		}
		postLinks = $$('a.title');
		for (i = 0; i < postLinks.length; i++ ) {
			postLinks[i].href = postLinks[i].href + "&groupId=" + groupId;
		} 
	}
}
Event.observe(window, 'load', addGroupIdToPostLinks);
*/


/*a slick way of dealing with Internet ExplorerÕs badly implemented getElementById() method*/
function betterIeGetElement() {
	if (/msie/i.test (navigator.userAgent)) //only override IE
	{
		document.nativeGetElementById = document.getElementById;
		document.getElementById = function(id)
		{
			var elem = document.nativeGetElementById(id);
			if(elem)
			{
				//make sure that it is a valid match on id
				if(elem.id == id)
				{
					return elem;
				}
				else
				{
					//otherwise find the correct element
					for(var i=1;i<document.all[id].length;i++)
					{
						if(document.all[id][i].id == id)
						{
							return document.all[id][i];
						}
					}
				}
			}
			return null;
		};
	}
}

/*Pets UGC Validator*/
MSLOvalidator = {
	validatedfields: [],
	checktrigger: '',
	validated : false,
	csslabelSelector: '',
	
	init : function(valinfo, checktrigger, callback, csslabelSelector) {
		this.validatedfields = valinfo;
		this.checktrigger = checktrigger;
		this.callback = callback;
		this.csslabelSelector = csslabelSelector;
		var i = 0;
		betterIeGetElement();
		while(i < this.validatedfields.length) {
			if (typeof(this.validatedfields[i].defaulttxt) != 'undefined') {
				if (typeof($(this.validatedfields[i].fieldid)) != 'undefined') {
					if (($(this.validatedfields[i].fieldid).value == null) || ($(this.validatedfields[i].fieldid).value.length == 0)) {
						$(this.validatedfields[i].fieldid).value = this.validatedfields[i].defaulttxt;
					}
				}
			}
			if (typeof($(this.validatedfields[i].fieldid)) != 'undefined') {
				$(this.validatedfields[i].fieldid).observe('click', this.replacedefault.bind(this, i));			
			}
			i++;	
		}
		$(this.checktrigger).observe('click', this.validate.bind(this));
	},
	check_valid: function(fieldnum) {
		if(this.validatedfields[fieldnum].required == true) {
		//alert($(this.validatedfields[fieldnum].fieldid).getValue());
				var curval = $(this.validatedfields[fieldnum].fieldid).getValue();
				if (typeof(this.validatedfields[fieldnum].defaulttxt) != 'undefined') {
					if(curval == this.validatedfields[fieldnum].defaulttxt || curval.length == 0) {
						this.validated = false;
						$(this.validatedfields[fieldnum].fieldid).previous(this.csslabelSelector).setStyle({color: 'red'});
						
					}
					else {
						$(this.validatedfields[fieldnum].fieldid).previous(this.csslabelSelector).setStyle({color: 'black'});
					}
				}
				else if(curval.length == 0) {
					
					this.validated = false;
					$(this.validatedfields[fieldnum].fieldid).previous(this.csslabelSelector).setStyle({color: 'red'});
					
				 }
				 else {
					$(this.validatedfields[fieldnum].fieldid).previous(this.csslabelSelector).setStyle({color: 'black'});
				 }
			}
	},
	validate: function() {
		var i = 0;
		this.validated = true;
		while(i < this.validatedfields.length) {
			this.check_valid(i);
			i++;
		}
		if (this.validated == true) {
			if($$('.validate_ok')) {
				$$('.validate_ok')[0].style.color='#0D995F';
				$$('.validate_ok')[0].innerHTML = 'Please tell us more about your photo.';
			}
			this.callback();
			return false;
		}
		else {
			if($$('.validate_ok')) {
				$$('.validate_ok')[0].innerHTML = 'Please complete all fields where the text is red.';
				$$('.validate_ok')[0].style.color='red';
				//jump them to the top to view the error msg
				location.href = location.href+"#col1_content";
			}
			return false;
		}
	
	},
	replacedefault: function(fieldnum) {
		if ($(this.validatedfields[fieldnum].fieldid).value == this.validatedfields[fieldnum].defaulttxt) {
			$(this.validatedfields[fieldnum].fieldid).value = '';
		}
	}
	
};


function disableTagsInput() {
	if (!document.getElementById('filter_tags')) {
		if (document.getElementById('display_photo_detail_fieldset')) {
			document.getElementById("desctags").style.display = "none";
			document.getElementById("desctags").value = "";
			document.getElementById("desctags").disabled = true;
	
			h3 = document.getElementById("display_photo_detail_fieldset").getElementsByTagName("h3");
			for (var i = 0; i < h3.length; i++) {
				if (h3[i].innerHTML == "<label>Descriptive Tags</label>") {
					h3[i].style.display = "none";
				}
			}
		}
	}
}
Event.observe(window, 'load', disableTagsInput);


function populate_syndicated_hdr(loginname, collectlink, accountlink, signoutlink, placelink) {
	var namestring = '<a href="'+placelink+'">'+loginname+'</a>';
	$('hed_greeting').innerHTML = 'Welcome '+namestring;

	data = ''+ 
	'|'+
	'<a href="'+collectlink+'">My Collections</a>'+
	'|'+
	'<a href="'+accountlink+'">My Account</a>'+
	'|'+
	'<a href="'+signoutlink+'">Sign out</a>';
	
	$('hed_links').innerHTML = data;
}

function populate_syndicated_hdr_loggedout(loginlink, registerlink) {

	data = ''+ 
	'<a href="'+loginlink+'">Sign in</a>'+
	'|'+
	'<a href="'+registerlink+'">Register Now</a>';
	
	$('hed_links').innerHTML = data;
}

function GetCookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	var a_tmp_cookie_val = '';

	for ( i = 0; i < a_all_cookies.length; i++ ){
		a_temp_cookie = a_all_cookies[i].substring(0,a_all_cookies[i].indexOf( '=' ));
		cookie_name = a_temp_cookie.replace(/^\s+|\s+$/g,"");
		if ( cookie_name == check_name ){
			a_tmp_cookie_val = a_all_cookies[i].substring(a_all_cookies[i].indexOf( '=' )+1);
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 ){
				cookie_value = unescape( a_tmp_cookie_val);
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ){
		return null;
	}
}
function GetParam(value, param){
	if (value == null) return null;
	var keyVals = value.split('|');
	var tmpK = '';
	for (i=0; i<keyVals.length;i++){
		tmpK = keyVals[i].split('=');
	if (param==tmpK[0]){
			return tmpK[1];
		}
	}
	return null;
}

function Delete_Cookie( name, path, domain ) {
if ( GetCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function Pager(tableName, itemsPerPage) {
    this.tableName = tableName;
    this.itemsPerPage = itemsPerPage;
    this.currentPage = 1;
    this.pages = 0;
    this.inited = false;
    
    this.showRecords = function(from, to) {        
        var rows = document.getElementById(tableName).rows;
        // i starts from 1 to skip table header row
        for (var i = 1; i < rows.length; i++) {
            if (i < from || i > to)  
                rows[i].style.display = 'none';
            else
                rows[i].style.display = '';
        }
    }
    
    this.showPage = function(pageNumber) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
    	}

        var oldPageAnchor = document.getElementById('pg'+this.currentPage);
        oldPageAnchor.className = 'pg-normal';
        
        this.currentPage = pageNumber;
        var newPageAnchor = document.getElementById('pg'+this.currentPage);
        newPageAnchor.className = 'pg-selected';
        
        var from = (pageNumber - 1) * itemsPerPage + 1;
        var to = from + itemsPerPage - 1;
        this.showRecords(from, to);
        
      var pgNext = document.getElementById('pgNext');
      var pgPrev = document.getElementById('pgPrev');
      if (this.currentPage == this.pages)
	  pgNext.style.display = 'none';
      else
	  pgNext.style.display = '';
	  
     if (this.currentPage == 1)
	  pgPrev.style.display = 'none';
      else
	  pgPrev.style.display = '';

    }   
    
    this.prev = function() {
        if (this.currentPage > 1)
            this.showPage(this.currentPage - 1);
    }
    
    this.next = function() {
        if (this.currentPage < this.pages) {
            this.showPage(this.currentPage + 1);
        }
    }                        
    
    this.init = function() {
        var rows = document.getElementById(tableName).rows;
        var records = (rows.length - 1); 
        this.pages = Math.ceil(records / itemsPerPage);
        this.inited = true;
    }

    this.showPageNav = function(pagerName, positionId) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
    	}
    	var element = document.getElementById(positionId);
    	
    	var pagerHtml = '<span style="color:#0CAABB; cursor:pointer;" onclick="' + pagerName + '.prev();" id="pgPrev"> Previous </span>  ';
        for (var page = 1; page <= this.pages; page++) 
            pagerHtml += ' <span style="color:#0CAABB;cursor:pointer;font-weight:bold" id="pg' + page + '" onclick="' + pagerName + '.showPage(' + page + ');">' + page + '</span>  ';
        pagerHtml += '<span style="color:#0CAABB;cursor:pointer;" onclick="'+pagerName+'.next();" class="single-dots" id="pgNext"> Next </span>';            
        
        element.innerHTML = pagerHtml;
    }
}





//  check cookies function for registration link.

function checkCookies() {
	var tmpcookie = new Date();
	chkcookie = (tmpcookie.getTime() + '');  
	document.cookie = "chkcookie=" + chkcookie + "; path=/";
	if (document.cookie.indexOf(chkcookie,0) < 0) {      
		// alert("You must enable cookies on your browser.");
		modalBox('cookies');
		return false;
	}
	return true;
}



// stand alone email validation without registration

 function noRegEmailValid(e){
	 var regex =  /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/;
	 emailaddy = $(e).value;
	 if(emailaddy.match(regex)){
		 return true;
	 } else {
		 return false;
	 }
 }
	   


function prepareLinks() {

	var currentSite = window.location.host;
	if (currentSite.indexOf("www.") != -1) {
		s = currentSite.split("www.");
		currentSite = s[1];
	}
	if (currentSite.indexOf("dev.") != -1) {
		s = currentSite.split("dev.");
		currentSite = s[1];
	}
	if (currentSite.indexOf("qa.") != -1) {
		s = currentSite.split("qa.");
		currentSite = s[1];
	}
	// if (currentSite.indexOf("preview.corp.mslo.com") != -1) {
	// 	currentSite = "marthastewart.com";
	// }

	
	var links = $$("a");
	links.each(function(a) {
		if ((a.href.indexOf("http") != -1) && (a.href.indexOf(currentSite) == -1)) {
			a.onclick = function() {
				tgt = "";
				if ($(this).href.indexOf("marthastewart.com") != -1) {
					tgt = "mso_win";
				}
				if ($(this).href.indexOf("wholeliving.com") != -1) {
					tgt = "bs_win";
				}
				if ($(this).href.indexOf("marthastewartweddings.com") != -1) {
					tgt = "msw_win";
				}

				// preview fixes
				if ($(this).href.indexOf("preview.corp.mslo.com") != -1) {
					tgt = "mso_win";
				}
				if ($(this).href.indexOf("previewbs.corp.mslo.com") != -1) {
					tgt = "bs_win";
				}
				if ($(this).href.indexOf("previewmsw.corp.mslo.com") != -1) {
					tgt = "msw_win";
				}


				if (tgt == "") {
					w = window.open($(this).href);
					if (window.focus) {w.focus();}					
					return false;
				} else {
					w = window.open($(this).href, tgt);
					if (window.focus) {w.focus();}					
					return false;
				}
			}
		}
	});

	if ((currentSite == "marthastewart.com") || (currentSite == "preview.corp.mslo.com")) {
		var navLinks = $$("#global_nav a");
		navLinks.each(function(a) {
			a.onclick = function() {
				tgt = "";
				if ($(this).href.indexOf("Wedding?") != -1) {
					tgt = "msw_win";
				}
				if ($(this).href.indexOf("wholeliving.com") != -1) {
					tgt = "bs_win";
				}

				if (tgt != "") {
					w = window.open($(this).href, tgt);
					if (window.focus) {w.focus();}					
					return false;
				}
				return true;
			}
		});

	}

}


function readCookie(name) {
	   var nameEQ = name + "=";

	   var ca = document.cookie.split(';');
	   for(var i=0;i < ca.length;i++) {
			   var c = ca[i];
			   while (c.charAt(0)==' ') c = c.substring(1,c.length);
			   if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	   }
	   return '';
}

function readVirtualCookie(name) {
	   var m_vck = readCookie('m_vck');
	   if (m_vck!='') {
			   m_vck = unescape(m_vck);
			   cki = m_vck.indexOf(name + '^^');
			   if(cki>=0) {
					   ckend = m_vck.indexOf('$$', cki);
					   if (ckend<0) ckend = m_vck.length - 1;
					   m_vck_tmp =  m_vck.substring(cki, ckend);
					   ck_vals = m_vck_tmp.split('^^');
					   return ck_vals[1];

			   }
	   }
	   return '';
}

function eraseVirtualCookie(name) {
	   saveVirtualCookie(name,"");
}

function saveVirtualCookie(name,value) {
	   if ((name=='mt_az') && (value=='mt_adzone@site_home')) {
            value = '';
	   }
	   if(value!='' || value != null )
			   ck = name + '^^' + value;

	   var m_vck = readCookie('m_vck');
	   if (m_vck!='' || m_vck!=null) {
			   m_vck = unescape(m_vck);
			   cki = m_vck.indexOf(name + '^^');
			   if(cki>=0) {
					   ckend = m_vck.indexOf('$$',cki);
					   if (ckend<0) ckend = m_vck.length - 1;
					   m_vck_tmp =  m_vck.substring(cki, ckend);
					   m_vck = m_vck.replace(m_vck_tmp + '$$', '');
			   }
	   }
	   if(value!='') {
			   m_vck = m_vck +  ck + '$$';
	   }
	   m_vck = escape(m_vck);
	   

	   document.cookie = 'm_vck'+"="+m_vck+"; path=/";
}

function getDefaultStr(val, def) {
	   if(val == null || val == 'undefined') return def;
	   return val;
}       



function getChannelPrefix(url) {
	   idx = url.indexof('vgnextoid');
	   chPrfx = '';
	   if(idx>=0) {
			   chPrfx = url.substring(idx+9, idx+49);
	   } else {
			   idx = url.lastindexof('/');
			   idxEnd = (url.indexof('?', idx) >=0) ? url.indexof('?', idx) : url.length - 1;
			   chPrfx = url.substring(idx, idxEnd);
	   }
}


/*


Event.observe(window, 'load', function() { 
	prepareLinks(); 
});
*/

Event.observe(window, 'load', function() { 
	var newscript = document.createElement('script');

	if (document.getElementById('pets')) {
		newscript.src = 'http://content.dl-rms.com/rms/23288/nodetag.js';
	}
	else {
		newscript.src = 'http://content.dl-rms.com/rms/23287/nodetag.js';
	}
	document.body.appendChild(newscript);
});



// TV show nav
function displayShowDetails(el) {
	
	// el.getElementsByTagName("span")[0].style.display = "none";
	// el.getElementsByTagName("span")[1].style.display = "none";
	// el.getElementsByTagName("span")[2].style.display = "block";

}

function hideShowDetails(el) {
	
	// el.getElementsByTagName("span")[0].style.display = "block";
	// el.getElementsByTagName("span")[1].style.display = "block";
	// el.getElementsByTagName("span")[2].style.display = "none";

}


/*
Tracking code
function tracking_createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function tracking_readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

window.onload = function() {
	if (tracking_readCookie('MSLOrandomSessionId') != 'null') {
		uniqueid = tracking_readCookie('MSLOrandomSessionId');
	}
	else {
		uniqueid = randomnumber=Math.floor(Math.random()*999999+888888);
		tracking_createCookie('MSLOrandomSessionId', uniqueid);
	}
	newscript = document.createElement('script');
	newscript.src = 'http://load.exelator.com/load/?p=1848&g=001&s='+uniqueid;
	document.body.appendChild(newscript);

}

*/


/* 	New UGC Comments Insertion
	Accepts a JSON string returned from teh server and the ID of the element to replace the contents of
	I'm assuming that the supplied markup matches existing css...otherwise it really should be re-written
	as its pretty div-a-licious
	
	had to use array-access to the object (comment['property']) instead of object notation (comment.property) because some
	of the property names have dashes, and javascript tries to subtract (derf!)
*/
function ugcInsertComments(commentsJSONtxt, IdOfElementToReplaceContentsOf) {
	commentsarray = eval('('+commentsJSONtxt+')');
	outputhtml = '';
	outputhtml = 	'<div id="comments_wrapper">' +
						'<h2 class="contributors_comment">Comments</h2>' +
						'<p class="total-comments">'+(commentsarray.length-1)+' comments (Last added '+commentsarray[1]['saved-date']+')</p>';
	var z = 1; //skip the first one which is the current token
	while (z < commentsarray.length) { //iterate over the comments array (0-indexed) and construct the HTML 
		var comment = commentsarray[z];
		outputhtml+=	'<div class="conversation-list">'+
						'<h3>'+ z +'.</h3>'+ //array 0-indexed, display should starts with one
						'<div class="inner">'+
							'<div class="member-box">'+
								'<div class="user">'+
									'<a href="/users/'+comment['user-screen-name']+'" title="username">'+
										'<img src="'+comment['thumbnail-uri']+'" alt="thumbnail">'+
										'<span class="name">'+
											comment['user-screen-name']+
											'<br>'+
										'</span>'+
									'</a>'+
								'</div>'+
							'</div>'+
							'<div class="comment">'+
								'<h5>'+comment['saved-date']+'</h5>'+
								'<div class="post-content">'+
									'<p>'+comment['comment-text']+'</p>'+
								'</div>'+
							'</div>'+
						'</div>'+
					'</div>';
		z++;
	}
	outputhtml+='</div>';
	document.getElementById(IdOfElementToReplaceContentsOf).innerHTML = outputhtml;
}


function getPageReferrer() {
	ref = "";
	var d = document.referrer != "" ? document.referrer.split("//")[1].split("/")[0] : "";
	if (d.indexOf("facebook") >= 0) {
	ref = "facebook";
	}
	if (d.indexOf("twitter") >= 0) {
	ref = "twitter";
	}	return ref;
}


function doucheWankeryFlashThing() {
	if (document.getElementById("food")) {
		var swf = "http://images.marthastewart.com/images/assets/global/flash_test.swf";
		var so = new SWFObject(swf, "notchThing", 300, 47, "8.0.23", "#FFFFFF");
		so.addParam("wmode","transparent");
		so.addParam("allowScriptAccess","always");
		so.write("ms-global-hdr-notch");
	}
}

Event.observe(window, 'load', function() { 
	doucheWankeryFlashThing();
});
