// Variables 			

var totalI = lrgImg.length
var imgN = Math.round(totalI/2)	
var totalQ = quote.length
var nandcN = Math.round((NandC.length)/2)
var quoteN = Math.round(totalQ/2)
var z = totalI
var stuN = Math.round(z/2)-1
var w = (80*z)+11 // Adds 11 as additional fix for IE6's padding issue
var m = (-80*(stuN-2)) // Works out the picbar margin
var i = 0;
var alink = '<a href="/international/life-in-bristol/student-experiences/">'
var isrc = '<img id="imgl" src="" height="80px" width="70px" alt="Student photo">'


//Changes CSS based on Javascript

function js() {
	if (window.opera) { 
		document.getElementById('studentexp').className = 'ojs';
		}
	else	{
		document.getElementById('studentexp').className = 'js';
		}
	}

// Inserts the small images
				
function picBar() {
	do {
  	var newdiv = document.createElement('div');
  	var divIdName = 'smlImg'+(i+1);
   	newdiv.setAttribute('id',divIdName);
    newdiv.style.background=('url('+smlImg[i]+') no-repeat top left');
  	newdiv.setAttribute('class','smlimg')
		newdiv.setAttribute('className','smlimg')
	  document.getElementById('picbar').appendChild(newdiv);
  	i=i+1;
  }
	while (i<smlImg.length)
}

// Dynamically set the picbar div to the perfect width

function divWidth() {
		document.getElementById('picbar').style.width = (w+'px');
		}

// Dynamically set the picbar margin

function divLeft() {
		document.getElementById('picbar').style.marginLeft = (m+'px');
		}

// Quote controls
function prevQ(){
		if(quoteN>1){
    	--quoteN;
			document.getElementById('quoteP').innerHTML=(alink+quote[quoteN-1]+'</a>');
    }
		else {
			quoteN=z;
			document.getElementById('quoteP').innerHTML=(alink+quote[quoteN-1]+'</a>');
		}
}
function nextQ(){
		if(quoteN<totalQ){
			++quoteN;
			document.getElementById('quoteP').innerHTML=(alink+quote[quoteN-1]+'</a>');	 
		}
		else {
			quoteN=1;
			document.getElementById('quoteP').innerHTML=(alink+quote[quoteN-1]+'</a>');
		}
}

// Name and Country controls
 
function prevN(){
		if(nandcN>1){
    	--nandcN;
			document.getElementById('NandC').innerHTML=('<p>'+NandC[nandcN-1]+'</p>');
    }
		else {
			nandcN=z;
			document.getElementById('NandC').innerHTML=('<p>'+NandC[nandcN-1]+'</p>');
		}
}
function nextN(){
		if(nandcN<totalQ){
			++nandcN;
			document.getElementById('NandC').innerHTML=('<p>'+NandC[nandcN-1]+'</p>');
		}
		else {
			nandcN=1;
			document.getElementById('NandC').innerHTML=('<p>'+NandC[nandcN-1]+'</p>');
		}
}

// Large image controls

function prevI(){
		if (imgN>1) {
		 			--imgN;
					document.getElementById('img').innerHTML=(alink+isrc+'</a>');
					document.getElementById('imgl').src=(lrgImg[imgN-1]);
         	}
		else {
					imgN=z;
					document.getElementById('img').innerHTML=(alink+isrc+'</a>');
					document.getElementById('imgl').src=(lrgImg[imgN-1]);
					}
}
function nextI(){
     if(imgN<totalI){
		 		  ++imgN;
					document.getElementById('img').innerHTML=(alink+isrc+'</a>');
					document.getElementById('imgl').src=(lrgImg[imgN-1]);
			 }
		else {
					imgN=1;
					document.getElementById('img').innerHTML=(alink+isrc+'</a>');
					document.getElementById('imgl').src=(lrgImg[imgN-1]);
					}
}

// picbar controller

function moveP() {
		if (stuN>1) {
		 			--stuN;
		 			new Effect.Move('picbar', {x: 80, transition: Effect.Transitions.sinoidal, duration: 1.1});
          moveimg();
          quotePrev();
          buttonFade('prev');
          buttonFade('next');
        	qmarkFade('openquote');
        	qmarkFade('closequote');
         	}
		else {
					new Effect.Move('picbar', {x: (-80*(z-1)), transition: Effect.Transitions.sinoidal, duration: 1.1});
          moveimg();
          quotePrev();
          buttonFade('prev');
          buttonFade('next');
        	qmarkFade('openquote');
        	qmarkFade('closequote');
					stuN=z;
					}
}
function moveN() {
		if (stuN<z) {
		 			++stuN;
		 			new Effect.Move('picbar', {x: -80, transition: Effect.Transitions.sinoidal, duration: 1.1});
          moveimg();
          quoteNext();
          buttonFade('prev');
          buttonFade('next');
        	qmarkFade('openquote');
        	qmarkFade('closequote');
         	}
		else {
					new Effect.Move('picbar', {x: (80*(z-1)), transition: Effect.Transitions.sinoidal, duration: 1.1});
          moveimg();
          quoteNext();
          buttonFade('prev');
          buttonFade('next');
        	qmarkFade('openquote');
        	qmarkFade('closequote');
					stuN=1;
					}
}
function moveimg() {
	new Effect.Move('imgholder', { y: +120, transition: Effect.Transitions.sinoidal, duration: 0.55, afterFinish: function() {
			new Effect.Move('imgholder', { y: -120, transition: Effect.Transitions.sinoidal, duration:0.55});
			}});
}
function quoteNext() {
	new Effect.Opacity('quoteP', { from: 1, to: 0, duration: 1.0});
  new Effect.Opacity('NandC', { from: 1, to: 0, duration: 1.0});
	setTimeout('nextQ()',1000);
	setTimeout('nextN()',1000);
	setTimeout('nextI()',550);
	new Effect.Opacity ('quoteP', {from: 0, to: 0.99, duration: 1.0, delay: 0.8});
  new Effect.Opacity ('NandC', {from: 0, to: 0.99, duration: 1.0, delay: 0.8});
}
function quotePrev() {
  new Effect.Opacity('quoteP', { from: 1, to: 0, duration: 1.0});
	new Effect.Opacity('NandC', { from: 1, to: 0, duration: 1.0});
  setTimeout('prevQ()',1000);
  setTimeout('prevN()',1000);
	setTimeout('prevI()',550);
  new Effect.Opacity ('quoteP', {from: 0, to: 0.99, duration: 1.0, delay: 0.8});
  new Effect.Opacity ('NandC', {from: 0, to: 0.99, duration: 1.0, delay: 0.8});
}
function buttonFade(element) {
	new Effect.Fade(element, { duration: 0.1, afterFinish: function() {new Effect.Appear (element, {duration: 0.4, delay: 2.0});}});
}
function qmarkFade(element) {
	new Effect.Opacity(element, {from: 1, to: 0, duration: 0.9, afterFinish: function() {new Effect.Opacity (element, {from:0, to:1, duration: 1});}});
}
function loadUp() {
	if (window.opera) { 
		new Effect.Opacity ('imgholder', {from: 1, to: 0.01, duration: 0.0});
		new Effect.Opacity ('openquote', {from: 1, to: 0, duration: 0.0});
	};
	setTimeout('load()',1300);
}
function load() {
	divWidth();
	divLeft();
	new Effect.Move('bottombar', { y: -40, transition: Effect.Transitions.sinoidal, duration: 0.55, delay:1.5});
	new Effect.Move('prev', { y: -40, transition: Effect.Transitions.sinoidal, duration: 0.55, delay:1.5});
	new Effect.Move('next', { y: -40, transition: Effect.Transitions.sinoidal, duration: 0.55, delay:1.5});
	if (window.opera) {
		new Effect.Opacity('openquote', {from: 0, to: 1, duration: 0.0, delay: 2.6});
	}
	new Effect.Move('openquote', { x: 40, transition: Effect.Transitions.sinoidal, duration: 0.55, delay:2.55});
	new Effect.Move('closequote', { x: -40, transition: Effect.Transitions.sinoidal, duration: 0.55, delay:2.55});
	new Effect.Opacity ('quoteP', {from: 1, to: 0, duration: 0.0, afterFinish: function () {new Effect.Move('quoteP', { x: 239, transition: Effect.Transitions.sinoidal, duration: 0.0, delay: 3.01});}});
	new Effect.Opacity ('quoteP', {from: 0, to: 0.99, duration: 1.0, delay: 3.0});
	new Effect.Opacity ('NandC', {from: 1, to: 0, duration: 0.0, afterFinish: function () {new Effect.Move('NandC', { x: 239, transition: Effect.Transitions.sinoidal, duration: 0.0, delay: 3.01});}});
	new Effect.Opacity ('NandC', {from: 0, to: 0.99, duration: 1.0, delay: 3.0});
	if (window.opera) {
		new Effect.Opacity('imgholder', {from: 0, to: 1, duration: 0.0, delay: 2.1});
	}
	new Effect.Move('imgholder', { y: -90, transition: Effect.Transitions.sinoidal, duration: 0.55, delay: 2.0});
  prevQ();
	prevI();
	prevN();
	setTimeout('buttonFade("prev")',1500);
	setTimeout('buttonFade("next")',1500);
	picBar();
}
function scrollButtons() {
		document.write(
			'<div id="prev" onclick="moveP()" onmouseover="buttonHoverP()" onmouseout="buttonHoverPo()">'+
			'<div id="prevbutton">'+
			'</div>'+
			'</div>'+
			'<div id="next" onclick="moveN()" onmouseover="buttonHoverN()" onmouseout="buttonHoverNo()">'+
			'<div id="nextbutton">'+
			'</div>'+
			'</div>'
			);
}
function buttonHoverN() {
	document.getElementById('nextbutton').style.background = 'url(/international/images/student-experience-photos/js/stuexp-arrows.jpg) right bottom no-repeat';
}
function buttonHoverNo() {
	document.getElementById('nextbutton').style.background = 'url(/international/images/student-experience-photos/js/stuexp-arrows.jpg) right top no-repeat';
}
function buttonHoverP() {
	document.getElementById('prevbutton').style.background = 'url(/international/images/student-experience-photos/js/stuexp-arrows.jpg) left bottom no-repeat';
}
function buttonHoverPo() {
	document.getElementById('prevbutton').style.background = 'url(/international/images/student-experience-photos/js/stuexp-arrows.jpg) left top no-repeat';
}

