﻿
/*
****************************************************************************
    Slide Show
****************************************************************************
*/
var intervalId;
var activeId = 0;
var jumpId = 0;
var description = new Array();
var numberOfSlides = 0;

$(function() {
    description[0] = ""; //not used
	populateSlides();
    startSlide();	
    
	$('#navPanel a').live('click', function() {
	    // Live handler called.
		stopSlide();				
		//jumpId = $(this).attr("href");
		jumpId = $(this).attr("id");
		jumpId = jumpId.replace("nav","");
		slideSwitch();
		startSlide();
		return false;
	});		
	
    $('#slideshow').live('mouseover', function(){
            stopSlide();
    });
    $('#slideshow').live('mouseout', function(){
            startSlide();
    });	
	
});

function stopSlide() {
	//alert(intervalId);
	clearInterval(intervalId);
	return false;
}

function startSlide() {
	intervalId = setInterval( "slideSwitch()", 5000 );	
	//alert(intervalId);
	return false;
}

function slideSwitch() {
	var $active = $('#slide'+activeId);	
    
	$('#nav'+activeId).removeClass('navigationActive');

	if(jumpId > 0) {
		activeId = jumpId;
		jumpId = 0;		
	}else{
		if(activeId == numberOfSlides)
			activeId = 1;
		else
			activeId++;
	}

	$('#slideshowDescription').html(description[activeId]);
    $active.addClass('last-active');

	var $next = $('#slide'+activeId);
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 3000, function() {
            $active.removeClass('active last-active');
        });	
	$('#nav'+activeId).addClass('navigationActive');
}

function populateSlides() {    
	$.ajax({
		type: "GET",
		url: "Scripts/SlideShow.xml",
		dataType: "xml",
		success: parseXml,
		error: function(xhr) {
		    //alert('Error: ' + xhr.status + ' | ' + xhr.statusText);
		}
	});
}

function parseXml(xml)
{    
	var output = "";
	var imageActiveClass = "active";
	var navActiveClass = "navigationActive";
	var imageDescription = "";
	var centerStart = "<span style='text-align:center;'>";
	var centerEnd = "</span>";

	//http://www.javascriptkit.com/javatutors/navigator.shtml
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
	    centerStart = "<center>";
	    centerEnd = "</center>";
	}	
	
	//find every the slide node
	$(xml).find("slide").each(function() {
	    activeId++;
	    //$(this).attr("attribute")
	    $('#slideshow').append("<img src='" + $(this).find("imageLocation").text() + "' alt='" + imageDescription + "' id='slide" + activeId + "' class='" + imageActiveClass + "' width='600'/>");
	    $("<li>" + centerStart + "<a href='" + activeId + "' id='nav" + activeId + "' class='" + navActiveClass + "'>" + activeId + "</a>"+centerEnd+"</li>").appendTo('ul#navPanel');
	    description[activeId] = $(this).find("imageDescription").text();
	    imageActiveClass = "";
	    navActiveClass = "";
	});
	numberOfSlides = activeId;
	activeId = 1;	
	$('#slideshowDescription').html(description[activeId]);
}

/*
****************************************************************************
    Commom Functions  
****************************************************************************
*/
function SetTextBoxValue(id, val) { $("#" + id).attr('value', ''); }
function ShowObject(id) { $("#" + id).show("slow"); }
function HideObject(id) { $("#" + id).hide("slow"); }
function EnableObject(id) { $("#" + id).removeAttr("disabled"); }
function DisableObject(id) { $("#" + id).attr("disabled", "disabled"); }
function ResetDropDownList(id) { $("#" + id).attr("selectedIndex", 0); }
function ToggleVisibility(id, val) {
    if (val)
        ShowObject(id);
    else
        HideObject(id);
}
function PrintArea(id) {
    $('#' + id).jqprint({
        operaSupport: true,
        importCSS: true,
        title: 'PDS',
        printContainer: false
    });
    return false;
}

function ModalDialogWithRemoteContent(containerID, mdTitle, mdUrl, mdWidth, mdHeight) {
    $('#' + containerID).empty().html('<p>Please wait...</p>');

    $.ajax({
        url: mdUrl,
        cache: false,
        success: function(html) {
            $('#' + containerID).html(html);
        }
    });


    var horizontalPadding = 30;
    var verticalPadding = 30;
    $('#' + containerID).dialog({
        title: mdTitle,
        autoOpen: true,
        width: mdWidth,
        height: mdHeight,
        modal: true,
        resizable: false,
        autoResize: true,
        draggable: false,
        /*
        open: function(type, data) {
        $(this).parent().appendTo("form");
        },
        */
        close: function(event, ui) {
            //alert("Closing");            
            $('#RemoteContent').empty();
        },
        buttons: {
            'Print': function() {
                //$(this).dialog('close');
                PrintArea(containerID);
            }
            /*
            ,
            Cancel: function() {
            $(this).dialog('close');
            }
            */
        },
        overlay: {
            opacity: 0.5,
            background: "black"
        }
        //})
    });
    //}).width(550 - horizontalPadding).height(500 - verticalPadding);
}
/*
****************************************************************************
    Internship Application
****************************************************************************
*/
function ToggleObjectFromCheckbox(checkboxID, objectID) {
    if (document.getElementById(checkboxID).checked) {
        EnableObject(objectID);
    } else {
        DisableObject(objectID);
    }
}

function ToggleCertification(id, btnID) {
    if (document.getElementById(id).checked) {        
        EnableObject(btnID);
    } else {    
        DisableObject(btnID);
    }
}

function ToggleHowDidYouHearRadionButton(id, txtOtherID, txtPersonListID) {
    var radionButtonList = document.getElementById(id);
    try {
        var inputElementArray = radionButtonList.getElementsByTagName('input');
        var divTxtOther = 'divTxtOther';
        var divPersonList = 'divPersonList';
        var found = false;
        var objectFound = '';

        for (var i = 0; i < inputElementArray.length; i++) {
            var inputElement = inputElementArray[i];
            if (inputElement.checked) {
                switch (inputElement.value) {
                    case 'Other':
                        ShowObject(divTxtOther);
                        SetTextBoxValue(txtOtherID, '');
                        HideObject(divPersonList);
                        break;
                    case 'Friend': case 'Professor':
                        if (!$('#' + divPersonList).is(":visible")) {
                            SetTextBoxValue(txtPersonListID, '');
                        }

                        ShowObject(divPersonList);
                        HideObject(divTxtOther);
                        break;
                    default:
                        HideObject(divTxtOther);
                        HideObject(divPersonList);

                        SetTextBoxValue(txtPersonListID, '');
                        SetTextBoxValue(txtOtherID, '');
                }
            }
        }      
    } catch (Err) {
        //alert(Err.description);
    }
}

function ValidateFileUpload(Source, args) {
    var fuData = document.getElementById('<%= fu.FileUploadClientID %>'); 
}

/*
****************************************************************************
    Office of Rehabilitation & Development 
****************************************************************************
*/
$(function() {
    $("a").each(function() {
        var _title = $(this).attr("href");
        var _id = $(this).attr("id");
        if (_title == "/PDS/OffenderRehabilitationDivision.aspx" && _id == "ctl00_tvLeftMenusn13") {
            $(this).append("</a><div style='color:#000000;width:200px;text-decoration:none;'>(formerly, Offender Rehabilitation)</div>");
        } 
    });
});


/*
****************************************************************************
Test
****************************************************************************
*/



