function checkStaff(){
	email_box = document.getElementById("email");
	name_box = document.getElementById("name");
	message_box = document.getElementById("message");
	if(name_box.value == ""){
		alert("Please fill the name area");
		name_box.focus();
		return false;
	}
	if(email_box.value == "" || !isValidEmail(email_box.value)){
		alert("Please fill out the email box correctly");
		email_box.focus();
		return false;
	}
	if(message_box.value == ""){
		alert("Please fill the message area");
		message_box.focus();
		return false;
	}
	return true;
}
function checkContact(){
	email_box = document.getElementById("email1");
	name_box = document.getElementById("name1");
	message_box = document.getElementById("message1");
	if(name_box.value == ""){
		alert("Please fill the name area");
		name_box.focus();
		return false;
	}
	if(email_box.value == "" || !isValidEmail(email_box.value)){
		alert("Please fill out the email box correctly");
		email_box.focus();
		return false;
	}
	if(message_box.value == ""){
		alert("Please fill the message area");
		message_box.focus();
		return false;
	}
	return true;
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


$(document).ready(function() {
    $('#mycarousel').jcarousel({
		buttonNextHTML: '<img src="images/buttons/btn_slideshow_next.gif" width="19" height="67" alt="button next" />',
        buttonPrevHTML: '<img src="images/buttons/btn_slideshow_prev.gif" width="19" height="67" alt="button previous" />'
    });
    $("#mycarousel a").attr("href","javascript:");
    $("#mycarousel a").click(function() {
    	$("#mainImage").attr("src",$(this).children("img").attr("alt"));
    });
	
	$('#listingcarousel').jcarousel({
		buttonNextHTML: '<img src="images/buttons/btn_slideshow_next.gif" width="19" height="67" alt="button next" />',
        buttonPrevHTML: '<img src="images/buttons/btn_slideshow_prev.gif" width="19" height="67" alt="button previous" />'
    });

	
    $("#tabs").tabs({ fxFade: true, fxSpeed: 'fast' });
	
	//$("#tour_nav li a").attr("name",$("#tour_nav li a").attr("href"));
	jQuery.each($("#tour_nav li a"), function(i, val){
			$(this).attr("name", $(this).attr("href"));								  
											  });
	$("#tour_nav li a").attr("href","javascript:");
	$("#tour_nav li a").click(function(){
		$("#tour_applet").attr("src", $(this).attr("name"));
		//$("#tour_applet").html("Test");
	});
	$("#slideshowControl li a.picLink").each(function(){
		$(this).click(function(){
			slideInterval = clearInterval(slideInterval);
			id = $(this).attr("class").replace(/picLink pic-/,"");
			slideSwitch(id);
			slideInterval = setInterval( "slideSwitch()", 5000 );
			return false;
		});
	});
	$("#slideshowControl #pauseplay a").click(function(){
			if(window.playing){
				slideInterval = clearInterval(slideInterval);
				window.playing = false;
			} else {
				slideInterval = setInterval( "slideSwitch()", 5000 );
				window.playing = true;
			}
			return false;
	});
	$("#slideshowControl #nextslide a").click(function(){
			if($("#slideshow DIV.active")){
				slideInterval = clearInterval(slideInterval);
				slideSwitch();
				slideInterval = setInterval( "slideSwitch()", 5000 );
			}
			return false;
	});
	$("#slideshowControl #prevslide a").click(function(){
			if($("#slideshow DIV.active")){
				slideInterval = clearInterval(slideInterval);
				currId = $("#slideshow DIV.active").attr("id").replace(/pic-/,"")
				slideSwitch(currId);
				slideInterval = setInterval( "slideSwitch()", 5000 );
			}
			return false;
	});
});

function slideSwitch(i) {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
	if(typeof(i)!="undefined"){
		$next =  $("#pic-"+i);
	} else {
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');
	}
    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    slideInterval = setInterval( "slideSwitch()", 8500 );
    window.playing = true
});
