// slider
$(document).ready(function(){
    $('#slider').nivoSlider({
        pauseTime: 8000,
        controlNav: false
    });
});

// hovereffect 
$(document).ready(function(){
    $('#menu_top a').mouseover(
        function(){
            $(this).stop();
            $(this).animate({"opacity":0.6, queue: false}, "slow");
            $(this).animate({"opacity":1.0, queue: false}, "fast");
        }
        ,function() {
        }
    );
});

// portfolio effect
$(document).ready(function(){
    $("#content .cloud-zoom").fancybox({
        'transitionIn'  :   'elastic',
        'transitionOut' :   'none',
        'speedIn'       :   600,
        'speedOut'      :   200,
        'overlayShow'   :   true,
        'overlayColor'  :   '#000',
        'cyclic'        :   true,
        'easingIn'      :   'easeInOutExpo'
    });

    // catch clood zoom conflict
    $("#content .mousetrap").live('click',function(){
        $(this).prev().trigger('click');
    });

    var $content = $('#content'),
    $thumb_list = $content.find('.thumb > ul');

    $thumb_list.each(function(){
        var $this_list  = $(this),
        total_w     = 0,
        loaded      = 0,
        //preload all the images first
        $images     = $this_list.find('img'),
        total_images= $images.length;
        $images.each(function(){
            var $img    = $(this);
            $('<img alt="">').load(function(){
                ++loaded;
                if (loaded == total_images){
                    $this_list.data('current',0).children().each(function(){
                        total_w += $(this).width();
                    });
                    $this_list.css('width', total_w + 'px');

                    //next / prev events

                    $this_list.parent()
                    .siblings('.next')
                    .bind('click',function(e){
                        var current = $this_list.data('current');
                        if(current == $this_list.children().length -1) return false;
                        var next    = ++current,
                        ml      = -next * $this_list.children(':first').width();

                        $this_list.data('current',next)
                        .stop()
                        .animate({
                            'marginLeft'    : ml + 'px'
                        },400);
                        e.preventDefault();
                    })
                    .end()
                    .siblings('.prev')
                    .bind('click',function(e){
                        var current = $this_list.data('current');
                        if(current == 0) return false;
                        var prev    = --current,
                        ml      = -prev * $this_list.children(':first').width();

                        $this_list.data('current',prev)
                        .stop()
                        .animate({
                            'marginLeft'    : ml + 'px'
                        },400);
                        e.preventDefault();
                    });
                }
            }).attr('src',$img.attr('src'));
        });
    });

});

// navigation script
$(document).ready(function() {
    /* for top navigation */
    $("#menu_top ul").css({display: "none"}); // Opera Fix
    $("#menu_top li")
    .hover(function(){
        $(this)
        .find('ul:first')
        .css({visibility: "visible",display: "none"})
        .slideDown(400);
        },
    function(){
        $(this).find('ul:first').css({visibility: "hidden"});
    });
});

