/**http://www.lasciviousdating.co.uk**/
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

var news_count;
var news_interval;
var old_news = 0;
var current_news = 0;

$(document).ready(function() {	
	/**Style attributes to control top member profiles display**/		
	$(".wld_badge_item").css({"float":"left", "width":"140px"});	
	$(".wld_badge_item_photo").css({"padding-bottom":"0"});
	$(".wld_badge_item_photo a").css({"margin-left":"25px"});
	$(".wld_badge_item_detail").css({"width":"140px","text-align":"center"});
	$(".wld_badge_item_region").css({"display":"none"});
	
	/**Style attributes to control member profile in left panel slide**/	
	$("#profileSliding .wld_badge_item").css({"float":"left", "width":"90px", "padding":"0 5px"});
	$("#profileSliding .wld_badge_item_photo").css({"padding-bottom":"0"});
	$("#profileSliding .wld_badge_item_photo a").css({"margin":"0"});
	$("#profileSliding .wld_badge_item_detail").css({"display":"none"});
	$("#profileSliding .wld_badge_item_region").css({"display":"none"});	
	
	$("#twitter").getTwitter({
		userName: "LasciviousD",
		numTweets: 2,
		loaderText: "Loading tweets...",
		slideIn: false,
		slideDuration: 0,
		showHeading: false,
		headingText: "Latest Tweets",
		showProfileLink: true,
		showTimestamp: false
	});
	
	/**Lascivious update**/
	headline_count = $("div.headline").size();
	$("div.headline:eq("+current_headline+")").css('left','5px');
	headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
	$('#scrollup').hover(function() {
		clearInterval(headline_interval);
	}, function() {
		headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
		headline_rotate();
	});
	
	/**Home page news display**/
	news_count = $('#newspreview li').size();
	$('#newspreview li:eq('+current_news+')').addClass('rp1_key4one_spl');
	$("#enlarge-"+current_news).show();
	news_interval = setInterval(rotateNews, 3000);
	$('#stopslide').hover(function() {
		clearInterval(news_interval);
	}, function() {
		$('.home_mainslide').hide();
		$("#enlarge-"+current_news).show();
		$('#newspreview li').removeClass('rp1_key4one_spl');
		$('#thumb-'+current_news).addClass('rp1_key4one_spl');
		news_interval = setInterval(rotateNews, 3000); //time in milliseconds				
	});	
	$('#newspreview li').mouseover(function() {		
		var selected_news = this.id.slice(6);
		$('#newspreview li').removeClass('rp1_key4one_spl');
		$('#thumb-'+selected_news).addClass('rp1_key4one_spl');
		$('.home_mainslide').hide();
		$('#enlarge-'+selected_news).show();
	});
});

function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count;
	$("div.headline:eq(" + old_headline + ")").animate({left: -800},"slow", function() {
		$(this).css('left','800px');
	});
	$("div.headline:eq(" + current_headline + ")").show().animate({left: 5},"slow");  
	old_headline = current_headline;
}
function rotateNews() {
	current_news = (old_news + 1) % news_count;
	$('#newspreview li').removeClass('rp1_key4one_spl');
	$('#newspreview li:eq('+current_news+')').addClass('rp1_key4one_spl');
	$("#enlarge-"+old_news).fadeOut('fast', function() {
		$("#enlarge-"+current_news).fadeIn('fast');
	});
	old_news = current_news;
}
function signupValidate() {
	if(document.signupform.firstname.value == "") {
		alert("Please enter your first name.\n\nThank you.");
		return false;
	}
	else if(document.signupform.dobday.value == "") {
		alert("Please select your date of birth.\n\nThank you.");
		return false;
	}
	else if(document.signupform.dobmonth.value == "") {
		alert("Please select your month of birth.\n\nThank you.");
		return false;
	}
	else if(document.signupform.dobyear.value == "") {
		alert("Please select your year of birth.\n\nThank you.");
		return false;
	}
	else if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(document.signupform.email.value) === false) {
		alert("Please enter a valid email address.\n\nThank you.");
		return false;
	}
	else if(document.signupform.password.value == "") {
		alert("Please choose your password.\n\nThank you.");
		return false;
	}
	else if(document.signupform.password.value.length < 4) {
		alert("Your password must be between 4 and 30 characters in length.\n\nThank you.");
		return false;
	}
	else if(document.signupform.password.value.length > 31) {
		alert("Your password must be between 4 and 30 characters in length.\n\nThank you.");
		return false;
	}
	else if(document.signupform.password.value != document.signupform.passconf.value) {
		alert("Please confirm your password.\n\nThank you.");
		return false;
	}	
	else if(document.signupform.howheard.value == "") {
		alert("Please tell us how did you hear about us?\n\nThank you.");
		return false;
	}
}
function validateContact() {
	$("#displayerr_post").hide();
	var err = 0;
	var msg = "";
	if($("input[name=firstname]").val() == "") {
		$("#displayerr").append('<span class="errmsg">First name is required.</span>');
		err++;
	}
	if($("input[name=surname]").val() == "") {
		msg = '<span class="errmsg">Surname name is required.</span>';
		err++;
	}
	if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test($("input[name=email]").val()) === false) {
		msg+= '<span class="errmsg">A valid email address is required.</span>';
		err++;
	}
	if($("input[name=message]").val() == "") {
		msg+= '<span class="errmsg">Message is required.</span>';
		err++;
	}
	if($("input[name=captcha]").val() == "") {
		msg+= '<span class="errmsg">Please enter the words as ahown in the image.</span>';
		err++;
	}
	if($("input[name=acceptpolicy]:checked").length == 0) {
		msg+= '<span class="errmsg">Please accept to our privacy policy.</span>';
		err++;
	}
	else if($("input[name=acceptpolicy]:checked").val() == "no") {
		msg+= '<span class="errmsg">To send mail you must accept to our privacy policy.</span>';
		err++;
	}
	if(err == 0)
		return true;
	else {
		$("#displayerr").html('<span class="errmsghead">Please correct the following errors</span>').append(msg);
		$("#displayerr").slideDown('slow');
		return false;
	}		
}
/*Function for member profile slides in home page*/
function memberSlide(direction) {
	var hiddenval = $("#slidewidth").val();
	var leftval;
	if(direction == "right") {
		if(hiddenval < 5) {			
			leftval = -(200 * hiddenval);
			hiddenval++;
			$("#profileSliding").animate({marginLeft: leftval}, 1200 );						
		}
		
	}
	else if(direction == "left") {
		if(hiddenval > 1) {			
			leftval = -(200 * (hiddenval - 2));
			hiddenval--;
			$("#profileSliding").animate({marginLeft: leftval}, 1200 );						
		}		
	}
	$("#slidewidth").val(hiddenval);
	
}
function changeSlideButton(direction, userevent)
{
	var hiddenval = $("#slidewidth").val();
	if(direction == "right")
	{
		if(hiddenval < 5)
		{			
			if(userevent == "mover")
				$("#slideRight").css("background-position", "-18px -36px");
			if(userevent == "mdown")
				$("slideRight").css("background-position", "-18px -54");
			if(userevent == "mout")
				$("#slideRight").css("background-position", "-18px -18");
		}
		else
		{
			$("#slideRight").css("background-position", "-18px 0");
			$("#slideLeft").css("background-position", "0 -18px");
		}
		
	}
	else if(direction == "left")
	{
		if(hiddenval > 1)
		{			
			if(userevent == "mover")
				$("#slideLeft").css("background-position", "0 -36px");
			if(userevent == "mdown")
				$("#slideLeft").css("background-position", "0 -54px");
			if(userevent == "mout")
				$("#slideLeft").css("background-position", "0 -18px");
		}
		else
		{
			$("#slideLeft").css("background-position", "0 0");
			$("#slideRight").css("background-position", "-18px -18px");
		}		
	}
}

