function isEmail(x) {

	mail_at = x.indexOf("@");

	mail_dot = x.lastIndexOf(".");

	if( mail_at < 2 || mail_dot < 4 || mail_dot < (mail_at + 2) ) { return false; }

	else { return true; }

}

// ctas
$(document).ready(function () {
	if ($('.landing_cta').length > 0) {
		$('.landing_cta').each(function() {
			if ($(this).attr('rel') != '') {
				$(this).css('cursor','pointer');
				$(this).click(function() { document.location=$(this).attr('rel');});
			}
		});
	}
});

$(document).ready(function () {

	//tabs for video/events/news box. 

	var tabContainers = $('#tabbox > div');

	$('#tabbox ul.tabs a').click(function () {

		tabContainers.hide().filter(this.hash).show();

		$('#tabbox ul.tabs li').removeClass('selected');

		$(this).parent().addClass('selected');	

		return false;

	}).filter(':first').click();

	// submit your event  button
	if ($('#submit_event_cta').length > 0) {
		$('#submit_event_cta').click(function() { document.location='/events/submit-your-event.html'; });	
	}
	// see more events button
	if ($('#see_more_events_cta').length > 0) {
		$('#see_more_events_cta').click(function() { document.location=$(this).attr('rel'); });	
	}
	
	if ($('#see_more_assets_cta').length > 0) {
		$('#see_more_assets_cta').click(function() { document.location='/trade/trade.html'; });	
	}
	

	// submit event form

	if ($('#submit_event').length > 0) {

		$('#submit_event').submit(function() {

			$('.req').removeClass('req');

			$('#form_error').hide();

			e = 0;

			if ($('#title').val() == '') { $('#label_title').addClass('req'); e=1; }

			if ($('#event_date').val() == '') { $('#label_event_date').addClass('req'); e=1; }

			if ($('#start_time').val() == '') { $('#label_start_time').addClass('req'); e=1; }

			if ($('#location').val() == '') { $('#label_location').addClass('req'); e=1; }

			if ($('#description').val() == '') { $('#label_description').addClass('req'); e=1; }

			if ($('#contact_info').val() == '') { $('#label_contact_info').addClass('req'); e=1; }

			if ($('#contact_email').val() == '') { $('#label_contact_email').addClass('req'); e=1; }

			if ($('#region option:selected').val() == '') { $('#label_region').addClass('req'); e=1; }

			if ($('#contributor_name').val() == '') { $('#label_contributor_name').addClass('req'); e=1; }

			if ($('#contributor_email').val() == '') { $('#label_contributor_email').addClass('req'); e=1; }

			if (e==1) { $('#form_error').show(); return false; }

			else {

				return true;

			}	

		});

	}

});



// newsletter signup *****************************************************

// ***********************************************************************

$(document).ready(function() {

	if ($('#newsletter_signup').length > 0) {

		$('#newsletter_signup').submit(function() {

			$('.req').removeClass('req');

			if ($('#first_name').val() == '') { $('#first_name_label').addClass('req'); }

			if ($('#last_name').val() == '') { $('#last_name_label').addClass('req');}

			if ($('#email').val() == '') { $('#email_label').addClass('req');}

			if ($('.req').length > 0) {

				$('#news_error').fadeIn();	

			}

			else if ( !isEmail( $('#email').val() ) ) { 

				$('#email_label').addClass('req'); 

				$('#news_error').html('Please supply a properly formatted Email.').delay(200).fadeIn();

			}

			else {

				$.post('/cust/signups/ajaxhosts/signup.php',$('#newsletter_signup').serialize(),function(data) {

					$('#newsletter').hide().html('<h1>Thank You</h1><p>You have successfully signed up for the Sak&Eacute; One Newsetter!</p>').fadeIn();																								  

				});	

			}

			return false;

		});

	}

});



// slideshow *************************************************************

// ***********************************************************************

$(document).ready(function() {

	if ($('#slideshow_wrapper').length > 0) {

		showSlide(1);

		$('.slide_button').click(function() {

			showSlide($(this).attr('rel'));

		});

		// pause/play button

		$('#slide_control').click(function() { 

			if($(this).attr('class') == 'play') { 

				$(this).removeClass('play').addClass('pause');

				showSlide( parseInt($('.slide_button_on').attr('rel')) +1 );

			}

			else {

				$(this).removeClass('pause').addClass('play');

				clearTimeout(to1);

			}

		});

	}

});



var to1;

function showSlide(x) {

	num_slides = parseInt($('#slide_img_wrapper').attr('rel'));

	if (x==(num_slides+1)) { x=1; }

	if ($('#slideimg').html() != '') { // subsequent loads

		$('#slideimg_below').html($('#slide'+x).html());

		$('#slideimg').fadeOut('slow', function() { 

			$('#slideimg').html($('#slide'+x).html()).show(); 

		});

	}

	else { // first time load

		$('#slideimg').html($('#slide'+x).html());

		$('#slideimg_below').html($('#slide'+x).html());

	}

	$('.slide_button').removeClass('slide_button_on');

	$('#btn'+x).addClass('slide_button_on');

	clearTimeout(to1);

	to1 = setTimeout('showSlide('+(parseInt(x)+1)+');',7000);

}



//*********************

var sakeone = {

	howsakeismade:{

		slideshow: function(){

			$.getScript('/assets/javascript/jquerycyclelite.js', function(){

				$('#imgcycle').cycle({ 

					prev:   '#leftimgnav', 

					next:   '#rightimgnav', 

					speed:  1000, 

					timeout: 3000 

				});

			});

		}

	}

}

//*********************
