var first_paragraph = {
    init : function() {
        $('#content-body > p:first').addClass('first-child');
    }
}

var main_nav = {
    init: function() {
        $('ul#main-nav li a.nav-control').live("click", function(e) {
            e.preventDefault();
            if($(this).hasClass('showit')) {
                $(this).stop().removeClass('showit').addClass('hideit');
                $(this).stop().parent().next('li.nsty').slideDown(600);
            } else {
                $(this).stop().removeClass('hideit').addClass('showit');
                $(this).stop().parent().next('li.nsty').slideUp(600);
            }
            return false;
        })
    }
}

var sub_nav = {
    init: function() {
        $('ul#sub-nav li a.nav-control').live("click", function(e) {
            e.preventDefault();
            if($(this).hasClass('showit')) {
                $(this).stop().removeClass('showit').addClass('hideit');
                $(this).stop().parent().next('li.nsty').slideDown(600);
            } else {
                $(this).stop().removeClass('hideit').addClass('showit');
                $(this).stop().parent().next('li.nsty').slideUp(600);
            }
            return false;
        })
    }
}

var default_actions = {
    init : function() {
        $('ul.inner-list').not('.no-js').parent('li').hide();
        $('li a.selected').parent().next('li.nsty').show();
    }
}

var lead_image_gallery = {
    init : function() {
        if($('img').hasClass('showing')) {
            setInterval(function(){
                $.post('/index.php/images/ajaximage',{
                    'cat_id':$('#cat_id').val()
                    },function(data) {
                    $(data).insertAfter($('img.showing'));
                    $('img.showing').animate({
                        opacity: '0'
                    }, 2500, 'linear', function() {
                        $(this).remove();
                    })
                    $('img.inactive').animate({
                        opacity: '1'
                    }, 2500, 'linear', function() {
                        $(this).removeClass('inactive').addClass('showing');
                    })
                })
            }, 10000);
        }
    }
}

var lead_full_image_gallery = {
    init : function() {
        if($('img').hasClass('showing')) {
            setInterval(function(){
                $.post('/index.php/images/ajaximage/full',{
                    'cat_id':$('#cat_id').val()
                    },function(data) {
                    $(data).insertAfter($('img.showing'));
                    $('img.showing').animate({
                        opacity: '0'
                    }, 2500, 'linear', function() {
                        $(this).remove();
                    })
                    $('img.inactive').animate({
                        opacity: '1'
                    }, 2500, 'linear', function() {
                        $(this).removeClass('inactive').addClass('showing');
                    })
                })
            }, 14000);
        }
    }
}

var thumb_image_gallery = {
    init : function() {
        setInterval(function(){
            $('img.active-thumb').each(function() {
                if(Math.round(Math.random()) % 2 == 0) {
                    var identifier = $(this);
                    var type='normal';
                    if(Math.round(Math.random()) % 17.9 == 0) {
                        type='dark';
                    }
                    if(type == 'dark') {
                        if(Math.round(Math.random()) % 26.3 == 0) {
                            type='normal';
                        }
                    }
                    $.post('/index.php/images/ajaxthumbnail',{
                        'cat_id':$('#cat_id').val(),
                        'type':type,
                        'pageref':$('#page_ref').val()
                        }, function(data) {
                        $(identifier).parent('li').css('background-image', 'url('+data.css_property+')');
                        $(data.markup).insertAfter($(identifier));
                        $(identifier).animate({
                            opacity: '0'
                        }, 2500, 'linear', function() {
                            $(identifier).remove();
                            $('#'+data.rand).removeClass('hidden').addClass('active-thumb');
                        })
                    }, 'json');
                }
            })
        },10000);
    }
}

var fancyBoxes = {
    init: function() {
        $('a.fbox').fancybox({
            modal : false,
            centerOnScroll: true,
            hideOnOverlayClick: true,
            hideOnContentClick: true,
            showCloseButton: true
        });
    }
}
