ML.cmsmode = ((window.self != window.top) && window.top.location.href.search('/cmsdesk/') !== -1);

var gaCodeActive = true;
if(gaCodeActive && document.location.host.search('.dev') === -1 && document.location.host.search('.stage') === -1 && !ML.cmsmode) {
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-2492198-1']);
	_gaq.push(['_trackPageview']);

	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js?v='+(new Date()*1);
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();
}

(function () {
	// let's create object to collect all temporary garbage in this
	// function (note, it will be deleted in the end of this function!):
	var cache = {};
	// sergey: clear object from junk
	cache.clean = function() {
		for(p in this) {
			if(p == 'clean') continue;
			delete this[p];
		}
	}
	
	// IE6 specific
		// IE6 png fix
			if(ML.ie6) {
				ML.init('DD_belatedPNG');
				DD_belatedPNG.fix('.shadow-title, .shadow-title span');
				
				// On public home page
					if(document.body.className.search('hanen-public-home-template') !== -1 ) {
						DD_belatedPNG.fix('div.links, div.icon, img');
						DD_belatedPNG.fixAspx('div.slider .entry img');
					}
				// On public home page End
				
				// On public level 1 page
					if(document.body.className.search('hanen-public-level-1-page-template-template') !== -1 ) {
						DD_belatedPNG.fix('div.icon, img');
						DD_belatedPNG.fixAspx('img');
					}
				// On public level 1 page End
				
				// On public level 2 page
					if(document.body.className.search('hanen-public-level-2-page-template') !== -1 ) {
						DD_belatedPNG.fix('div.icon, img');
						DD_belatedPNG.fixAspx('img');
					}
				// On public level 2 page End
				
				//For home page
					if( ML.classInBody('hanen-home-template') ) {
						// Png fix for IE6
							cache.slider_title = $('#homeSlideRotate .sliderWelcomeTab');
	
							if( !ML.$empty( cache.slider_title ) ) {
								DD_belatedPNG.fix( cache.slider_title.selector );
							}
						// Png fix for IE6 End
					}
				//For home page End
				
				// Fix png for forums template
					if( ML.classInBody('hanen-forums-template') ) {
						cache.go_input = $('#ContentContainer div.ForumSearchBox input.XShortButton');
						if( !ML.$empty(cache.go_input) ) {
							DD_belatedPNG.fix( cache.go_input.selector );
						}
					}
				// Fix png for forums template End
				
				//min-width fix for IE6 for .shadow-title
						cache.title = $('.shadow-title');
						
						if( !ML.$empty(cache.title) ) {
							for (var i=0, il = cache.title.length; i < il; i++) {
								if(cache.title[i].clientWidth < 109) {
									cache.title[i].style.cssText = 'width:100px;';
								}
							}
						}
				//min-width fix for IE6 for .shadow-title

				// Layout fix for store
					if( ML.classInBody('hanen-online-store-template') || ML.classInBody('hanen-members-store-template') ) {
						cache.leftbar = $('#MoreProductsContainer');
						cache.centerpart = $('#OnlineStoreMainContentContainer');
						if( !ML.$empty( [cache.leftbar, cache.centerpart] ) ) {
							cache.centerpart.css({'margin-top':-( parseInt(cache.leftbar.css('padding-top')) + cache.leftbar.get(0).offsetHeight - 60 )+"px"});
						}
					}
				// Layout fix for store End
				
				cache.clean();
			}
		// IE6 png fix End
	// IE6 specific End
	
	// IE fix when conditional styles don't load
		if( $.browser.msie ) {
			cache.head = $('head');
			cache.head_ie_css = cache.head.html().search('ie.css');
			cache.head_ie7_mode = cache.head.html().toLowerCase().search('ie=7');
			
			if(cache.head_ie7_mode !== -1 && cache.head_ie_css === -1) {
				cache.head_style = document.createElement('link');
				cache.head_style.type = 'text/css';
				cache.head_style.rel = 'stylesheet';
				cache.head_style.href = document.location.protocol+'//'+document.domain+'/App_Themes/HanenPortal/css/ie.css';
				cache.head_style.media = 'all';
				
				cache.head.append(cache.head_style);
			}
			cache.clean();
		}
	// IE fix when conditional styles don't load End

	cache.tooltips = $('.tooltip');
	if(!ML.$empty(cache.tooltips)) {
		ML.init('tooltip');

		cache.tooltips.each(function(num, el) {
			$(document).ready(function() {
				$(el).html('');
				$(el).tooltip({extraClass:'cvc-help tooltip1', opacity:1});
			});
		});

		cache.clean();
	}
	
	// Select issue fix for newsletter in IE
		//if( ML.ie8 || ML.ie7 || ML.ie6 ) {
			cache.selects = $('.newsletter-registration .subscription-fields select');
			if( !ML.$empty(cache.selects) ) {
				ML.init('ieSelectWidth');
				
				for (var i=0, il = cache.selects.length; i < il; i++) {
					$(cache.selects[i]).ieSelectWidth();
				}
			}
			
			cache.clean();
		//}
	// Select issue fix for newsletter in IE End
	
	//Remove background on last items
		cache.styles = {'margin-bottom':'0', 'padding-bottom':'0', 'background':'none'};
			
		//For home page
			if( ML.classInBody('hanen-home-template') ) {
				cache.home_blogs = $('#homeCol1 .blogsHome:last');
				if( !ML.$empty(cache.home_blogs) ) {
					cache.home_blogs.css(cache.styles);
				}
				
				cache.workshop_item = $('#homeCol1 .workshop-item:last');
				if( !ML.$empty(cache.workshop_item) ) {
					cache.workshop_item.css(cache.styles);
				}

				cache.titles = $('.shadow-title');
				if( !ML.$empty(cache.titles) && $.browser.msie && document.location.href.search('/cms/') === -1 ) {
					ML.init('DD_roundies');
					DD_roundies.addRule(cache.titles.selector, '0 0 10px 10px');
				}
			}
		//For home page End

		//For profile page
			if(document.body.className.search('profile') !== -1) {
				cache.home_blogs = $('div#zoneLeftContainer .news-item:last .news-item-description');
				if( !ML.$empty(cache.home_blogs) ) {
					cache.home_blogs.css(cache.styles);
				}
				
				cache.workshop_item = $('div#zoneLeftContainer .discussion-item:last .person-comment');
				if( !ML.$empty(cache.workshop_item) ) {
					cache.workshop_item.css(cache.styles);
				}
			}
		//For profile page End
		
		//For professional-development page
			if( ML.classInBody('professional-development') ) {
				cache.home_blogs = $('#ContentContainer .workshop-item:last');
				if( !ML.$empty(cache.home_blogs) ) {
					cache.home_blogs.css(cache.styles);
				}
			}
		//For professional-development page End
		cache.clean();

		//for public-list-page web part
		if( ML.classInBody('hanen-public-list-page-template') ) {
			cache.web_part_list_items = $('#PageContainer div.web-part .list-item:first');

			if( !ML.$empty(cache.web_part_list_items) ) {
				for (var i=0, il = cache.web_part_list_items.length; i < il; i++) {
					cache.web_part_list_items[i].style.cssText = "background-image:none;";
				};
				//.list-item
			}
			cache.clean();
		}
		//for public-list-page web part End
		
	//Remove background on last items End
	
	// Remove background on first items
		if( ML.classInBody('public') && ML.classInBody('home') ) {
			cache.featured_articles_list = $('body.public div.more-articles li:first');
			if( !ML.$empty(cache.featured_articles_list) ) {
				cache.featured_articles_list.css({'background':'none'});
			}
			cache.clean();
		}
	// Remove background on first items End

	//function below will add text in inputs	
		//On professional development page
	    	if(document.body.className.search('professional-development') !== -1) {
		    	//we are using jQuery method for placeholder, plugin is stored in mixed_before_load.js
		    	cache.search_input = $("#divZoneRight input.search-line");
		    	if( !ML.$empty(cache.search_input) && cache.search_input.placeholder) {
		    		cache.search_input.placeholder({'text':'Enter Keyword(s)'});
		    	}
		    	
		    	cache.name_input = $("#divZoneRight .subscription-fields input.name");
		    	if( !ML.$empty(cache.name_input) && cache.name_input.placeholder) {
		    		cache.name_input.placeholder({'text':'Name'});
		    	}
		    	
		    	cache.email_input = $("#divZoneRight .subscription-fields input.email");
		    	if( !ML.$empty(cache.email_input) && cache.email_input.placeholder) {
		    		cache.email_input.placeholder({'text':'Email Address'});
		    	}
		    	
		    	cache.clean();
			}
	//add text in inputs End
	
	// hanen-order-complete-template
		if( ML.classInBody('hanen-order-complete-template') ) {
			cache.print_link = $('#orderResultsContainer div.print a');
			if( !ML.$empty(cache.print_link) ) {
				cache.print_link.click(function() {
					print();
					return false;
				});
			}
			
			cache.clean();
		}
	// hanen-order-complete-template End
	
	// hanen-pdf-manual-template
		if( ML.classInBody('hanen-pdf-manual-template') ) {
		}
	// hanen-pdf-manual-template End

	// hanen-manage-preferences-template
		if( ML.classInBody('hanen-manage-preferences-template') ) {
			var update_message = {};
			update_message.container = $('#update-message');
			update_message.pref_message = $('#ContentContainer td.UserPrefButtons div#userProfileInfo');
			update_message.password_message = $('#ContentContainer div.change-password-wr .ErrorLabel');
			update_message.password_message2 = $('#ContentContainer div.change-password-wr .InfoLabel');

			if( !ML.$empty([update_message.container, update_message.pref_message]) ) {
				update_message.container.html(update_message.pref_message.html());
				update_message.pref_message.hide();
				if( !ML.$empty( update_message.password_message ) ) {
					update_message.container.html(update_message.container.html()+'<br>'+update_message.password_message.html());
					update_message.password_message.addClass('clear').css({'padding':'0'});
				} else if( !ML.$empty( update_message.password_message2 ) ) {
					update_message.container.html(update_message.container.html()+'<br>'+update_message.password_message2.html());
					update_message.password_message2.addClass('clear').css({'padding':'0'});
				}
			} else if( !ML.$empty([update_message.container, update_message.password_message]) ) {
				update_message.container.html(update_message.password_message.html());
				update_message.password_message.addClass('clear').css({'padding':'0'});
			} else if( !ML.$empty([update_message.container, update_message.password_message2]) ) {
				update_message.container.html(update_message.password_message2.html());
				update_message.password_message2.addClass('clear').css({'padding':'0'});
			}
		}
	// hanen-manage-preferences-template End
	
	// Blue list
		if( ML.classInBody('public') ) {
			cache.content_uls = $('div.content ul');
			if( !ML.$empty(cache.content_uls) ) {
				for (var i=0, il = cache.content_uls.length; i < il; i++) {
					if(cache.content_uls[i].innerHTML.search('blue-list-odd') !== -1 || cache.content_uls[i].innerHTML.search('blue-list-even') !== -1) {
						if(cache.content_uls[i].className) {
							cache.content_uls[i].className += " blue-list";
						} else {
							cache.content_uls[i].className += "blue-list";
						}
					}
				};
				
				// Add rounders to IE6-8
					if( ML.ie7 || ML.ie6 ) {
						ML.init('DD_roundies');
						DD_roundies.addRule('.blue-list', '10px');
					}
			}
			
			cache.clean();
		}
	// Blue list End

	// Blue bullets/numbers list
		cache.list_wraps = $('div.content div.BlueList');
		if( !ML.$empty(cache.list_wraps) ) {
			for (var i=0, il = cache.list_wraps.length; i < il; i++) {
				$.each($(cache.list_wraps[i]).find("li"), function(index, li) {
					cache.li = $(li);
					cache.li.html("<span class=\"MainText\">"+cache.li.html()+"</span>");
				});
			};
		}
		
		cache.clean();
	// Blue bullets/numbers list End
	
	// Online store terms
		if( ML.classInBody('hanen-public-level-1-page-template-4-callouts-template') || ML.classInBody('public-article-index-template-template') || ML.classInBody('hanen-article-public-article-home-template') || ML.classInBody('hanen-article-public-bridging-page-template') ) {
			var add_content = $('#PageContainer div.additional-content-4-callouts');
			if( !ML.$empty(add_content) ) {
				// Add rounders to IE6-8
				if( ML.ie7 || ML.ie6 ) {
					
						try {
							ML.init('DD_roundies');
						} catch(e) {}
						DD_roundies.addRule(add_content.selector, '10px');
				}

				add_content.find('.entry:first').css({
					'background-position':'-2px 0'
				});
			}
			
			cache.clean();
		}
	// Online store terms End
	
	//list pages
		cache.list_last_item = $('#PageContainer div.articles-list-template');
		if( !ML.$empty(cache.list_last_item) ) {
			cache.list_last_item.each(function () {
				$(this).find('div.article:first').css({'background-image':'none'});
			})
		}
		cache.clean();
	//list pages End
	
	//member search tooltips
	if( ML.classInBody('hanen-members-search-results-template') ) {
		$(window).load(function() {
			var tooltip_friend_request = $('#memberSearchResults td div.ov-h a');
			if( !ML.$empty( tooltip_friend_request ) ) {
				try {
					ML.init('tooltip');
				} catch(e) {
				}
				
				tooltip_friend_request.each(function(num, element) {
					$(element).tooltip({
						showURL: false,
						extraClass: "tooltip-actions",
						positionLeft: true,
						left:-15,
						top:-18
					});
				});
			}
		});
	}
	//member search tooltips End

	// hanen-certificate-print-template
	if( ML.classInBody('hanen-certificate-print-template') && !ML.classInBody('EditMode') ) {
		//$(window).load(function() {
		//	window.print();
		//});
	}
	// hanen-certificate-print-template End

	// hanen-manage-profile-template
	if( ML.classInBody('hanen-manage-profile-template') && !ML.classInBody('EditMode') && !ML.classInBody('DesignMode') ) {
		cache.pwd = $('#change-pwd');
		cache.pwd_container = $('#container-change-pwd');

		if( !ML.$empty([cache.pwd, cache.pwd_container]) ) {
			cache.pwd_container.html(cache.pwd.html());
			cache.pwd.hide();
		}

		cache.clean()
	}
	// hanen-manage-profile-template End

	// hanen-member-workshops-template
	if( ML.classInBody('hanen-member-workshops-template') || ML.classInBody('hanen-members-e-seminars-template') ) {
		cache.ULs = $('#ContentContainer ul');
		cache.OLs = $('#ContentContainer ol');
		if( !ML.$empty(cache.ULs) ) {
			$.each(cache.ulLIs, function(index, element) {
				$(element).find('li:first').css({'background':'none'});
			});
		}

		if( !ML.$empty(cache.OLs) ) {
			$.each(cache.OLs, function(index, element) {
				$(element).find('li:first').css({'background':'none'});
			});
		}
		cache.clean();
	}
	// hanen-member-workshops-template End

	// hanen-shopping-cart-template
	if( ML.classInBody('hanen-shopping-cart-template') ) {
		var cvchelp = $('#shoppingCartCreditCardTable span.CreditCardCVCHelp');
		var cvcquestion = $('#shoppingCartCreditCardTable span.CreditCardCVC');

		if( !ML.$empty([cvchelp, cvcquestion]) ) {
			try {
				ML.init('tooltip');
			} catch(e) {	
			}
			cvchelp.css({'display':'none'});
			cvcquestion.attr( {'title': cvchelp.html()} );
			$(window).load(function() {
				cvcquestion.tooltip({extraClass:'cvc-help', opacity:1});
			});
		}
	}
	// hanen-shopping-cart-template End

	// hanen-article-list-template
	if( ML.classInBody('hanen-article-list-template') && ML.classInBody('did-you-know--five-interesting-facts-about-sleep') && ML.ie6 ) {
		var article_image = $('img.article-image');

		if( !ML.$empty(article_image) ) {
			article_image.css({'margin-right':'25px'});
		}
	}
	// hanen-article-list-template End

	//this code will remove all 'Please don't delete this' from page layout
	//page layout clean up
		cache.clear_items = $('.shadow-title').parent().find('.clear');
		if( !ML.$empty(cache.clear_items) ) {
			cache.clear_items.each(function() {
				if(this.innerHTML == 'Please don\'t delete this') {
					this.innerHTML = '';
				}
			});
		}
	//page layout clean up End
	
	cache = null;
})();




