/*
Removed By Iain 18/08/2009 as this is no longer needed 

$('contentsTopTitle').addEvents({
	mouseenter: function(){
		// This morphes the opacity and backgroundColor
		this.morph({
			'color': '#aaaaaa'
		});
	},
	mouseleave: function(){
		// Morphes back to the original style
		this.morph({
			'color': '#ffffff'
		});
	}
});

if($('newsSideTitle')){
$('newsSideTitle').addEvents({
	mouseenter: function(){
		// This morphes the opacity and backgroundColor
		this.morph({
			'color': '#aaaaaa'
		});
	},
	mouseleave: function(){
		// Morphes back to the original style
		this.morph({
			'color': '#ffffff'
		});
	}
});
}

*/

function objectRollOver(box){
	box = this.id.replace('bb', '');
	
	$('bbcont' + box).addClass('box-bottom-contents2');
		$('bbl' + box).css('background-image', 'url(images/object-top-left2.png)');
		$('bbc' + box).css('background-image', 'url(images/object-top-center2.jpg)');
		$('bbr' + box).css('background-image', 'url(images/object-top-right2.png)');		
}

function objectRollOut(box){
	box = this.id.replace('bb', '');
	
	$('bbcont' + box).addClass('box-bottom-contents');
	

		$('bbl' + box).css('background-image', 'url(images/object-top-left.png)');
		$('bbc' + box).css('background-image', 'url(images/object-top-center.jpg)');
		$('bbr' + box).css('background-image', 'url(images/object-top-right.png)');		

}

var boxes = $('div.box-bottom');

for(var x = 0; x < boxes.length; x++){
	boxes[x].onmouseover 	= objectRollOver;
	boxes[x].onmouseout		= objectRollOut;
}

updateClock();
window.setInterval('updateClock();', 1000);

function updateClock(){
	var clockHtml = '';
	var d = new Date();
	
	var weekday = new Array(7);
	weekday[0]	= "Sunday";
	weekday[1]	= "Monday";
	weekday[2]	= "Tuesday";
	weekday[3]	= "Wednesday";
	weekday[4]	= "Thursday";
	weekday[5]	= "Friday";
	weekday[6]	= "Saturday";
	
	clockHtml += weekday[d.getDay()];
	
	var date = d.getDate();
	var abrv = 'th';
	
	if(date.toString().charAt(date.toString().length - 1) == '1'){
		abrv = 'st';
	}else if(date.toString().charAt(date.toString().length - 1) == '2'){
		abrv = 'nd';
	}
	
	clockHtml += ' ' + date + abrv;
	
	var month = new Array(12);
	month[0]	= "January";
	month[1]	= "February";
	month[2]	= "March";
	month[3]	= "April";
	month[4]	= "May";
	month[5]	= "June";
	month[6]	= "July";
	month[7]	= "August";
	month[8]	= "September";
	month[9]	= "October";
	month[10]	= "November";
	month[11]	= "December";
	
	clockHtml += ' ' + month[d.getMonth()];

	var h = lessThan10(d.getHours());
	var m = lessThan10(d.getMinutes());
	var s = lessThan10(d.getSeconds());
	
	clockHtml += ' ' + h + ':' + m + ':' + s;

	$('divClock').innerHTML = clockHtml;	
}

function lessThan10(num){
	if(num < 10){
		return '0' + num;
	}else{
		return num;
	}
}

function searchGoogle(query){
	var url = 'http://www.google.co.uk/search?&hl=en&rlz=&=&q=' + URLEncode(query) + '&btnG=Google+Search&meta=';
	window.open(url);
}

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";


	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

//Tabs on MiView
	function showTab(obj){
		var sec = obj.substr(3,1);
		var sub = obj.substr(7,1);

		/*for(var x = 0; x < $('div.miViewTaba').length; x++){
			$('div.miViewTaba')[x].css("color",'#cccccc');
			$('div.miViewTaba')[x].addClass('miViewTab');
		}*/
		$('div.miViewTaba').each(function(){
			$('div.miViewTaba').css("color",'#cccccc');
			$('div.miViewTaba').addClass('miViewTab');
		});
		
		
		$("#obj").addClass('miViewTaba');
		$("#obj").css ("color" ,"#F39E34");
		
		/*for(var x = 0; x < $('div.miViewSuba').length; x++){
			$('div.miViewSuba')[x].addClass('miViewSub');
		}*/
		
		$('div.miViewSuba').each(function(){
			$('div.miViewSuba').addClass('miViewSub');
		})
		
		$('"#sec' + sec + 'sub' + sub+'"').addClass('miViewSuba');
	}
	
	function showSec(obj){
		var sec = obj.replace('title','');

		/*var isSelected = false;
		if($(obj).class == 'miViewSecTitlea'){
		alert("is selected");
			isSelected = true;	
		}*/
		if($(obj).hasClass("miViewSecTitlea")){
			isSelected = true;	
		}else{
			isSelected =false;
			}
		
		$(".miViewSection").each(function(){
			$(".miViewSection").css("display","none");
			$(".miViewSection").css("color", "#000");
		});
		
		
		$(".miViewSecTitlea").each(function(){
			$('.miViewSecTitlea').css("color" ,"#000");
			$('.miViewSecTitlea').addClass('miViewSecTitle');
		});

		if(isSelected == false){
			
			$('#'+obj).css("color","#000");
			$('#'+obj).addClass('miViewSecTitlea');
			$('#'+sec).css("display","block");
		}
	}
	

function tabOver(obj){
	$('#'+obj).css("color" , '#0000');
}

function tabOut(obj){
var ourId = '#' + obj;
	if($(obj).hasClass('miViewSecTitle') || $(obj).hasClass('miViewTab')){
		$('#'+obj).css("color","#000");
	}else{
		$('#'+obj).css("color","#000");
	}
}

/*function tabOver2(obj){
	$(obj).css("color","#000");
}

function tabOut2(obj){
	if($(obj).class== 'miViewSecTitle2' || $(obj).class == 'miViewTab'){
		$(obj).css("color","#000");
	}else{
		$(obj).css("color","#000");	
	}
}

function showSec2(obj){
	var sec = obj.replace('title','');

	var isSelected = false;
	if($(obj).class == 'miViewSecTitlea2'){
		isSelected = true;	
	}

	for(var x = 0; x < $$('div.miViewSection2').length; x++){
		$('div.miViewSection2')[x].style.display = 'none';
		$('div.miViewSection2')[x].style.color = '#000';
	}
	
	for(var x = 0; x < $$('h5.miViewSecTitlea2').length; x++){
		$$('h5.miViewSecTitlea2')[x].style.color = '#000';
		$$('h5.miViewSecTitlea2')[x].className = 'miViewSecTitle2';
	}

	if(isSelected == false){
		$(obj).style.color = '#F39E34';
		$(obj).className = 'miViewSecTitlea2';

		$(sec).style.display = 'block';
	}
}

//sortout quotes
*/
window.setTimeout('updateStyle();', 500);

function updateStyle(){
	var quotes = $('div.quote');
	for(var x = 0; x < quotes.length; x++){
		var quoteText 	= quotes[x].innerHTML;
		var height		= parseInt(quotes[x].offsetHeight + 15);
		var quoteHtml 	= '';
		
		quoteHtml += '<div class="quoteTop"><div class="smTop"></div></div>';
		quoteHtml += '<div class="quoteMid" style="height:' + height + 'px;">';
		quoteHtml += '<div class="quoteMidText">'
		quoteHtml += quoteText;
		quoteHtml += '</div>';
		quoteHtml += '<div class="smBot" style="margin-top:' + parseInt(height - 28) + 'px;"></div>';
		quoteHtml += '</div>';
		quoteHtml += '<div class="quoteBot"></div>';
		
		quotes[x].innerHTML = quoteHtml;
		
		quotes[x].style.height = parseInt(height + 31) + 'px';
	}
	
	var blurbs = $('div.blurb');
	for(var x = 0; x < blurbs.length; x++){
		var blurbText 	= blurbs[x].innerHTML;
		var height		= parseInt(blurbs[x].offsetHeight + 6);
		var blurbHtml 	= '';
		
		blurbHtml += '<div class="quoteTop"></div>';
		blurbHtml += '<div class="quoteMid" style="height:' + height + 'px;">';
		blurbHtml += '<div class="quoteMidText" style="">'
		blurbHtml += blurbText;
		blurbHtml += '</div>';
		blurbHtml += '</div>';
		blurbHtml += '<div class="quoteBot"></div>';
		
		blurbs[x].innerHTML = blurbHtml;
		
		blurbs[x].style.height = parseInt(height + 31) + 'px';
	}
	
	//fix pngs
}

function changeTab(tab){
	for(var x = 0; x < $$('div.miViewTaba').length; x++){
			$('con' + $$('div.miViewTaba')[x].id.replace('tab', '')).className = 'miViewSub';
			$$('div.miViewTaba')[x].style.color = '#cccccc';
			$$('div.miViewTaba')[x].className = 'miViewTab';
	}
	
	tab.className = 'miViewTaba';
	tab.style.color = '#000000';
	$('con' + tab.id.replace('tab', '')).className = 'miViewSuba';
	if($('swf' + tab.id.replace('tab', ''))){
		//$(tab.id.replace('tab', 'swf')).Rewind();
		try{
			$(tab.id.replace('tab', 'swf')).Rewind();
			$(tab.id.replace('tab', 'swf')).Play();
		}catch(ex){
			
		}
	}
}

var tablocation = window.location.href.toString();
var tab = null;
if(tablocation.lastIndexOf('&tab=') > 0){
	tabSwitch();
}

function tabSwitch(){
	tab = tablocation.substr(tablocation.lastIndexOf('&tab=') + 5);
	
}



/*
  if(window.attachEvent)
    window.attachEvent("onload",setListeners);

  function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
      inputList[i].attachEvent("onpropertychange",restoreStyles);
      inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
      selectList[i].attachEvent("onpropertychange",restoreStyles);
      selectList[i].style.backgroundColor = "";
    }
  }

  function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "")
      event.srcElement.style.backgroundColor = "";
  }//-->
  */
  
  
  
  //News Cycle
  var NewsInterval 	= null;
  var CurrentNews		= 0;
  
  if($('NewsItem0')){
  	NewsInterval = window.setInterval('nextNews();', 5000);
  
  	$('div.NewsItems').each(function(NewsItem){
    	Event.observe(NewsItem, 'mouseover', function(){
      	window.clearInterval(NewsInterval);
        NewsInterval = null;
      });
      
     	Event.observe(NewsItem, 'mouseout', function(){
      	NewsInterval = window.setInterval('nextNews();', 5000);
      });    
    });
  
  }
  
  function nextNews(){
			
  	$('div.NewsItems').each(function(NewsItem){
    	
    	if(NewsItem.css("display","block")){
        NewsItem.css("display","none");
      }
    });
    
     $('NewsItem' + CurrentNews).css("display" ,"block");
   
    
  	CurrentNews++;
    
  	if(CurrentNews == $('div.NewsItems').length){
    	CurrentNews = 0;
    }
  }
  
