var Quotation=new Array() // do not change this!

Quotation[0] = "wentworth.xml";

// ======================================
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation(){
	return Quotation[whichQuotation];
	}


function swfmc(movie,width,height)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"  width="');
		// Width for Object TAG
	document.write(width);
	document.write('" height="');
		// Height for Object TAG
	document.write(height);
	document.write('">\n');
		// File for Object TAG
	document.write('<param name="movie" value="');
	document.write(movie + showQuotation());
	document.write('">\n');
	
	// Params for Object TAG
	document.write('<param name="quality" value="high">\n');
	document.write('<param name="menu" value="false">\n');
	document.write('<PARAM NAME=wmode VALUE=transparent>\n');
	
		// File for EMBED TAG
	document.write('<embed src="');
	document.write(movie + showQuotation());
	document.write('" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" width="');
		// Width for EMBED TAG
	document.write(width);
	document.write('" height="');
		// Height for EMBED TAG
	document.write(height);
	
	// Params for Object TAG
	document.write('" menu="false"></embed>\n');
	document.write('</object>');
}




/* NON-IE FUNCTIONS */
/* FOR SAFARI */

var req;
var xmlDocument;
var imageShow = new Array();
var image1 = "";
var image2 = "";
var lastIndex = 0;

function jsImageShow() {
    document.write("<img id='flashImage1' name='flashImage1' src='' width='487px' height='179px' />");
    document.write("<img id='flashImage2' name='flashImage2' src='' width='487px' height='179px' />");
    
    startImageShow();
}

function startImageShow() {
    var xmlFile = "/library/multimedia/flash/" + showQuotation();
  
    req = new XMLHttpRequest();
    req.open('GET', xmlFile, true);
    req.onreadystatechange = loadImageShow;
    req.send(null); 
}

function loadImageShow() {
    if (req.readyState == 4) {
        if(req.status == 200) {
            xmlDocument = req.responseXML;
            var portfolio = xmlDocument.getElementsByTagName('portfolio')[0];
            var contentGroups = portfolio.getElementsByTagName('pContent');

            for( var i=0; i<contentGroups.length; i++ ) {
                imageShow[i] = contentGroups[i].getElementsByTagName('id')[0].childNodes[0].nodeValue;
                imageShow[i] += "::" + contentGroups[i].getElementsByTagName('id')[1].childNodes[0].nodeValue;
            }
            iniateImages();
        }
    }
}

function getImages() {
    var randIndex = lastIndex;
    while( randIndex == lastIndex ) {
        randIndex = Math.round(Math.random()*( imageShow.length - 1));
    }
    lastIndex = randIndex;
    return imageShow[ randIndex ];
}

function iniateImages() {
    document.images.flashImage1.style.opacity = 0;
    document.images.flashImage2.style.opacity = 0;
    displayImages();
    shiftOpacity( 'flashImage1', 1000 );
    shiftOpacity( 'flashImage2', 1000 );
    setTimeout( "updateImages()", 6000 );
}

function displayImages() {
    var images = getImages();
    image1 = images.split("::")[0];
    image2 = images.split("::")[1];
    document.images.flashImage1.src = image1;
    document.images.flashImage2.src = image2;
}

function alertAllImages() { /* for debugging purposes */
    for( var i=0; i<imageShow.length; i++) {
        alert( imageShow[i] );
    }
}

function updateImages() {
    shiftOpacity( 'flashImage1', 1000 );
    shiftOpacity( 'flashImage2', 1000 );
    setTimeout( "displayImages()", 1000 );
    setTimeout( "shiftOpacity( 'flashImage1', 1000 )", 1000 );
    setTimeout( "shiftOpacity( 'flashImage2', 1000 )", 1000 );

    setTimeout( "updateImages()", 7000 );
}


function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 