﻿$(document).ready(function () {
    //browser window sizing template
    /*
    $('#sizer').hover(
    function () {
    $('#sizer').css('color', '#FF9900');
    $('#window_size_template').toggle();
    },
    function () {
    $('#sizer').css('color', '#cccccc');
    setTimeout("$('#window_size_template').fadeOut();", 3000)
    }
    );

    //for IE6
    $('.rbroundbox').css("height", $(window).height()-28);
    */
    /*
    //remove ad animation on landing page
    $('#ad1').css('width', $('div.rbcontent').width() - 100);
    $('#ad2').css('width', $('div.rbcontent').width() - 100);
    $('#ad1').toggle();
    $('#ad1').animate({ left: 64 }, 800, "swing", function () {
    setTimeout("showAnim(2,1)", 5000);
    });
    */
    $('#ctl00_dismissButton').button();


    $('#regLinkButton').button();
    $('#regLinkButton').unbind('click')
    $('#regLinkButton').click(function (e) {
        document.location='/account/register/';
        return false;
    })

    $('td.a').each(function (intIndex) {
        var corpPanelH = $('div.corp_panel').height();
        $(this).css("height", corpPanelH);
    });

    $('button').button();

    $('.accordion .head').click(function () {
        $(this).next().toggle('slow');
        return false;
    }).next().hide();


    $('div.qButton').each(function (intIndex) {
        $(this).css("left", -400);
    });
    setupTopics();

    $('div.qButton a').each(function (intIndex) {
        $(this).removeAttr("href");
        $(this).css("margin-top", -($(this).height() / 2));
        $(this).css("margin-left", "20px");
    });

    $('div.corp_details').each(function (intIndex) {
        var corpPanelW = $('div.corp_panel').width();
        var row = 1;
        var col = 1;
        $(this).css('left', (corpPanelW * 2));
    });
});

function showQ(which) {
    var hideArray = new Array("#a1", "#a2", "#a3", "#a4", "#a5", "#a6");
    var theTarg = '#'+which;
    if ($(theTarg).is(':visible')) {
        $(theTarg).slideToggle();
    } else {
        for (x in hideArray){
          if ($(hideArray[x]).is(":visible")) {
            $(hideArray[x]).slideToggle();
          }
        }
        $(theTarg).slideToggle();
    }
}

var curDetail

function setupTopics() {
    curDetail = "";
    var spaceH = 171;
    var spaceV = 90;
    var row = 0;
    var col = 0;
    var topOfPage = 50;
    var leftOfPage = 0;
    var colimit = 4;
    var corpPanelW = $('div.corp_panel').width();
    $('div.qButton').each(function (intIndex) {
        if ($(this).hasClass('qButtonSel')) {
            $(this).removeClass('qButtonSel');
            $(this).addClass('qButton');
        }
        $(this).unbind("click");
        $(this).click(function () {
            $(this).removeClass('qButton');
            $(this).addClass('qButtonSel');
            var detStr = $(this).attr('id');
            detStr += "_detail";
            showDetail(detStr);
        });
        var colPredictor = Math.round(corpPanelW / spaceH)
        leftOfPage = (corpPanelW - (spaceH * colPredictor)) / 3;
        $(this).animate({ left: ((col * spaceH) + leftOfPage), width: '160px', height: '80px', top: ((row * spaceV) + topOfPage) }, 500, "swing");
        col++;
        var willBeWidth = spaceH + ((col * spaceH) + leftOfPage)
        if (willBeWidth > corpPanelW) {
            //if ((intIndex != 0) && (intIndex % colimit == 0)) {
            row++
            col = 0;
        }
    });
}

function listTopics() {
    //var spaceV = 90;
    var spaceV = 45;
    var row = 0;
    var topOfPage = 50;
    var leftOfPage = 0;
    var corpPanelW = $('div.corp_panel').width();
    $('div.qButtonSel').each(function (intIndex) {
        $(this).animate({ left: leftOfPage, width: '100px', height: '40px', top: ((row * spaceV) + topOfPage) }, 500, "swing", function(){
            $(this).removeClass('qButtonSel');
            $(this).addClass('sqButtonSel');
        });
        $(this).unbind("click");
        $(this).click(function () {
            $(this).removeClass('sqButton');
            $(this).addClass('sqButtonSel');
            var detStr = $(this).attr('id');
            detStr += "_detail";
            showDetail(detStr);
        });
        row++;
    });
    $('div.qButton').each(function (intIndex) {
        var corpPanelW = $('div.corp_panel').width();
        $(this).animate({ left: leftOfPage, width: '100px', height: '40px', top: ((row * spaceV) + topOfPage) }, 500, "swing", function(){
            $(this).removeClass('qButton');
            $(this).addClass('sqButton');
        });
        $(this).unbind("click");
        $(this).click(function () {
            $(this).removeClass('sqButton');
            $(this).addClass('sqButtonSel');
            var detStr = $(this).attr('id');
            detStr += "_detail";
            showDetail(detStr);
        });
        row++;
    });
    $('div.qButtonSel a').each(function () {
        $(this).animate({ fontSize: '11pt' }, 500, "swing")
        if ($(this).height() > 40) {
            $(this).css("line-height", ".9em");
        } else {
            $(this).css("line-height", "normal");
        }
        $(this).css("margin-top", -($(this).height() / 3));
        $(this).css("margin-left", "5px");
    });
    $('div.qButton a').each(function () {
        $(this).animate({ fontSize: '11pt' }, 500, "swing")
        if ($(this).height() > 40) {
            $(this).css("line-height", ".9em");
        } else {
            $(this).css("line-height", "normal");
        }
        $(this).css("margin-top", -($(this).height() / 3));
        $(this).css("margin-left", "5px");
    });
}


function showDetail(which) {
    //alert(which)
    //for audio narration
    if (which == 'proc_detail') {
        curStep = 0;
        //showStep(0);
        showStep(0);
        //doStart();
    } 
    
    var corpPanelW = $('div.corp_panel').width();
    if ((curDetail != null) && (curDetail != "")) {
        var topicStr = curDetail.substring(0, curDetail.indexOf("_"));
        $('#' + topicStr).removeClass("sqButtonSel");
        $('#' + topicStr).addClass("sqButton");
        $('#' + which).addClass("selecteds");
        if (which == curDetail) {
            $('#' + curDetail).animate({ left: corpPanelW }, 200, "swing");
            $('#' + curDetail).removeClass("selecteds");
            curDetail = "";
            $('div.sqButton').each(function (intIndex) {
                $(this).removeClass('sqButton');
                $(this).addClass('qButton');
            });
            $('div.sqButtonSel').each(function (intIndex) {
                $(this).removeClass('sqButtonSel');
                $(this).addClass('qButton');
            });

            $('div.qButton a').each(function () {
                $(this).animate({ fontSize: '18pt', marginLeft:'20px' }, 200, "swing", function () {
                    if ($(this).height() > 45) {
                        $(this).css("line-height", ".9em");
                    } else {
                        $(this).css("line-height", "normal");
                    }
                    $(this).css("margin-top", -($(this).height() / 2));
                });
            });
            $('div.qButtonSel a').each(function () {
                $(this).animate({ fontSize: '18pt', marginLeft:'20px' }, 200, "swing", function () {
                    if ($(this).height() > 45) {
                        $(this).css("line-height", ".9em");
                    } else {
                        $(this).css("line-height", "normal");
                    }
                    $(this).css("margin-top", -($(this).height() / 2));
                });
            });

            setupTopics();
        } else {
            $('#' + curDetail).css("left", corpPanelW);
            $('#' + curDetail).removeClass("selecteds");
            $('#' + which).css("left", 140);
            $('#' + which).addClass("selecteds")
            curDetail = which;

            //remove the zoom transition
            /*
            $('#' + curDetail).animate({ left: corpPanelW }, 200, "swing", function () {
                $('#' + which).animate({ left: 140 }, 400, "swing");
                curDetail = which;
            });
            */
        }
    } else {
        listTopics();
        $('#' + which).addClass("selecteds")
        $('#' + which).animate({ left: 140 }, 400, "swing");
        curDetail = which;
    }
}

function showAnim(which,last) {
    //alert("on:" + which);
    var myPanel = "#ad";
    myPanel += which;
    var prevPanel = "#ad";
    prevPanel += last;

    $(prevPanel).fadeOut(400, function () { $(prevPanel).css("left", "150%");});

    var nextWhich = which + 1;
    if (which == 2) {
        nextWhich = 1;
    }
    if ($(myPanel).not(':visible')) {
        $(myPanel).toggle();
    }
    $(myPanel).animate({ left: 64 }, 800, "swing", function () {
        setTimeout("showAnim(" + nextWhich + ","+which+")", 8000);
    });

}

function randomXToY(minVal, maxVal, floatVal) {
    var randVal = minVal + (Math.random() * (maxVal - minVal));
    return typeof floatVal == 'undefined' ? Math.round(randVal) : randVal.toFixed(floatVal);
}

function toggleBill() {
    $('#bill_feed').slideToggle(200, function () {
        if ($('#bill_feed').is(':visible')) {
            $('#fedLegPeek').html("Hide Federal Legislation Status");
        } else {
            $('#fedLegPeek').html("Peek at Federal Legislation Status");
        }
    });
}
