//BASIC AJAX INIT
var tidin = new Array (); 
var tidout = new Array (); 
var timeout = 0;
var timein = 0;
var menu_in = "busy";
var tmptxt = "";

function myAIAS (location, handler ) {

	var httphandler = false;
	//initialize HTTP obj
    /*@cc_on @*/
   	/*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
   	// and security blocked creation of the objects.
    try {
   	 httphandler = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
   	  try {
      	httphandler = new ActiveXObject("Microsoft.XMLHTTP");
     	} catch (E) {
         httphandler = false;
     	}
   	}
   	@end @*/
   
   	if (!httphandler && typeof XMLHttpRequest!='undefined') {
       	httphandler = new XMLHttpRequest();
   	}
   	
   	httphandler.open('GET', location, true);
    httphandler.onreadystatechange= function () {
   		
   
   		if ( httphandler.readyState == 4 ) {
   			//alert ( "done loading" );
   			handler ( httphandler);
   		}
   	}
   	
	httphandler.setRequestHeader("Cache-Control", "no-cache");
	httphandler.send (null);

}

function setFlashTitle ( str ) {
	
	flashobject = window.document.flashtitle;
	flashobject.SetVariable ( "/:htext", str );
	flashobject.Play ();
}



function menuDataHandler (httphandler) {
	
	xml = httphandler.responseXML;
	//only one item will be returned 
	d = document;
	
	//d.getElementById("body").style.backgroundImage = "url(resize_bg.php?fn=uploads/"+xml.getElementsByTagName("topimg")[0].firstChild.nodeValue+")";
	
	if ( xml.getElementsByTagName("top_image")[0].firstChild.nodeValue.length  )
		d.getElementById("pica").firstChild.src="return_image.php?x=150&fn=uploads/"+xml.getElementsByTagName("top_image")[0].firstChild.nodeValue;
	else d.getElementById("pica").firstChild.src = "img/pix.gif";
	 	
	
	d.getElementById("content_body").innerHTML = "<div class=\"title\">" + xml.getElementsByTagName("txt_title")[0].firstChild.nodeValue + "</div>" + xml.getElementsByTagName("body")[0].firstChild.nodeValue;
	
	
	//d.getElementById("content_header").innerHTML = xml.getElementsByTagName("txt_title")[0].firstChild.nodeValue;


	setFlashTitle ( xml.getElementsByTagName("txt_title")[0].firstChild.nodeValue );
	
}

function artistListHandler (httphandler) {
	
	var xml = httphandler.responseXML;
	var d = document;
	var root = xml.getElementsByTagName ( "items" )[0];

	var htmlBuffer = "";
	
	items = root.getElementsByTagName ( "item" );
	for ( i = 0; i < items.length; i ++ ){
		
		//name, image, url, bio
		htmlBuffer += "<a href=\"#\" onclick=\"menuclick('a','"+items[i].getElementsByTagName ("artist_id")[0].firstChild.nodeValue+"');return false;\">"+items[i].getElementsByTagName ("name")[0].firstChild.nodeValue + "</a><br />\n";
	}

	d.getElementById( "content_body" ).innerHTML = htmlBuffer;
	setFlashTitle ( ".artists" );
}

function artistDataHandler ( httphandler ) {

		var xml = httphandler.responseXML;
		var d = document;
		var root = xml.getElementsByTagName ( "items" )[0];

		var htmlBuffer = "";
	
		items = root.getElementsByTagName ( "item" );

		if ( items[0].getElementsByTagName("image")[0].firstChild.nodeValue.length > 0 )
			d.getElementById("pica").firstChild.src="return_image.php?x=150&fn=uploads/"+items[0].getElementsByTagName("image")[0].firstChild.nodeValue;
		else d.getElementById("pica").firstChild.src="img/pix.gif";;
		
		d.getElementById("content_body").innerHTML = "<div class=\"title\">" + items[0].getElementsByTagName("name")[0].firstChild.nodeValue + "</div>" + items[0].getElementsByTagName("bio")[0].firstChild.nodeValue;
		
		//set flash title	
		setFlashTitle ( items[0].getElementsByTagName("name")[0].firstChild.nodeValue );
		
		if ( xml.getElementsByTagName("url")[0].firstChild.nodeValue.length )d.getElementById("content_body").innerHTML += "<div class=\"hspacer\">&nbsp;</div>Website: <a href=\""+xml.getElementsByTagName("url")[0].firstChild.nodeValue+"\">"+xml.getElementsByTagName("url")[0].firstChild.nodeValue+"</a>";
}


function newsListHandler (httphandler) {

	//first three are fully visible
	var xml = httphandler.responseXML;
	var d = document;
	var root = xml.getElementsByTagName ( "items" )[0];
	var htmlBuffer = "";
	

	
	items = root.getElementsByTagName ( "item" );
	for ( i = 0; i < items.length && i < 3; i ++ ){
		
		htmlBuffer += "<table><tr><td class=\"content_image\"><img src=\"return_image.php?x=150&fn=uploads/"+items[i].getElementsByTagName("image")[0].firstChild.nodeValue +"\" /></td>" ;
		htmlBuffer += "<td class=\"content_body\"><div class=\"title\">" + items[i].getElementsByTagName ( "name" )[0].firstChild.nodeValue + "</div><div class=\"date\">"+ items[i].getElementsByTagName ( "ts" )[0].firstChild.nodeValue +"</div><div class=\"hspacer\">&nbsp;</div>" + items[i].getElementsByTagName("body_short")[0].firstChild.nodeValue + "</td></tr></table>";
		htmlBuffer += "<div class=\"readmore\"><a href=\"#\" onclick=\"menuclick('n','"+items[i].getElementsByTagName ( "news_id" )[0].firstChild.nodeValue+"');return false;\"><img src=\"img/readmore.gif\" /></a></div><br /><hr /><div class=\"hspacer\">&nbsp</div>";		
	}
	
	htmlBuffer += '<object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="475" height="22"  align="middle">'+
									'<param name="allowScriptAccess" value="sameDomain" />'+
									'<param name="movie" value="REMF_header.swf?htext=.more" />'+
									'<param name="quality" value="high" />'+
									'<param name="salign" value="lt" />'+
									'<param name="bgcolor" value="#009933" />'+
									'<param name="scale" value="noscale" />'+
									'<embed src="REMF_header.swf?htext=.more" scale="noscale" quality="high" salign="lt" bgcolor="#009933" width="475" height="22"  align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
								'</object><div class=\"hspacer\">&nbsp;</div>';
		
	//go on looping other items
	for ( ;i < items.length && i < 5; i ++ ){
		
		htmlBuffer += "<a class=\"newslist\" href=\"#\" onclick=\"menuclick('n','"+items[i].getElementsByTagName ( "news_id" )[0].firstChild.nodeValue+"');return false;\"><div class=\"title\"><span class=\"date\">" + items[i].getElementsByTagName ( "ts" )[0].firstChild.nodeValue + "</span> " + items[i].getElementsByTagName("name")[0].firstChild.nodeValue + "</div></div><div class=\"hspacer\">&nbsp;</div></a>";
		//htmlBuffer += "<div class=\"readmore\"><a href=\"#\" onclick=\"menuclick('n','"+items[i].getElementsByTagName ( "name" )[0].firstChild.nodeValue+"');return false;\"><img src=\"img/readmore.gif\" /></a></div><br /><hr /><div class=\"hspacer\">&nbsp</div>";		
	}

	d.getElementById("pica").firstChild.src="img/pix.gif";
	d.getElementById( "content_body" ).innerHTML = htmlBuffer;
	setFlashTitle ( ".news" );

}


function newsDataHandler (httphandler) {

	var xml = httphandler.responseXML;
	var d = document;
	var root = xml.getElementsByTagName ( "items" )[0];

	var htmlBuffer = "";
	
	items = root.getElementsByTagName ( "item" );
	d.getElementById("pica").firstChild.src = "return_image.php?x=150&fn=uploads/"+items[0].getElementsByTagName("image")[0].firstChild.nodeValue;
	d.getElementById("content_body").innerHTML = "<div class=\"title\">" + items[0].getElementsByTagName("name")[0].firstChild.nodeValue + "</div>" + items[0].getElementsByTagName("body")[0].firstChild.nodeValue;
		
	//set flash title	
	setFlashTitle ( ".news" );

}

function responseHandler (httphandler) {
	
	document.getElementById('email').value = httphandler.responseXML.getElementsByTagName( "response" )[0].firstChild.nodeValue;
}


function eventListHandler ( httphandler ) {

	
}

function submitEmail () {

	addr = document.getElementById('email').value;
	A = new myAIAS ('ajax/subscribe.php?e=' + addr, responseHandler );
}



function menuclick ( type, id ) {
	
	//newslist
	switch ( type ) {
	
		case "a":
				A = new myAIAS ( "ajax/artist.php?a="+id, artistDataHandler );
		break;
		
		case "s": //sub
			A = new myAIAS ( "ajax/menu.php?s="+id, menuDataHandler );
		break;
		
		case "m": //main
			
			if ( id == 1) A = new myAIAS ( "ajax/news.php", newsListHandler )
			else if ( id == 9 ) A = new myAIAS ( "ajax/artist.php", artistListHandler )
			else A = new myAIAS ( "ajax/menu.php?m="+id, menuDataHandler );
			
			
		break;

		case "n": //news
			A = new myAIAS ( "ajax/news.php?n="+id, newsDataHandler );
		break;
		
		case "e": //event
			A = new myAIAS ( "ajax/event.php?e="+id, eventDataHandler );
		break;
	
	}
	
}
