// intro.js

$(document).ready(function(){
		$('#enter').click(function () {
			$('#enter').hide(0, function () {
				$('header,.wrap2').animate({
					marginTop: '-=250',
				}, {
					queue: false,
					duration: 333,
					easing: 'easeInExpo'
				});
				$('footer,.wrap3').animate({
					marginBottom: '-=225',
				}, {
					queue: false,
					duration: 333,
					easing: 'easeInExpo'
				});
				$('#loading').fadeIn(500);
				$('#overlay').delay(500).fadeIn(800, function () {
					$('#loading').hide(0, function () {
						$('#s5,#topSlider').show();						
						$('.logged-in-message').delay(250).fadeOut('slow');
					});
					return false;
				});
			});
		});

$(function() {
    $('#s5,#topSlider').cycle({
        fx: 'scrollHorz',
        speed: 'slow',
        prev:    '#prev2',
        next:    '#next2',
    	cleartype:  'true',
    	cleartypeNoBg:  true,
        easeIn: 'easeInExpo',
        easeOut: 'easeOutExpo',
        timeout: 9000,
        	cssBefore: {
        		opacity: 0
        	},
        	animIn: {
        		opacity: 1
        	},
        	animOut: {
        		opacity: 0
        	},
        	cssAfter: {
           		opacity: 1
        	},
        delay: -3000,
        timeoutFn: calculateTimeout 
    });
});

// timeouts per slide (in seconds) 
var timeouts = [900,30,20,20,5,5,5,5,5]; 
function calculateTimeout(currElement, nextElement, opts, isForward) { 
    var index = opts.currSlide; 
    return timeouts[index] * 1000; 
}


$('.subscribe-popup').delay(120000).fadeIn(1000);
	$('.subscribe-close-button').click(function() {
		$(this).hide(0);
		$('.subscribe-popup').fadeOut(250);
	});
	
	
//instant verification

$(function() {
		$('#login').fancybox({
			'overlayColor'      : '#000',
			'titlePosition'		: 'inside',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width'				: '100%',
			'height'			: '100%',
			'autoScale'     	:  true,
			'speedIn'			: 600, 
			'speedOut'			: 200,
			'onComplete'  		: function() {
					 	$('#sub_cont').hide(0, function() {
						$('#IDsearchform input,#signupForm input').val('');
					 });
			}
	});
});

$(function(){
	$("a.post_fancybox").fancybox({
		'width'				: '75%',
		'height'			: '75%',
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
});

$(function() {
    $('#instantBanner').cycle({
		fx: 'fade' 
	});
    $('#4e-central-button').cycle({
		fx: 'fade',
		speed: 300,
		timeout: 1
		});
	});
});

$(function()
{
	$("#login_form").submit(function()
	{
		$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
		$.post("../../../utilities/ajax_login.php",{ username:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='yes')
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()
			{ 
			  $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
              function() { 
				document.location = 'index.php';				
				});
			});
		  }
		  else 
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()
			{ 
			  $(this).html('Our system has recently changed, please email <a href="mailto:eligible@4evergreengroup.com" title="4E+ Tech Support" alt="4E+ Tech Support">4E+ Tech Support</a>').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	$("#password").blur(function()
	{
	});
});


$(function() {	
	function showLoader(){
		$('.search-background').stop(true,true).fadeIn(200);
	}
	//hide loading bar
	function hideLoader(){
		$('#sub_cont').fadeIn(1500);
		$('.search-background').fadeOut(200);
	};
	$('#searchInput').keydown(function(e) {
	  if(e.keyCode == 13) {
		showLoader();
		$('#sub_cont').fadeIn(1500);
		$('#content #sub_cont').load('../../../secure/superfetch.php?val=' + $('#searchInput').val(), hideLoader());
		e.preventDefault();
	  }
	  });	  
	$('.searchBtn').click(function(){	
		//show the loading bar
		showLoader();
		$('#sub_cont .loader').fadeIn(1500);		 
		$('#content #sub_cont').load('../../../secure/superfetch.php?val=' + $('#searchInput').val(), hideLoader());
	
	});
});

$slideshow = {
    context: false,
    tabs: false,
    timeout: 13000,      // time before next slide appears (in ms)
    slideSpeed: 300,   // time it takes to slide in each slide (in ms)
    tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'scrollHorz',   // the slide effect to use

    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#post-slider');

        // set tabs to current hard coded navigation items
        this.tabs = $('ul.slides-nav li', this.context);

        // remove hard coded navigation items from DOM
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();

        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },
    prepareSlideshow: function() {
        /* initialize the jquery cycle plugin -
         * for information on the options set below go to:
         * http://malsup.com/jquery/cycle/options.html */
        $('div.slides > ul', $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $('ul.slides-nav', $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true
        });
    },
    prepareTabs: function(i, slide) {
        /* return markup from hardcoded tabs for use as jQuery cycle tabs
         * (attaches necessary jQuery cycle events to tabs) */
        return $slideshow.tabs.eq(i);
    },
    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);

        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideshow.tabs.removeClass('on');

            // add active styling to active button
            activeTab.parent().addClass('on');
        }
    }
};

$(function() {
    // add a 'js' class to the body
    $('body').addClass('js');
	$('div.slides a').each(function(i) {
		$(this).attr('target', '_blank');
	});
    // initialize the slideshow when the DOM is ready
    $slideshow.init();
});

