function trigger() {
		$('#flash-end-movie').fadeTo(0, 0.01).css({'top':'216px'}).fadeTo(500, 1.0);
		//jwplayer("flash-video").setup({
//			autostart: true,
//			controlbar: "none",
//			file: "/media/whats-your-future-2.mp4", 
//			flashplayer: "/js/player.swf", 
//			volume: 100, 
//			width: 480,
//			height: 270
//		}).onComplete(function() { $('#future').children().fadeOut(700); });
	}
$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};
$(function(){
	
//HoverIntent script for dropdown menu start
	$(function(){
	    var config = {    
	         sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
	         interval: 100,  // number = milliseconds for onMouseOver polling interval    
	         over: doOpen,   // function = onMouseOver callback (REQUIRED)    
	         timeout: 200,   // number = milliseconds delay before onMouseOut    
	         out: doClose    // function = onMouseOut callback (REQUIRED)    
	    };
	    function doOpen() {
	        $(this).addClass("hover");
	        $('ul:first',this).css('visibility', 'visible');
	    }
	    function doClose() {
	        $(this).removeClass("hover");
	        $('ul:first',this).css('visibility', 'hidden');
	    }
	    //$("ul.dropdown li").hoverIntent(config);
	    $("ul.dropdown li ul li:has(ul)").find("a:first");
	
	});
	//HoverIntent script for dropdown menu end
	
	$('#future').wrapInner('<div class="flash-holder" />');
	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
	if (agentID) {
		$('#flash-end-movie').fadeTo(0, 0.01).css({'top':'300px', 'left':'400px'}).fadeTo(500, 1.0);
		$('#future').css({ 'background' : 'url(http://theonline401k.com/d401k/ecs/img/tok-homepage-future-area.jpg) 0 0 no-repeat'});
	}
	
//  Script for slideout contact buttons start
	$('#global-sliders').find('.slider-buttons').hover(function () {
		$(this).stop().animate( { width: '300px'}, { queue:false, duration:250 } );
		$(this).find('.sub-slider-button').delay(200).fadeIn('fast');
	}, function() {
		$(this).stop().animate( { width: '45px'}, { queue:false, duration:250 } );
		$(this).find('.sub-slider-button').fadeOut('fast');
	});
	
	
//  For the header magic that slides the contact button down.
	var headercontactTop = $('#header-contact-slider').css('top');
	$('#header-contact-slider').hover(function () {
		$(this).stop().animate( { top: '+=36px'}, 200 );
	}, function() {
		$(this).stop().animate( { top: headercontactTop }, 200 );
	});
	
	var timetofade = 200;
	var defW = $('.egg-hover .img-egg-non-hover').css('width');
	var defH = $('.egg-hover .img-egg-non-hover').css('height');
	var defL = $('.egg-hover .img-egg-non-hover').css('left');
	var defT = $('.egg-hover .img-egg-non-hover').css('top');
	$('.egg-hover').hover(function () {
		$(this).find('.img-egg-non-hover').addClass('hovered');
		//$('.img-egg-non-hover, .egg-hover h3').stop().animate({ opacity: '0'}, { queue:false, duration:timetofade } );
		//$('.static h3').stop().animate({ opacity: '0'}, { queue:false, duration:timetofade } );
		$('.static h3, static h2').fadeOut(50);
		//$('.img-egg-hover').stop().animate({ opacity: '0.6'}, { queue:false, duration:timetofade } );
		//$('.static h2').stop().animate({ opacity: '0.2'}, { queue:false, duration:timetofade } );
		//$(this).find('.hovered, h2').stop().animate({ opacity: '1.0'}, 0 ).find('.img-egg-hover').stop().animate({ opacity: '0'}, 0 );
		//$(this).find('h2').stop().animate({ opacity: '1.0'}, 0 );
		$('.hovered').stop().animate( { width: '222px', height: '306px', left: '10px', top:'-40px' }, { queue:false, duration:timetofade } );
		$(this).find('.hover').stop().delay(200).animate( { opacity: '1.0', top: '100px' }, timetofade  );
	}, function() {
		//$('.img-egg-non-hover, .egg-hover h2, .egg-hover h3').animate({ opacity: '1.0'}, timetofade );
		$('.static h2, .static h3').fadeIn(50);
		//$('.img-egg-hover').animate({ opacity: '0'}, timetofade );
		$('.hovered').animate( { width: defW, height: defH, left: defL, top: defT }, timetofade ).removeClass('hovered');
		$(this).find('.hover').animate( { opacity: '0', top: '150px' }, timetofade );
	});
	//Script for Plans page animations end
	//Script for slideout contact buttons start
	
	//Script for TOKer hover stuff start
	$('.toker').hover(function () {
		$('.toker-hover, .toker-non-hover', $(this)).animate( { width: '200px', height: '200px', top: '-50px', left: '-50px'}, { queue:false, duration:400 } );
		$('.toker-non-hover', $(this)).fadeOut(400);
	}, function() {
		$('.toker-hover, .toker-non-hover', $(this)).animate( { width: '100px', height: '100px', top: '0px', left: '0px'}, { queue:false, duration:400 } );
		$('.toker-non-hover', $(this)).fadeIn(400);
	});
	var slideWidth = 980;
	var slides = $('.toker-panel');
	var numberOfSlides = slides.length;
	$('#all-toker-panels').css('width', slideWidth * numberOfSlides);
	
	var currentPosition = 0;
	$('#all-toker-panels')
	manageControls(currentPosition);
	$('.control')
	.bind('click', function(){
	currentPosition = ($(this).attr('id')=='more-control') ? currentPosition+1 : currentPosition-1;
	manageControls(currentPosition);
	$('#all-toker-panels').animate({marginLeft : slideWidth*(-currentPosition) }, 1000);
	});
	function manageControls(position){
		if (position==0){ 
			  $('#back-control').hide() 
		} else{ 
			  $('#back-control').show() 
		}
		if (position==numberOfSlides-1) { 
			  $('#more-control').hide() 
		} else{ 
			$('#more-control').show() 
		}
	}
	//Script for TOKer hover stuff end
	
	//Script for Sidebar icons hover stuff start
	$('.icon').hover(function () {
		$(this).find('.icon-hover, .icon-non-hover').animate( { width: '200px', height: '200px', top: '-50px', left: '-50px'}, { queue:false, duration:200 } );
		$(this).find('.icon-non-hover').fadeOut(200);
	}, function() {
		$(this).find('.icon-hover, .icon-non-hover').animate( { width: '100px', height: '100px', top: '0px', left: '0px'}, { queue:false, duration:200 } );
		$(this).find('.icon-non-hover').fadeIn(200);
	});
	//Script for Sidebar icons hover stuff end
	
	// super fancy tooltips
	$('.tooltip').hover(function () {
		var tip = $(this).attr('title');
		$('#tooltip').remove();
		$(this).attr('title','');
		$(this).parent().append('<div id="tooltip">' + tip + '</div>');		
		$('#tooltip').fadeIn(300);
	}, function() {
		$(this).attr('title',$('#tooltip').html());
		$('#tooltip').fadeOut(300);
	});
	// tooltip that closes with "x" box
	$('.tooltip-close').click(function (e) {
		$('#close-btn-fluid').remove();
		var divLink = $(this).attr('href');
		$(divLink).prepend('<div id="close-btn-fluid">X</div>').fadeIn(300);
		$('#close-btn-fluid').click(function () {
			$('.hidden-tooltip').fadeOut(300);
			$(this).remove();
		});
		e.preventDefault();
	});
	

	//Script for Plans page animations start
	
	
	
	//Script for dropdown login start
	$('#loginButton').click(function(e) {
		$('#loginBox').animate( {'height':'toggle'}, 200 );
		e.preventDefault();
	});

	$('input.clear').each(function() {
		$(this).data('default', $(this).val()).addClass('inactive').focus(function() {
			$(this).removeClass('inactive');
				if ($(this).val() == $(this).data('default') || '') {
					$(this).val('');
				}
		}).blur(function() {
			var default_val = $(this).data('default');
			if ($(this).val() == '') {
			$(this).addClass('inactive');
			$(this).val($(this).data('default'));
			}
		});
	});	
	//Script for dropdown login end
	
	// Script for Request a Quote & 401(k) Guide form start
	$(function(){
	$("input'[type=text]', input'[type=password]', textarea").each(function(){
	$(this).bind("focus",function(){
	$(this).parent().find("label").css({color:"#CCC"});
	});
	$(this).bind("blur",function(){
	$(this).parent().find("label").removeAttr("style");
	});
	$(this).bind("keyup",function(e){
	//console.log($(this).val().length)
	if($(this).val().length>0){
	$(this).parent().find("label").addClass("sleep");
	}else{
	$(this).parent().find("label") .removeClass("sleep");
	}
	});
	})
	$("label").click(function(){
	$(this).parent().find("input, textarea").focus();
	})
	})
	// Script for Request a Quote & 401(k) Guide form end
	
	// accordion stuff
	$('.hidden-accordion, #singlek-alert').hide();
	$("#singlek-alert h4, .accordion-header").click(function(){
		$(this).toggleClass("active").next('.hidden-accordion').slideToggle('fast');
	});
	
	// Error message capture
		if ($('#spanError').html()) {
		var spanError = $('#spanError').html();
		$('#spanError').html('');
		$('body').append('<div id="close-btn">X</div><div id="error-message" class="popup box-shadow">' + spanError + '</div>');
		$('#error-message').css({ width: '600px', height :'auto', 'font-size' :'18px', 'padding' :'30px 10px'});
		var popMargL = ($('#error-message').width() + 80) / 2;
		var popMargT = ($('#error-message').height()) / 2;
		$('#error-message').css({ 
			'margin-left' : -popMargL,
			'margin-top' : -popMargT,
			'text-align' : 'center'
		});
		$('#error-message').fadeIn();
		var closeMargin = ( $('#error-message').width()/2 );
		var closeMarginT = ( $('#error-message').height()/2 );
		$('#close-btn').css( { 'margin-left' : $('body').width()/2 + closeMargin, 'top' : '50%', 'margin-top' :-closeMarginT } );
		$('body').prepend('<div id="fade"></div>');
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
	  }
	  else
	  {
		// do nothing. the damn span is empty.
	  }	
  
	
	

	
	// show a popup if user enters "0" as the number of employees
	function noEmployees() {
		$('#singlek-alert').css({ width: '600px', top : '45px'});
		var popMargL = ($('#singlek-alert').width() + 80) / 2;
		$('#singlek-alert').css({ 
			'margin-left' : -popMargL
		});
		$('#singlek-alert').fadeIn();
		$('body').append('<div id="close-btn">X</div>')
		var closeMargin = ( $('#singlek-alert').width()/2 );
		$('#close-btn').css( { 'margin-left' : $('body').width()/2 + closeMargin  } );
		$('body').prepend('<div id="fade"></div>');
		$('#fade').css({'filter' : 'alpha(opacity=80)', 'z-index' :'1'}).fadeIn(); 
		return false;
	}
	$('#number_of_employees').change(function(){  
		if ($(this).val()=='0') {  
		  noEmployees();
		  $(this).clearForm();
		}  
	  });  	
	
	// Modal action
	$('a.modal-link[href^=#]').click(function() {
		var popID = $(this).attr('rel'); 
		var popURL = $(this).attr('href'); 
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; 
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) });
		$('body').append('<div id="close-btn">X</div>')
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		var closeMarg = ( $('#' + popID).width()/2 );
		$('#close-btn').css( { 'margin-left' : $('body').width()/2 + closeMarg  } );
		$('body').append('<div id="fade"></div>');
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); 
		return false;
	});
	$('#close-btn, #fade, #single-k-return input').live('click', function() {
	  	$('#fade , .popup, #legal-data, #close-btn').fadeOut(400, function() {
			$('#close-btn, #fade').remove(); 
		}); 
		return false;
	});
	$('.modal-link-legal').click(function(e) {
		$('#legal-data').remove();
		$('body').append('<div id="legal-data"><div id="the-data-goods"></div></div>');
		$('#legal-data').before('<div id="close-btn">X</div>');
		$('#legal-data').addClass('popup');
		$('#the-data-goods').load('/company/legal.php #legal');
		$('#legal-data').fadeIn().css({'width' : '1030px'});
		var MargTop = ($('#legal-data').height() + 80) / 2;
		var MargLeft = ($('#legal-data').width() + 80) / 2;
		$('#legal-data').css({ 
			'margin-top' : -MargTop,
			'margin-left' : -MargLeft
		});
		$('#close-btn').css( { 'margin-left' : ($('body').width()/2 + 500) } );
		$('body').append('<div id="fade"></div>');
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); 
		e.preventDefault();
	});
	
    // Check for and add support for Placeholder in non-modern (IE) browsers
	//$(function() {
//		jQuery.support.placeholder = false;
//		test = document.createElement('input');
//		if('placeholder' in test) jQuery.support.placeholder = true;
//	});
//	$(function() {
//		if(!$.support.placeholder) { 
//			var active = document.activeElement;
//			$(':text').focus(function () {
//				if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
//					$(this).val('').removeClass('hasPlaceholder');
//				}
//			}).blur(function () {
//				if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
//					$(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
//				}
//			});
//			$(':text').blur();
//			$(active).focus();
//			$('form').submit(function () {
//				$(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
//			});
//		}
//	});	
	
	// Toggles password in plain text to encrypted for placeholder text in IE 
	$('#password-clear').show();
	$('#password-password').hide();
	
	$('#password-clear').focus(function() {
		$('#password-clear').hide();
		$('#password-password').show();
		$('#password-password').focus();
	});
	$('#password-password').blur(function() {
		if($('#password-password').val() == '') {
			$('#password-clear').show();
			$('#password-password').hide();
		}
	});
	
	// Toggles password in plain text to encrypted for placeholder text in IE 
	$('#password-clear-1').show();
	$('#password-password-1').hide();
	
	$('#password-clear-1').focus(function() {
		$('#password-clear-1').hide();
		$('#password-password-1').show();
		$('#password-password-1').focus();
	});
	$('#password-password-1').blur(function() {
		if($('#password-password-1').val() == '') {
			$('#password-clear-1').show();
			$('#password-password-1').hide();
		}
	});	
	
});
