//<![CDATA[
// load handler
$(document).ready(function () {
	
	var TemplateB = Template.extend();
	TemplateB.init = function() {
		this.renderStraplines();
		this.renderTitles('#c-main h3, #foot-panel dt');
		ModuleManager.init('#column2-of-2 .module300-glass.expandable');
		changeLineHeightforCn.init();
	}	
	
	TemplateB.init();

	
	// correct IE6 display bug
	StyleSwitcher.onNarrowband = function() {
		var interval = setInterval(function() {
			$('#column2-of-2 .module300-glass .head h3').each(function() {
				clearInterval(interval);
				$(this).css('float','none'); 
			});
		},10);
	};
	StyleSwitcher.onBroadband = function() {
		var interval = setInterval(function() {
			$('#column2-of-2 .module300-glass .head h3').each(function() {
				clearInterval(interval);
				$(this).css('float','left'); 
			});
		},10);
	};


});

/**
 * Class for managing template-specific scripts
 */

/*
var TemplateB =
{
	_modules: null
	,
	init: function () {
		this.doSIFR();
		this.initModules();
	}
	,
	doSIFR: function () {
		if (typeof sIFR == "function")
		{
			// sIFR wMode causes strange layout issues, so read current color styles to apply to sIFR
			// define templates
			if(document.getElementById('strapline1')){
			var strapline1 = named({
				sFlashSrc:	"https://secure.cmax.americanexpress.com/Internet/International/sharedDotCom/flash/AgendaLt.swf",
				sColor:		rgb2hex($('#strapline1 h2').css('color')),
				sBgColor:	rgb2hex($('#strapline1 h2').css('background-color')),
        sWmode:		"opaque",
				sFlashVars:	"textalign=center"
			});
			}
			if(document.getElementById('strapline2')){
				
			var strapline2 = named({
				sFlashSrc:	"https://secure.cmax.americanexpress.com/Internet/International/sharedDotCom/flash/AgendaLt.swf",
				sColor:		rgb2hex($('#strapline2 h2').css('color')),
				sBgColor:	rgb2hex($('#strapline2 h2').css('background-color')),
        sWmode:		"opaque",
				sFlashVars:	"textalign=center"
			});
			}
			var blueHeader = named({
				sFlashSrc:	"https://secure.cmax.americanexpress.com/Internet/International/sharedDotCom/flash/Agenda.swf",
				sColor:		"#5d8db1",
				sWmode:		"transparent",
				sFlashVars:	""
			});
			//textalign=center in FlashVars is causing problems with 'low graphic' stylesheet (css/light/light.css)
			
			// replace elements
			if(document.getElementById('strapline1')){
				sIFR.replaceElement('#strapline1 h2', strapline1);
			}
			if(document.getElementById('strapline2')){
				sIFR.replaceElement('#strapline2 h2', strapline2);
			}
			sIFR.replaceElement('#c-main h3', blueHeader);
			sIFR.replaceElement('#foot-panel dt', blueHeader);
		};
	}
	,	
	initModules: function () {
		//ModuleManager.init('#column2-of-2 .panel-308-exp');
		ModuleManager.init('#column2-of-2 .module300-glass.expandable');
	}	
} */

/**
 * Manage the collapsing/expanding modules
 **/
var ModuleManager = 
{
	_accessor: null
	,
	init: function (accessor)
	{
		this._accessor = accessor;
		this.setStates('');
		// scope hack
		var that = this;
		// bind click events
		$(this._accessor + ' .head').each(
			function (index) {
				$(this).css('cursor', 'pointer');
				$(this).bind('click', {scope: that, obj: $(this)}, that.handleClick);
			}
		);
	}
	,
	setStates: function (state) 
	{
		$(this._accessor).each(
			function () {
				$(this).removeClass('expanded');
				$(this).removeClass('collapsed');
				$(this).addClass(state);
			}
		)
	}
	,
	handleClick: function (event)
	{
		var o = $(event.data.obj).parent();
		if (o.is('.expanded')) {
			event.data.scope.setStates('');
		} else {
			event.data.scope.setStates('collapsed');
			o.removeClass('collapsed').addClass('expanded');
		}
	}
}

//Function to fix the characters truncating issue in Cantanese pages
var changeLineHeightforCn = 
{
	init: function () { 
		if (StyleSwitcher.isCantanese() == false) return;
		$('.module300-glass.expandable .head h3').css('line-height','1.4');
        $('#h-page-tools a').css('line-height','1.4');
		$('.module300-glass .body .content a').css('line-height','1.6');
	}
}
//]]>