$(window).load(function(){
        //set and get some variables
        var thumbnail = {
                imgIncrease : 100, /* the image increase in pixels (for zoom) */
                effectDuration : 400, /* the duration of the effect (zoom and caption) */
                imgWidth : $('.thumbnailWrapper ul li').find('img').width(),
                imgHeight : $('.thumbnailWrapper ul li').find('img').height()
        };
        //make the list items same size as the images
        $('.thumbnailWrapper ul li').css({
                'width' : thumbnail.imgWidth,
                'height' : thumbnail.imgHeight
        });
        //when mouse over the list item...
        $('.thumbnailWrapper ul li').hover(function(){
                $(this).find('img').stop().animate({
                        /* increase the image width for the zoom effect*/
                        width: parseInt(thumbnail.imgWidth) + thumbnail.imgIncrease,
                        left: thumbnail.imgIncrease/2*(-1),
                        top: thumbnail.imgIncrease/2*(-1)
                },{
                        "duration": thumbnail.effectDuration,
                        "queue": false
                });
                //show the caption using slideDown event
                $(this).find('.caption:not(:animated)').slideDown(thumbnail.effectDuration);
        //when mouse leave...
        }, function(){
                //find the image and animate it...
                $(this).find('img').animate({
                        /* get it back to original size (zoom out) */
                        width: thumbnail.imgWidth,
                        /* get left and top positions back to normal */
                        left: 0,
                        top: 0
                }, thumbnail.effectDuration);
                //hide the caption using slideUp event
                $(this).find('.caption').slideUp(thumbnail.effectDuration);
        });
});

// Slide
$(window).load(function() {
    $('#slider').nivoSlider({
        effect:'random',
        slices:15,
        animSpeed:500,
        pauseTime:5500,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:true, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:true, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){} //Triggers after all slides have been shown
    });
});

//Menu
$(function() {
    $('#navigation a').stop().animate({
        'marginLeft':'-85px'
    },1000);
    $('#navigation > li').hover(
        function () {
            $('a',$(this)).stop().animate({
                'marginLeft':'-2px'
            },200);
        },
        function () {
            $('a',$(this)).stop().animate({
                'marginLeft':'-85px'
            },200);
        }
        );
});

//ajax request Comment
function addcomment(id) {

    if($("#comment").val()==""){
        alert("กรอกข้อความก่อนครับ");
        return false;
    }else {
        var uid = FB.getSession().uid;
        var url = "addcomment";
        var dataset = {
//            name : "<fb:name uid='"+uid+"' useyou='false></fb:name>",
//            pic : "<fb:profile-pic uid='"+uid+"'></fb:profile-pic>",
            name : uid,
            pic : uid,
            comment : $("#comment").val(),
            bid : id
        };
        $.post(url,dataset,function(dataset) {
            $(".commentbox").hide();
            $(".result").html(dataset);
        });
    }
}

$(document).ready(function() {
    $(".addcomment").hide();
    $("#loading").hide();
    $(".result").hide();
    $("#loading").ajaxStart(function() {
        $("#loading").show();
        $(".result").show();
    });
    $("#loading").ajaxStop(function() {
        $("#loading").hide();
    });
});

 //facebook connect
 function doLogin() {
     $("#fbloginbutton").hide();
     $(".addcomment").show();
     var html = "<div id=\"userlogin\">"+
         "<fb:profile-pic uid='loggedinuser'></fb:profile-pic>"+
         "<fb:name uid='loggedinuser' useyou='false'></fb:name>"+
         "</div>";
     $("#userbox").html(html);
     FB.XFBML.parse();
 }