//----------------------------------------
// Assimil8 Website Javascript
// Chris Taylor // Bright Fox Solutions
//----------------------------------------

//preload function
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

//switches to the named tab
function switchtoname(name){
	$('li.on').removeClass('on');
	$('li#'+name).addClass('on');
	
	//Load content into div
	$('div#switchercontent').html('');
	$('div#switchercontent').css({ backgroundImage : "url("+backgrounds[findPos(name)]+")" });
	//$('div#switchercontent').load(name+'.aspx');
	$('div#switchercontent').html($('div#preload'+findPos(name)).html());
}

//moves to the next tab
function switchnext(){
	currenttab = (currenttab >= tabs.length - 1 ? 0 : currenttab + 1);
	switchtoname(tabs[currenttab]);
	t=setTimeout("switchnext()", timebetweenswitch);
}

//find position in array
function findPos(name){
	for (var i=0, len=tabs.length; i<len; ++i ){
	  if (tabs[i]==name)
	  {
			return i;
	  }
	}
}


function loadContent() {
	for (var i=0, len=tabs.length; i<len; ++i ){
		$('div#preload'+i).load(tabs[i]+'.aspx');
	}
	
}

//tab click function
function clickto(name){
	clearTimeout(t)
	switchtoname(name);
	t=setTimeout("switchnext()", timebetweenswitch*2);
	currenttab=findPos(name);
}


//setup the clicks
function setupClicks(){
	for (var i=0, len=tabs.length; i<len; ++i ){
	  $('li#'+tabs[i]).click(function () { clickto($(this).attr("id")); }).css("cursor","pointer");
	}
}


function shownews(newsid){
	$("div#news"+newsid+"content").toggle("slow");
	$("span#news"+newsid+"minus").toggle();
	$("span#news"+newsid+"plus").toggle();
}

//document ready function - set up tabs, time, clicks and initialise
$(document).ready(function() {

	//switcher
	//--------
	//preload backgrounds
	$.preloadImages("styles/background-a8productportfolio.gif","styles/background-snavswitchertalend.gif","styles/background-ibmcognos.gif","styles/background-microsoftbi.gif","styles/background-lbibpwm3.gif", "styles/background-consulting.gif");
	//preload tabs
	$.preloadImages("styles/bttn1-switcher-a8productportfolio.gif", "styles/bttn1-switcher-consulting.gif","styles/bttn1-switcher-ibmcognos.gif","styles/bttn1-switcher-lbibpwm3.gif","styles/bttn1-switcher-microsoftbi.gif","styles/bttn1-switcher-talend.gif");
	tabs = "snavswitcheraproductportfolio,snavswitcherconsulting,snavswitchertalend,snavswitcheribmcognos,snavswitchermicrosoftbi,snavswitcherlbibpwm".split(',');
	backgrounds = "styles/background-a8productportfolio.gif,styles/background-consulting.gif,styles/background-snavswitchertalend.gif,styles/background-ibmcognos.gif,styles/background-microsoftbi.gif,styles/background-lbibpwm3.gif".split(',');
	$('div#switchercontent').css({ backgroundImage : "url("+backgrounds[0]+")" });
	$('div#switchercontent').load(tabs[0]+'.aspx');
	loadContent();
	currenttab = -1;
	timebetweenswitch=10000;
	setupClicks();	
	switchnext();
	
	
	//news
	$("div.newscontent").hide();
	$("h2.shownews").css('cursor', 'pointer');

	var myFile = document.location.toString();
	if (myFile.match('#')) { 
	  var myAnchor = myFile.split('#')[1];
		$("div#news"+myAnchor+"content").show();
		$("span#news"+myAnchor+"minus").show();
		$("span#news"+myAnchor+"plus").hide();
	  }
	
	
	
});
