
//Init stuff
$(document).ready(function() {
	//engage promotion thingy
	promotionEngine();
	promotionEngineHome();
});




//promtion Engine
var promotionIndex = 0;
function promotionEngine() {
	if ( $('#promotion .promotionEntry').length <= 1 ) { return; } //just don't bother

	$('#promotion .promotionEntry:eq(' + promotionIndex + ')').fadeOut(500,function() {
		//Fade out current
		
		//Try to find next
		promotionIndex++;
		if ( $('#promotion .promotionEntry:eq(' + promotionIndex + ')').length == 0 ) {
			promotionIndex = 0;
		} 
		
		//Fade in
		$('#promotion .promotionEntry:eq(' + promotionIndex + ')').fadeIn(500,function() {
			setTimeout("promotionEngine();",5000);  //Start next cycle
		});	
	
	});
}

//promtion Engine home (used same index)
function promotionEngineHome() {
	if ( $('.social_copy .promotionEntry').length <= 1 ) { return; } //just don't bother

	$('.social_copy .promotionEntry:eq(' + promotionIndex + ')').fadeOut(500,function() {
		//Fade out current
		
		//Try to find next
		promotionIndex++;
		if ( $('.social_copy .promotionEntry:eq(' + promotionIndex + ')').length == 0 ) {
			promotionIndex = 0;
		} 
		
		//Fade in
		$('.social_copy .promotionEntry:eq(' + promotionIndex + ')').fadeIn(500,function() {
			setTimeout("promotionEngineHome();",5000);  //Start next cycle
		});	
	
	});
}


//Function to process singup attempt
function singupNewsletter() {
	var sendVars = {
		name:$('#name').val().replace('Your Name',''),
		email:$('#email').val().replace('Your Email',''),
		code:$('#code').val().replace('Enter Code','')
	};
	
	url = "/signup.php";
	
	$.post(url,sendVars,function(xh, s) {
		if ( xh == 'success' ) {
			$('#sub_newsletter').html('<span style="color:black">Thank you for signing up !</span>');
			$('#newsletter').html('<span style="color:black">Thank you for signing up !</span>');
		} else { //Error
			alert(xh);
			$('.captcha').each(function() {
				$(this).attr('src','/image.php?sub=1&rand=' + Math.random());
			});
		}
		
	});

}

