﻿var mouse_is_inside = false;
var rotatorWidth;
var rotatorItemAmount;
var rotatorPanelWidth
var matht;
var i = 1;

$(document).ready(function () {

    //
    // Main Menu
    $("#Menu ul").css({ display: "none" }); // Opera Fix
    $("#Menu li").hover(function () {
        $(this).find('ul:first').css({ visibility: "visible", display: "none" }).show(268);
    }, function () {
        $(this).find('ul:first').css({ visibility: "hidden" });
    });

    //
    // Initiate Scolling Panes
    var scrollsettings = {
        showArrows: false,
        autoReinitialise: true
    };


    $('#ContentScrollPane').jScrollPane(scrollsettings);
    $('.BranchList').jScrollPane(scrollsettings);
    $('#WhatsNewScrollPane').jScrollPane(scrollsettings);

    //
    // Hide branch list initially
    $('#pnlBranchList').hide();

    // Does something??
    $('.closeStaffSelection').click(function (e) {
        $(".panelOverlay").hide(500);
        $(".closeStaffSelection").removeAttr("style");
    });

    $('.panelOverlay').hover(function () {
        mouse_is_inside = true;
    }, function () {
        mouse_is_inside = false;
    });

    $('body').mouseup(function (event) {
        if (!mouse_is_inside) $(".panelOverlay").hide(500);
    });

    // Content Rotator
    // Set Rotator Width
    rotatorItemAmount = $('.rotatorWrapper ul').children().size();
    var rotatorImageWidth = $('.rotatorWrapper ul li').outerWidth(true);
    rotatorWidth = rotatorImageWidth * rotatorItemAmount;
    rotatorPanelWidth = $('.rotatorWrapper').width();
    $('.rotatorWrapper ul').css('width', rotatorWidth);
    //Hide Left Arrow

    $('#leftArrow').hide();
    
    //
    // Homepage news slider

    $('ul#LatestNewsSlider').bxSlider({
        alignment: 'vertical',
        controls: false,
        speed: 700,
        pager: false,
        pager_short: false,
        pager_short_separator: ' / ',
        margin: 0,
        next_image: '/App_Assets/Images/sliderNext.png',
        prev_image: '/App_Assets/Images/sliderPrevious.png',
        auto: true,
        pause: 5500,
        auto_controls: false,
        ticker: false,
        ticker_controls: false,
        ticker_direction: 'next',
        ticker_hover: true,
        stop_text: 'stop',
        start_text: 'start',
        wrapper_class: 'bxslider_wrap'
    });

    // Homepage Slider (horizontal rotation of images on home page)

    $('ul#HomepageSlides').bxSlider({
        alignment: 'horizontal',        // '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: 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: 5000,                    // 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


    });

    //
    // Fix flash embed wmode
    // FF
    $("embed").attr("wmode", "transparent").wrap('<div>');
    // IE
    var embedTag;
    $("embed").each(function (i) {
        embedTag = $(this).attr("outerHTML");
        if ((embedTag != null) && (embedTag.length > 0)) {
            embedTag = embedTag.replace(/embed /gi, "embed wmode=\"transparent\" ");
            $(this).attr("outerHTML", embedTag);
        }
    });

});

//
// Map Functions

function ShowStates(e) {
    $('#QLD').hide();
    $('#NSW').hide();
    $('#VIC').hide();
    $('#SA').hide();
    $('#WA').hide();
    $('#pnlMapSearch').hide();    
    $('#pnlBranchList').show();
    $('#' + e).show();
    $('.BranchList').jScrollPane();
}

//
// panelOverlay Functions

function setSelection(e) {
    var staffID = e.id;
    if ($("div.panelOverlay:visible").length === 0) {
        $("." + staffID).show(500);
    }
     
}

//
// Content Rotator Functions
function setRotatorPosition(e) {
    var rotatorDirection = e.id;
    var rotatorWrapper = $(".rotatorWrapper ul");
    var position = rotatorWrapper.position();
    
    if (rotatorDirection == 'leftArrow') {
        $('#rightArrow').fadeIn(200);
        if (position.left != 0) {
            if (!$(".rotatorWrapper ul").is(":animated")) {
                $(".rotatorWrapper ul").animate({ left: '+=' + rotatorPanelWidth, queue: false}, "slow", function () {
                    i -= 1;
                    if (i == 1) {
                        $('#leftArrow').fadeOut(200);
                    }
                });
            }
        } 
    } 
    
    else {
        var rw = ((rotatorWidth * -1) + rotatorPanelWidth);
        if (position.left != rw) {
            $('#leftArrow').fadeIn(200);
            if (!$(".rotatorWrapper ul").is(":animated")) {
                $(".rotatorWrapper ul").animate({ left: '-=' + rotatorPanelWidth, queue: false}, "slow", function () {
                    i++;
                    if (i == rotatorItemAmount) {
                        $('#rightArrow').fadeOut(200);
                    }
                });
                    
            }
        } 
    }
}

function setRotatorPositionDD() {
    var id = $(".ProductSelect").val();
    var rotatorNumber = id ++;
    var rotatorPanelWidthID = rotatorPanelWidth * rotatorNumber *-1;
    var rotatorWrapper = $(".rotatorWrapper ul");
    var position = rotatorWrapper.position();
    var rw = ((rotatorWidth * -1) + rotatorPanelWidth);
    $(".rotatorWrapper ul").stop().animate({ "left": rotatorPanelWidthID }, "slow", function () {
        if (rotatorNumber != 0) {
            $('#leftArrow').fadeIn(200);
        }

        if (rotatorNumber == 0) {
            $('#leftArrow').fadeOut(200);
        }

        if (rotatorItemAmount == id) {
            $('#rightArrow').fadeOut(200);
        } else {
            $('#rightArrow').fadeIn(200);
        }
    });
}
