$.noConflict();
Global = {
	init: function () {
		log('Init');
		Global.searchFormInit();
		Global.leftNavigationInit();
		Global.tabPodConnectInit();
		Global.footerInit();
		Global.sectionHeightInit();
		Global.content_main_widthInit();
		Global.breadcrumbInit();
		Global.heroCaptionPositionUpdated();
		Global.columnRenderInit();
		Global.figureListBorderInit();
		Global.addColumnHeight();
		Global.splitGroupMatch();
		Global.fontResizerInit();
		Global.printScreenInit();
		Global.adaDisplayInit();
		Global.splitViewHeightMatch();
		Global.findADentistSubmit();
		Global.smileTalkSignup();
		Global.unifiedFooterInit();
		Global.careCenterInit();
		Global.heroSwfHeader();
	}, //-- init()
	
	unifiedFooterInit: function () {
		log('---->Global.unifiedFooterInit()');
		jQuery('#unifiednav_footer5').css('width','955px');
	}, //-- unifiedFooterInit()
	
	searchFormInit: function () {
		log('---->Global.searchFormInit()');
		var searchTermsField = jQuery('input[id="src_search"]'), testVal = jQuery('#src_form').find('label:first').html();
		jQuery('#src_form').find('label').hide();
		jQuery(searchTermsField).click(function(event) {
			jQuery(this).select();
		});
		jQuery(searchTermsField).keyup(function(event) {
			var stfVal = jQuery(searchTermsField).val();
			if ((stfVal !== '') && (stfVal !== testVal)) {
				jQuery('input[id="src_submit"]').css('visibility','visible');
			} else {
				jQuery('input[id="src_submit"]').css('visibility','hidden');
			}
		});
	}, //-- searchFormInit()
	
	leftNavigationInit: function () {
		log('---->Global.leftNavigationInit()');
		if(jQuery('#left_navigation').size() === 0) return;
		jQuery('#left_navigation').find('ul:first li:last a').css('border-bottom','none');
		jQuery('#left_navigation').find('ul').not(':first').find('li:first').addClass('subNavTopper');
		jQuery('#left_navigation').find('ul').not(':first').find('li:last').addClass('subNavFooter');
		if (jQuery('li a[class="ON"]:first').parent().children().has('li').size() === 0) {
			jQuery('li a[class="ON"]').css('background-position','0 center');
		}
		if (jQuery('li').hasClass('slideSub')) {
			jQuery('li.slideSub').each(function() {
				jQuery(this).find('a').hasClass('ON') === false ? jQuery(this).find('ul').hide() : jQuery(this).find('ul').show();
				jQuery(this).find('a:first').click(function() {
					slideNav(jQuery(this).parent().find('ul'), jQuery(this).parent());
					return false;
					this.blur();
				});
				var slideNav = function(slideGroup, slideParent) {
					if (jQuery(slideGroup).css('display') !== 'block') {
						jQuery(slideGroup).slideDown();
						jQuery(slideParent).find('a:first').addClass('ON');
					} else {
						jQuery(slideParent).find('a:first').removeClass('ON');
						jQuery(slideGroup).slideUp();
					}
				};
			});
			if(jQuery('li.slideSub:last').find('a').hasClass('ON') === false) {
				jQuery('li.slideSub:last').find('a').css('border-bottom','none');
			}
		}
	}, //-- leftNavigation()
	
	tabPodConnectInit: function() {
		log('---->Global.tabPodConnectInit()');
		if (jQuery('.section_tabbed.thin').size() > 1) {
			jQuery('.section_tabbed.thin').not(':first, .footer').addClass('connected');
		}
		if (jQuery('.section_tabbed.wide').size() > 1) {
			jQuery('.section_tabbed.wide').not(':first, .footer').addClass('connected');
		}
	}, //-- tabPodConnect
	
	footerInit: function () {
		log('---->Global.footerInit()');
		if (jQuery('#sub_footer').size() === 0) return;
		var pod_size_total = jQuery('.sub_footer_pod').size() * 311;
		var sub_footer_left = (955 - pod_size_total) / 2 + 'px';
		jQuery('#sub_footer').css('left',sub_footer_left);
		jQuery('.sub_footer_pod').not(':last').css('border-right','1px dashed #CCC');
		var subPod = jQuery('.sub_footer_pod');
		jQuery(subPod).each(function () {
			var imgWidth = jQuery(this).find('img').width();
			var captionWidth = 292 - imgWidth;
			jQuery(this).find('.caption').css('width',captionWidth + 'px');
		});
	}, //-- footerInit()
	
	sectionHeightInit: function ( setTime ) {
		log('---->Global.sectionHeightInit()');
		var sH_set = setTimeout("Global.sectionHeightInit('init')", 500);
		if (setTime === 'init') {
			jQuery('.section').not('.searchResults .section').each(function() {
				log('sectionHeightInit in progress');
				if(jQuery(this).parent().hasClass('aside') === false) {
					jQuery(this).not('.pt_section, .video_guide_pagelist').each(function () {
						//var categoryGrouping = jQuery(this).find('.category').not('.category.video_guide_section');
						var categoryGrouping = jQuery(this).find('.category').not('.category.figure_list, .category.specialoffer, .category.ada');
						var categoryMinMax = Global.get_min_max(jQuery(categoryGrouping), 'vertical');
						jQuery(categoryGrouping).each(function() {
							jQuery(this).css('height',categoryMinMax[1] + 'px');
						});
					});
				}
			});
			if (jQuery('.sub_footer_pod').size() !== 0) {
				var footerPodMinMax = Global.get_min_max(jQuery('.sub_footer_pod'), 'vertical');
				jQuery('.sub_footer_pod').each(function() {
					jQuery(this).css('height',footerPodMinMax[1] + 'px');
				});
				var footerContainer_height = footerPodMinMax[1] + 16;
				jQuery('#sub_footer_container').css('height',footerContainer_height + 'px');
				if ( jQuery('.sub_footer_pod').hasClass('alternate') === true ) {
					jQuery('#sub_footer_container').css({
						'height': 0,
						'border': 'none',
						'padding': 0
					});
				}				
			}
			clearTimeout(sH_set);
		}
	}, //-- sectionHeightInit()
	
	content_main_widthInit: function () {
		log('---->Global.content_main_widthInit()');
		if (jQuery('.aside').size() !== 0) return;
		jQuery('.content_main').css('width','auto');
	}, //-- content_main_widthInit()
	
	get_item_count: function ( pushGroup ) {
		log('---->Global.get_item_count()');
		return jQuery(pushGroup).size();
	}, //-- get_item_count()
	
	print_screen: function () {
		log('---->Global.print_screen()');
		window.print();
	}, //-- print_screen()
	
	is_iOS: function () {
		log('---->Global.is_iOS()');
		if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
			return true;
		}
	}, //-- is_iOS
	
	get_min_max: function ( pushGroup, type ) {
		log('---->Global.get_min_max()');
		var type_array = new Array(), minmax_array = new Array();
		jQuery(pushGroup).each(function(i) {
			if (type === 'vertical') type_array.push(jQuery(this).innerHeight());
			if (type === 'horizontal') type_array.push(jQuery(this).innerWidth());
			if (type === 'number') type_array.push(jQuery(this).toArray()[0]);
		});		
		var max_type = type_array[0], min_type = type_array[0];
		jQuery(type_array).each(function(i) {
			if (max_type <= type_array[i]) max_type = type_array[i];
			if (min_type >= type_array[i]) min_type = type_array[i];
		});
		minmax_array.push(min_type, max_type);
		return minmax_array;
	}, //-- get_min_max()
	
	get_scroll_top: function () {
		log('---->Global.get_scroll_top()');
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0) {
			if (window.pageYOffset) {
				ScrollTop = window.pageYOffset;
			} else {
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
		}
		return ScrollTop;
	}, //-- get_scroll_top()
	
	nonInputFormSubmit: function (formId, submitAltId) {
		log('---->Global.nonInputFormSubmit()');
		jQuery('#' + submitAltId).click(function(event) {
			jQuery('#' + formId).submit();
			return false;
			this.blur();
		});
	}, //-- nonInputFormSubmit()
	
	// set breadcrumb display class || add dividers
	breadcrumbInit: function () {
		log('---->Global.breadcrumbInit()');
		if (jQuery('#breadcrumbs').size() === 0) {
			jQuery('#container_header_gradient, #content_suspension').addClass('noBreadcrumbs');
		} else {
			jQuery('<span class="breadcrumb_divider">&gt;</span>').insertAfter(jQuery('#breadcrumbs').find('a'));
		}
	}, //-- breadcrumbInit()
	
	// set position of hero caption
	heroCaptionPositionUpdated: function () {
		log('---->Global.heroCaptionPosition()');
		if (jQuery('.hero_caption').size() === 0) return;
		var heroContainer = jQuery('.hero_container'),
		    heroCHeight = (heroContainer.height() - parseInt(heroContainer.css('margin-bottom'), 10)) / 2,
		    caption = jQuery('.hero_caption'),
		    captionHeight = caption.height() / 2,
		    diffArray = [heroCHeight,captionHeight],
		    setDiff = Global.get_min_max(diffArray,'number')[1] - Global.get_min_max(diffArray,'number')[0];
		caption.css('top',setDiff);
		if (caption.hasClass('addition') === true) {
			jQuery(caption).css('top','30%');
			return;
		}
	}, //-- heroCaptionPositionUpdated
	
	heroCaptionPosition: function () {
		log('---->Global.heroCaptionPosition()');
		if (jQuery('.hero_caption').size() === 0) return;
		var caption = jQuery('.hero_caption'),
			captionHeight = jQuery(caption).height();
		if (caption.hasClass('addition') === true) {
			jQuery(caption).css('top','30%');
			return;
		}
		switch ( captionHeight ) {
			case 36:
				jQuery(caption).css('top','40%');
				break;
			case 72:
				jQuery(caption).css('top','30%');
				break;
			case 100:
				jQuery(caption).css('top','30%');
				break;
			case 108:
				jQuery(caption).css('top','15%');
				break;
			case 144:
				jQuery(caption).css('top','5%');
				break;
			default:
				jQuery(caption).css('top','0%');
		}
	}, //-- heroCaptionPosition
	
	// setup rendering of columns
	columnRenderInit: function () {
		log('---->Global.columnRenderInit()');
		if (jQuery('.section').find('.category').size() === 0) return;
		jQuery('.section').not('.aside .section, .thin').each(function (s) {
			if (jQuery('.section').hasClass('video_guide_pagelist')) {
				log('video_guide_pagelist');
				jQuery('.section').find('.video_guide_section').not(':last').each(function() {
					jQuery(this).css('border-bottom','1px solid #F6F6F6');
				});
				jQuery('.section').find('.video_guide_section:last').css('padding-bottom','0');
				return;
			}
			var category = jQuery(this).find('.category').not('.popular_topic, .figure_list, .fad_detail');
			var category_count = category.size();
			var category_width = 100 / category_count;
			var category_border_setup = '1px solid #E0E0E0';
			if (jQuery(category).hasClass('topic_section')) {
				log('topic_section');
				jQuery('.section').each(function() {
					jQuery(this).find('.category.topic_section').not(':last').each(function() {
						jQuery(this).css('border-bottom','1px solid #E0E0E0');
					});
				});
			} else if (jQuery(category).hasClass('specialoffer')) {
				log('specialoffer');
				jQuery('.section').each(function() {
					jQuery(this).find('.category.specialoffer').not(':last').each(function() {
						jQuery(this).css('border-bottom','1px solid #E0E0E0');
					});
				});
			} else {
				jQuery(category).each(function (c) {
					log('mainset');		
					if (c !== category_count - 1) {
						log('c !== category_count - 1\nc: ' + c + ' category_count: ' + category_count);
						log('category_width: ' + category_width);
						jQuery(this).css({
							'width' : category_width + '%',
							'marginLeft' : '-1px',
							'border-left' : category_border_setup,
							'border-right' : category_border_setup
						});
						if (category_count < 5) {
							log('category_count < 5');
							jQuery(this).find('h3, ul, .figure, .figcaption').not('.figcaption h3, .section.product ul').css({
								'marginLeft' : category_width + 'px',
								'marginRight' : category_width + 'px'
							});
						} 
					} else {
						log('c === category_count - 1\nc: ' + c + ' category_count: ' + category_count);
						log('category_width - 1: ' + category_width - 1);
						jQuery(this).css({
							'width':category_width - 1 + '%',
							'marginLeft' : '-1px',
							'border-left' : category_border_setup
						});
						if (category_count < 5 && category_count !== 1) {
							log('category_count < 5 && category_count !== 1');
							jQuery(this).find('h3, ul, .figure, .figcaption').not('.figcaption h3, .section.product ul').css({
								'marginLeft' : category_width - 1 + 'px',
								'marginRight' : category_width - 1 + 'px'
							});
						}
					}
					if(jQuery(this).parent().hasClass('wide')) {
						log('wide');
						var figure_mLeft = jQuery(this).find('.figure');
						var column_width = Global.get_min_max(jQuery(this), 'horizontal')[1];
						var image_width = jQuery(this).find('.figure img').attr('width');
						var margin_left = parseInt(jQuery(this).find('.figure').css('marginLeft').replace('px',''));
						var adjust_val = column_width - image_width;
						switch (category_count) {
							case 5: log('5');
								jQuery(figure_mLeft).css('marginLeft',adjust_val/2 + 'px');
								break;
							case 4: log('4');
								jQuery(figure_mLeft).css('marginLeft',adjust_val/2 + 'px');
								break;
							case 3: log('3');
								jQuery(figure_mLeft).css('marginLeft',margin_left/2 + 'px');
								break;
							case 2: log('2');
								jQuery(figure_mLeft).css('marginLeft','-' + (margin_left - 10) + 'px');
								break;
							case 1: log('1');
								jQuery(figure_mLeft).css('marginLeft','-' + (column_width - (image_width + 20)) + 'px');
								break;
							default: log('default');
								jQuery(figure_mLeft).css('marginLeft',adjust_val/2 + 'px');
						}
					}
					if(jQuery(this).parent().hasClass('smiletalk')) {
						log('smiletalk');
						jQuery('#content_container #content_suspension').css({
							'min-height' : '0',
							'margin-bottom' : '-115px'
						});
						jQuery('#content_container #container_lower_gradient').css('height','117px');
						category_width = 95 / category_count;
						switch(c) {
							case 0:
								jQuery(this).css({
									'border-left' : 'none',
									'border-right' : 'none',
									'margin' : '8px 32px auto 12px'
								});
								break;
							case 1:
								jQuery(this).css({
									'border-left' : 'none',
									'margin-top' : '8px'
								});
								break;
							default:
								log(c);
								jQuery(this).css('margin-top','8px');
						}
						jQuery(this).find('h3, ul, .figure, .figcaption').not('.figcaption h3, .section.product ul').css({
							'marginLeft' : category_width + 'px',
							'marginRight' : category_width + 'px'
						});
					}
				});
			}
			if(jQuery(category).parent().hasClass('product')) {
				log('product');
				if(jQuery(category).parent().hasClass('ingredientItem')) {
					log('ingredientItem');
					jQuery(category).each(function () {
						jQuery(this).width(106);
						jQuery(this).find('.figure img').width(107);
					});
				} else {
					if(jQuery(category).size() % 2) {
						jQuery(category).css('width',category_width / 2 + '%');
					}
				}
			}
			if(jQuery(category).parent().parent().hasClass('fad_Results')) {
				log('fad_Results');
				if (jQuery('.section').size() > 2) {
					if ((jQuery(category).size() % 2) === 0) {
						jQuery(category).filter(':first').css('width','33.3333%');
						jQuery(category).filter(':last').css('width','65.6666%');
					}
				}
			}
		});		
	}, //-- columnRenderInit()
	
	// Match height for split_view columns
	splitViewHeightMatch: function (setTime) {
		log('---->Global.splitViewHeightMatch()');
		if (jQuery('.split_view').size() === 0) return;
		var sVHM = setTimeout("Global.splitViewHeightMatch('init')", 100);
		if (setTime === 'init') {
			var colGroup = new Array(), matchCols, colDiff, addHeightCol;
			jQuery('.split_view').each(function(m) {
				colGroup.push(Global.get_min_max(jQuery(this), 'vertical')[1]);
			});
			colDiff = Global.get_min_max(colGroup, 'number')[1] - Global.get_min_max(colGroup, 'number')[0];
			colGroup[0] > colGroup[1] ? addHeightCol = jQuery('.split_view:last') : colGroup[1] > colGroup[0] ? addHeightCol = jQuery('.split_view:first') : addHeightCol = jQuery('.split_view');
			jQuery(addHeightCol).find('.addHeight_Border').css('height', colDiff + 'px');
			clearTimeout(sVHM);
		}
	}, //-- splitViewHeightMatch()
	
	// OCC Landing Specific
	addColumnHeight: function () {
		log('---->Global.addColumnHeight()');
		if (jQuery('.featured_column').size() === 0) return;
		var thinCol = Global.get_min_max(jQuery('.featured_column').filter('.thin'), 'vertical')[1];
		var wideCol = Global.get_min_max(jQuery('.featured_column').filter('.wide'), 'vertical')[1];
		var colGroup = new Array();
		colGroup.push(thinCol, wideCol);
		var colDiff = Global.get_min_max(colGroup, 'number')[1] - Global.get_min_max(colGroup, 'number')[0];
		if (thinCol > wideCol) {	
			jQuery('.addwide').css({
				'width': '642px',
				'height': colDiff + 'px'
			});
		}
		if (wideCol > thinCol) {
			jQuery('.addthin').css({
				'width': '281px',
				'height': colDiff + 'px'
			});
		}
	}, //-- addColumnHeight()
	
	//Match height for .splitGroup columns
	splitGroupMatch: function () {
		log('---->Global.splitGroupMatch()');
		if (jQuery('.splitGroup').size() === 0) return;
		log('splitGroupMatch()');
		jQuery('.splitGroup').each(function() {
			var addHGroup = new Array();
			jQuery(this).find('.article').each(function() {
				addHGroup.push(Global.get_min_max(jQuery(this), 'vertical')[1]);
			});
			var addHHeight = Global.get_min_max(addHGroup, 'number')[1];
			jQuery(this).find('.article').css('height',addHHeight + 'px');
		});
	}, //-- splitGroupMatch()
	
	// OCC Landing Specific
	figureListBorderInit: function () {
		log('---->Global.figureListBorderInit()');
		if (jQuery('.figure_list').size() === 0) return;
		jQuery('.figure_list').not(':last').each(function() {
			jQuery(this).css('border-bottom','1px solid #E0E0E0');
		});
	}, // figureListBorderInit()
	
	// initialize fontResizer()
	fontResizerInit: function () {
		log('---->Global.fontResizerInit()');
		if ( jQuery('.page_options').size() !== 0) {
			jQuery('.article').fontResizer({minFont:10,maxFont:20,increment:2});
		}
	}, //-- fontResizerInit()
	
	// setup print screen
	printScreenInit: function () {
		log('---->Global.printScreenInit()');
		jQuery('.options_print').click(function() {
			Global.print_screen();
			this.blur();
			return false;
		});
	}, //-- printScreenInit()
	
	// ADA Landing Specific
	adaDisplayInit: function () {
		log('---->Global.adaDisplayInit()');
		if ( jQuery('.ada_group').size() === 0) return;
		var cGroup = jQuery('.ada_group:first');
		jQuery(cGroup).find('.ada_display_button').addClass('ON');
		jQuery('.ada_group').not(':first').each(function() { jQuery(this).find('.ada').hide(); });
		jQuery('.ada_display_button').click(function(event) {
			var g_ada = jQuery(this).parent().find('.ada');
			jQuery(g_ada).css('display') !== 'block' ? Global.showAdaGroup('show', this, g_ada, cGroup) : Global.showAdaGroup('hide', this, g_ada, cGroup);			
			cGroup = jQuery(this).parent();
			if (Global.get_scroll_top() !== 0) {
				jQuery('html, body').animate({scrollTop: 0}, 500);
			}
			this.blur();
			return false;
		});
	}, //-- adaDisplayInit
	
	// ADA Landing Specific -- called from adaDisplayInit
	showAdaGroup: function ( display, group, g_ada, cGroup ) {
		log('---->Global.showAdaGroup()');
		var up_easing_type = 'easeInOutCirc';
		var down_easing_type = 'easeInOutCirc';
		var up_easing_duration = 1000;
		var down_easing_duration = 1000;
		var cGroup_ada = jQuery(cGroup).find('.ada');
		var cGroup_button = jQuery(cGroup).find('.ada_display_button');
		if (display === 'show') {
			jQuery(g_ada).each(function() {
				jQuery(this).slideDown({
					duration: down_easing_duration,
					easing: down_easing_type,
					complete: function () {
						jQuery(group).addClass('ON');
					}
				});
			});
			jQuery(cGroup_ada).each(function() {
				jQuery(this).slideUp({
					duration: up_easing_duration,
					easing: up_easing_type,
					complete: function () {
						jQuery(cGroup_button).removeClass('ON');
					}
				});
			});
		} else {
			if(jQuery(cGroup_button).hasClass('ON')) return;
			jQuery(g_ada).each(function() {
				jQuery(this).slideUp({
					duration: up_easing_duration,
					easing: up_easing_type,
					complete: function () {
						jQuery(group).removeClass('ON');
					}
				});
			});
			jQuery(cGroup_ada).each(function() {
				jQuery(this).slideDown({
					duration: down_easing_duration,
					easing: down_easing_type,
					complete: function () {
						jQuery(cGroup_button).addClass('ON');
					}
				});
			});
		}
	}, //-- showAdaGroup()
	
	findADentistSubmit: function () {
		log('---->Global.findADentistSubmit()');
		if (jQuery('#fad_form').size() === 0) return;
		Global.nonInputFormSubmit('fad_form', 'fad_form_Submit');
	}, //-- findADentistSubmit
	
	smileTalkSignup: function () {
		log('---->Global.smileTalkSignup()');
		if (jQuery('#smiletalkSignup').size() === 0) return;
		jQuery('#fn, #ln, #e').focus(function () { this.value = ""; });
		Global.nonInputFormSubmit('smiletalkSignup', 'sts_submit');
	}, //-- smileTalkSignup
	
	careCenterInit: function () {
		log('---->Global.careCenterInit()');
		if (jQuery('#CareCenter_ProductScroller').size() === 0) return;
		CC_ProductScroller.init();
	}, //-- careCenterInit()
	
	virtualDentistSearch: function (searchTerms, filters, srvPath) {
		log('---->Global.virtualDentistSearch()');
		log('srvPath passed from swf: ' + srvPath);
		var searchURL = srvPath + 'Search.srv?search=', filterParam = '&filters=';
		log('searchURL: ' + searchURL);
		if ((filters === undefined) || (filters === '')) {
			filters = 'article,product,video,guide';
		}
		var setSearch = 'http://' + location.host + searchURL + searchTerms + filterParam + filters;
		log('new location: ' + setSearch);
		window.location.href = setSearch;
	}, //-- virtualDentistSearch()
	
	heroSwfHeader: function () {
		log('---->Global.heroSwfHeader()');
		if (jQuery('#flash_item').size() === 0) return;
		try {
			delaySWFOBJ();
		} catch ( err ) {
			log('ERROR: ' + err);
		}
		
	} //-- heroSwfHeader
	
};
jQuery(window).load(function() {
	Global.init();
});
