

//holder arrays
var nodeLeftProperty;
var textArray = [];
var buttonArray = [];
var imageIDArray = [];
var soundIDArray = [];
var imageArray = [];
var soundArray = [];
var buttonXArray= [];
var picAlignArray=[];
keys = new Array();
description = new Array();

	
	
	
var color;
var face;
var style;
var size;
var align;
var contentStyles = new Object();
var buttonStyles = new Object();
var letterStyles = new Object();
var headerStyles = new Object();
var instStyles = new Object();
var generalStyles = new Object();
var cluesStyles = new Object();
var lettersArray = new Array();
var answersArray = new Array();
var width
var height

wordsearchUse1 = {
	onLoad: function()
	{
		if ( ! this.captivate )
			return;
		var handle
				handle = this.captivate.CPMovieHandle;
		if(handle.isWidgetVisible() == true)
		{
		this.movieProps = this.captivate.CPMovieHandle.getMovieProps();
		if ( ! this.movieProps )
			return;
		this.varHandle = this.movieProps.variablesHandle;
		this.eventDisp = this.movieProps.eventDispatcher;
		this.xmlStr = this.captivate.CPMovieHandle.widgetParams();
		var size = this.OpenAjax.getSize();
		width = size.width;
		height = size.height;
		this.internalImage = '';
		this.externalImage = '';
		this.instructions = '';
		this.buttonLabel = '';
		this.buttonContent = '';
		this.soundName = '';
		this.title = '';
		this.directions = '';
		this.currentTheme
		this.updateData();
		this.doUpdate();                               
		/*if (this.captivate.CPMovieHandle.pauseMovie ) {
			setTimeout("parent.cp.movie.pause(parent.cp.ReasonForPause.INTERACTIVE_ITEM)",100);
		}*/
		}
	},

	updateData: function()
	{
		var id = 0;
		var initresult = jQuery.parseXML( this.xmlStr );
		var initresultDoc = jQuery( initresult );
		var thexml = initresultDoc.find( 'string' ).text();  
		
		var result = jQuery.parseXML( thexml );
		var resultDoc = jQuery( result );
		//alert(jQuery.isXMLDoc(resultDoc));
		var theButtons = resultDoc.find( 'buttons' ); 
		var theTextProps = resultDoc.find( 'textProperties' );
		var theContentProps = resultDoc.find( 'buttonContent' );
		var theButtonProps = resultDoc.find( 'labelText' );
		var theLettersProps = resultDoc.find( 'buttonLabel' );
		var theHeaderProps = resultDoc.find( 'headerTitle' );
		var theInstProps = resultDoc.find( 'headerInst' );
		var theCluesProps = resultDoc.find( 'answerClues' );
		currentTheme = parseInt(theTextProps.children('general').attr("themeNum"));
		
		//setup styles
		contentStyles.color = theContentProps.children('color').attr("textColor");
		contentStyles.face = theContentProps.children('font').attr("face");
		contentStyles.style = theContentProps.children('font').attr("style");
		contentStyles.size = theContentProps.children('font').attr("size");
		contentStyles.align = theContentProps.children('font').attr("align");
		
		var tempString = theContentProps.children('letters').text();
		lettersArray = tempString.split(",");
		tempString = theContentProps.children('answers').text();
		answersArray = tempString.split(",");

		buttonStyles.color = theButtonProps.children('color').attr("textColor");
		buttonStyles.textColorOver = theButtonProps.children('color').attr("textOver");
		buttonStyles.textColorDown = theButtonProps.children('color').attr("textDown");
		buttonStyles.face = theButtonProps.children('font').attr("face");
		buttonStyles.style = theButtonProps.children('font').attr("style");
		buttonStyles.size = theButtonProps.children('font').attr("size");
		buttonStyles.align = theButtonProps.children('font').attr("align");	
		
		letterStyles.textColor = theLettersProps.children('color').attr("textColor");
		letterStyles.textColorOver = theLettersProps.children('color').attr("textOver");
		letterStyles.textColorDown = theLettersProps.children('color').attr("textDown");
		letterStyles.face = theLettersProps.children('font').attr("face");
		letterStyles.style = theLettersProps.children('font').attr("style");
		letterStyles.size = theLettersProps.children('font').attr("size");
		letterStyles.align = theLettersProps.children('font').attr("align");	
		
		
		cluesStyles.titletxt = theCluesProps.children('txt').attr("titletxt");
		cluesStyles.bodytxt = theCluesProps.children('txt').attr("bodytxt");		
		
		headerStyles.color = theHeaderProps.children('color').attr("textColor");
		headerStyles.face = theHeaderProps.children('font').attr("face");
		headerStyles.style = theHeaderProps.children('font').attr("style");
		headerStyles.size = theHeaderProps.children('font').attr("size");
		headerStyles.align = theHeaderProps.children('font').attr("align");		
		
		instStyles.color = theInstProps.children('color').attr("textColor");
		instStyles.face = theInstProps.children('font').attr("face");
		instStyles.style = theInstProps.children('font').attr("style");
		instStyles.size = theInstProps.children('font').attr("size");
		instStyles.align = theInstProps.children('font').attr("align");				

		generalStyles.headerActive = theTextProps.children('general').attr("headerActive");
		generalStyles.headerColor = theTextProps.children('general').attr("headerColor");
		generalStyles.clueColor = theTextProps.children('general').attr("clueColor");
		generalStyles.contentHeaderColor = theTextProps.children('general').attr("contentHeaderColor");
		generalStyles.contentBodyColor = theTextProps.children('general').attr("contentBodyColor");
		generalStyles.bodyColor = theTextProps.children('general').attr("bodyColor");
		generalStyles.btnColorUp = theTextProps.children('general').attr("btnColorUp");
		generalStyles.btnColorOver = theTextProps.children('general').attr("btnColorOver");
		generalStyles.btnColorDown = theTextProps.children('general').attr("btnColorDown");
		maxAttempts = theTextProps.children('general').attr("attempts");
		
		

		//headerActive, arrowColor, headerColor, contentBodyColor, bodyColor, btnColorUp, btnColorDown, btnColorOver, 
		//loop through each button node
		theButtons.children('button').each(function(index) {
			if (jQuery( this ).children('text').text() != "") {
				textArray.push( cleanIt(jQuery( this ).children('text').text().toUpperCase()));	
				buttonArray.push(cleanIt(jQuery( this ).children('buttonContent').text()))//.toUpperCase());	
				imageIDArray.push(jQuery( this ).children('image').attr("id"));	//grab image id
				soundIDArray.push(jQuery( this ).children('sound').attr("id"));	//grab sound id		
				buttonXArray.push(jQuery( this ).children('buttonLocX').text());	
				picAlignArray.push(jQuery( this ).children('image').attr("picAlign"));	
			}
		});
		
		wordsArray=textArray//["FIRST", "WORD"];
		questionsArray=buttonArray//["Before second", "Letters go together to form a..."];


		//access other items on the stage
		this.title = resultDoc.find( 'general' ).attr("titleText");
		this.instructions = resultDoc.find( 'general' ).attr("instructionsText");
		
		
		///access audio and images
		
		for (num=0; num < imageIDArray.length; num++) {
			//first check images
			id = parseInt( imageIDArray[num] );	
			if (id != -1) { 
				imageArray[num] = this.movieProps.ExternalResourceLoader.getResourcePath( id )
				imageArray[num] = imageArray[num].replace("index.html", "");
			} else {
				imageArray[num] = -1;
			}
			//then check sound
			id = parseInt( soundIDArray[num] );	
			if (id != -1) { 
				soundArray[num] = this.movieProps.ExternalResourceLoader.getResourcePath( id )
		   		soundArray[num] = soundArray[num].replace("index.html", "");
			} else {
				soundArray[num] = -1;
			}
			
		}
	},
	
	doUpdate: function() 
	{
		//init the default html values
		//var divHtmlHeader = "<div class='header'><a>aaaa this button to see the response in the drop down box.</a></div>";
		//var divHtmlContent = "<div class='content'>aaaa job! That was easy, wasn't it?</div>";
		
		var tabHtmlHeader = "<li style='width: percent;'><a href='#placeholder'>Button Label JQuery</a></li>";
		var tabHtmlContent = "<div id='placeholder' class='tab_content' style='display: block;'><p>Testing JQuery</p></div>";



		//init the other elements on the page		
		var elem = document.getElementById('intTitle');
		elem.innerHTML = this.title;
		elem = document.getElementById('intInstructions');
		elem.innerHTML = this.instructions;
				
				
				
		var button_elem;
		var body;
		var tabCount = textArray.length;
		var header
		//600, 14, 4
		var tabWidthPercentage
		if (tabCount == 2) {
			tabWidthPercentage = 560 / tabCount;
		} else if (tabCount == 3) {
			tabWidthPercentage = 530 / tabCount;
		} else if (tabCount == 4) {
			tabWidthPercentage = 510 / tabCount;
		}
		if (currentTheme == 3) { tabWidthPercentage = 100 } 
		//(1 / tabCount * 100) - 2;
		if (currentTheme == 2) { tabWidthPercentage -= 5 } 
		
		//	for (var i = 0; i < nodeCount; i++) {
		//$("#Timeline_Container").append("<div id='" + i + "' class='timelineNode' style='left: " + nodeLeftProperty[i] + "'>" + timelineLabel[i] + "</div>");
	
	//tabs_container
	//--> .timlineNode or id 1
	//--> id=tab1, .tab_content
	
	var leftPos;
		//alert(tabWidthPercentage);
		jQuery.each(textArray, function(index, value) {
			button_elem = document.getElementById('canvasWordList');
		  	button_elem.innerHTML += "<div class='clues' id='" + index + "'>" + buttonArray[index] + "</div>";			
		});	
		
		button_elem = document.getElementById('endGameScreen');
		button_elem.innerHTML = "<p style='font-family:Arial'>" + cluesStyles.titletxt + "</p>"
		button_elem.innerHTML += "<p style='font-family:Arial'>" + cluesStyles.bodytxt + "</p>"
		
		
		
		changeTheme("themes/wordsearchTheme" + currentTheme + ".css", "themes/headerTheme" + currentTheme + ".css" );
		setupCustomStyles();
		setupStyle("#intTitle", headerStyles)
		setupStyle("#intInstructions", instStyles)
		setupStyle(".clues", contentStyles)
		//setupStyle("#Search_Result_Container", contentStyles)
		//setupStyle("#Search_Result_Container", letterStyles)
		
		//setupStyle(".tab_content", contentStyles)
		
		//getKeys();
    	//populateGlossary();
		resizeInteraction(width,height);
		addClickHandlers(); //setup the click handlers
		setup();
	}
};

wordsearch_use = function ()
{
	return wordsearchUse1;
}

