// Synthetix Accordion Script is Copyright (c) 2007, Synthetix Ltd.
// ****************************************************************

// Preload header graphics
// ***********************

s1up 		   = new Image(0,0);
s1up.src   = "images/accordion/clients_up.gif";
s1down     = new Image(0,0);
s1down.src = "images/accordion/clients_down.gif";
s2up		   = new Image(0,0);
s2up.src   = "images/accordion/news_up.gif";
s2down 		 = new Image(0,0);
s2down.src = "images/accordion/news_down.gif";
s3up 		   = new Image(0,0);
s3up.src   = "images/accordion/product_up.gif";
s3down 		 = new Image(0,0);
s3down.src = "images/accordion/product_down.gif";

// Accordion default data

var default_client_data="<table width=277 height=402 border=0 cellpadding=0 cellspacing=0><tr><td><a href=\"#\" onClick=\"flip_up('s1')\"><img src=\"images/accordion/clients_down.gif\" border=0 name=\"s1image\"></a></td>	<tr>		<td>			<table border=0 width=277 height=365 cellspacing=0 cellpadding=0 background=\"images/accordion/acc_clients_back.gif\"><tr><td><center><img src=\"images/accordion/loading.gif\"></center><BR></td></tr></table></td></tr></table>";

var default_news_data="<table width=277 height=402 border=0 cellpadding=0 cellspacing=0><tr><td><a href=\"#\" onClick=\"flip_up('s2')\"><img src=\"images/accordion/news_up.gif\" border=0 name=\"s2image\"></a></td>	<tr>		<td>			<table border=0 width=277 height=365 cellspacing=0 cellpadding=0 background=\"images/accordion/acc_news_back.gif\"><tr><td><center><img src=\"images/accordion/loading.gif\"></center><BR></td></tr></table></td></tr></table>";

var default_product_data="<table width=277 height=402 border=0 cellpadding=0 cellspacing=0><tr><td><a href=\"#\" onClick=\"flip_up('s3')\"><img src=\"images/accordion/product_up.gif\" border=0 name=\"s3image\"></a></td>	<tr>		<td>			<table border=0 width=277 height=365 cellspacing=0 cellpadding=0 background=\"images/accordion/acc_product_back.gif\"><tr><td><center><img src=\"images/accordion/loading.gif\"></center><BR></td></tr></table></td></tr></table>";

var new_client_data="<table width=277 height=402 border=0 cellpadding=0 cellspacing=0><tr><td><a href=\"#\" onClick=\"flip_up('s1')\"><img src=\"images/accordion/clients_down.gif\" border=0 name=\"s1image\"></a></td><tr><td><!-- START Contents of Clients container --><table border=0 width=277 height=365 cellspacing=0 cellpadding=0 background=\"images/accordion/acc_clients_back.gif\"><tr><td height=21 colspan=5></td></tr><tr valign=top class=\"news\"><td width=7 height=57></td><td width=124 height=57><a href=\"&link1\" border=0><img src=\"&logo1\" border=0></a></td><td width=16 height=57></td><td width=124 height=57><a href=\"&link2\" border=0><img src=\"&logo2\" border=0></a></td><td width=6 height=57></td></tr><tr><td height=9 colspan=5></td></tr><tr valign=top class=\"news\"><td width=7 height=57></td><td width=124 height=57><a href=\"&link3\" border=0><img src=\"&logo3\" border=0></a></td><td width=16 height=57></td><td width=124 height=57><a href=\"&link4\" border=0><img src=\"&logo4\" border=0></a></td><td width=6 height=57></td></tr><tr><td height=9 colspan=5></td></tr><tr valign=top class=\"news\"><td width=7 height=57></td><td width=124 height=57><a href=\"&link5\" border=0><img src=\"&logo5\" border=0></a></td><td width=16 height=57></td><td width=124 height=57><a href=\"&link6\" border=0><img src=\"&logo6\" border=0></a></td><td width=6 height=57></td></tr><tr><td height=9 colspan=5></td></tr><tr valign=top class=\"news\"><td width=7 height=57></td><td width=124 height=57><a href=\"&link7\" border=0><img src=\"&logo7\" border=0></a></td><td width=16 height=57></td><td width=124 height=57><a href=\"&link8\" border=0><img src=\"&logo8\" border=0></a></td><td width=6 height=57></td></tr><tr><td height=9 colspan=5></td></tr><tr valign=top class=\"news\"><td width=7 height=57></td><td width=124 height=57><a href=\"&link9\" border=0><img src=\"&logo9\" border=0></a></td><td width=16 height=57></td><td width=124 height=57><a href=\"&linkA\" border=0><img src=\"&logoA\" border=0></a></td><td width=6 height=57></td></tr><tr><td height=20 colspan=5></td></tr></table><!-- END Contents of Clients container --></td></tr></table>";

var new_news_data="<table width=277 height=402 border=0 cellpadding=0 cellspacing=0><tr><td><a href=\"#\" onClick=\"flip_up('s2')\"><img src=\"images/accordion/news_up.gif\" border=0 name=\"s2image\"></a></td></tr><tr><td><!-- START Contents of News container --><table border=0 width=277 height=365 cellspacing=0 cellpadding=0 background=\"images/accordion/acc_news_back.gif\"><tr><td height=25 colspan=3></td></tr><tr valign=top class=\"news\"><td width=16 height=94></td><td width=245 height=94><a href=\"&link1\" class=\"acc_link\">&heading1</a><BR><b class=\"acc_bold\">&date1</b><BR>&article1</td><td width=16 height=94></td></tr><tr><td height=19 colspan=3></td></tr><tr valign=top class=\"news\"><td width=16 height=94></td><td width=245 height=94><a href=\"&link2\" class=\"acc_link\">&heading2</a><BR><b class=\"acc_bold\">&date2</b><BR>&article2</td><td width=16 height=94></td></tr><tr><td height=19 colspan=3></td></tr><tr valign=top class=\"news\"><td width=16 height=94></td><td width=245 height=94><a href=\"&link3\" class=\"acc_link\">&heading3</a><BR><b class=\"acc_bold\">&date3</b><BR>&article3</td><td width=16 height=94></td></tr><tr><td height=20 colspan=3></td></tr></table><!-- END Contents of News container --></td></tr></table>";

var new_product_data="<table width=277 height=402 border=0 cellpadding=0 cellspacing=0><tr><td><a href=\"#\" onClick=\"flip_up('s3')\"><img src=\"images/accordion/product_up.gif\" border=0 name=\"s3image\"></a></td></tr><tr><td><!-- START Contents of Products container --><table border=0 width=277 height=365 cellspacing=0 cellpadding=0 background=\"images/accordion/acc_product_back.gif\"><tr><td height=15 colspan=3></td></tr><tr valign=top class=\"news\"><td width=11 height=30></td><td width=254 height=30><a href=\"&link\" border=0><img src=\"&banner\" border=0></a></td><td width=12 height=30></td></tr><tr><td height=12 colspan=3></td></tr><tr valign=top class=\"news\"><td width=21 height=185></td><td width=235 height=185><a href=\"&link\" class=\"acc_link\">&heading</a><BR><BR>&article</td><td width=21 height=185></td></tr><tr><td height=5 colspan=3></td></tr><tr valign=top class=\"news\"><td width=21 height=53></td><td width=235 height=53><a href=\"&link\"><img src=\"&logo\" border=0></a><BR><BR></td><td width=21 height=53></td></tr><tr><td height=22 colspan=3></td></tr></table><!-- END Contents of Products container --></td></tr></table>";

// Accordion Global Variables
// **************************

var _scripts = [];
var acc_data=new Array();
var accordion_speed=1;
var inertia;
var inertia_factor=5;
var open_height=402;
var closed_height=38;
var openI;
var closeI;
var open_timer;
var close_timer;
var s1expanded=true;
var s2expanded=false;
var s3expanded=false;

// Accordion functions
// *******************

String.prototype.replaces=strReplace;
String.prototype.matches=strMatch;

function strReplace(str,wit)
{
	return this.split(str).join(wit);
}

function strMatch(strM)
{
	return this.indexOf(strM);
}

function do_expand(val)
{
	inertia=(open_height-openI)/inertia_factor;
	clearTimeout(open_timer);
	document.getElementById(val).style.height=openI;
	if(openI<=open_height)
	{
		openI+=inertia;
		open_timer=setTimeout("do_expand('"+val+"')",accordion_speed);
	}
	else
		document.getElementById(val).style.height=open_height;
}

function do_contract(val)
{
	clearTimeout(close_timer);
	document.getElementById(val).style.height=closeI;
	if(closeI>=closed_height)
	{
		closeI-=inertia;
		close_timer=setTimeout("do_contract('"+val+"')",accordion_speed);
	}
	else
		document.getElementById(val).style.height=closed_height;
}

function expand(val)
{
	document[val+"image"].src=eval(val+"down.src");
	openI=closed_height;
	do_expand(val);
}

function contract(val)
{
	document[val+"image"].src=eval(val+"up.src");
	closeI=open_height;
	do_contract(val);
}

function instant_contract(val)
{
	document.getElementById(val).style.height=closed_height;
}

function display_accordion_data()
{
	new_client_data=new_client_data.replaces("&logo1",acc_data[0]);
	new_client_data=new_client_data.replaces("&link1",acc_data[1]);
	new_client_data=new_client_data.replaces("&logo2",acc_data[2]);
	new_client_data=new_client_data.replaces("&link2",acc_data[3]);
	new_client_data=new_client_data.replaces("&logo3",acc_data[4]);
	new_client_data=new_client_data.replaces("&link3",acc_data[5]);
	new_client_data=new_client_data.replaces("&logo4",acc_data[6]);
	new_client_data=new_client_data.replaces("&link4",acc_data[7]);
	new_client_data=new_client_data.replaces("&logo5",acc_data[8]);
	new_client_data=new_client_data.replaces("&link5",acc_data[9]);
	new_client_data=new_client_data.replaces("&logo6",acc_data[10]);
	new_client_data=new_client_data.replaces("&link6",acc_data[11]);
	new_client_data=new_client_data.replaces("&logo7",acc_data[12]);
	new_client_data=new_client_data.replaces("&link7",acc_data[13]);
	new_client_data=new_client_data.replaces("&logo8",acc_data[14]);
	new_client_data=new_client_data.replaces("&link8",acc_data[15]);
	new_client_data=new_client_data.replaces("&logo9",acc_data[16]);
	new_client_data=new_client_data.replaces("&link9",acc_data[17]);
	new_client_data=new_client_data.replaces("&logoA",acc_data[18]);
	new_client_data=new_client_data.replaces("&linkA",acc_data[19]);
	
	new_news_data=new_news_data.replaces("&heading1",acc_data[20]);
	new_news_data=new_news_data.replaces("&link1",acc_data[21]);
	new_news_data=new_news_data.replaces("&date1",acc_data[22]);
	new_news_data=new_news_data.replaces("&article1",acc_data[23]);
	new_news_data=new_news_data.replaces("&heading2",acc_data[24]);
	new_news_data=new_news_data.replaces("&link2",acc_data[25]);
	new_news_data=new_news_data.replaces("&date2",acc_data[26]);
	new_news_data=new_news_data.replaces("&article2",acc_data[27]);
	new_news_data=new_news_data.replaces("&heading3",acc_data[28]);
	new_news_data=new_news_data.replaces("&link3",acc_data[29]);
	new_news_data=new_news_data.replaces("&date3",acc_data[30]);
	new_news_data=new_news_data.replaces("&article3",acc_data[31]);
	
	new_product_data=new_product_data.replaces("&banner",acc_data[32]);
	new_product_data=new_product_data.replaces("&heading",acc_data[33]);
	new_product_data=new_product_data.replaces("&article",acc_data[34]);
	new_product_data=new_product_data.replaces("&logo",acc_data[35]);
	new_product_data=new_product_data.replaces("&link",acc_data[36]);
	
	document.getElementById("s1").innerHTML=new_client_data;
	document.getElementById("s2").innerHTML=new_news_data;
	document.getElementById("s3").innerHTML=new_product_data;
}

function rand(x,y)
{
	return Math.floor(Math.random()*(y-x+1))+x;
}

function load_accordion_data()
{
	var script  = document.createElement('script');
	script.src  = 'syn_menu_anim_data.js?data='+rand(1,9999);
	script.type = 'text/javascript';
	script      = document.getElementsByTagName('head')[0].appendChild(script);
	_scripts.push(script);
}

function run_accordion()
{
	document.getElementById("s1").innerHTML=default_client_data;
	document.getElementById("s2").innerHTML=default_news_data;
	document.getElementById("s3").innerHTML=default_product_data;
	
	if(s1expanded==true) document.getElementById("s1").style.height=open_height;
	if(s2expanded==true) document.getElementById("s2").style.height=open_height;
	if(s3expanded==true) document.getElementById("s3").style.height=open_height;
	
	load_accordion_data();
}

function flip_up(val)
{
	switch(val)
	{
		case "s1":
			if(s1expanded==false)
			{
				s1expanded=true;
				expand("s1");
				if(s2expanded==true)
				{
					contract("s2");
					instant_contract("s3");
					s2expanded=false;
				}
				
				if(s3expanded==true)
				{
					contract("s3");
					instant_contract("s2");
					s3expanded=false;
				}
			}
		break;
		
		case "s2":
			if(s2expanded==false)
			{
				s2expanded=true;
				expand("s2");
				
				if(s1expanded==true)
				{
					contract("s1");
					instant_contract("s3");
					s1expanded=false;
				}
				
				if(s3expanded==true)
				{
					contract("s3");
					instant_contract("s2");
					s3expanded=false;
				}
			}
		break;
		
		case "s3":
			if(s3expanded==false)
			{
				s3expanded=true;
				expand("s3");
				
				if(s1expanded==true)
				{
					contract("s1");
					instant_contract("s2");
					s1expanded=false;
				}
				
				if(s2expanded==true)
				{
					contract("s2");
					instant_contract("s1");
					s2expanded=false;
				}
			}
		break;
	}
}
