// JavaScript Document

$(document).ready(function () {
	$('.fbOver').fadeOut(1);
	$('.fbOut').hover(function() {
		$('.fbOver').fadeIn(300);
	});
	
	$('.fbOver').hover(function() {
	}, function() {
		$('.fbOver').fadeOut(300);
	});
	
	$('.twitterOver').fadeOut(1);
	$('.twitterOut').hover(function() {
		$('.twitterOver').fadeIn(300);
	});
	
	$('.twitterOver').hover(function() {
	}, function() {
		$('.twitterOver').fadeOut(300);
	});
	
	$('.piOver').fadeOut(1);
	$('.piOut').hover(function() {
		$('.piOver').fadeIn(300);
	});
	
	$('.piOver').hover(function() {
	}, function() {
		$('.piOver').fadeOut(300);
	});
	
	$('.flickrOver').fadeOut(1);
	$('.flickrOut').hover(function() {
		$('.flickrOver').fadeIn(300);
	});
	
	$('.flickrOver').hover(function() {
	}, function() {
		$('.flickrOver').fadeOut(300);
	});
	
	$('.buttonText').hover(function() {
		$(this).parent().css("background-color","#6acee0");
	}, function() {
		$(this).parent().css("background-color","#df4e2a");
	});
	
	$('.prevBtn').click(function() {
		if (curimg != 0) {
			curimg--;
			toSlide += 665;
			imgnewheight = $('.allImages img').eq(curimg).height();
			$('.allImages').animate({marginLeft:toSlide+"px"}, 500, function() {
				$('#imageMask').animate({height:imgnewheight+"px"}, {duration: 500, specialEasing:{marginLeft:'easeOutCirc'}})
			});
		} else {
			curimg=totalimages-1;
			toSlide = -(665*(totalimages-1));
			imgnewheight = $('.allImages img').eq(curimg).height();
			$('.allImages').animate({marginLeft:toSlide+"px"}, 500, function() {
				$('#imageMask').animate({height:imgnewheight+"px"}, {duration: 500, specialEasing:{marginLeft:'easeOutCirc'}})
			});
		}
	});
	
	$('.nextBtn').click(function() {
		if (curimg < totalimages-1) {
			curimg++;
			toSlide -= 665;
			imgnewheight = $('.allImages img').eq(curimg).height();
			$('.infoText').html(descriptions[curimg]);
			$('.allImages').animate({marginLeft:toSlide+"px"}, 500, function() {
				$('#imageMask').animate({height:imgnewheight+"px"}, {duration: 500, specialEasing:{marginLeft:'easeOutCirc'}})
			});
		} else {
			curimg=0;
			toSlide = 0;
			imgnewheight = $('.allImages img').eq(curimg).height();
			$('.infoText').html(descriptions[curimg]);
			$('.allImages').animate({marginLeft:toSlide+"px"}, 500, function() {
				$('#imageMask').animate({height:imgnewheight+"px"}, {duration: 500, specialEasing:{marginLeft:'easeOutCirc'}})
			});
		}
	});
});

function sendContact() {
	tname = $('#zname').val();
	temail = $('#zemail').val();
	tmsg = $('#zmessage').val();
	
	if (temail.length < 6 || temail.indexOf("@") == -1 || temail.indexOf(".") == -1) {
		$('#zemail').val("Please enter a valid email.");
	}
	if (tmsg.length < 1) {
		$('#zmessage').val("Please enter a message.");
	}
	if (tname.length < 1) {
		$('#zname').val("Please enter your name.");
	}
	
	if (tname.length > 1 && tname != "Please enter your name." && temail != "Please enter a valid email." && tmsg != "Please enter a message." && temail.length > 6 && temail.indexOf("@") != -1 && temail.indexOf(".") != -1 && tmsg.length > 1) {
		$('#zname').val("");
		$('#zemail').val("");
		$('#zmessage').val("Thanks! Message sent.");
		var loadUrl = "http://www.jeffmcmillan.com/wp-content/themes/jeff/email.php?sname="+tname+"&semail="+temail+"&smsg="+tmsg;
		$.ajaxSetup ({
			cache: false
		});
		$.get(
			loadUrl,
			{language: "php", version: 5},
			function(responseText) {
			},
			"html"
		);
	}
	
}

function sendNewsletter() {
	form = $('#nlemail').val();
	if (form.length < 6 || form.indexOf("@") == -1 || form.indexOf(".") == -1) {
		$('#nlemail').val("Please enter a valid email.");
	} else {
		$('#nlemail').val("Thanks for signing up!");
		var loadnUrl = "http://www.jeffmcmillan.com/wp-content/themes/jeff/newsletter.php?semail="+form;
		$.ajaxSetup ({
			cache: false
		});
		$.get(
			loadnUrl,
			{language: "php", version: 5},
			function(responseText) {
			},
			"html"
		);
	}
}

function buyNow(des,pr) {
	$('#itemname').val(des);
	$('#totalprice').val(pr);
	 document.forms["pp"].submit();
}

function initSlider() {
		totalimages = $('.allImages img').length;
		firstheight = $('.allImages img').eq(0).height();
		$('.allImages').css("height",firstheight);
		$('#imageMask').css("height",firstheight);
		$('.allImages').css("width",totalimages*665);
		curimg = 0;
		toSlide = 0;
		$('.infoText').html(descriptions[0]);
}
