﻿
$(document).bind("ready", function() {

    //
    // MAIN
    //

    $(".tabs").tabs();
    
    // DATE PICKERS

    $(".date").datepicker({
        showOn: 'both',
        buttonImage: gUrl + '/app_themes/default/images/calendar-icon.gif',
        buttonImageOnly: true,
        dateFormat: "dd/mm/yy",
        showAnim: "fadeIn"
    });

    $('.text-size-icon-button').click(function() {
        if ($('.sizable-text').is('.large')) {
            $('.sizable-text').removeClass('large');
        } else {
            $('.sizable-text').addClass('large');
        }
    });

    //
    // TOP SEARCH
    //

    var tc = $('.sc-textbox');
    var sb = $('.sc-search-button');
    var initVal = 'Search The Gisborne Herald';
    var css = 'sc-init';

    // handles the search textbox mouse down event
    tc.bind('mousedown', function() {
        if ($(this).val() == initVal) {
            $(this).val('');
            $(this).removeClass(css);
        }
    });

    // handles the search textbox change event
    tc.bind('change', function() {

        if ($(this).val() == '' || $(this).val() == initVal) {

            $(this).val(initVal);
            $(this).removeClass(css);
            $(this).addClass(css);

        }

    });

    // handles the search buttons mouse click event
    sb.bind('click', function() {
        if (tc.val() == '' || tc.val() == initVal) {
            return false;
        }
        return true;
    });

    tc.change();

    //
    // MAIN NAV
    //

    $('.nav-menu .nav-menu-button').hover(
        function() {

            var buttonId = $(this).attr('button-id');

            // hide all the bottom panels                                            
            $('.nav-submenu').hide();

            // dislay the selected panel      
            $('.nav-submenu[@panel-id=' + buttonId + ']').show();

            // change the hover state of the selected button            
            $('.nav-menu .nav-menu-button-hover').removeClass('nav-menu-button-hover');

            $(this).parent().addClass('nav-menu-button-hover');

        },
        function() { });

    //
    //  LEAD STORY
    //

//    $('.ls-cnt img').each(function() {
//        $('.ls-cnt img')
//            .attr('src', $('.ls-cnt img').attr('image'))
//            .load(function() {

//                // fit and show the photo
//                $(this).fitImage({ width: 310, height: 225 });
//                $(this).show();  

//            });
//    });


    // ALL PHOTOS

    var close = '../app_themes/default/images/window-close.png';
    var loading = '../app_themes/default/images/loading-icon.gif';
    var prev = '../app_themes/default/images/prev-icon.png';
    var next = '../app_themes/default/images/next-icon.png';

    $('.gallery a').lightBox({
        imageBtnClose: close,
        imageLoading: loading,
        imageBtnPrev: prev,
        imageBtnNext: next
    });

    $('.photos .item a.photo').lightBox({
        imageBtnClose: close,
        imageLoading: loading,
        imageBtnPrev: prev,
        imageBtnNext: next
    });

});    // end 'bind'


