/* 
 * Author: Mark Host, iNet Solutions Group, Inc. - 2011
 */
$(document).ready(function(){
	// FAQ scrolling
    $('.questions li').localScroll({
    	duration: 800,
    	hash: false
    });
    $('.answers dd').localScroll({
    	duration: 400,
    	hash: false
    });


	$('#masonry').masonry({	// masonry - national press page
		itemSelector: 'div'
	}); 
	$("header .logo img").tipTip({	// logo tooltip
		// maxWidth: "auto", 
		edgeOffset: 5,
		fadeIn: 100
	});
	$("#mobileSlider .images img").tipTip({	// mobile slideshow tooltip
		// maxWidth: "auto", 
		edgeOffset: 5,
		fadeIn: 100
	});
	// registration signup page
	$(".verification .adminText").tipTip({	// mobile slideshow tooltip
		maxWidth: '250px',
		activation: 'focus', 
		attribute: 'rel',
		defaultPosition: 'right',
		delay: 0,
		edgeOffset: 5,
		fadeIn: 100
	});
	/* FancyBox calls */
	$("a.presidentVideoLink").fancybox({
		'hideOnOverlayClick'	: 'false',
		'overlayColor'			: '#333',
		'padding'				: '15',
		'transitionIn'			: 'elastic',
		'speedIn'				: '500',
		'transitionOut'			: 'elastic',
		'speedOut'				: '100'
	});
	$(".testimonialVid").click(function() {
		$.fancybox({
			'padding'		: 15,
			'transitionIn'	: 'fade',
			'speedIn'		: '500',
			'transitionOut'	: 'fade',
			'speedOut'		: '100',
			'title'			: this.title,
			'width'			: 560,
			'height'		: 315,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	'wmode'				: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});
		return false;
	});
	$(".kenRootLink").click(function() {
		$.fancybox({
			'padding'		: 15,
			'onStart'		: function() {
	        	_gaq.push(['_trackEvent', 'pressVideo', 'watch video', $(this).attr('title')]);
	    	},
			'transitionIn'	: 'fade',
			'speedIn'		: '500',
			'transitionOut'	: 'fade',
			'speedOut'		: '100',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 390,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	'wmode'				: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});
		return false;
	});
	$("a.watchVideo").fancybox({
		'height'		: '350',
		'width'			: '855',
		'overlayColor'	: '#333',
		'onStart'		: function() {
	        _gaq.push(['_trackEvent', 'introVideo', 'watch video', $(this).attr('title')]);
	    },
		'padding'		: '15',
		'transitionIn'	: 'elastic',
		'speedIn'		: '500',
		'transitionOut'	: 'elastic',
		'speedOut'		: '100',
		'type'			: 'swf',
		'swf'			: {
			'wmode'				: 'window',
			'allowfullscreen'	: 'false',
			'AllowScriptAccess'	: 'always'
		}
	});
	$(".national a.wraptocenter, #pressList a").fancybox({
        'width'             : '95%',
        'height'            : '85%',
        'autoScale'         : false,
        'onStart'			: function() {
	        _gaq.push(['_trackEvent', 'pressList', 'view article', $(this).children().text()]);
	    },
        'transitionIn'      : 'elastic',
        'transitionOut'     : 'fade',
        'type'              : 'iframe'
    });
    $(".press .content a.pdf").fancybox({
        'width'             : '95%',
        'height'            : '85%',
        'autoScale'         : false,
        'onStart'			: function() {
	        _gaq.push(['_trackEvent', 'inThePressPDF', 'download', $(this).attr('title')]);
	    },
        'transitionIn'      : 'elastic',
        'transitionOut'     : 'fade',
        'type'              : 'iframe'
    });
    /* prop-ups for fancybox items */
	$('.watchVideoLink').click(function(){
		$('.watchVideo').click();
	});
	$('.watchVideo').css({opacity: 0.85}).hover(
		function(){
			$(this).animate({
				opacity: 1.0
			}, 200);
		},
		function(){
			$(this).animate({
				opacity: 0.85
			}, 200);
		}
	);
	$('#mobileSlider .images').anythingSlider({	// mobile GE slideshow
	    resizeContents			: false,
	    easing					: "easeOutQuart",
	    buildNavigation			: false,
	    buildStartStop 			: false,
	    appendForwardTo			: '#mobileNext',
	    appendBackTo			: '#mobilePrevious',
	    startText				: 'Play',
	    stopText				: 'Pause',
	    autoPlay				: true,
	    stopAtEnd				: true,
	    delay 					: 5000,
	    animationTime			: 400
	}); 
	$('#sliderSlides').anythingSlider({ // howItWorks slider
	    resizeContents 			: false,
	    easing					: "easeOutQuart",
	    buildArrows				: false,
	    appendNavigationTo		: '#sliderNav',
	    appendStartStopTo		: '#sliderPlayPause',
	    startText				: 'Play',
	    stopText				: 'Pause',
	    navigationFormatter		: function(index, panel) {
	        return "" + index;
	    },
	    autoPlay				: true,
	    delay 					: 12500,
	    animationTime 			: 500
	});
	$('.altSlider').anythingSlider({	// diff. howItWorks slideshow
	    resizeContents			: false,
	    easing					: "easeOutQuart",
	    buildArrows				: false,
	    appendNavigationTo		: '#sliderNav',
	    appendStartStopTo		: '#sliderPlayPause',
	    startText				: 'Play',
	    stopText				: 'Pause',
	    autoPlay				: true,
	    stopAtEnd 				: true,
	    delay 					: 12500,
	    animationTime 			: 500
	});
	// remove hover title 
	$('.thumbNav li a, #sliderPlayPause a').removeAttr('title');
	// stop slider if zipCode is focused
	$('input#myZipCode').focusin( function(){
		$('.start-stop.playing').click();
	});
	$('.turnOff').click( function(){
		$('.start-stop.playing').click();
	});
	$('#coda-slider-1').codaSlider({	// findProfits.aspx slider
        autoHeight: 		1,
		dynamicArrows: 		false,
    	dynamicTabs: 		false
    });
    $('#headerLoginBg').css('opacity', '0');
    $('#headerLogin input').focus(function() {
    	$('#headerLoginBg').animate({
    		opacity: 1	
    	}, 300);
    });
    // clear header login input fields
	$('#headerLogin input#emailInput, #homeForm input[type="text"]').focus(function() {
	    var title = $(this).attr('title');
	    if ($(this).val() == title) {
	        $(this).val('');
	    }
	}).blur(function() {
	    var title = $(this).attr('title');
	    if ($(this).val() == '') {
	        $(this).val(title);
	    }
	});

	// Cookie for storing email - only /INDEX.HTML
	$('form.headerLogin').submit(function() {
		var url = location.href;  // entire url including querystring
    	var baseURL = url.substring(0, url.indexOf('/', 14));
    	var username = $('#emailInput').attr("value");
		var password = $('#passwordInput').attr("value");
		if (baseURL.indexOf('http://growersedge.inetsgi.net') != -1)  {
			$('#loginForm').attr('action', 'http://growersedge.inetsgi.net/gelogin.aspx?r=1');
			$.cookie('emailInput', username, { expires: 28 }); // expire in 28 days
			$.cookie('passwordInput', password, { expires: 28 }); // expire in 28 days
		} else {
			$('#loginForm').attr('action', 'https://www.growers-edge.com/gelogin.aspx?r=1');
			$.cookie('emailInput', username, { expires: 28, domain: '.growers-edge.com' }); // expire in 28 days
			$.cookie('passwordInput', password, { expires: 28, domain: '.growers-edge.com' }); // expire in 28 days
		}
		// $.cookie('emailInput', username, { expires: 28 }); // expire in 28 days
		// $.cookie('passwordInput', password, { expires: 28 }); // expire in 28 days
		if ($('#rememberLogin').attr('checked')) { // if remember email is checked
			$.cookie('rememberMe', true, { expires: 28 });
		} else { // reset cookies
			$.cookie('rememberMe', null);
		}	
	}); // END submit
	var remembered = $.cookie('rememberMe');
	if ( remembered == 'true' ) {
		var username = $.cookie('emailInput');
		var password = $.cookie('passwordInput');
		$('#emailInput').attr("value", username);
		$('#passwordInput').attr("value", password);
		$('#rememberLogin').attr("checked", "checked");
	} else {
		$('#rememberLogin').removeAttr("checked");
	}
	// END cookie 
	// if password remembered hide fake input and show real one
	if ($('#passwordInput').val() != '') {
		$('#fakePasswordInput').hide();
		$('#passwordInput').show();
	}	 
	// Google event tracking 
    $('header:first a').click(function() {
        _gaq.push(['_trackEvent', 'header', 'click', $(this).text()]);
    });
    $('footer a').click(function() {
        _gaq.push(['_trackEvent', 'footer', 'click', $(this).attr('title')]);
    });
    $('.login .grey a').click(function() {
        _gaq.push(['_trackEvent', 'login', 'click', $(this).attr('title')]);
    });
	// track PDFs on press page
	/*$('.press .HIWcontent a:not(.video)').click(function() {
        _gaq.push(['_trackEvent', 'inThePressPDF', 'download', $(this).attr('title')]); 
    });*/
    $('.HIWnav.company ul a').click(function() {
        _gaq.push(['_trackEvent', 'CompanyNAV', 'click', $(this).attr('title')]);
    });
    $('.howitworks .HIWnav ul a').click(function() {
        _gaq.push(['_trackEvent', 'howItWorksNAV', 'click', $(this).attr('title')]);
    });
    $('a.presidentVideoLink').click(function() {
        _gaq.push(['_trackEvent', 'presidentVideo', 'watch video', 'A message from the President']);
    });
    $('#main:not(.press, .national) .content a:not(.getStarted, .watchVideo, .watchVideoLink)').click(function() {
        _gaq.push(['_trackEvent', 'bodyLinks', 'click', $(this).text()]);
    });
    $('#container section a').click(function() {
        _gaq.push(['_trackEvent', 'homeSectionLinks', 'click', $(this).attr('href')]);
    });
    $('#main .content a.getStarted').click(function() {
        _gaq.push(['_trackEvent', 'howItWorksNAV', 'sign up', $(this).attr('title')]);
    });
    // END Google event tracking
    

// END js call 
});
