//shorthand document.write
function dw(s)
{
	document.write(s);
}

function opacityLogos(opacStart, opacEnd, millisec, CallbackFunction) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeLogoOpac(" + i + ",'" + opacEnd + "','" + CallbackFunction + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeLogoOpac(" + i + ",'" + opacEnd + "','" + CallbackFunction + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 
//change the opacity for different browsers 
function changeLogoOpac(opacity, desired, callback) { 
    var object; 
	for(i = 1; i < 5; i++)
	{
		object = document.getElementById("clientLogo" + i).style
		object.opacity = (opacity / 100); 
		object.MozOpacity = (opacity / 100); 
		object.KhtmlOpacity = (opacity / 100); 
		object.filter = "alpha(opacity=" + opacity + ")"; 
	}
	if(opacity == desired && callback != '')
	{
		setTimeout(callback, 50);
	}
}
var logoSet = 1;
function FadeLogos()
{
	opacityLogos(100, 0, 600, 'ChangeLogosAndFadeIn()');
}
function ChangeLogosAndFadeIn()
{
	if(logoSet == 1)
	{
		document.getElementById('clientLogo1').src = 'images/client-logos/rentsmart.gif';
		document.getElementById('clientLogo2').src = 'images/client-logos/passion.gif';
		document.getElementById('clientLogo3').src = 'images/client-logos/nhs.gif';
		document.getElementById('clientLogo4').src = 'images/client-logos/castuk.gif';
	}
	else if(logoSet == 2)
	{
		document.getElementById('clientLogo1').src = 'images/client-logos/keele.gif';
		document.getElementById('clientLogo2').src = 'images/client-logos/cb.gif';
		document.getElementById('clientLogo3').src = 'images/client-logos/pbi.gif';
		document.getElementById('clientLogo4').src = 'images/client-logos/landmark.gif';
	}
	else
	{
		document.getElementById('clientLogo1').src = 'images/client-logos/manuni.gif';
		document.getElementById('clientLogo2').src = 'images/client-logos/encircle.gif';
		document.getElementById('clientLogo3').src = 'images/client-logos/repo.gif';
		document.getElementById('clientLogo4').src = 'images/client-logos/qfonic.gif';
	}
		
	opacityLogos(0, 100, 600, 'SetFadeLogosTimer()');
}
function SetFadeLogosTimer()
{
	if(logoSet == 1)
		logoSet = 2;
	else if(logoSet == 2)
		logoSet = 3;
	else
		logoSet = 1;
	setTimeout('FadeLogos()', 2300);
}

function mouseOver(buttonName)
{
	document['button-'+buttonName].src = '/images/button-'+buttonName+'-hover.jpg';
}

function mouseOut(buttonName)
{
	document['button-'+buttonName].src = '/images/button-'+buttonName+'.jpg';
}

function switchStyleSheet(title)
{
	var linkElms = document.getElementsByTagName("link");
	var i, linkElm;
	
	for(i = 0; i < linkElms.length; i++)
	{
		linkElm = linkElms[i];
		if(linkElm.getAttribute("rel").indexOf("style") != -1 && linkElm.getAttribute("title"))
			linkElm.disabled = true;
		if(linkElm.getAttribute("rel").indexOf("style") != -1 && linkElm.getAttribute("title") == title)
			linkElm.disabled = false;
	}
	
	var a = new Array('standard', 'large', 'xlarge');
	
	for(i = 0; i < a.length; i++)
	{
		if(title == a[i])
			document.getElementById('styleSwitcher-'+a[i]).className = 'active';
		else
			document.getElementById('styleSwitcher-'+a[i]).className = '';
	}
	
	createCookie(title);
}

function createCookie(style)
{
	// validate style value
	if(style != 'standard' && style != 'large' && style != 'xlarge')
		style = 'standard';
	
	// set cookie to expire in 30 days
	var date = new Date();
	date.setTime(date.getTime() + (30*24*60*60*1000));
	
	var expires = '; expired='+date.toGMTString();
	
	// create the cookie
	document.cookie = 'acidstyle='+style+expires+'; path=/';
}

function readCookie()
{
	// get the cookie values
	var cookieArray = document.cookie.split(';');
	var arg;
	// for each cookie value find the acidstyle value
	for(var i = 0; i < cookieArray.length; i++)
	{
		arg = trimWhitespace(cookieArray[i]);
		// if found acidstyle value return it
		if(arg.indexOf('acidstyle') == 0)
			return arg.substring(10, arg.length);
	}
	// acidstyle not found, return standard by default
	return 'standard';
}

function SwitchImage(imgObj, imgFile)
{
	imgObj.src = imgFile;
}

function trimWhitespace(string)
{
	return string.replace(/^\s*|\s*$/g, '');
}