/*
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).className = 'box-bottom-contents2';
	
	if(Prototype.Browser.IE){
		$('bbl' + box).setStyle('background-image', 'none');
		$('bbc' + box).setStyle('background-image', 'none');	
		$('bbr' + box).setStyle('background-image', 'none');
		
		$('bbl' + box).setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/object-top-left2.png,sizingMethod=\'scale\')');
		$('bbc' + box).setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/object-top-center3.jpg,sizingMethod=\'scale\')');
		$('bbr' + box).setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/object-top-right2.png,sizingMethod=\'scale\')');
	}else{
		$('bbl' + box).setStyle('background-image', 'url(images/object-top-left2.png)');
		$('bbc' + box).setStyle('background-image', 'url(images/object-top-center2.jpg)');
		$('bbr' + box).setStyle('background-image', 'url(images/object-top-right2.png)');		
	}
}

function objectRollOut(box){
	box = this.id.replace('bb', '');
	
	$('bbcont' + box).className = 'box-bottom-contents';
	
	if(Prototype.Browser.IE){
		$('bbl' + box).setStyle('background-image', 'none');
		$('bbc' + box).setStyle('background-image', 'none');
		$('bbr' + box).setStyle('background-image', 'none');
		
		$('bbl' + box).setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/object-top-left.png,sizingMethod=\'scale\')');
		$('bbc' + box).setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/object-top-center.jpg,sizingMethod=\'scale\')');
		$('bbr' + box).setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/object-top-right.png,sizingMethod=\'scale\')');
	}else{
		$('bbl' + box).setStyle('background-image', 'url(images/object-top-left.png)');
		$('bbc' + box).setStyle('background-image', 'url(images/object-top-center.jpg)');
		$('bbr' + box).setStyle('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].style.color = '#cccccc';
			$$('div.miViewTaba')[x].className = 'miViewTab';
		}
		
		$(obj).className = 'miViewTaba';
		$(obj).style.color = '#F39E34';
		
		for(var x = 0; x < $$('div.miViewSuba').length; x++){
			$$('div.miViewSuba')[x].className = 'miViewSub';
		}
		
		$('sec' + sec + 'sub' + sub).className = 'miViewSuba';
	}
	
	function showSec(obj){
		var sec = obj.replace('title','');

		var isSelected = false;
		if($(obj).className == 'miViewSecTitlea'){
			isSelected = true;	
		}

		for(var x = 0; x < $$('div.miViewSection').length; x++){
			$$('div.miViewSection')[x].style.display = 'none';
			$$('div.miViewSection')[x].style.color = '#cccccc';
		}
		
		for(var x = 0; x < $$('h5.miViewSecTitlea').length; x++){
			$$('h5.miViewSecTitlea')[x].style.color = '#cccccc';
			$$('h5.miViewSecTitlea')[x].className = 'miViewSecTitle';
		}

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

			$(sec).style.display = 'block';
		}
	}
	
if(pageID == 28){

}

function tabOver(obj){
	$(obj).style.color = '#ffffff';
}

function tabOut(obj){
	if($(obj).className == 'miViewSecTitle' || $(obj).className == 'miViewTab'){
		$(obj).style.color = '#cccccc';	
	}else{
		$(obj).style.color = '#F39E34';	
	}
}

function tabOver2(obj){
	$(obj).style.color = '#ffffff';
}

function tabOut2(obj){
	if($(obj).className == 'miViewSecTitle2' || $(obj).className == 'miViewTab'){
		$(obj).style.color = '#cccccc';	
	}else{
		$(obj).style.color = '#F39E34';	
	}
}

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

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

	for(var x = 0; x < $$('div.miViewSection2').length; x++){
		$$('div.miViewSection2')[x].style.display = 'none';
		$$('div.miViewSection2')[x].style.color = '#cccccc';
	}
	
	for(var x = 0; x < $$('h5.miViewSecTitlea2').length; x++){
		$$('h5.miViewSecTitlea2')[x].style.color = '#cccccc';
		$$('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
	if(Prototype.Browser.IE){
		var divs = $$('div');
		for(var x = 0; x < divs.length; x++){
			if(divs[x].getStyle('background-image').indexOf('.png') > 0){
				var backUrl = divs[x].getStyle('background-image').replace('url(', '').replace(')', '');
				divs[x].style.backgroundImage ='none';
				divs[x].style.filter = ('progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + backUrl + ',sizingMethod=\'crop\')');
			}
		}
	}
}

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.style.display == 'block'){
        NewsItem.style.display = 'none';
      }
    });
    
     $('NewsItem' + CurrentNews).style.display = 'block';
   
    
  	CurrentNews++;
    
  	if(CurrentNews == $$('div.NewsItems').length){
    	CurrentNews = 0;
    }
  }
  