/** 
 *  @fileoverview TextResizeDetector
 * 
 *  Detects changes to font sizes when user changes browser settings
 *  <br>Fires a custom event with the following data:<br><br>
 * 	iBase  : base font size  	
 *	iDelta : difference in pixels from previous setting<br>
 *  	iSize  : size in pixel of text<br>
 *  
 *  * @author Lawrence Carvalho carvalho@uk.yahoo-inc.com
 * @version 1.0
 */

/**
 * @constructor
 */
 
TextResizeDetector = function() {
    var el  = null;
	var iIntervalDelay  = 200;
	var iInterval = null;
	var iCurrSize = -1;
	var iBase = -1;
 	var aListeners = [];
 	var createControlElement = function() {
	 	el = document.createElement('span');
		el.id='textResizeControl';
		el.innerHTML='&nbsp;';
		el.style.position="absolute";
		el.style.left="-9999px";
		var elC = document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID);
		if (elC)
			elC.insertBefore(el,elC.firstChild);
		iBase = iCurrSize = TextResizeDetector.getSize();
 	};

 	function _stopDetector() {
		window.clearInterval(iInterval);
		iInterval=null;
	};
	function _startDetector() {
		if (!iInterval) {
			iInterval = window.setInterval('TextResizeDetector.detect()',iIntervalDelay);
		}
	};
 	
 	 function _detect() {
 		var iNewSize = TextResizeDetector.getSize();
		
 		if(iNewSize!== iCurrSize) {
			for (var 	i=0;i <aListeners.length;i++) {
				aListnr = aListeners[i];
				var oArgs = {  iBase: iBase,iDelta:((iCurrSize!=-1) ? iNewSize - iCurrSize + 'px' : "0px"),iSize:iCurrSize = iNewSize};
				if (!aListnr.obj) {
					aListnr.fn('textSizeChanged',[oArgs]);
				}
				else  {
					aListnr.fn.apply(aListnr.obj,['textSizeChanged',[oArgs]]);
				}
			}

 		}
 		return iCurrSize;
 	};
	var onAvailable = function() {
		
		if (!TextResizeDetector.onAvailableCount_i ) {
			TextResizeDetector.onAvailableCount_i =0;
		}

		if (document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID)) {
			TextResizeDetector.init();
			if (TextResizeDetector.USER_INIT_FUNC){
				TextResizeDetector.USER_INIT_FUNC();
			}
			TextResizeDetector.onAvailableCount_i = null;
		}
		else {
			if (TextResizeDetector.onAvailableCount_i<600) {
	  	 	    TextResizeDetector.onAvailableCount_i++;
				setTimeout(onAvailable,200)
			}
		}
	};
	setTimeout(onAvailable,500);

 	return {
		 	init: function() {
		 		
		 		createControlElement();		
				_startDetector();
 			},
 			addEventListener:function(fn,obj,bScope) {
				aListeners[aListeners.length] = {
					fn: fn,
					obj: obj
				}
				return iBase;
			},
 			detect:function() {
 				return _detect();
 			},
 			getSize:function() {
	 				var iSize;
			 		return el.offsetHeight;
		 		
		 		
 			},
 			stopDetector:function() {
				return _stopDetector();
			},
 			startDetector:function() {
				return _startDetector();
			}
 	}
 }();

/*!
 * jQuery doTimeout: Like setTimeout, but better! - v0.4 - 7/15/2009
 * http://benalman.com/projects/jquery-dotimeout-plugin/
 * 
 * Copyright (c) 2009 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */

(function($){
	'$:nomunge';
	var cache = {},
	doTimeout = 'doTimeout',
	aps = Array.prototype.slice;
	$[doTimeout] = function() {
		return p_doTimeout.apply( window, [ 0 ].concat( aps.call( arguments ) ) );
	};
	$.fn[doTimeout] = function() {
		var args = aps.call( arguments ),
		result = p_doTimeout.apply( this, [ doTimeout + args[0] ].concat( args ) );
		return typeof args[0] === 'number' || typeof args[1] === 'number'
		? this
		: result;
	};
	function p_doTimeout( jquery_data_key ) {
		var that = this,
		elem,
		data = {},
		args = arguments,
		slice_args = 4,
		id        = args[1],
		delay     = args[2],
		callback  = args[3];
		if ( typeof id !== 'string' ) {
		slice_args--;
		id        = jquery_data_key = 0;
		delay     = args[1];
		callback  = args[2];
    }
	if ( jquery_data_key ) { 
		elem = that.eq(0);
		elem.data( jquery_data_key, data = elem.data( jquery_data_key ) || {} );
	} else if ( id ) {
		data = cache[ id ] || ( cache[ id ] = {} );
	}
	data.id && clearTimeout( data.id );
	delete data.id;
    
	function cleanup() {
		if ( jquery_data_key ) {
			elem.removeData( jquery_data_key );
		} else if ( id ) {
			delete cache[ id ];
		}
	};
	function actually_setTimeout() {
		data.id = setTimeout( function(){ data.fn(); }, delay );
	};
	if ( callback ) {
		data.fn = function( no_polling_loop ) {
		callback.apply( that, aps.call( args, slice_args ) ) && !no_polling_loop
		? actually_setTimeout()
		: cleanup();
	};
	actually_setTimeout();
    } else if ( data.fn ) {
		delay === undefined ? cleanup() : data.fn( delay === false );
		return true;
	} else {
		cleanup();
	}
};
})(jQuery);

function setActiveStyleSheet(title) {
	var i, a, main;
	for ( i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	var sizeLoc = document.getElementById("Resize");
	if (sizeLoc == null) {
		return false;
	}
	else {
		var anchors = new Array();
		anchors = sizeLoc.getElementsByTagName("a");	
		for (var i=0; i < anchors.length; i++) {
			var links = anchors[i];
			links.className = '';
		}
		switch (title) {
			case 'Standard':
			anchors[2].className="active";
			break;
			case 'Larger':
			anchors[1].className="active";
			break;
			case 'Largest':
			anchors[0].className="active";
			break;
			case 'null':
			anchors[2].className="active";
			break;
			default:
			anchors[2].className="active";
		}
	}
}

function getActiveStyleSheet() {
	var i, a;
	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("rel").indexOf("alt") == -1
			&& a.getAttribute("title")
		) 
		return a.getAttribute("title");
	}
	return null;
}

function createCookie(name,value) {
	document.cookie = name+"="+value+"; path=/tna/20111130080930/http://www.dh.gov.uk/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function startUp() {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

function shutDown() {
	var title = getActiveStyleSheet();
	createCookie("style", title);
}

plusEvent(window, 'load', startUp);
plusEvent(window, 'load', init);
plusEvent(window, 'unload', shutDown);

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

function TakesCookies() {
	var GetsCookie = (navigator.cookieEnabled);
	if(typeof navigator.cookieEnabled=="undefined" && !cookieEnabled) {
		document.cookie = "SampleCookie";
		GetsCookie = (document.cookie.indexOf("SampleCookie")!=-1)
	}
	return GetsCookie;
}

function init() {						   
	if(TakesCookies()){		
		var html = document.getElementsByTagName("html");
		html = html[0];
		var language = html.getAttribute("lang");
		var tabValue = $('#GlobControl .lastLink').attr('tabindex') + 3;
		switch (language) {
			case 'en':
				var aaa = '';
				aaa += "<li id=\"Resize\"><div>";
				aaa += "<ul>";
				tabValue--;
				aaa += "	<li class='large'><a href=\"#largest\" tabindex=\""+String(tabValue)+"\" onclick=\"setActiveStyleSheet('Largest'); return false; \"><span><span class='access'>Resize text to largest </span>A</span></a></li>";
				tabValue--;
				aaa += "	<li class='medium'><a href=\"#larger\" tabindex=\""+String(tabValue)+"\" onclick=\"setActiveStyleSheet('Larger'); return false;\"><span><span class='access'>Resize text to larger </span>A</span></a></li>";
				tabValue--;
				aaa += "	<li><a href=\"#standard\" tabindex=\""+String(tabValue)+"\" onclick=\"setActiveStyleSheet('Standard'); return false;\"><span><span class='access'>Resize text to standard </span>A</span></a></li>";
				aaa += "</ul></div></li>";
			break;
		}
		
		var loc = document.getElementById("GlobControl");
		var contents = loc.innerHTML;
		var textMod = aaa+contents;	
		loc.innerHTML = textMod;
		
		var sizeLoc = document.getElementById("Resize");
		var anchors = new Array();
		anchors = sizeLoc.getElementsByTagName("a");	
		for (var i=0; i < anchors.length; i++) {
			var links = anchors[i];
			links.className = '';
		}
		switch (title) {
			case 'Standard':
			anchors[2].className="active";
			break;
			case 'Larger':
			anchors[1].className="active";
			break;
			case 'Largest':
			anchors[0].className="active";
			break;
			default:
			anchors[2].className="active";
		}
	}	
}

function setupRHM() {
	$('#dhr03 .pinkBox .more').each(function(){
		var value = $(this).attr('class');
		value = parseInt(value.replace("more ", ""));
		var listChilds = $(this).children('li').length;
		var listChilds = listChilds - value - 1;		
		$(this).children('li:gt('+listChilds+')').addClass('noShow');
	});	
	$('#dhr03 .social-sites .inner-soc').addClass('js-on');
	$('#dhr03 .noShow a, #dhr03 .inner-soc a').attr('tabindex', '-1');
	var rssHeader = $('#dhr03 .rssBox h3').text();
	$('#dhr03 .social-sites .inner-soc').after('<div class="showToggle"><a href="#">More<span class="access">'+' '+rssHeader+'</span></a></div>');
	$('#dhr03 .pinkBox .more').each(function(){
		var headerText = $(this).prev('h3').text();
		headerText = '<div class="showToggle"><a href="#">More<span class="access">'+' '+headerText+'</span></a></div>'; 
		$(this).after(headerText);
	});
	$('#dhr03 .social-sites .showToggle a').toggle(
		function(){
			var headerText = $(this).parent('.showToggle').parent('.social-sites').prev('.rssBox').children('h3').text();
			headerText = '<span class="access">'+' '+headerText+'</span>';
			$(this).html('Close'+' '+headerText).addClass('close');
			$(this).parent('.showToggle').prev('.inner-soc').show();
			$('#dhr03 .inner-soc ul li a').removeAttr('tabindex');
			return false;
		},
		function(){
			var headerText = $(this).parent('.showToggle').parent('.social-sites').prev('.rssBox').children('h3').text();
			headerText = '<span class="access">'+' '+headerText+'</span>';
			$(this).html('More'+' '+headerText).removeClass('close');
			$(this).parent('.showToggle').prev('.inner-soc').hide();
			$('#dhr03 .inner-soc ul li a').attr('tabindex','-1');
			return false;
		}
	);
	$('#dhr03 .pinkBox .showToggle a').toggle(
		function(){
			var headerText = $(this).parent('.showToggle').prev('ul').prev('h3').text();
			headerText = '<span class="access">'+' '+headerText+'</span>'; 
			$(this).html('Close'+' '+headerText).addClass('close');
			$(this).parent('.showToggle').prev('ul.more').children('.noShow').show().children('a').removeAttr('tabindex');
			return false;
		},
		function(){
			var headerText = $(this).parent('.showToggle').prev('ul').prev('h3').text();
			headerText = '<span class="access">'+' '+headerText+'</span>'; 
			$(this).html('More'+' '+headerText).removeClass('close');
			$(this).parent('.showToggle').prev('ul.more').children('.noShow').hide().children('a').attr('tabindex','-1');
			return false;					 
		}
	);	
}

(function($){
	$.fn.hoverIntent = function(f,g) {
		var cfg = {
			sensitivity: 7,
			interval: 200,
			timeout: 0
		};
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );
		var cX, cY, pX, pY;
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				pX = cX; pY = cY;
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};
		var handleHover = function(e) {
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }
			var ev = jQuery.extend({},e);
			var ob = this;
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
			if (e.type == "mouseover") {
				pX = ev.pageX; pY = ev.pageY;
				$(ob).bind("mousemove",track);
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
			} else {
				$(ob).unbind("mousemove",track);
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};
		return this.mouseover(handleHover).mouseout(handleHover);
	};
})(jQuery);

/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"></span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};
	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 400,
		animation	: {opacity:'show'},
		speed		: 0,
		autoArrows	: false,
		dropShadows : false,
		disableHI	: false,
		onInit		: function(){},
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);

function addAlert() {
	$('.tab-nav li.first').addClass('altOn');
	if ($('.tab-nav li.first').hasClass('active')) {
		$('#c07').addClass('alert-box');
	}
	else {
		$('#c07').removeClass('alert-box');
	}
}

function addNormal() {
	var activeTop = $('.tab-nav li.first').hasClass('active');
	if (activeTop) {
		$('.tab-nav').addClass('noAlert');
	}
	else {
		$('.tab-nav').removeClass('noAlert');
	}
}

function runCarousel() {
	$(".items").each (function() {
		if (($(this).children('li').size()) > 1) {
			var carouselItem = 0;
			var itemParent = this;
			$(this).children('li:first').addClass('active');
			$(this).children('li:not(:first)').addClass('hide');		
			function nextItem() {
				if (carouselItem < ($(itemParent).children('li').size() - 1)) {
					carouselItem++;
					if ($(itemParent).prev('.controls').children('.previous-slide').length === 0) {
						$(itemParent).prev('.controls').prepend(prevLink);
						$(itemParent).prev('.controls').children('.previous-slide').bind('click',prevItem);
					}
				}
				if (carouselItem === ($(itemParent).children('li').size() - 1)) {
					$(itemParent).prev('.controls').children('.next-slide').remove();
				}
				$(itemParent).children('li').removeAttr('class');
				$(itemParent).children('li:eq('+String(carouselItem)+')').addClass('active');
				$(itemParent).children('li:not(:eq('+String(carouselItem)+'))').addClass('hide');
				return false;
			}
			function prevItem() {
				if (carouselItem > 0) {
					carouselItem--;
				}
				if (carouselItem === ($(itemParent).children('li').size() - 2)) {
					$(itemParent).prev('.controls').append(nextLink);
					$(itemParent).prev('.controls').children('.next-slide').bind('click',nextItem);					
				}
				if (carouselItem === 0) {
					$(itemParent).prev('.controls').children('.previous-slide').remove();
				}
				$(itemParent).children('li').removeAttr('class');
				$(itemParent).children('li:eq('+String(carouselItem)+')').addClass('active');
				$(itemParent).children('li:not(:eq('+String(carouselItem)+'))').addClass('hide');
				return false;
			}	
			var openLinks = '<ul class="controls">';
			var nextLink = '<li class="next-slide"><a href="#">Next<span class="access"> slide</span></a></li>';
			var prevLink = '<li class="previous-slide"><a href="#">Previous<span class="access"> slide</span></a></li>';
			var closeLinks = '</ul>';
			$(this).parent('.wrapper').prepend(openLinks+nextLink+closeLinks);
			$(this).prev('.controls').children('.next-slide').bind('click',nextItem);
		}		
	});
}
	
function setPanelHeight() {

	function calcPad(e) {
		return parseInt($(e).css('padding-top').replace(/px,*\)*/g,"")) + parseInt($(e).css('padding-bottom').replace(/px,*\)*/g,""));
	}
	
	function roundUp(number) {
		var calc = Math.round(number / 4)*4;
		if (calc < number) {
			number = calc + 4;
		}
		else {
			number = calc;	
		}
		return number;
	}
	
	var spanLoc = $('#centralPanel .tab-nav li a > span');
	var spanLocLast = $('#centralPanel .tab-nav li a > span:last');
	var tabLoc = $('.tab-content');
	var tabNavLoc = $('.tab-nav-wrap');
	
	var tabButtonHeight = 0;
	$(spanLoc).each(function() {
		$(this).removeAttr('style');
		if ($(this).height() > tabButtonHeight) {
			tabButtonHeight = $(this).height();
		}
	});

	$(spanLoc).each(function() {
		if ($.browser.msie && $.browser.version == 6.0) {
			$(this).height(Math.round(tabButtonHeight+calcPad(this)+2));
		}
		else {
			$(this).height(Math.round(tabButtonHeight));
		}
	});
	
	var tabContentHeight = 0;
	$(tabLoc).each(function() {
		$(this).removeAttr('style');
		if ($(this).height() > tabContentHeight) {
			tabContentHeight = $(this).height();
		}
	});
	
	$(tabNavLoc).removeAttr('style');
	var tabHeight = $(tabNavLoc).height();
	
	if (tabHeight >= tabContentHeight) {
		$(tabLoc).height($(tabNavLoc).height()-6);	
	}
	else {
		$(tabLoc).height(roundUp(tabContentHeight));
		$(tabNavLoc).height(roundUp(tabContentHeight));
		if ($.browser.msie && $.browser.version == 6.0) {
			$(spanLoc).each(function() {
				$(this).height($(tabNavLoc).height() / 4);
			});
		}
		else {
			$(spanLoc).each(function() {
				$(this).height(($(tabNavLoc).height() / 4) - calcPad(this));
			});
		}
		if ($.browser.msie && $.browser.version == 6.0) {
			$(tabNavLoc).height($(tabNavLoc).height() + 1);
			$(spanLocLast).height($(spanLocLast).height() + 1 + calcPad($(spanLocLast)));
		}
		else {
			$(tabNavLoc).height($(tabNavLoc).height() + 6);
			$(spanLocLast).height($(spanLocLast).height() + 1);
		}
	}
	
	function roundEm(number) {
		var calc = Math.round(number);
		if (calc < number) {
			number = calc + 1;
		}
		else {
			number = calc;	
		}
		return number;		
	}
	
}

function promoHeight() {
	$('$#dhr21 .inner').removeAttr('style');
	var promoHeight = $('#dhr21').height();
	$('$#dhr21 .inner').css({minHeight : promoHeight - 14});
	if ($.browser.msie && $.browser.version == 6.0) {
		$('$#dhr21 .inner').css({height : promoHeight});
	}
}
	
function setupPanel() {	
	$('#c07').addClass('panel-enabled');
	var tabCon = $('#centralPanel .tab-content');
	for (var i=0; i < tabCon.length; i++) {
		var tabs = tabCon[i];
		tabId = "tab-content-"+i;
		$(tabs).attr('id', tabId);
	}
	var tabNav = '<div class="tab-nav-wrap"><ul class="tab-nav">';
	var tabText = $('#centralPanel h2');
	var linkText = $('#centralPanel p.linkText');
	for (var i=0; i < tabText.length; i++) {
		var textHeader = tabText[i].innerHTML;
		var linkHeader = linkText[i].innerHTML;
		tabNavLI = '<li><div><a href="#tab-content-'+i+'"><span>'+textHeader+' <br /><span class="internalLink">'+linkHeader+'</span></span></a></div></li>';
		tabNav = tabNav+tabNavLI;
	}
	tabNav = tabNav+'</ul></div>';
	$('#centralPanel h2, #centralPanel .linkText').addClass('access');
	$('#centralPanel').prepend(tabNav);
	$('#centralPanel .tab-nav li:first-child').addClass('first');
	$('#centralPanel .tab-content').addClass('disable');
	$('#centralPanel .tab-nav li:first').addClass('active');
	$('#centralPanel .tab-content:first').removeClass('disable');
	if ($('#centralPanel #dhr13').length > 0 ) {
		addAlert();
	}
	else {
		addNormal();
	}
	$('#centralPanel .tab-nav li a').click(function() {						
		$('#centralPanel .tab-nav li').removeClass('active');
		$('#centralPanel .tab-nav').removeAttr('style');
		var activeTab = $(this).attr('href');
		activeTab = activeTab.split('#');
		activeTab = '#'+activeTab[1];
		$(this).parent('div').parent('li').addClass('active');
		$("#centralPanel .tab-content").addClass('disable');
		$(activeTab).removeClass('disable');
		if ($('#centralPanel #dhr13').length > 0 ) {
			addAlert();
		}
		if ($('#centralPanel #dhr13').length == 0) {
			addNormal();
		}	
		return false;
	});
	$('#centralPanel .tab-nav li div').hover(
		function(){
			$(this).addClass('hover');
			var hoverTop = $(this).parent('li').hasClass('first');
			var activeTop = $(this).parent('li').hasClass('active');
			if ($('#dhr13').length > 0 && hoverTop && activeTop) {
				$('.tab-nav').css({backgroundPosition : '-460px top'});
			}
			else if ($('#dhr13').length > 0 && hoverTop) {
				$('.tab-nav').css({backgroundPosition : '-690px top'});
			}
			else if (hoverTop) {
				$('.tab-nav').css({backgroundPosition : '-230px top'});
			}
		},
		function(){
			$(this).removeClass('hover');
			$('.tab-nav').removeAttr('style');
		}
	);	
}

function vidWidth(){
	var vidWidthTo = $(".tab-content").width();
	vidWidthTo = vidWidthTo - 26;
	if (vidWidthTo > 426) {
		var vidWidthTo = 426;
	}
	var vidHeightTo = Math.round(vidWidthTo / 1.777);
	if (vidHeightTo > 240) {
		var vidHeightTo = 240;
	}
	$(".tab-content .video-wrap .video").css({
		height : vidHeightTo, 
		width : vidWidthTo
	});
}

function initFont(){
	var iBase = TextResizeDetector.addEventListener(onFontResize,null);
}

function onFontResize(){
	setPanelHeight();
	promoHeight();	
}

TextResizeDetector.TARGET_ELEMENT_ID = 'c00';
TextResizeDetector.USER_INIT_FUNC = initFont;

$(document).ready(function(){
	
	if ($('#dhr03').length > 0) {
		setupRHM();
	}
	
	$('#dhr06 .sf-menu').removeClass('js-off');
	$('#dhr06 .sf-menu').superfish();
	
	if ($('#home').length > 0) {
		var videoOn = false;
		$(".video-wrap object").each(function() {
			$(this).parent().addClass('video');
			videoOn = true;
		});
		$(".video-wrap embed").each(function() {
			$(this).parent().addClass('video');
			videoOn = true;
		});
		runCarousel();
		setupPanel();
		vidWidth();
		setPanelHeight();
		promoHeight();
	}
	
	
	$('.tab-nav li a').click( function() {
		if ($.browser.msie) {
			if (typeof player1 != "undefined") {
				player1.sendEvent('STOP');
			}
			if (typeof player2 != "undefined") {
				player2.sendEvent('STOP');
			}
			if (typeof player3 != "undefined") {
				player3.sendEvent('STOP');
			}
			if (typeof player4 != "undefined") {
				player4.sendEvent('STOP');
			}
			//if(Silverlight.isInstalled("1.0")) {
				if (typeof ply1 != "undefined" && Silverlight.isInstalled("1.0")) {
					ply1.sendEvent('STOP');
				}		
				if (typeof ply2 != "undefined" && Silverlight.isInstalled("1.0")) {
					ply2.sendEvent('STOP');
				}	
				if (typeof ply3 != "undefined" && Silverlight.isInstalled("1.0")) {
					ply3.sendEvent('STOP');
				}	
				if (typeof ply4 != "undefined" && Silverlight.isInstalled("1.0")) {
					ply4.sendEvent('STOP');
				}
			//}
		}
   });
	
	$(window).resize(function(){
		$.doTimeout('resize', 250, function(){
		if (videoOn) {
			vidWidth();
		}
		setPanelHeight();
		promoHeight();
	  });
	});

});

