$(document).ready(function() {

    $("#LogoRotator_div img:first").addClass("active");

    /*if ($("body").attr("class") != "form step_1") {
    $("#form1").fadeIn(500);
    }*/

    //"obeforeunload" Functions

    window.onbeforeunload = function() {
        var getTsource = querySt("tsource");
        if (getTsource == "ggdrtv" || getTsource == "ggdrtv2" || getTsource == "msndrtv" || getTsource == "ovdrtv") {
            return;
        }
        else {
            return '-------------------------------------------------------------------------------------------------------------------------------------------------------------- \n\nIf you leave now, we won\'t be able to help you go back to school and change your life.\n\nAlso, if you stay with us, you\'ll soon have access to our free career and salary report and also be able to apply for the $4,000 Next Step scholarship that you can use towards your online education!\n\n--------------------------------------------------------------------------------------------------------------------------------------------------------------';
        }
    }

    $('#treeview img').parent('a').removeAttr("href");

    $('#treeview img').parent('a').click(function() {
        $(this).parent().parent().parent().parent().next("div").addClass("treeview-div").slideToggle(400);
    });

    $("a").not($('#treeview img').parent('a')).not($('#moreTxt')).click(function() {
        window.onbeforeunload = null;
    });

    $(".step_4 select[onchange]").not($("#dropDownHolder select[onchange]")).change(function() {
        window.onbeforeunload = null;
    });

    $("form").submit(function() {
        window.onbeforeunload = null;
    });

    $("#ctl04_bpau_rblMilitary input").click(function() {
        window.onbeforeunload = null;
    });

    //End "obeforeunload" Functions

    //Adding Close Button to val sumary for regpth and removing inline styles

    $("blockquote input").val("Request More Info.");

    var regpathvalidationid = "#ctl04_frmCtl_ctl53_errSummary"
    $(regpathvalidationid).removeAttr("style");

    var errorsumorigval = $(regpathvalidationid).html();

    if ($(errorsumorigval + "ul").length) {
        $(regpathvalidationid).html("<img src='http://www.elearners.com/drtv/images/close_button.gif' alt='Close' class='close_button'/>" + errorsumorigval);
        $(regpathvalidationid).fadeIn(200);
    }

    $(regpathvalidationid).click(function() {
        $(this).fadeOut(500);
    });

    //End Adding Close Button to val sumary for regpth and removing inline styles



    //Read More Text for Regpath
    function querySt(ji) {
        hu = window.location.search.substring(1);
        gy = hu.split("&");
        for (i = 0; i < gy.length; i++) {
            ft = gy[i].split("=");
            if (ft[0] == ji) {
                return ft[1];
            }
        }
    }

    var getDegId = querySt("degId");

    $("#moreTxt").removeAttr("href").before("<div style=\"display:none;\" class=\"clearfix\" id=\"readMoreDiv\"><img src='http://www.elearners.com/drtv/images/close_button.gif' alt='Close' class='readmore_close_button'/><div id=\"readMoreDivInner\">Loading...</div></div>");

    $("#readMoreDivInner").load("../../regpath/degdesc.aspx?bp=DRTV&degId=" + getDegId);

    $("#moreTxt").click(function() {
        $("#readMoreDiv").slideToggle("slow");
        $(this).text($(this).text() == "(more)" ? "(Hide)" : "(more)");
    });

    $(".readmore_close_button").click(function() {
        $("#readMoreDiv").slideUp("slow");
        $("#moreTxt").text("(more)");
    });

    //End Read More Text for Regpath

    //Tabs
    $('.step_1 #tabs #tabs-menu li:first').addClass("active");
    $('#tabs #tabs-menu li a').click(function() {
        $('#tabs #tabs-menu li').removeClass('active');
        $(this).parent().addClass('active');
        var currentTab = $(this).attr('href');
        $('#tabs .tabs-containers').hide();
        $(currentTab).fadeIn(500);
        return false;
    });

});

//SlideShow for Step 1

function slideSwitch() {
	var $active = $('.step_1 #LogoRotator_div img.active');
	
	if ( $active.length == 0 ) $active = $('.step_1 #LogoRotator_div img:last');

	var $next =  $active.next().length ? $active.next()
		: $('.step_1 #LogoRotator_div img:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}

$(function() {
	setInterval( "slideSwitch()", 3000 );
});

//End ofSlideShow for Step 1
