function animated()
{
	$.fn.cycle.defaults.speed = 900;
	$.fn.cycle.defaults.timeout = 5000; 
			
	$(function() {
		$('#animated').cycle({
		fx:        'cover',
		cssBefore: { opacity: 1 },
		animOut:   { opacity: 0 }
		});
	});
}

function mainmenu()
{
	$(" #nav ul ").css({display: "none"}); // Opera Fix
	$(" #nav li").hover(function(){
			$(this).find('ul:first').css({display: "block", display: "none"}).show(400);
			},function(){
			$(this).find('ul:first').css({display: "none"});
	});
}
    var updatingProcess = false;
 
$(document).ready(function(){

	animated();
	mainmenu();
	
	// Switch categories of photo.
	$('select.photo').change(function() {
		window.location = $(this).attr('rel') + $(this).val();
	});
    
    if(updatingProcess == false) {
    // Shoutbox clicking event.
    $("#s_submit").click(function() {
        shoutboxCheck();
    });
    
    // Shoutbox update event.
    $("#shoutbox").mouseover(function() {
        shoutboxUpdate();
    });
    
    }
});

function shoutboxCheck() {
    var s_name = $("#s_name").val();
    var s_address = $("#s_address").val();
    var s_message = $("#s_message").val();
    
    if(s_name == '' || s_message == '') {
        alert("Please complete all required input.")
        return false;
    }
    var updatingProcess = true;
    
    $.ajax({
        type: "POST",
        url: '/shoutbox.php',
        data: "mode=insert_shoutbox_and_update&name=" + escape(s_name) + "&address=" + escape(s_address) + "&message=" + escape(s_message),
        success: function(html) {
            $("#shoutbox-begin").after(html);
            $("#s_address").val("");
            $("#s_message").val("");
        }
    });
}

function shoutboxUpdate() {
    updatingProcess = true;
    $.ajax({
        type: "GET",
        url: '/shoutbox.php',
        data: "mode=update_shoutbox",
        success: function(html) {
            $("#shoutbox-begin").after(html);
        }
    });
}
		