/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the previous button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: prevButtonStateHandler
 **/

var handlePrevButtonState = function(type, args) {

    var enabling = args[0];
    var leftImage = args[1];
    if(enabling) {
        leftImage.src = "http://www.kansas.gov/img/icons/arrow_left.jpg";    
    } else {
        leftImage.src = "http://www.kansas.gov/img/icons/arrow_left_dis.jpg";    
    }
    
};


/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the next button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: nextButtonStateHandler
 **/
 
var handleNextButtonState = function(type, args) {

    var enabling = args[0];
    var rightImage = args[1];
    
    if(enabling) {
        rightImage.src = "http://www.kansas.gov/img/icons/arrow_right.jpg";
    } else {
        rightImage.src = "http://www.kansas.gov/img/icons/arrow_right_dis.jpg";
    }
    
};


/**
 * You must create the carousel after the page is loaded since it is
 * dependent on an HTML element (in this case 'mycarousel'.) See the
 * HTML code below.
 **/
/*var carousel;*/ // for ease of debugging; globals generally not a good idea
var pageLoad = function() 
{
	makeRequest();
	
	carousel = new YAHOO.extension.Carousel("mycarousel", 
		{
			numVisible:        6,
			animationSpeed:    0.75,
			scrollInc:         6,
			navMargin:         20,
			prevElement:     "prev-arrow",
			nextElement:     "next-arrow",
			size:              18,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);
	
	
};


var handleSuccess = function(o){
	if (o.responseText !== undefined) {
		if (o.responseText != "<!-- no AMBER alert -->") {
			/*
			var theDiv = document.getElementById('amberAlert');
			theDiv.removeAttribute('class');
			theDiv.removeAttribute('className');
			theDiv.innerHTML = o.responseText;
			var theDiv = document.getElementById('mycarousel');
			theDiv.removeAttribute('style');
			*/
			var theDiv = document.getElementById('mycarousel');
			theDiv.innerHTML = o.responseText;
			document.getElementById('mycarousel').style.width = "950px";
		}
	}
}
var handleFailure = function(o){
	if(o.responseText !== undefined){
		//alert('failure');
	}
}

var callback =
{
  success:handleSuccess,
  failure:handleFailure
};

var sUrl = "/layout/ksamber/alert_ssi.html";

function makeRequest(){
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
}

YAHOO.util.Event.addListener(window, 'load', pageLoad);

