// Rethna Thurai - 2006-06-06
// Dynamic Tab Menu

window.onload = initJavaScript;
var selected;

function initJavaScript() {
	var tabs = document.getElementById("main").childNodes;
	for(i=0;i<tabs.length;i++){
		if(tabs[i].nodeType==1){
			tabs[i].onmouseover = rollOver;
			tabs[i].onmouseout = rollBack;
			tabs[i].onClick = selectTab;
		}
	}
}



function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

var http = createRequestObject(); 

/* Function called to get the product categories list */
function getTabStuff(id){
	selectTab(id);
	http.open('get', 'TabThing.php?id=' + id);
	http.onreadystatechange = handleTabStuff; 
	http.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleTabStuff(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response

		var response = http.responseText;
		document.getElementById('mainHolder').innerHTML = response;
	}
}

function rollOver(){
this.className="tabOver";
  //document.getElementById("tab_"+id).className="tabOver";
}

function rollBack(){
  var tabs = document.getElementById("main").childNodes;
  for(i=0;i<tabs.length;i++){
	  if(tabs[i].nodeType==1){
      if(tabs[i].getAttribute("id") == selected.getAttribute("id")) {
    	  tabs[i].className="tabChoice";
    	} else {
    	  tabs[i].className="tab";
    	}
		}
	}
}

function selectTab(id){

  selected = document.getElementById("tab_"+id);
  var tabs = document.getElementById("main").childNodes;
  for(i=0;i<tabs.length;i++){
	  document.getElementById("main").childNodes[i].className="tab";
	}
	document.getElementById("tab_"+id).className="tabChoice";
}



// Rethna Thurai - 2006-06-06
// Recently Added Dynamic Effect
//List of transitional effects to be randomly applied to billboard:

// Rethna Thurai - 2006-06-06
// Changing the style to always display randomly one style once started
// var billboardeffects=["GradientWipe(GradientSize=1.0 Duration=0.7)", "Inset", "Iris", "Pixelate(MaxSquare=5 enabled=false)", "RadialWipe", "RandomBars", "Slide(slideStyle='push')", "Spiral", "Stretch", "Strips", "Wheel", "ZigZag"]
var billboardeffect=["GradientWipe(GradientSize=1.0 Duration=0.7)", "Inset", "Iris", "Pixelate(MaxSquare=5 enabled=false)", "RadialWipe", "RandomBars", "Slide(slideStyle='push')", "Spiral", "Stretch", "Strips", "Wheel", "ZigZag"]
var styleid = Math.floor(Math.random()*billboardeffect.length)
if (styleid == 0)
	var billboardeffects=["GradientWipe(GradientSize=1.0 Duration=0.7)"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.
else if (styleid == 1)
	var billboardeffects=["Inset"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.
else if (styleid == 2)
	var billboardeffects=["Iris"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.
else if (styleid == 3)
	var billboardeffects=["Pixelate(MaxSquare=5 enabled=false)"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.
else if (styleid == 4)
	var billboardeffects=["RadialWipe"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.
else if (styleid == 5)
	var billboardeffects=["RandomBars"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.
else if (styleid == 6)
	var billboardeffects=["Slide(slideStyle='push')"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.
else if (styleid == 7)
	var billboardeffects=["Spiral"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.
else if (styleid == 8)
	var billboardeffects=["Stretch"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.	
else if (styleid == 9)
	var billboardeffects=["Strips"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.	
else if (styleid == 10)
	var billboardeffects=["Wheel"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.	
else 
	var billboardeffects=["ZigZag"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.	

	
var tickspeed=6000 //ticker speed in miliseconds (2000=2 seconds)
var effectduration=1000 //Transitional effect duration in miliseconds
var hidecontent_from_legacy=1 //Should content be hidden in legacy browsers- IE4/NS4 (0=no, 1=yes).

var filterid=Math.floor(Math.random()*billboardeffects.length)

document.write('<style type="text/css">\n')
if (document.getElementById)
	document.write('.billcontent{display:none;\n'+'filter:progid:DXImageTransform.Microsoft.'+billboardeffects[filterid]+'}\n')
else if (hidecontent_from_legacy)
	document.write('#contentwrapper{display:none;}')
document.write('</style>\n')

var selectedDiv=0
var totalDivs=0

function contractboard(){
var inc=0
while (document.getElementById("billboard"+inc)){
	document.getElementById("billboard"+inc).style.display="none"
	inc++
}
}

function expandboard() {
	var selectedDivObj=document.getElementById("billboard"+selectedDiv)
	contractboard()
	if (selectedDivObj.filters){
		if (billboardeffects.length>1){
			filterid=Math.floor(Math.random()*billboardeffects.length)
			selectedDivObj.style.filter="progid:DXImageTransform.Microsoft."+billboardeffects[filterid]
		}
		selectedDivObj.filters[0].duration=effectduration/1000
		selectedDivObj.filters[0].Apply()
	}
	selectedDivObj.style.display="block"
	if (selectedDivObj.filters)
		selectedDivObj.filters[0].Play()
	selectedDiv=(selectedDiv<totalDivs-1)? selectedDiv+1 : 0
	setTimeout("expandboard()",tickspeed)
}

function startbill(){
	while (document.getElementById("billboard"+totalDivs)!=null)
		totalDivs++
	if (document.getElementById("billboard0").filters)
		tickspeed+=effectduration
	expandboard()
}

if (window.addEventListener)
	window.addEventListener("load", startbill, false)
else if (window.attachEvent)
	window.attachEvent("onload", startbill)
else if (document.getElementById)
	window.onload=startbill
