/**
 * Image src URLs
 **/
var imageList = [

"",

"http://www.excite-enterprises.com/images/uploads/vfw7383-main-screen.jpg",

"http://www.excite-enterprises.com/images/uploads/doodlestix-main-screen.jpg"
                 ];
var urlList = [

"javascript:ajaxpage('http://www.excite-enterprises.com/embeds/carousel_interior/custom-paintball-solutions/', 'rightcolumn');loadobjs('http://www.excite-enterprises.com/scripts/carousel/carousel_int_real.css')",

"javascript:ajaxpage('http://www.excite-enterprises.com/embeds/carousel_interior/vfw-post-7383/', 'rightcolumn');loadobjs('http://www.excite-enterprises.com/scripts/carousel/carousel_int_real.css')",

"javascript:ajaxpage('http://www.excite-enterprises.com/embeds/carousel_interior/doodlestix/', 'rightcolumn');loadobjs('http://www.excite-enterprises.com/scripts/carousel/carousel_int_real.css')"                
                 ];
				 
var titleName = [

"Custom Paintball Solutions",

"VFW Post 7383",

"Doodlestix, Inc."                
                 ];
				 

var lastRan = -1;

/**
 * Since carousel.addItem uses an HTML string to create the interface
 * for each carousel item, this method formats the HTML for an LI.
 **/

 /*
 
 imageLIst is for the actual image url, urlList is where its going, title is what goes underNeath
fmtItem(imageList[i], urlList[i], "Number " + i)

javascript:ajaxpage('ajaxfiles/external.htm', 'rightcolumn')
*/

var fmtItem = function(imgUrl, url, title) {

      var innerHTML = 
          '<a href="' + url + ';"><img src="' + imgUrl + '" width="' + 75 + '" height="' + 75+ '"/>' + title + '<\/a>';
  
    return innerHTML;
    
};

/**
 * Custom inital load handler. Called when the carousel loads the initial
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadInitHandler
 **/
var loadInitialItems = function(type, args) {
    var start = args[0];
    var last = args[1]; 
    load(this, start, last);    

};

/**
 * Custom load next handler. Called when the carousel loads the next
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadNextHandler
 **/
var loadNextItems = function(type, args) {    

    var start = args[0];
    var last = args[1]; 
    var alreadyCached = args[2];
    
    if(!alreadyCached) {
        load(this, start, last);
    }
};

/**
 * Custom load previous handler. Called when the carousel loads the previous
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadPrevHandler
 **/
var loadPrevItems = function(type, args) {
    var start = args[0];
    var last = args[1]; 
    var alreadyCached = args[2];
    
    if(!alreadyCached) {
        load(this, start, last);
    }
};

var load = function(carousel, start, last) {
    for(var i=start;i<=last;i++) {
        var randomIndex = getRandom(18, lastRan);
        lastRan = randomIndex;
        carousel.addItem(i, fmtItem(imageList[i-1], urlList[i-1], titleName[i-1]));
/*
        // Example of an alternate way to add an item (passing an element instead of html string)
        var p = document.createElement("P");
        var t = document.createTextNode("Item"+i);
        p.appendChild(t);
        carousel.addItem(i, p );
*/
    }
};

var getRandom = function(max, last) {
    var randomIndex;
    do {
        randomIndex = Math.floor(Math.random()*max);
    } while(randomIndex == last);
    
    return randomIndex;
};

/**
 * 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.excite-enterprises.com/scripts/carousel/images/left-enabled.gif";    
    } else {
        leftImage.src = "http://www.excite-enterprises.com/scripts/carousel/images/left-disabled.gif";
    }
    
};

/**
 * You must create the carousel after the page is loaded since it is
 * dependent on an HTML element (in this case 'dhtml-carousel'.) See the
 * HTML code below.
 **/

var carousel; // for ease of debugging; globals generally not a good idea
var pageLoad = function() 
{
    carousel = new YAHOO.extension.Carousel("dhtml-carousel", 

        {
            numVisible:        8,
			size:              imageList.length,
            animationSpeed:    0.25,
            scrollInc:         3,
            navMargin:         40,
            prevElement:       "prev-arrow",
            nextElement:       "next-arrow",
            loadInitHandler:   loadInitialItems,
            loadNextHandler:   loadNextItems,
            loadPrevHandler:   loadPrevItems,
            prevButtonStateHandler:   handlePrevButtonState
        }
    );
};

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

/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}
