// JavaScript Document

$(document).ready(function(){

    var defaultFont = 0.85;
    var currentFont = defaultFont;
    // dynamically insert text-resize buttonsss
    $('#linksBar ul').prepend('<li class="sizedown"><a href="#"><img src="/local_giving/port_phillip/include/data_new/sizedown.gif" alt="Text size down" /></a></li><li class="sizeup"><a href="#"><img src="/local_giving/port_phillip/include/data_new/sizeup.gif" alt="Text size up" /></a></li>');
    
    // resize text when click on buttons
    $('#linksBar ul .sizeup').click(function(){
        if(currentFont < 1.45)
           currentFont += 0.1;
        $('body').css({'font-size':currentFont+'em'});

    });
    $('#linksBar ul .sizedown').click(function(){
        if(currentFont > 0.45)
            currentFont -= 0.1;
        $('body').css({'font-size':currentFont+'em'});
    });
    $('#linksBar ul li').hover(function(){
        $(this).css({'opacity': 0.7, 'cursor':'pointer'});
    }, function(){
        $(this).css({'opacity': 1});
    });
    
    // insert faux drop-down on homepage 'Other Port Phillip Sites'
    $('.home #otherPPsites ol').before('<img class="otherPPsitesSelect" src="/media/selectCoppSite.gif" />');
    // open up dropdown when clicked
    $('.home .otherPPsitesSelect').toggle(function(){
        $('.home #otherPPsites ol').slideDown(100);
    },function(){
        $('.home #otherPPsites ol').slideUp(100);
    });
    
    // insert faux text into search boxes...
    $('.globalSearchInput').val('Global Search');
    $('#header .searchInput').val('Search Site');
    // remove text when focused...
    $('.globalSearchInput, #header .searchInput').focus(function(){
        if($(this).val() == 'Global Search' || $(this).val() == 'Search Site'){
            $(this).val('');
        }
    });
    // re-enters default text...
    $('.globalSearchInput').blur(function(){
        if( $(this).attr('value') == ''){
            $(this).val('Global Search');
        }
    });
    $('.#header .searchInput').blur(function(){
        if( $(this).attr('value') == ''){
            $(this).val('Search Site');
        }
    });
    
    // home main nav hover for IE6
    $('.home #mainNav li').hover(function(){
        $(this).css({'background-position':'0 -115px'});
    }, function(){
        $(this).css({'background-position':'0 0'});
    });
    
    // home announcements hover for IE6
    $('.home .announcements').hover(function(){
        $(this).css({'background':'url("/media/home-announcement-over-bg.gif")', 'cursor':'pointer'});
    }, function(){
        $(this).css({'background':'url("/media/home-announcement-bg.gif")'});
    });
    
    // subNav goes from opacity 70% -> 100%
    $('#subNav li img').css({'opacity': 0.7});
    $('#subNav li.on img').css({'opacity': 1});
    $('#subNav li img').hover(function(){
        $(this).css({'opacity':1});
    }, function(){
        $(this).css({'opacity':0.7});
        $('#subNav li.on img').css({'opacity': 1});
    });
    
    // breadcrumbs goes opacity 0.7 > 1
    $('#breadcrumbs li').css({'opacity': 0.7});
    $('#breadcrumbs li').hover(function(){
        $(this).css({'opacity':1});
    }, function(){
        $(this).css({'opacity':0.7});
        $('#breadcrumbs li:last').css({'opacity':1});
    });
    $('#breadcrumbs li:last').css({'opacity':1});
    
    // sideNav background appear on hover (for IE6)
    $('#sideNav li').hover(function(){
        if($(this).attr('class') != 'on'){
            $(this).css({'background':'url("/media/sideNav-on-bg.gif")'});
            $(this).css({'background-color':'#f0f3f6'});
            $(this).css({'background-repeat':'repeat-x'});
        }
    }, function(){
        if($(this).attr('class') != 'on'){
            $(this).css({'background':'none'});
        }
    });
    $('#sideNav li ul li').hover(function(){
        if($(this).attr('class') != 'on'){
            $(this).css({'background':'url("/media/sideNav-on-bg.gif")'});
            $(this).css({'background-color':'#f0f3f6'});
            $(this).css({'background-repeat':'repeat-x'});
        }
    },function(){
        $(this).css({'background':'none'});
    });

    //Add anchors to H3s
    AddAnchors('#content h3');

});

function AddAnchors(elementID) {
    //add anchors to element
    var elIndex = 1
    $(elementID).each(function(i) {
        $(this).prepend('<a name="L' + elIndex + '"></a>');
        elIndex ++;
    });
}
