var slideshowInterval;
var currentPromo = 1;
	
function advanceSlideshow(nextPromo)
{
	if (nextPromo == null) {
		var nextPromo = currentPromo + 1;
		if (nextPromo == 6) {
			nextPromo = 1;
		}
	}
	jQuery('#homepagePromo' + currentPromo).fadeOut('slow');
	jQuery('#homepagePromo' + nextPromo).fadeIn('slow');
	
	window.setTimeout("advanceNav(" + currentPromo + ", " + nextPromo + ")", 300);
	
	currentPromo = nextPromo;
}

function advanceNav(currentPromo, nextPromo)
{
	jQuery('#homepageNav' + currentPromo).removeClass('current');
	jQuery('#homepageNav' + nextPromo).addClass('current');
}

function promoNav(promoClicked)
{
	clearInterval(slideshowInterval);
	advanceSlideshow(promoClicked);
	
}

function preloadImages(images) {

	var cache = [];
  	var args_len = images.length;
    for (var i = args_len; i--;) {
		var cacheImage = document.createElement('img');
		cacheImage.src = images[i];
		cache.push(cacheImage);
    }
}

/* clears the default text in input boxes */
function clearText(element, text)
{
	if (element.value == text) {
		element.value = "";
	}
}

function emailSubmit() {

	/*var vars = { 
    	ea: jQuery('.email').val(),
		m: '1102067516508',
		p: 'oi',
		go: 'Go'
    };*/
	
	var vars = new Array(); 
	vars['ea'] = jQuery('.email').val();
	vars['m'] = '1102067516508';
	vars['p'] = 'oi';
	vars['go'] = 'Go';
		
		
	jQuery.ajax({
		type: "post",
		url: "http://visitor.constantcontact.com/d.jsp",
		data: vars,
		beforeSend: function() {
			// fade out the current content
			jQuery("#emailForm").fadeTo(200, 0.00);
		}, success: function(html) {
			// write the new html
			jQuery("#emailForm").html('<p class="thankyou">Thank you for signing up for our newsletter.</p>');
			// fade in the current view
			jQuery("#emailForm").fadeTo(200, 1);
		}
	});

}


jQuery(document).ready(function() {
								
	// start slideshow
	slideshowInterval = window.setInterval('advanceSlideshow()', 5000);
	
	// array of pages used for preloading and rollover states
	var pages = new Array("Products", "MoYeah", "News", "Testimonials", "Shop", "Contact");
	
	// make array of images to load for top nav
	var images = new Array();
	for (i in pages) {
		images.push("/wp-content/themes/ohyeah/images/topnav/" + pages[i] + "_over.png");
	}
	
	preloadImages(images);
	
	
	// rollover states
	jQuery('.topNav').each(function(i) {
		var current = this;
		jQuery(this).mouseover(function() {
			jQuery('#nav' + pages[i] + ".topNav img").attr("src", "/wp-content/themes/ohyeah/images/topnav/" + pages[i] + "_over.png");
		});
		jQuery(this).mouseout(function() {
			jQuery('#nav' + pages[i] + ".topNav img").attr("src", "/wp-content/themes/ohyeah/images/topnav/" + pages[i] + ".png");
		});
  	});
	
});




