// create array to hold home page banner content
var $banners = new Array();

// set animation durations and easing
var $animate = {
	bannerNav: {
		duration: 250,
		easing: 'easeInCubic'
	},
	bannerFlyout: {
		duration: 250
	},
	bannerImg: {
		duration: 250,
		easing: 'easeInCubic'
	},
	cta: {
		duration: 250,
		easing: 'easeOutCubic'
	},
	ctaHover: {
		duration: 150
	},
	carouselItem: {
		duration: 100,
		easing: 'easeOutCubic'
	},
	entryItem: {
		duration: 150,
		easing: 'easeOutCubic'
	},
	entryItemInfo: {
		duration: 150,
		easing: 'easeOutCubic',
		delay: 800 
	}
};


// set banner auto-cycle timeout
var $bannerTimeout = 10000;


// set threashold for aplha pager elements to be marked
var $alphaPagerThreshold = 0;


// custom functions
(function($){
	// create action button
	$.fn.actionButton = function()
	{
		this.hover(function(){
			$(this).addClass('action-hover');
		}, function(){
			$(this).removeClass('action-hover');
		}).structureActionButton().click(function(e){
			var parentForm = $(this).parents('form:not(.ajaxSubmit)');


			if (parentForm.length > 0){
				e.preventDefault();


				parentForm.submit();
			};
		});

		return this;
	}


	// handle multi-part forms
	$.fn.multiPartForm = function()
	{
		var thisForm = this;
		var fieldSetCount = $('.fieldset', this).length;


		// check that the element provided is a form and contains fieldsets
		if (this.is('form') && fieldSetCount > 0)
		{
			// set percent and status variables
			var statusBarId = $(this).attr('id').replace(/^multipart-/, 'status-bar-');
			var statusBar = $('[id=' + statusBarId + '] .status-bar-fill');
			var incrementPercent = parseInt((100  - parseInt(statusBar.text())) / fieldSetCount);


			// remove any click events and rebind with new click event
			$('.action', this).unbind('click').bind('click', function(e){
				e.preventDefault();


				// set variables for current fieldset and current percent
				var thisFieldSet = $(this).parents('.fieldset');
				var statusPercent = parseInt(statusBar.text());


				// check that current fieldset is active
				if (thisFieldSet.is('.fieldset-active'))
				{
					// handle button actions based on state
					if ($(this).is('.action-prev'))
					{
						// move to previous fieldset
						thisFieldSet.removeClass('fieldset-active').prev('.fieldset').addClass('fieldset-active');


						// fill status bar
						statusBar.statusFill(statusPercent - incrementPercent);
					}
					else if (thisFieldSet.index() + 1 < fieldSetCount)
					{
						// move to next fieldset
						thisFieldSet.removeClass('fieldset-active').next('.fieldset').addClass('fieldset-active');


						// fill status bar
						statusBar.statusFill(statusPercent + incrementPercent);
					}
					else
					{
						var formData = thisForm.serialize();
						var formAction = thisForm.attr('action');


						// post form and replace form with results
						$.post(formAction, formData, function(html){
							html = $('.status-bar-fill', html).statusFill().end().find('table tr, table tr td, table tr th, .result').oddEven().end().find('a.modal-content').structureModalOverlay().end();


							// replace form with result
							thisForm.before(html).remove();


							// fill status bar
							statusBar.statusFill(100);
						});
					}
				}
			});
		}

		return this;
	}


	// set status bar width
	$.fn.statusFill = function(fill)
	{
		// set default for static fill
		var staticFill = true;


		// check if fill variable was passed
		if (typeof fill == 'undefined')
		{
			staticFill = false;
		}


		// iterate through each status bar
		this.each(function(i){
			// default the "fill" variable to 0 if not passed
			if (!staticFill)
			{
				var currentVal = parseInt($(this).text());


				if (isNaN(currentVal))
				{
					fill = 0;
				}
				else
				{
					fill = currentVal;
				}
			}


			// set a max fill of 100
			if (fill > 100)
			{
				fill = 100;
			}


			// set default width
			var width = 'auto';


			// set width
			if (fill < 8)
			{
				width = 8 + '%';
			}
			else if (fill < 99)
			{
				width = fill + '%';
			}


			// set new width and add text value
			$(this).width(width).text(fill + '%');
		});

		return this;
	}


	// apply odd/event classes to elements
	$.fn.oddEven = function()
	{
		// iterate each through each element
		$(this).each(function(i){
			// check if the element has an even index
			if ($(this).index() % 2)
			{
				$(this).addClass('even');
			}
			else
			{
				$(this).addClass('odd');
			}


			// add classes to the first and last element
			$(this).filter(':first-child').addClass('first');
			$(this).filter(':last-child').addClass('last');
			
			
		});
		return this;
	}

	// resize banner flyout based on document width
	$.fn.bannerFlyoutSet = function()
	{
		var documentWidth = $(document).width();
		var containerWidth = $('#wrapper .container').width();
		var flyoutPaddingLeftNew = ((documentWidth - containerWidth) / 2) + 20;

		this.css('padding-left', flyoutPaddingLeftNew);

		return this;
	}


	// hide banner flyout
	$.bannerFlyoutHide = function()
	{
		// check if the banner flyout is hidden and not animating or if the hiding is forced
		if ($('#banner-flyout').data('hidden') != 'true' && $('#banner-flyout').data('animating') != 'true')
		{
			// hide the banner flyout
			$('#banner-flyout').data('animating', 'true').data('hidden', 'true').hide('slide', {}, $animate.bannerFlyout.duration, function(){
				// indicate that banner flyout is hidden
				$(this).data('animating', 'false');
			});
		}
	}
	
	
	// show banner flyout
	$.bannerFlyoutShow = function()
	{
		// check if the banner flyout is hidden and not animating or if the hiding is forced
		if ($('#banner-flyout').data('hidden') == 'true')
		{
			// show banner flyout
			$('#banner-flyout').data('animating', 'true').data('hidden', 'false').show('slide', {}, $animate.bannerFlyout.duration, function(){
				$(this).data('animating', 'false');


				// cycle banner automatically
				$.bannerCycleAuto();
			});
		}
	}


	// handle changing of home page banner
	$.bannerCycle = function(index, initial)
	{
		// default the "initial" variable to false if not passed
		if (typeof initial == 'undefined')
		{
			initial = false;
		}


		// check if this is the initial load
		if (initial)
		{
			// prepend banner flyout HTML shell
			$('#container').prepend('<div id="banner-flyout"><h2></h2><p></p><div class="indicator"></div></div>');


			// indicate that banner flyout is hidden
			$('#banner-flyout').data('hidden', 'true');
		}


		// set variables
		var activeLi = $('#banner-nav li:eq(' + index + ')');


		// fade in/out banner image and set active banner nav item
		if ((!$(activeLi).hasClass('active') || initial) && ($('#banner-img').data('animating') != 'true' && $('#banner-flyout').data('animating') != 'true'))
		{
			// hide the banner flyout
			$.bannerFlyoutHide();


			// fade out current banner image
			$('#banner-img').data('animating', 'true').animate({opacity: 'hide'}, $animate.bannerImg.duration, $animate.bannerImg.easing, function(){
				// set new banner image and fade in
				$(this).css('background-image', 'url(' + $banners[index].img + ')').animate({opacity: 'show'}, $animate.bannerImg.duration, $animate.bannerImg.easing, function(){
					$(this).data('animating', 'false');

					// check if this is the initial banner being loaded
					if (initial)
					{
						// fade in the banner navigation
						$('#banner-nav').animate({opacity: 'show'}, $animate.bannerNav.duration, $animate.bannerNav.easing);
					}


					// resize banner flyout and set content
					$('#banner-flyout').find('h2').html($banners[index].title).end()
						.find('p').html($banners[index].subtitle).end()
						.bannerFlyoutSet().data('animating', 'true').show('slide', {}, $animate.bannerFlyout.duration, function(){
							$(this).data('hidden', 'false').data('animating', 'false').click(function() {
								self.document.location = $banners[index].href;
							});


							// cycle banner automatically
							$.bannerCycleAuto();
						});


					// resize banner flyout on window resize
					$(window).wresize(function(){
						$('#banner-flyout').bannerFlyoutSet();
					});
				});


				// set active banner image nav item
				$('#banner-nav li').removeClass('active').filter(activeLi).addClass('active');
			});
		}

		return this;
	}


	// auto cycle banner
	$.bannerCycleAuto = function()
	{
		$('#banner-nav').stopTime().oneTime($bannerTimeout, function(i){
			var newIndex = $('#banner-nav li.active').index() + 1;


			// check if new index is not valid
			if (newIndex ==  $('#banner-nav li').length)
			{
				// set index to first item
				newIndex = 0;
			}


			// cycle to next banner
			$.bannerCycle(newIndex);
		});
	}


	// get hash value
	$.hashVal = function(hash)
	{
		return hash.replace(/^[#]/, '');
	}
})(jQuery);


jQuery(document).ready(function($){
	// preload button images
	$.preloadImages('/media/system/img/btn/next-hover.png', '/media/system/img/btn/prev-hover.png', '/media/system/img/btn/prev-sm-hover.png', '/media/system/img/btn/next-sm-hover.png', '/media/system/img/btn/next-sm-hover-alt.png', '/media/system/img/btn/action-right-hover.png', '/media/system/img/btn/action-prev-left-hover.png','/media/system/img/btn/large-header-hover.png', '/media/system/img/ico/rss-hover.gif');


	// preload Nav drop-down images
	$.preloadImages('/media/system/img/bg/nav-active-b.png', '/media/system/img/bg/nav-active-bl.png', '/media/system/img/bg/nav-active-br.png', '/media/system/img/bg/nav-active-l.png', '/media/system/img/bg/nav-active-r.png', '/media/system/img/bg/nav-active-rpt.png', '/media/system/img/bg/nav-active-rt.png', '/media/system/img/bg/nav-active-t.png', '/media/system/img/bg/nav-active-tl.png', '/media/system/img/bg/nav-active-tr.png');

	// preload jQuery UI hover states
	$.preloadImages('/media/system/lib/jquery_ui_custom/images/ui-icons_ffffff_256x240.png');

	//HLP: Commented out because of inconsistency. The span with class="teaser-text" is used to supply the double arrow icons for external links.
	//Nothing similar is used for internal links. Apart from this inconsistancy the double arrows would only be present with JS turned on, which
	//is not desired.
	// add style element to teaser anchor
	//$('ul.links-teaser li a').wrapInner('<span class="teaser-text" />').prepend('<span class="teaser"></span>');


	// remove external link class from documents
	$('a.document').removeClass('external');
	
	// remove external link class from gallery links
	$('ul.ad-thumb-list a').removeClass('external');

	// set example text for text fields
	
	$('form input[type=text]').not('.field-date').example(function(){
		return $(this).attr('title');
	});


	// set text for date fields
	$('form input[type=text].field-date').val(function(){
		return $(this).attr('title');
	});

	/* empulse: commented out, because this is only valid for EN. Localized values getting included in html head now
	// attach jQuery UI datepicker to date fields
	$('input.field-date').wrap('<span class="field-date-wrap" />').datepicker({
		firstDay: 1,
		dateFormat: 'mm/dd/yy',
		showOn: 'both',
		showAnim: 'fadeIn',
		buttonText: '+',
		beforeShow: function(input, inst){
			$('#ui-datepicker-div').not('.ui-datepicker-div').addClass('ui-datepicker-div').wrap('<div id="ui-datepicker-wrapper" />');
		}
	});
	*/

	// handle navigation drop-downs
	$('#nav > li').has('ul').hover(function(e){
		// hide active meta navigation item
		$('#nav-meta > li.active').removeClass('active').find('shape').hide();


		// remove focus from all select elements to avvoid z-index issues
		$('select, option, input').blur();

 
		// show navigation drop-down
		$(this).each(function(i){
			$(this).addClass('nav-active');
		}).find('shape').show().end().find('div[class^=nav-]').fixPNG();
	}, function() {
		$(this).find('shape').hide().end().removeClass('nav-active');
	}).each(function(i){
		$(this).structureSubNav();
	}).find('ul li:first').addClass('first').end().find('.nav-sub').bgiframe();


	// handle sub-navigation hover state
	$('#nav li ul li').hover(function(){
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});


	$('#nav-meta > li.collapsible').structureMetaNav().find('> .nav-l .nav-r .nav-wrap a').click(function(e){
		e.preventDefault();


		// create reference for parent li
		var thisLi = $(this).parents('li');


		// check if this item is active
		if (!thisLi.hasClass('active')){
			// hide active items and make this item active
			thisLi.siblings('li').removeClass('active')
				.find('shape').hide().end().end()
				.addClass('active')
				.find('shape').show().end()
				.find('button, div[class^=nav-]').fixPNG().filter('.nav-b').hide().show();


			// hide active CTA content for current CTA
			$('#ctas .cta-active').removeClass('cta-active').find('.cta-content').fadeOut($animate.cta.duration).siblings('.cta-info').animate({marginLeft: '+=10', paddingRight: '-=10'}, $animate.cta.duration, $animate.cta.easing).find('.indicator').fadeOut($animate.cta.duration).end().find('.cta-close').fadeOut($animate.cta.duration);


			// fade in the banner navigation
			$('#banner-nav').animate({opacity: 'show'}, $animate.bannerNav.duration, $animate.bannerNav.easing);


			// show banner flyout
			$.bannerFlyoutShow();
		}
		else
		{
			// make this item inactive
			thisLi.removeClass('active').find('shape').hide();
		}
	});


	// check if current page is the home page
	if ($('body').is('#home'))
	{
		// build banner navigation
		//$.get('../xml/banners.xml', function(banners){
		$.get(hlp_bannerUrl, function(banners){
			// create banner navigation
			var bannerNav = $('<ul />').attr('id', 'banner-nav').hide();


			// iterate through each banner in the obtained XML file
			$('item', banners).each(function(i){
				// create new nav item to banner navigation
				var bannerNavItem = $('<li />').append('<a href="#banner-img" />').hover(function(e){
					$(this).not('.active').addClass('hover');
				}, function() {
					$(this).removeClass('hover');
				});


				// check if this is the first nav item
				if (i == 0)
				{
					bannerNavItem.addClass('active');
				}


				// set variables from XML
				var banner = {
					'img': $('img', this).attr('src'),
					'title': $('title', this).text(),
					'subtitle': $('subtitle', this).text(),
					'href': $(this).attr('href')
				}


				// add new object to $banners array
				$banners.push(banner);


				// add new nav item to banner navigation
				bannerNav.append(bannerNavItem);
			});


			// add banner navigation to DOM
			$('#wrapper .container').prepend(bannerNav);

			
			// cycle banner to first item
			$.bannerCycle(0, true);


			// preload banner image
			$($banners).each(function(i){
				$.preloadImages($banners[i].img);
			});
		});
	}


	// preload banner images and handle changing of banner images
	$('#banner-nav li a').live('click', function(e){
		e.preventDefault();


		$.bannerCycle($(this).parent('li').index());
	})


	// handle button hover state
	$('button').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});


	// add indicator and close elements to cta-info
	$('#ctas .cta-info').prepend('<div class="indicator" />').append('<a href="#close" class="cta-close"></a>');


	// handle CTA fly-outs
	$('#ctas .cta').not('.cta-active').hover(function(){
		// fix arrow indicator PNG and fade in
		$('.cta-info .indicator', this).fadeIn($animate.ctaHover.duration);
	}, function(){
		// fade out arrow indicator
		$('.cta-info .indicator', this).fadeOut($animate.ctaHover.duration);
	}).click(function(e){

		// Standard link behaviour for content links
		// 2010-11-25 empulse fjn
		if($(this).find('h2 a.content_link').length > 0) {
			return true;
		}

		// prevent default click event
		e.preventDefault();


		// set refrence variables
		var cta = $(this);
		var ctaContent = $('.cta-content', cta);


		// check if current target is the close button
		if ($(this).find('.cta-close').filter(e.target).length > 0)
		{
			if (cta.hasClass('cta-active'))
			{
				// hide active CTA content for current CTA
				cta.removeClass('cta-active').find('.cta-content').fadeOut($animate.cta.duration).siblings('.cta-info').animate({marginLeft: '+=10', paddingRight: '-=10'}, $animate.cta.duration, $animate.cta.easing).find('.indicator').fadeOut($animate.cta.duration).end().find('.cta-close').fadeOut($animate.cta.duration);


				// fade in the banner navigation
				$('#banner-nav').animate({opacity: 'show'}, $animate.bannerNav.duration, $animate.bannerNav.easing);


				// hide banner flyout
				$.bannerFlyoutShow();
			}
		}
		else
		{
			// set location for linked CTA
			var href = $('h2 a', this).attr('href');


			// check if current CTA is active and contains content
			if (ctaContent.length > 0 && !cta.hasClass('cta-active'))
			{
				// fade out the banner navigation
				$('#banner-nav').animate({opacity: 'hide'}, $animate.bannerNav.duration, $animate.bannerNav.easing);


				// stop banner flyout timer
				$('#banner-nav').stopTime();


				// hide the banner flyout
				$.bannerFlyoutHide();


				// hide active meta navigation element
				$('#nav-meta li.active').removeClass('active').find('shape').hide();
			
				// set current CTA to active
				cta.addClass('cta-active');


				// hide all active CTAs
				cta.siblings('.cta-active').removeClass('cta-active').find('.cta-content').fadeOut($animate.cta.duration).siblings('.cta-info').animate({marginLeft: '+=10', paddingRight: '-=10'}, $animate.cta.duration, $animate.cta.easing).find('.indicator').fadeOut($animate.cta.duration).end().find('.cta-close').fadeOut($animate.cta.duration);


				// adjust current CTA info box, fading out indicator arrow and fading in close button
				$('.cta-info', this).animate({marginLeft: '-=10', paddingRight: '+=10'}, $animate.cta.duration, $animate.cta.easing).find('.indicator').fadeOut($animate.cta.duration).end().find('.cta-close').fadeIn($animate.cta.duration)


				// add rounded corners to active CTA
				DD_roundies.addRule('#cta-location-finder .cta-content', '10px 0 0 10px', true);
				DD_roundies.addRule('#cta-solution-finder .cta-content', '10px 0 10px 10px', true);
				DD_roundies.addRule('#cta-tuvdotcom-finder .cta-content', '10px 0 0 10px', true);
				DD_roundies.addRule('#cta-locations .cta-content', '10px 0 0 10px', true);


				// fade in active CTA content
				$('.cta-content', cta).hide().fadeIn($animate.cta.duration).find('form #solution-finder-submit p button').fixPNG();
			}
			else
			{
				// check if href is set
				if (typeof href != 'undefined')
				{
					// redirect to href location
					// empulse: need to click the a tag instead to navigate to the href
					// to trigger click handlers which might be set
					// self.document.location = href;

						cta.find('h2 a').click();

					// 2010.10.15, i.cousin: links on standard content (marked with class 'content_link')
					// don't need the click event (opens lightbox!) 
/*					class_a = $('h2 a', this).attr('class');
					if (typeof class_a != 'undefined' && class_a == 'content_link') 
					{
						  self.document.location = href;
					} else {
						cta.find('h2 a').click();
					}
*/
				}
			}
		}
	});

	// 15.04.2011, I.Cousin
  // Register click handler for submit button  tuvdotcom search
  /*
	jQuery("#tuvdotcom button").click(function(e) {
		var tuvdotcom = window.open("/media/system/img/ico/tuvanim.gif", "tuvdotcom", "width=970,height=600,left=100,top=200"); 
		var tuvdotcom = window.open("", "tuvdotcom", "width=970,height=600,left=100,top=200"); 
    tuvdotcom.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head></head><body><div style="position: absolute; top: 40%; bottom:40%; left: 45%; right: 45%"><img src="/media/system/img/ico/tuvanim.gif"></div></body></html>');
		e.stopPropagation();
		e.preventDefault();
		tuvdotcom.focus();
		window.setTimeout('jQuery("#tuvdotcom").submit()', 1000);
	});
	*/
	
	jQuery("#tuvdotcom button").click(function(e) {
		jQuery("#tuvdotcom").submit();
	});


	// set custom radio buttons and checkboxes functionality
	$('form').customRadioCheckboxes();


	// create carousel
	$('.carousel').structureCarousel().carousel('.prev a', '.next a',{
		ease: 'easeInOutExpo'
	}).find('li').hover(function(){
		// create reference variables
		var info = $('.info', this);
		var content = $('.content', info);


		// get content and image heights
		var contentHeight = parseInt($(content).height());
		var imgHeight = parseInt($(info).prev('p').find('img').height());


		// check if content height is greater than the image height
		if (contentHeight > imgHeight)
		{
			// set content height to same as image height
			contentHeight = imgHeight;
		}


		// show carousel item content
		$(info).animate({top: '-=' + contentHeight}, $animate.carouselItem.duration, $animate.carouselItem.easing).find('.content').addClass('content-visible').fadeIn($animate.carouselItem.duration, function(){
			$(this).addClass('content-visible');
		});
	}, function(){
		// create reference variable
		var info = $('.info', this);


		// hide carousel item content
		$(info).animate({top: '0'}, $animate.carouselItem.duration, $animate.carouselItem.easing, function(){
			$('.content', this).removeClass('content-visible');
		}).find('.content').fadeOut($animate.carouselItem.duration);
	}).click(function(e){
		e.preventDefault();

		// get href
		var href = $('.info > h2 a', this).attr('href');


		// check if href is set
		if (typeof href != 'undefined')
		{
			// redirect to href location
			self.document.location = href;
		}
	});


	// apply classes to first/last elements
	$('.article:first-child').addClass('article-first');
	$('.article:last-child').addClass('article-last');
	$('ul li:first-child, .country .languages h5:first-child').addClass('first');
	$('ul li:last-child, .country .languages h5:last-child').addClass('last');

	// iterate through each alpha pager element
	$('.pager-alpha li a').each(function(i){
		// create reference of link title
		var tipText = $(this).attr('title');

		// remove title attribute
		$(this).removeAttr('title');


		// get count of items from title attribuste
		var count = parseInt(tipText);


		// check if count is greater than threshold
		if (count > $alphaPagerThreshold)
		{
			// add large class to element
			$(this).addClass('large').qtip({
				content: {
					text: tipText,
					prerender: true
				},
				position: {
					adjust: {
						y: -3,
						scroll: false,
						resize: false
					},
					corner: {
						target: 'topMiddle',
						tooltip: 'bottomMiddle'
					}
				},
				style: {
					border: {
						width: 1,
						radius: 2,
						color: '#86DE42'
					},
					width: {
						max: 210,
						min: 28
					},
					tip: {
						corner: true,
						color: false,
						size: {
							width: 7,
							height: 4
						},
						opacity: 1
					}
				},
				show: {
					delay: 20,
					solo: true,
					effect: function(){
						if ($.browser.msie)
						{
							$(this).show();
						}
						else
						{
							$(this).animate({top: '-=8', opacity: 'show'}, 120, 'easeOutCubic');	
						}
					}
				},
				hide: {
					delay: 0,
					fixed: true,
					effect: function(){
						if ($.browser.msie)
						{
							$(this).hide();
						}
						else
						{
							$(this).animate({top: '+=8', opacity: 'hide'}, 120, 'easeOutCubic');	
						}
					}
				},
				api: {
					beforeRender: function(){
						if ($.browser.msie)
						{
							this.options.show.delay = 0;
							this.options.position.adjust.y = -11;
						}
					},
					beforeShow: function(e){
						this.updatePosition(e, false);

						return true;
					}
				}
			});
		}
	});


	var pageTitleExists = ($('#content h2').length > 0);


	// create tabs
	$('.tabs').tabs({
		show: function(event, ui){
			var thisLi = $(ui.tab).parents('li');
			var otherLi = $('.ui-tabs-nav li', event.target).not(thisLi);


			// hide/show shape objects, inserted by DD_belatedPNG, to fix IE6 artifacting issue
			$('shape', thisLi).show();
			$('shape', otherLi).hide();


			// apply structure for shadows to both tabs and panels
			$(thisLi).structureTabsTab();
			$(ui.panel).structureTabsPanel();


			// apply scroll pane to News/Events tabs on home page
			
			if ($(event.target).is('#news-events'))
			{
				$('.content', ui.panel).not('.content-scrollable').addClass('content-scrollable').wrapInner('<div class="scroll-pane"></div>').find('.scroll-pane').jScrollPane({
					scrollbarWidth: 22,
					showArrows: true,
					scrollbarMargin: 30
				});
			}


			// set default wrap header type
			var wrapHeader = 'h3';

			// change wrap header type for news/events tabs
			if ($(ui.panel).parents('#news-events').length > 0 || !pageTitleExists)
			{
				wrapHeader = 'h2';
			}


			// wrap active tab with header
			$('a', thisLi).wrap('<' + wrapHeader + ' />');


			// unwrap inactive tabs
			$('a', otherLi).each(function(i){
				if ($(this).parent(wrapHeader).length > 0)
				{
					$(this).unwrap();
				}
			});


			// get panel ID
			var panelID = $(ui.panel).attr('id');


			// hide dissashow associated actions
			$('.tabs-rel').removeClass('tabs-rel-active').filter('[id=tabs-' + panelID + ']').addClass('tabs-rel-active');


			// fix PNG-24 backgrounds
			$('div[class^=tab-]', event.target).fixPNG();
			
		}
	});


	// print page when print button is clicked
	$('#share #print a').click(function(e){
		e.preventDefault();

		window.print();
	});


	// handle collapsible table on address listing result page
	$('#content #results .result p.collapsible a').each(function(i){
		var more = $(this).text();
		var less = $(this).attr('rel');

		$(this).data('more', more).data('less', less);
	}).toggle(function(e){
		var text = $(this).data('less');


		$(this).addClass('collapsed').text(text).parents('.result').find('table tr.collapsed').removeClass('collapsed').addClass('collapsible');
	}, function(e){
		var text = $(this).data('more');


		$(this).removeClass('collapsed').text(text).parents('.result').find('table tr.collapsible').addClass('collapsed').removeClass('collapsible');
	});
	

	// handle collapsible sitemap
	$('#content ul#sitemap').delegate('li a.collapse', 'click', function(e){
		e.preventDefault();

		var parentLi = $(this).parents('li').first();

		if (parentLi.hasClass('collapsed'))
		{
			parentLi.removeClass('collapsed').addClass('expanded');
		}
		else
		{
			parentLi.addClass('collapsed').removeClass('expanded');
		}
	}).find('li ul li ul li').each(function(i){
		if ($('ul', this).length > 0)
		{
			$(this).addClass('collapsed collapsible').prepend('<a href="#" class="collapse">+</a>').find('a.collapse');
		}
	});


	// wrap list item contents
	$('#content .content-sub ul li, #content .content-sub ol li').structureListItems();


	// add modal overlay
	$('a.modal-content').structureModalOverlay();


	// add classes to tables for styling purposes
	$('table tr, table tr td, table tr th, .result').oddEven();


	// struture content boxes
	$('.content-box').structureContentBox().find('div[class^=tab-]').fixPNG();


	// create cross-browser inline-block
	$('.action, #content .actions li, #content ul.pager li, #content dl.languages').inlineBlock();


	// create array for storing entry item positions
	var entryPositions = new Array();


	// get height of entry's parent
	var entriesHeight = $('.entry').parent().height();
	
	
	// get orignial width of entry items
	var originalEntryWidth = $('.entry').width();


	// iterate through each entry and set parent's height
	$('.entry').structureEntryItem().each(function(i){
		var position = $(this).position();


		// add position to entryPositions array
		entryPositions.push(position);
	}).each(function(i){
		// set boolean for every fourth item
		var fourth = !((i + 1) % 4);


		// set initial absolute position value of entry item
		entryPosition = {
			left: entryPositions[i].left,
			top: entryPositions[i].top
		}


		// check if entry item is divisible by four
		if (fourth)
		{
			// add class to entry item
			$(this).addClass('entry-fourth');


			// set right value
			entryPosition.right = 10;


			// remove left value
			delete entryPosition.left;
		}


		// position entry item and add class
		$(this).addClass('entry-positioned').css(entryPosition).find('.entry-l, .entry-r').fixPNG();


		// detect over of entry item
		$(this).hover(function(){
			if (!$(this).parents('.entries').hasClass('entry-list'))
			{
				// set width to animate to
				var entryAnimate = {
					width: (originalEntryWidth * 2) + parseInt($(this).css('marginRight'))
				}


				// hide info, animate width of entry item, and fade info in
//				$(this).not('.entry-active').addClass('entry-active').animate(entryAnimate, $animate.entryItem.duration, $animate.entryItem.easing, function(){
//					$('.info', this).addClass('info-active').fadeIn($animate.entryItemInfo.duration).find('.content').show();
//				}).find('.info').fadeOut($animate.entryItemInfo.duration);
        //05.04.2011, I.Cousin set fadeIn time via var "delay" 
				$(this).delay($animate.entryItemInfo.delay).not('.entry-active').addClass('entry-active').animate(entryAnimate, $animate.entryItem.duration, $animate.entryItem.easing, function(){
					$('.info', this).addClass('info-active').fadeIn($animate.entryItemInfo.duration).find('.content').show();
				}).find('.info').delay($animate.entryItemInfo.delay).fadeOut($animate.entryItemInfo.duration);


				
			}
		}, function(){
			if (!$(this).parents('.entries').hasClass('entry-list'))
			{
				// reset entry item width and info
				$(this).stop(true, true).removeClass('entry-active').css('width', null).find('.info').stop(true, true).show().removeClass('info-active').end().find('.content').hide();
			}
		}).click(function(){
			// get href
			var href = $('.info > h3 a', this).attr('href');


			// check if href is set
			if (typeof href != 'undefined')
			{
				// redirect to href location
				self.document.location = href;
			}
		});
	}).parent().height(entriesHeight);
	

	// toggle list/photo views
	$('ul.view-toggle li a').click(function(e) {
		e.preventDefault();


		// check if anchor clicked is the active view
		if (!$(this).hasClass('active'))
		{
			// get hash from href value
			var hash = $(this).attr('href');


			// get view type from anchor hash
			var viewType = $.hashVal(hash);


			// check if view type is list or photo
			if (viewType === 'list')
			{
				$('.entries').addClass('entry-list').find('shape').hide();
				$('.entries .info .content').show();
			}
			else if (viewType === 'photo')
			{
				$('.entries').removeClass('entry-list').find('shape').show();
				$('.entries .info .content').hide();
			}


			// toggle active/inactive view anchor
			$(this).parents('ul.view-toggle')
				.find('li a')
				.not(this).removeClass('active').end()
				.filter(this).addClass('active');
		}
	});


	$('#content form#solution-finder.hide-form .content-box .container').prepend('<a class="content-box-close" href="#"></a>').find('.content-box-close');


	$('#content form#solution-finder .actions-description ul.actions li.expand a').click(function(e){
		e.preventDefault();

		$('#content form#solution-finder').removeClass('hide-form');
	});

	
	$('#content form#solution-finder .content-box a.content-box-close').live('click', function(e){
		e.preventDefault();

		$('#content form#solution-finder').addClass('hide-form');
	});


	// custom scroll bar for locations on map pages
	$('.locations .scroll-pane').jScrollPane({
		scrollbarWidth: 22,
		showArrows: true,
		scrollbarMargin: 0,
		scrollbarOnLeft: false
	});
	

	// create action buttons
	$('.action').actionButton();


	// set status bar width	
	$('.status-bar-fill').statusFill();


	// handle multi-part forms
	$('form.multipart').multiPartForm();


	// disable webkit textarea resize
	$('form textarea.field-text').css('resize', 'none');


	// fix PNG-24 backgrounds in IE6
	$('#header, #navbar, #ctas, [id^=main-], #breadcrumb, #sidebar div[class^=nav-], #share, #content .search-results .result h3 a, #sidebar a.mail, #content a.mail, #content .two-column-rss ul a').fixPNG();

	
	// remove first and last class from gallery list elements
	$('ul.ad-thumb-list li:first-child').removeAttr('class');
	$('ul.ad-thumb-list li:last-child').removeAttr('class');
	$('.ad-gallery a').removeAttr('class');
	
	// add form error example link
	/*
	$('body').prepend('<a href="#" id="show-form-errors">Toggle Form Errors</a>').find('a#show-form-errors').css({'position': 'absolute', 'right': '10px', 'top': '10px', 'z-index': '100', 'font-size': '13px', 'color': '#CA1A34'}).click(function(e){
		e.preventDefault();


		$('#content input, #content textarea, #content select, #content .tabs table thead tr th.first, #content .tabs table tbody tr th').not('#content .tabs table tbody tr.last th').toggleClass('form-error');


		$('#content .tabs form table').each(function(i){
			var tableErrorHead = $('thead tr th.first', this);

			var tableError = 'Please choose an answer';
			var tableErrorHeadText = tableErrorHead.text();

			if(tableErrorHeadText == tableError)
			{
				tableErrorHead.text('');
			}
			else
			{
				tableErrorHead.text(tableError);
			}
		});
	});
	*/
});

function enableLoginDropDown() {
	    
	    thisLi = jQuery("#login2").parents('li');
		// alert(thisLi.attr('id'));
	
		// check if this item is active
		if (!thisLi.hasClass('active')){
			// hide active items and make this item active
			thisLi.siblings('li').removeClass('active')
				.find('shape').hide().end().end()
				.addClass('active')
				.find('shape').show().end()
				.find('button, div[class^=nav-]').fixPNG().filter('.nav-b').hide().show();


			// hide active CTA content for current CTA
			jQuery('#ctas .cta-active').removeClass('cta-active').find('.cta-content').fadeOut($animate.cta.duration).siblings('.cta-info').animate({marginLeft: '+=10', paddingRight: '-=10'}, $animate.cta.duration, $animate.cta.easing).find('.indicator').fadeOut($animate.cta.duration).end().find('.cta-close').fadeOut($animate.cta.duration);


			// fade in the banner navigation
			jQuery('#banner-nav').animate({opacity: 'show'}, $animate.bannerNav.duration, $animate.bannerNav.easing);


			// show banner flyout
			jQuery.bannerFlyoutShow();
		}
		else
		{
			// make this item inactive
			thisLi.removeClass('active').find('shape').hide();
		}
	}
	
