$(document).ready(function() {
 
  	$('.level-two-widget').click(function(){
		window.location = getDomain(window.location.href) + $(this).find('a').attr("href");
 	}); 
 
    $("#SecondSP").hide();
    $(".feature-panel-scroll-up").addClass("inactive-up");
    if ($(".feature-panel-navigation li").length < 6) {
        $(".feature-panel-scroll-down").addClass("inactive-down");
    }
	$(".feature-panel-navigation ul").removeClass("feature-panel-navigation");

    $(".feature-panel-scroll-down").click(function() {
        var liLength = $(".feature-panel-navigation li").length
        if (liLength < 6)
            return true;
        $(".feature-panel-scroll-down").addClass("inactive-down");
        $(".feature-panel-scroll-up").removeClass("inactive-up");
        var showFeatureId = $(".feature-panel-navigation li:eq(" + (liLength - 5) + ") a").attr("id");
        $('.showFeature').attr("class", "hideFeature");
        $('#' + showFeatureId + '_feature').attr("class", "showFeature");
        $("#SecondSP").show();
        $("#FirstSP").hide();
        return true;
    });

    $(".feature-panel-scroll-up").click(function() {
        if ($(".feature-panel-navigation li").length < 6)
            return true;
        $(".feature-panel-scroll-down").removeClass("inactive-down");
        $(".feature-panel-scroll-up").addClass("inactive-up");
        var showFeatureId = $(".feature-panel-navigation li:eq(0) a").attr("id");
        $('.showFeature').attr("class", "hideFeature");
        $('#' + showFeatureId + '_feature').attr("class", "showFeature");
        $("#SecondSP").hide();
        $("#FirstSP").show();
        return true;
    });
 
	var searchMsg = 'Enter a keyword or a search term';
	var textBoxId = "ctl00_ContentAll_SearchBox_S9C518FEC_InputKeywords";
	var searchButtonId = "ctl00_ContentAll_SearchBox_S9C518FEC_go";
	var searchTerms = $("#" + textBoxId).val();
	if (searchTerms == '')
	{
		$("#" + textBoxId).val(searchMsg);
	}
	
	// If the user clicks on the search box, i.e. to enter a 
	// search term, then remove the help text
	$("#" + textBoxId).click(function () { 
		var searchTerms = $("#" + textBoxId).val();
		if (searchTerms == searchMsg)
		{
			$("#" + textBoxId).val('');
		}
	});

	// If the user clicks on search when there is only the 
	// help text in search box then remove it before searching
	$("#" + searchButtonId).click(function () { 
		var searchTerms = $("#" + textBoxId).val();
		if (searchTerms == searchMsg)
		{
			$("#" + textBoxId).val('');
		}
	});


	$('#moreInfoLink').supersleight();

	// Swap out Get Adobe Reader html as it does not render correctly
	$("img[src='http://nsccmossauthor:90/SiteCollectionImages/get-adobe-reader.gif']").parent().parent().html("<a target='_blank' href='http://get.adobe.com/reader/' title='Get adobe Reader. '><img vspace='5' border='0' src='/SiteCollectionImages/get-adobe-reader.gif' alt='Get adobe Reader.' style='border: 0px solid ;'/></a>");

	$(".feature-panel-navigation a").hover(function() {
	    $('.showFeature').attr("class", "hideFeature");
	    $('#' + this.id + '_feature').attr("class", "showFeature");
	    /*$('.featureSelected').removeClass("featureSelected");
	    $('#' + this.id).addClass("featureSelected");*/
	});
	
    $(".feature-panel-navigation a").hover(function() {
    $(this).addClass("feature-panel-navigation-active");
    $(this).children("p").addClass("feature-link-info-active");
    }, function() {
    $(this).removeClass("feature-panel-navigation-active");
    $(this).children("p").removeClass("feature-link-info-active");
    });


		$(".dio-help").toggle(function() {
				$("#" + $(this).parent().parent().attr("id") + " span").slideDown("fast");
				}, function() {
				$("#" + $(this).parent().parent().attr("id") + " span").slideUp("fast");	
				});



                $(".all-other-services dd").hide();
                $(".all-other-services").addClass("closed");
                $(".dio-toggle-button").removeClass("close");
                $(".dio-toggle-button").addClass("open");

                // If not on homepage then leave it open
                if ($('.all-services').length) {

                                $("#dio-section0").removeClass("closed");
                                $('#dio-section0 dd').slideDown("normal");
                                $("#dio-section0 .dio-toggle-button").removeClass("open");  
                                $("#dio-section0 .dio-toggle-button").addClass("close");
                }

                $(".dio-toggle-button").click(function() {

 

                // Check if section is already open
            if ($(this).hasClass("close")) {

                 // If not on homepage then leave it open

                //if ($('.all-services').length) {

                // Do nothing                   

                //}

                //else {

                // If on homepage then close section

                $("#" + $(this).parent().parent().attr("id") + " dd").slideUp("normal");
                $("#" + $(this).parent().parent().attr("id")).addClass("closed");
                $(this).removeClass("close");
                $(this).addClass("open");

                //}

                }

                else {

                //if ($('.all-services').length)
                $(".all-other-services").addClass("closed");
                $(".dio-toggle-button").removeClass("close");
                $(".dio-toggle-button").addClass("open");
                $(".all-other-services dd:visible").slideUp("normal");

                $("#" + $(this).parent().parent().attr("id") + " dd").slideDown("normal").removeClass("closed");
                $("#" + $(this).parent().parent().attr("id")).removeClass("closed");
                $(this).removeClass("open");
                $(this).addClass("close");

                }

                return false;

                });
	
	$(".service-header").hover(
		function() {
			$(this).addClass("service-hover");
		},
		function() {
			$(this).removeClass("service-hover");
		}
	);

	$(".service-header").click(function() {	
		var aidIndex = $(this).attr("class").indexOf('aid');
		if (aidIndex > 0) {
			location.href = "/Services/OnlineServices/Pages/OnlineServices.aspx?aid=" + $(this).attr("class").substring(aidIndex + 3, aidIndex + 4);
		}
	});
	
    $(".feature-panel-navigation").jCarouselLite({
        btnNext: ".feature-panel-scroll-down",
        btnPrev: ".feature-panel-scroll-up",
        circular: false,
        vertical: true,
        scroll:5,
        visible:5,
        speed: 800
    });


 });
 

if (document.location.href.indexOf('PrintPreview') > 0) {
	window.setTimeout("print();",1500);
	var links = document.getElementsByTagName("LINK");
	for(var i=0;i<links.length;i++){
		if(links[i].title=="print"){
			links[i].rel="stylesheet";
			links[i].disabled=true;
			links[i].disabled=false;
		}
	}

	if(document.getElementById("print")){
		document.getElementById("print").onclick = function() {
			print();
		};
	}
}

function mailpage()
{
	mail_str = "mailto:?subject=Check out the " + document.title;
	mail_str += "&body=I thought you might be interested in the " + document.title;
	mail_str += ". You can view it at, " + location.href;
	location.href = mail_str;
}

//<!--
function PrintPreview() 
{
   var sURL=document.location.href;
	if (sURL.indexOf('?') >0) {
		sURL=document.location+"&PrintPreview";}
	else {
		sURL=document.location+"?PrintPreview";}
	window.open(sURL);
}
//  alert(document.getElementsByTagName("LINK")[0].media);
//-->
function redirectToParent()
{
	window.location = xtractFle_sans(window.location.href);
}

function xtractFle_sans(data) {

				var m = data.match(/(.*)([\/\\]\w+[\/\\])([Pp]ages[\/\\][^\/\\]+\.\w+)$/);
				
				if (m[1] != null && m[2] != null) {
				
				return m[1].toString() + m[2].toString(); ;
				}
				
				return "#";
}

function getDomain(data) {
				var m = data.match(/(http:\/\/[^\/\\]+)\/(.*)$/);
				if (m[1] != null) {
					return m[1].toString();
				}				
				return "";
}

function GetQueryStringFromUrlByParameterName( name )
{
				name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
				var regexS = "[\\?&]"+name+"=([^&#]*)";
				var regex = new RegExp( regexS );
				var results = regex.exec( window.location.href );
				if( results == null )
				return "";
				else
				return results[1];
}

function URLDecode(s) {
	var o=s;
	var binVal,t;
	var r=/(%[^%]{2})/;
  	while((m=r.exec(o))!=null && m.length>1 && m[1]!='') {
  		b=parseInt(m[1].substr(1),16);
  		t=String.fromCharCode(b);
 		o=o.replace(m[1],t);
  	}
  	return o;
}

function clickButton(e, buttonid) {
	var evt = e ? e : window.event;
	var bt = document.getElementById(buttonid);
	if (bt) {
		if (evt.keyCode == 13) {
			//it is "Enter" key
			bt.click();
			return false;
		}
	}
}

