// News Slider (Vertical rotation of news items on home page)

$(document).ready(function () {

    $('ul#newsSlider').bxSlider({
        alignment: 'vertical',        // 'horizontal', 'vertical' - direction in which slides will move
        controls: false,                 // determines if default 'next'/'prev' controls are displayed
        speed: 700,                     // amount of time slide transition lasts (in milliseconds)
        pager: false,                    // determines if a numeric pager is displayed (1 2 3 4...)
        pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
        pager_short_separator: ' / ',   // text to be used to separate the short pager
        margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
        // bottom margin is applied. example: margin: 50
        next_image: '/App_Assets/Images/sliderNext.png',                 // image to be used for the 'next' control
        prev_image: '/App_Assets/Images/sliderPrevious.png',                 // image to be used for the 'prev' control
        auto: true,                    // determines if slides will move automatically
        pause: 5500,                    // time between each slide transition (auto mode only)	        auto_direction: 'next',         // order in which slides will transition (auto mode only)	        auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
        auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
        ticker: false,                  // determines if slideshow will behave as a constant ticker
        ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
        ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
        ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
        stop_text: 'stop',              // text to be displayed for the 'stop' control
        start_text: 'start',            // text to be displayed for the 'start' control
        wrapper_class: 'bxslider_wrap'  // class name to be used for the outer wrapper of the slideshow

    });

    // Image Slider (horizontal rotation of images on home page)

    $('ul#slides1').bxSlider({
        alignment: 'horizontal',        // 'horizontal', 'vertical' - direction in which slides will move
        controls: true,                 // determines if default 'next'/'prev' controls are displayed
        speed: 700,                     // amount of time slide transition lasts (in milliseconds)
        pager: true,                    // determines if a numeric pager is displayed (1 2 3 4...)
        pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
        pager_short_separator: ' / ',   // text to be used to separate the short pager
        margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
        // bottom margin is applied. example: margin: 50
        next_image: '/App_Assets/Images/sliderNext.png',                 // image to be used for the 'next' control
        prev_image: '/App_Assets/Images/sliderPrevious.png',                 // image to be used for the 'prev' control
        auto: true,                    // determines if slides will move automatically
        pause: 5500,                    // time between each slide transition (auto mode only)	        auto_direction: 'next',         // order in which slides will transition (auto mode only)	        auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
        auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
        ticker: false,                  // determines if slideshow will behave as a constant ticker
        ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
        ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
        ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
        stop_text: 'stop',              // text to be displayed for the 'stop' control
        start_text: 'start',            // text to be displayed for the 'start' control
        wrapper_class: 'bxslider_wrap'  // class name to be used for the outer wrapper of the slideshow


    });


    $('.expandableContent h2').click(function (e) {
        $(".expandableContent").each(function (idx, el) {
            el.style.overflow = '';
            el.style.height = '';
        });
        $(".expandableContent h2").each(function (idx, el) {
            el.style.backgroundImage = '';
        });
        $(e.target).closest(".expandableContent").css('overflow', 'auto');
        $(e.target).closest(".expandableContent").css('height', 'auto');
        $(e.target).closest(".expandableContent h2").css('background-image', 'url("/App_Assets/Images/arrow_down.png")');
    });
    
});




// Milestones (hover over milestones div and change the background image to match the year)

function SetMilestone(e) {
    var MilestoneImage = e.id;
    $('#milestonesParent').css('background-image', 'url("/App_Assets/Images/' + MilestoneImage + '.gif")');

}

// Our Network (click state div and change background image)

function SetState(e) {
    $('#map').children().css('background-image', 'none');
    $('#map_text').children().css('height', '0px');
    $('#map_text').children().css('overflow', 'hidden');
    var StateImage = e.id;
    $('#' + StateImage).css('background-image', 'url("/App_Assets/Images/' + StateImage + '.png")');
    $('#' + StateImage + '_text').css('overflow', 'auto');
    $('#' + StateImage + '_text').css('height', 'auto');
}

// Show Map

function ShowMap(BranchSuburbVar, SuburbVar, StateVar, StreetVar, PostcodeVar, PhoneVar, FaxVar) {
    $('.MapContainer').empty();
    $('.BranchContainer').show();
    $('.BranchSuburb').empty().html(BranchSuburbVar);
    $('.BranchAddress').empty().html(StreetVar + '<br>' + SuburbVar + " " + StateVar + ' ' + PostcodeVar);
    $('.BranchPhone').empty().html('Ph.' + ' ' + PhoneVar);
    $('.BranchFax').empty().html('Fax.' + ' ' + FaxVar);
    codeAddress(StreetVar + ' ' + SuburbVar + ' ' + PostcodeVar + ' ' + StateVar);
}

function codeAddress(address) {
    var geocoder;
    var map;
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644)
    var myOptions = {
        zoom: 15,
        mapTypeControl: false,
        navigationControl: true,
        navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    geocoder.geocode({ 'address': address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
        } else {
            //alert("Geocode was not successful for the following reason: " + status);
        }
    });
} 


