/*
 In-Field Label jQuery Plugin
 http://fuelyourcoding.com/scripts/infield.html

 Copyright (c) 2009 Doug Neiner
 Dual licensed under the MIT and GPL licenses.
 Uses the same license as jQuery, see:
 http://docs.jquery.com/License

*/
(function(d){d.InFieldLabels=function(e,b,f){var a=this;a.$label=d(e);a.label=e;a.$field=d(b);a.field=b;a.$label.data("InFieldLabels",a);a.showing=true;a.init=function(){a.options=d.extend({},d.InFieldLabels.defaultOptions,f);if(a.$field.val()!==""){a.$label.hide();a.showing=false}a.$field.focus(function(){a.fadeOnFocus()}).blur(function(){a.checkForEmpty(true)}).bind("keydown.infieldlabel",function(c){a.hideOnChange(c)}).bind("paste",function(){a.setOpacity(0)}).change(function(){a.checkForEmpty()}).bind("onPropertyChange",
function(){a.checkForEmpty()})};a.fadeOnFocus=function(){a.showing&&a.setOpacity(a.options.fadeOpacity)};a.setOpacity=function(c){a.$label.stop().animate({opacity:c},a.options.fadeDuration);a.showing=c>0};a.checkForEmpty=function(c){if(a.$field.val()===""){a.prepForShow();a.setOpacity(c?1:a.options.fadeOpacity)}else a.setOpacity(0)};a.prepForShow=function(){if(!a.showing){a.$label.css({opacity:0}).show();a.$field.bind("keydown.infieldlabel",function(c){a.hideOnChange(c)})}};a.hideOnChange=function(c){if(!(c.keyCode===
16||c.keyCode===9)){if(a.showing){a.$label.hide();a.showing=false}a.$field.unbind("keydown.infieldlabel")}};a.init()};d.InFieldLabels.defaultOptions={fadeOpacity:0.5,fadeDuration:300};d.fn.inFieldLabels=function(e){return this.each(function(){var b=d(this).attr("for");if(b){b=d("input#"+b+"[type='text'],input#"+b+"[type='search'],input#"+b+"[type='tel'],input#"+b+"[type='url'],input#"+b+"[type='email'],input#"+b+"[type='password'],textarea#"+b);b.length!==0&&new d.InFieldLabels(this,b[0],e)}})}})(jQuery);


/* Own code from here */
(function($){
	/* simple plugin to create equal heights in boxes */
	$.fn.eqHeight = function() {
 		var height = 0;
		this.each(function() {
			var thisHeight = $(this).height();
			if (thisHeight > height) {
				height = thisHeight;
			}
		});
		
		return this.height(height);
	}
	
	/* init - kick-start! */
	$(function(){		
		//Toggle login box
		$('a[href="#login"]').click(function(e){
			e.preventDefault();
			
			var $loginBox = $('.loginBox');
			
			if ($loginBox.is(':visible')) {
				$loginBox.slideUp('fast');
			} else {
				$loginBox.slideDown('fast');
				$loginBox.find('input').first().focus();
			}
		});
		
		//Make Chrome numbers
		var $h4xNumbers = $('.h4xNumbers');
		if ($h4xNumbers.length > 0) {
			var htmlArr = [], html;
			
			html = $h4xNumbers.text().replace(/(\d)/g, '<div class="number$1">$1</div>');
			$h4xNumbers.html(html);
			
			//Recalculate width
			var newWidth = 0;
			$h4xNumbers.find('div').each(function() {
				newWidth = newWidth + $(this).width();
			});
			//Set it
			$h4xNumbers.width(newWidth);
		}

		//Equal height frontpage small boxes
		$('.lower .box p').eqHeight();
		
		//Equal height subpages! 
		if ($('.subpage').length > 0) {
			//$('.grid_16 .box').css('min-height', $('.grid_8').height() - 32 ); //32 is padding + borders
		}
		
		
		//Infield labels
		$('label').inFieldLabels();
		
		//News ticker
		var tickerBlock = false;
		
		//Pause the newsticker if the user hovers above it
		$('.newsList a').hover(function(){
			tickerBlock = !tickerBlock;
		});
		
		if ($('.newsList').length > 0) {
			setInterval(function() {
				
				if (tickerBlock) {
					return true;
				}
				
				var $this = $('.newsList a:visible');

				if ($this.parent('li').next().length === 0) {
					$this.fadeOut('fast', function() {
						$('.newsList li a').first().fadeIn('fast');
					});
				} else {
					$this.fadeOut('fast', function() {
						$this.parent('li').next().children('a').fadeIn('fast');
					});
				}

			}, 5000); //Change this value if you want more delay	
		}
		
		//Map Pulse
		if ($('.mapPulse').length > 0) {
			setInterval(function() {
				$('.yellowDot').toggleClass('pulse');
			}, 1000); //Change this value and the CSS valye if you want more delay	
		}		
		
		// Faq foldout/foldin
		if ($('.faq').length > 0) {
			$('.faq li > a').live('click', function(e){
				e.preventDefault();
				
				$(this).next('p').slideToggle('fast');
				
			});
		}
				
		
	});
	
})(jQuery);


