var oldTempId = '';

function ow2() {
	window.open($('#temporaryOWid').attr('href'));
	if (oldTempId) {
		$('#temporaryOWid').attr('id', oldTempId);
	} else {
		$('#temporaryOWid').attr('id', '');
	}
}

function ow(e) {
	if ($(e).attr('id') == $(e).attr('id')+'') {
		oldTempId = $(e).attr('id');
	}

	$(e).attr('id', 'temporaryOWid');
	setTimeout('ow2()', 0);
	return false;
}

var is_partnership = (typeof(partnership_area) != 'undefined');
var col = (is_partnership ? '008fb4' : 'aa1f6b');

var din = {
    src: '/din.swf'
  };
  sIFR.activate(din);

  sIFR.replace(din, {
    selector: 'body h1',
	css: [
      '.sIFR-root { color: #59595c; }',
	  'em { font-style: normal; color: #'+col+'; }'
    ],
	wmode: 'transparent',
	transparent: true
  });

  sIFR.replace(din, {
    selector: '#menu_container h2, #searchH2',
	css: [
      '.sIFR-root { color: #'+col+'; }'
    ],
	wmode: 'transparent',
	transparent: true
  });

$(document).ready(function(){
	if (typeof($("#news_ticker_list").attr('id')) != 'undefined') {
		$("#news_ticker_list").newsTicker();
	}

	$('#resources_top').bind('click', function() {
		$('#res_arrow_img').attr('src', (($('#res_arrow_img').attr('src').indexOf('/images/resources_arrow'+(is_partnership ? '_blue' : '')+'.gif') > -1) ? '/images/resources_arrow2'+(is_partnership ? '_blue' : '')+'.gif' : '/images/resources_arrow'+(is_partnership ? '_blue' : '')+'.gif'));
		$('#res_arrow_img').attr('alt', (($('#res_arrow_img').attr('alt') == 'collapse resources') ? 'expand resources' : 'collapse resources'));
		$('#res_arrow_img').attr('title', (($('#res_arrow_img').attr('title') == 'collapse resources') ? 'expand resources' : 'collapse resources'));
		$('#resources_content').toggle('fast');
		$('#res_bg_bottom').toggle();
		return false;
	});

	$('#resources_top').css('cursor', 'hand');
	$('#resources_top').css('cursor', 'pointer');

	/*
	 * ... uncommenf the following code to fold resources part on page load
	$('#resources_content').toggle();
	$('#res_bg_bottom').toggle();
	$('#res_arrow_img').attr('alt', 'expand resources');
	$('#res_arrow_img').attr('title', 'expand resources');
	*/


	// assign event listener for background color changes to specific DIVs
	$('div').each(function () {
		if ($(this).attr('class') == 'whiteBG') {
			$(this).bind('mouseover', function() {
				$(this).attr('class', 'greyBG');
			});

			$(this).bind('mouseout', function() {
				$(this).attr('class', 'whiteBG');
			});
		}
	});

	// replace the SAVE AS PDF button with an internal one
	$('img').each(function () {
		if ($(this).attr('src').indexOf('http://web2pdf.freepdfconvert.com') > -1) {
			$(this).attr('src', '/images/make_pdf.gif');
			$(this).attr('width', '106');
			$(this).attr('height', '27');
			$(this).attr('alt', 'make a PDF from this case study');
			$(this).attr('title', 'Opens a new window where the page will be converted into PDF using external conversion service.');
		}
	});

	// mail a friend
	$("a.emailPage").click(function(){
		myWindow = window.open($(this).attr("href"), "emailPage", "width=470, height=400");
		myWindow.focus();
		return false;
	})
});

jQuery(function($) {
	$('a').each(function(){
		if (typeof $(this).attr("title")=="undefined") {
			$(this).attr("title",(typeof $(this).text()!="undefined") ? $(this).text() : "");
		}
	});
	$('a[rel=external],area[rel=external]').click(function(){window.open($(this).attr('href'));return false;}).each(function(){
		$at=$(this).attr('title');
		$linktext = /Link opens in new window/.test($at);
		if (!$linktext) $(this).attr('title',((typeof $at!="undefined") ? $at : $(this).text()) +' - Link opens in new window');
	});
});