$(document).ready(function(){
	$(".fadebg").css("height", $(document).height());
	
	$(".caption-overlay").click(function(event) {
		var picName = "./webimg/portfolio/" + $(this).attr('id');
		var picDesc = $(this).children().attr('title')
		var parentLi = $(this).closest('li');
		var imgTitle = parentLi.children('img').attr('alt');
		var imgLink = parentLi.children('img').attr('title');
		var siteName = parentLi.children('.caption').html();
		var altText = "Click here to visit the " + siteName + " live website.";
		$("#portimg").attr({ src: picName });
		$("#portpicdesc").text(imgTitle);
		$("#portlink").attr('href', imgLink);
		$("#portimg").attr({alt: altText, title: altText });
		$(".portpic").fadeIn("slow"); 
		$("#fadeport").fadeIn("slow").click(function(event){ $("#fadeport").fadeOut("fast"); $("#portimg").attr({ src: '' }); }); 
	});

	
	var first = 0;
	var pauseIt = 500;
	var speed = 6500;
	
	interval = setInterval(mover, speed);
	
	$('ul#slide-list').hover(function(){clearInterval(interval);}, function(){interval = setInterval(mover, speed);});
	
	function mover() {
		first = $('ul#slide-list li:first').html();
		firstClass = $('ul#slide-list li:first').attr('class');
		last = '<li class="' + firstClass + '">' + first + '</li>';
		$('ul#slide-list li:first').stop().animate({height: '0'}, pauseIt)
			.slideUp('medium', function(){ $(this).remove(); $('ul#slide-list').append(last)});
	}
	
	function reqField() {
	var isError = false;
	var wsdErr = "Please fill in the required fields: ";
	if ( $('#name').attr('value') == "" ) { wsdErr = wsdErr + " - Name"; isError = true; }
	if ( $('#email').attr('value') == "" ) { wsdErr = wsdErr + " -  E-Mail"; isError = true; }
	if ( $('#comments').attr('value') == "" ) { wsdErr = wsdErr + " -  Comments or Questions"; isError = true; }
	if ( isError == true ) { document.wsdform.submit(); }
	else { alert(wsdErr); return false; }
	}
	
	$(function() {
		$("ol#sortfolio").sortable({ opacity: 0.5, cursor: 'pointer', update: function() {
			var order = $(this).sortable("serialize") + '&act=sort';
			$.post("sortfolio.php", order, function(result){
				$("#message").delay(200).show(1000).html(result).delay(1000). hide(500);
			});
		}
		});
	});

	
});
