$(function(){

	// Setup font resizer
	$('#layer-body').fontresizer({excluded: '#layer-menu-main'});
	
	// Capture the link on header menu and open new window
	$('#layer-menu-top a').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	
	// Fixed IE 6 width
	if(is_ie6()) {
		$('#layer-teasers').width($('body').width());
		$('#layer-teasers-cop').width($('body').width());
		$('#layer-teasers-portal').width($('body').width());

		$(window).resize(function(){
			$('#layer-teasers').width($('body').width());
			$('#layer-teasers-cop').width($('body').width());
			$('#layer-teasers-portal').width($('body').width());
		});
	}

	// Glossary tooltip
	$("a.link-glossary").tooltip({
		track: true, 
		showURL: false
	});		
	
	// Initialise collapsible toggle 				
	$('a.toggle-item').click(function(){
		if($(this).hasClass('collapse')) {
			$(this).removeClass('collapse');
			$('#'+$(this).attr('rel')).show();
			// Toggle Hide/Show wordings
			$('span.expand', this).hide();	
			$('span.collapse', this).show();
			
		} else {
			$(this).addClass('collapse');
			$('#'+$(this).attr('rel')).hide();
			// Toggle Hide/Show wordings
			$('span.expand', this).show();	
			$('span.collapse', this).hide();	
		}		
		return false;
	});		
	// Hide default wordings 
	$('a.toggle-item').each(function(){
		var toggleItem = $('#'+$(this).attr('rel'));
		if(toggleItem.hasClass('hidden')){
			toggleItem.removeClass('hidden');
			
			$(this).addClass('collapse');
			toggleItem.hide();
			$('span.collapse', this).hide();
		}
		else {

			$('span.expand', this).hide();
		}
	});	
	
	// Equal height for left column
	var sHeight = $('#layer-body').height();
	$('#layer-left-panel').height(sHeight);
	$('#layer-bg-left-panel').height(sHeight);
	$('#layer-col-2').height(sHeight-50); // ugly hack
	
	// For Faq
	$('a.toggle-item').click(function(){
		if($(this).hasClass('collapse')) {
			$('#layer-left-panel').height(sHeight);
			$('#layer-bg-left-panel').height(sHeight);
			$('#layer-col-2').height(sHeight-50);
		} else {
			var sHeight2 = $('#layer-body').height();
			$('#layer-left-panel').height(sHeight2);
			$('#layer-bg-left-panel').height(sHeight2);
			$('#layer-col-2').height(sHeight2-50); // ugly hack	
		}		
		return false;
	});
	
	$("label.overlabel").overlabel();
	
	// pullquote functions
	$('span.pullquote-left').each(function() {
		var parentTag = $(this).parent();
		var newNode = $('<blockquote class="pulledquote"></blockquote>');
		
		$(this).removeClass('pullquote-left');
		$('<span class="pulledquote-text>'+$(this).html()+'</span>').appendTo(newNode);
		$('<span class="pullquote-bottom"></span>').appendTo(newNode);
		newNode.removeClass('pullquote-left');
		newNode.addClass('pulledquote-left').prependTo( $(this).parent());
		
	});
	
	$('span.pullquote-right').each(function() {
		var parentTag = $(this).parent();
		var newNode = $('<blockquote class="pulledquote"></blockquote>');
		
		$(this).removeClass('pullquote-right');
		newNode.html('<span class="pulledquote-text>'+$(this).html()+'</span>');
		$('<span class="pullquote-bottom"></span>').appendTo(newNode);
		newNode.removeClass('pullquote-right');
		newNode.addClass('pulledquote-right').prependTo( $(this).parent());
	});
	
	$('span.pullquote-center').each(function() {
		var newNode = $('<blockquote class="pulledquote"></blockquote>');
		
		$(this).removeClass('pullquote-center');
		newNode.html('<span class="pulledquote-text>'+$(this).html()+'</span>');
		$('<span class="pullquote-bottom"></span><span style="display:block;clear:both></span>"').appendTo(newNode);
		newNode.removeClass('pullquote-center');
		newNode.addClass('pulledquote-center').prependTo($(this).parent());
	});
	
});	

function is_ie6(){
	return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined));
}