var SponsorImages = new Array(4);
var sponsorLinks;

function loadXMLXSLDoc(fileName)
{
	if (window.XMLHttpRequest)
	{
		xhttp=new XMLHttpRequest();
	}
	else
	{
		xhttp=new ActiveXObject("Microsoft.XMLHTTP");
        //var xslt = new ActiveXObject("Msxml2.XSLTemplate.3.0"); 
        //var xsldoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0"); 
	}
	xhttp.open("GET", fileName, false);
	xhttp.send(""); 
	return xhttp.responseXML;
}

var DropDownMenuSpeed = 15;
var DropDownTimer = 10;

function DropDownMenu(id, itemsD)
{
	var items = document.getElementById('DropDownItems' + id);
	var header = document.getElementById('DropDownHeader' + id);
	clearInterval(items.timer);
	if(itemsD == 1)
	{
		clearTimeout(header.timer);
		if (items.maxh && items.maxh <= items.offsetHeight)
			return;
		else if(!items.maxh)
		{
			items.style.display = 'block';
			items.style.height = 'auto';
			items.maxh = items.offsetHeight;
			items.style.height = '0px';
		}
		items.timer = setInterval(function(){ ExpandMenu(items, 1) }, DropDownTimer);
  	}
	else
	{
    	header.timer = setTimeout(function(){ RetractMenu(items) }, 50);
	}
}

function RetractMenu(items)
{
	items.timer = setInterval(function(){ExpandMenu(items, -1)}, DropDownTimer);
}

function CancelMenu(id)
{
	var header = document.getElementById('DropDownHeader' + id);
	var items = document.getElementById('DropDownItems' + id);
	clearTimeout(header.timer);
	clearInterval(items.timer);
	if(items.offsetHeight < items.maxh)
	{
		items.timer = setInterval(function(){ExpandMenu(items, 1)}, DropDownTimer);
	}
}

function ExpandMenu(items, itemsD)
{
	var currh = items.offsetHeight;
	var dist;
	if(itemsD == 1)
	{
    	dist = (Math.round((items.maxh - currh) / DropDownMenuSpeed));
	}
	else
	{
    	dist = (Math.round(currh / DropDownMenuSpeed));
	}

	if(dist <= 1 && itemsD == 1)
	{
    	dist = 1;
	}

	items.style.height = currh + (dist * itemsD) + 'px';
	items.style.opacity = currh / items.maxh;
	items.style.filter = 'alpha(opacity=' + (currh * 100 / items.maxh) + ')';
  	if((currh < 2 && itemsD != 1) || (currh > (items.maxh - 2) && itemsD == 1))
  	{
    	clearInterval(items.timer);
	}
}

function GoHome()
{
	window.location="index.html";
}

function OpenFile(fileName)
{
	ContentFrame.window.location=fileName;
}

function getBannerImage()
{
//	var randomnumber=Math.ceil(Math.random()*4);

//	document.getElementById("BannerImage").src = "images/" +  randomnumber + ".png";
}


function ShowPreviousImage()
{
	if(currentImageId == 0)
	{
		currentImageId = eventImages.length - 1;
		document.getElementById("ShowImage").src= eventImages[currentImageId].src;
	}
	else
	{
		currentImageId--;
		document.getElementById("ShowImage").src= eventImages[currentImageId].src;
	}
}

function ShowNextImage()
{
	if(currentImageId == eventImages.length - 1)
	{
		currentImageId = 0;
		document.getElementById("ShowImage").src= eventImages[currentImageId].src;
	}
	else
	{
		currentImageId++;
		document.getElementById("ShowImage").src= eventImages[currentImageId].src;
	}
}

function getRandomNo()
{
	rand_no = Math.floor(Math.random() * 4);
	return rand_no;
}

function getSponsorLink()
{
	var sponsorsText="";
	sponsorsText += " <div id='silverlightControlHost' align='center' style='margin-top: 60px;'>";
    sponsorsText += "<object data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='600' height='85'>";
	sponsorsText += "<param name='source' value='AAWBCSponsors.xap'/>";
	sponsorsText += "<param name='onError' value='onSilverlightError' />";
	sponsorsText += "<param name='background' value='white' />";
	sponsorsText += "<param name='autoUpgrade' value='true' />";
	sponsorsText += "<a href='http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0' style='text-decoration:none'>";
 	sponsorsText += "<img src='http://go.microsoft.com/fwlink/?LinkId=108181' alt='Get Microsoft Silverlight' style='border-style:none'/>";
	sponsorsText += "</a>";
	sponsorsText += "</object><iframe id='_sl_historyFrame' style='visibility:hidden;height:0px;width:0px;border:0px'></iframe></div>";
	document.write(sponsorsText);
}


        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
              appSource = sender.getHost().Source;
            }
            
            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
              return;
            }

            var errMsg = "Unhandled Error in Silverlight Application " +  appSource + "\n" ;

            errMsg += "Code: "+ iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {           
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " +  args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }

