$(document).ready(function() {
    var isIE = jQuery.browser.msie;
    var isIE6 = (jQuery.browser.version < 7);
    // Colorbox
    $("[rel=refer]").colorbox({ rel: "nofollow", width: "700px", height: "530px", overlayClose: false, iframe: true });
    $("[rel=signup]").colorbox({ rel: "nofollow", width: "400px", height: "450px", overlayClose: false, iframe: true });
    $("[rel=questions]").colorbox({ rel: "nofollow", width: "700px", height: "620px", overlayClose: false, iframe: true });

    // Show Bio
    $(".biolink").click(
		function() {
		    var id = $(this).attr("id").substring(2);
		    $('#' + id).toggle();
		    if ($(this).text() == "View Biography") {
		        $(this).text("Close Biography");
		    } else {
		        $(this).text("View Biography");
		    }
		}
	);

    // Load Survey
    if (isIE) {
        $("[rel=survey]").click(function() {
            var url = $(this).attr('href');
            popUp(url, 880, 560);
            return false;
        });
    } else {
        $("[rel=survey]").colorbox({ rel: "nofollow", width: "890px", height: "80%", overlayClose: false, iframe: true });
    }

    // Popup Window
    function popUp(url, w, h) {
        var l = ($(window).width() / 2) - (w / 2);
        var t = ($(window).height() / 2) - (h / 2);
        var day = new Date();
        var id = day.getTime();
        eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + w + ",height=" + h + ",left = " + l + ",top = " + t + "');");
    }

    // Scroll To Application
    $(".application").click(
		function() {
		    $("html, body").animate({ scrollTop: $("#application").offset().top }, 800);
		}
	);
	
    // Show Hide
    $(".faq_body").hide();
    $(".faq_title").click(function() {
        $(this).parent().find(".faq_body").slideToggle("fast");
        $(this).toggleClass("faq_title_close");
        return false;
    });

    // Toggle Welcome
    $("#welcome,#welcome2").click(function() {
        $("#welcomecontent,#welcomecontent2").slideToggle("fast");
        $(".welcomebutton").toggleClass("welcomebuttonclose");
        return false;
    });

});

// Character Count
function limitChars(textid, limit, infodiv) {
    var text = $('#' + textid).val();
    var textlength = text.length;
    if (textlength > limit) {
        $('#' + textid).val(text.substr(0, limit));
        return false;
    }
    else {
        $('#' + infodiv).html('(' + (limit - textlength) + ' characters left)');
        return true;
    }
}

