var MSLO = {};

/* 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];
			
			// 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() });
	},
	show: function() {
		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() {
		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')

	{

		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;
	
	}




	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');
		if(action.indexOf('contest')>-1)
			window.location.href='/portalext/contest/photo?contestId='+contest_id;		
	}
	else
	{
		var s=s_gi(s_account);
		s.linkTrackVars='prop27,prop28';
		s.prop27='logged in';
		s.prop28='li:'+omniturePageName;



	}
}


function trackAction(action)

{

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

}


/*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);

/*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 Your Password" link below.',
			
			activetab: 1,
			replacedcheckedflag: 0,
			//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')) {
					switch (loggedinstatus) {
						case 'in':
							Event.observe($('state1anxt'), 'click', function() { quicknews.changestate('loggedinstate1b') });					
							$('loggedinstate1a').show();
							$('emailaddr').value = emailaddress;
							break;
						case 'out':
							Event.observe($('loggedoutstate1anxt'), 'click', function() { quicknews.check_is_user($('emailaddrloggedout').value) });
							$('loggedoutstate1a').show();
							break;
					}
					Event.observe($('tab1_hdr'), 'click', function() { quicknews.switch_tab('1') });
					Event.observe($('tab2_hdr'), 'click', function() { quicknews.switch_tab('2') });
					Event.observe($('state1bnxt'), 'click', function() { quicknews.submitsignup() });
					Event.observe($('enterpwd'), 'focus', function() { $('enterpwd').value=''; $('enterpwd').type='password'});
				}
			},
			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
				
				//after the ajax call, the following methods should be used:
				//
				//Opt in successfull: 		this.changestate('thankyou');
				//Opt in password wrong:	this.changestate('loggedinstate1b', this.passworderror);
				
				
			},
			
			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;
				
				switch(ajaxresult) {
					case true:
						this.hideall();
						this.changestate('loggedinstate1b');
						$('email_inline_container').innerHTML = useremail;
						break;
					case false:
						this.hideall();
						this.changestate('notsignedup');
						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) {
				switch(state) {
					case 'loggedinstate1a':
						this.hideall();
						$('loggedinstate1a').show();
						break;
					case 'loggedinstate1b':
						this.hideall();
						$('loggedinstate1b').show();
						if (this.replacedchecksflag == 1) {
							
						}
						else {
							$('email_inline_container').innerHTML = $('emailaddr').getValue();
							els = $$('input.newsopt');
							els.each(function(s) { 
								if (s.getValue() == 1) {
									s.hide();
									new Insertion.Before(s.ancestors()[0], '<ul><li><\/li><\/ul>');
								}
								else {
									s.ancestors()[0].hide();
								}
							});
							this.replacedchecksflag = 1;
						}
						$('sent_to_container').show();
						break;
					case 'notsignedup':
						$('state1').hide();
						$('notsignedup').show();
						break;
					case 'thankyou':
						$('state1').hide();
						$('notsignedup').hide();
						$('thanksdone').show();
					}
				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();
			}
		};


