var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var lastOpened = ''

function showHistoryPop(e)
{
	Event.stop(e);
	var element = e.element();
	var timeBox = element.up();
	if (timeBox.id == "") {
		timeBox = element.up(1);
	}	
	var timeBox_pos = timeBox.positionedOffset();
	var boxID = timeBox.id;
	lastOpened = boxID.sub('year', '');
	pageTracker._trackEvent('History', 'Opened', 'Opened History for Year '+lastOpened);
	if (timeBox.hasClassName('lastCol'))
	{
		var posX = timeBox_pos[0]-118;
	}
	else
	{
		var posX = timeBox_pos[0]-6;
	}
	if (timeBox.hasClassName('lastRow'))
	{
		var posY = timeBox_pos[1]-115;
	}
	else
	{
		var posY = timeBox_pos[1]-6;
	}
	
	//alert(timeBox.id);
	//alert("x="+timeBox_pos[0]+" y="+timeBox_pos[1]);
	var popYear = timeBox.down('h4').innerHTML;
	var popTitle = timeBox.down('div.title').innerHTML;
	var popDescription = timeBox.down('div.descriptor').innerHTML;
	if (IE6) {  var bg = 'transparent url(/img/history/'+boxID.sub('year', '')+'.gif)';  }
	else{ var bg = 'transparent url(/img/history/'+boxID.sub('year', '')+'.png)'; }
	
	//insert($('popYear'), popYear);
	
	$('popYear').update(popYear);
	$('popTitle').update(popTitle);
	$('popDescription').update(popDescription);
	
	$('historyPop').setStyle({ background: bg });
	
	if ((timeBox.id == "year1945")||(timeBox.id == "year1950")||(timeBox.id == "year1969")||(timeBox.id == "year1979a")||(timeBox.id == "year1979b")||(timeBox.id == "year1992")||(timeBox.id == "year1997c")||(timeBox.id == "year2008a")) {
		$('popDescription').setStyle({ padding: '10px 65px 0px 16px' });
		$('popTitle').setStyle({ padding: '15px 16px 0px 16px' });
	}
	else if ((timeBox.id == "year1959")||(timeBox.id == "year2006a")||(timeBox.id == "year2007")||(timeBox.id == "year2008b")||(timeBox.id == "year2009c")) {
		$('popTitle').setStyle({ padding: '7px 16px 0px 16px' });
		$('popDescription').setStyle({ padding: '4px 16px 0px 16px' });
	}
	else if (timeBox.id == "year1973") {
		$('popDescription').setStyle({ padding: '10px 90px 0px 16px' });
		$('popTitle').setStyle({ padding: '15px 16px 0px 16px' });
	}
	else if (timeBox.id == "year2009a") {
		$('popDescription').setStyle({ padding: '10px 12px 0px 16px' });
		$('popTitle').setStyle({ padding: '15px 16px 0px 16px' });
	}
	else {
		$('popDescription').setStyle({ padding: '10px 16px 0px 16px' });
		$('popTitle').setStyle({ padding: '15px 16px 0px 16px' });
	}
	
	
	new Effect.Move('historyPop', { y: posY, x: posX, mode: 'absolute', duration: 0 });
	

	$('historyPop').show();
}

function hideHistoryPop(e)
{
	Event.stop(e);
	pageTracker._trackEvent('History', 'Closed', 'Closed History for Year '+lastOpened);
	$('historyPop').hide();
}
function hidePresence(){
	$('stationary_presence').hide();
	$('lighters_presence').hide();
	$('shavers_presence').hide();
	
	$('pres_nav_1').removeClassName('sel');
	$('pres_nav_2').removeClassName('sel');
	$('pres_nav_3').removeClassName('sel');
}
function showStationary(e){
	Event.stop(e);
	hidePresence();
	pageTracker._trackEvent('International Presence', 'Clicked', 'Viewed Stationery International Presence');
	$('stationary_presence').show();
	$('pres_nav_1').addClassName('sel');
}
function showLighters(e){
	Event.stop(e);
	hidePresence();
	pageTracker._trackEvent('International Presence', 'Clicked', 'Viewed Lighters International Presence');
	$('lighters_presence').show();
	$('pres_nav_2').addClassName('sel');
}
function showShavers(e){
	Event.stop(e);
	hidePresence();
	pageTracker._trackEvent('International Presence', 'Clicked', 'Viewed Shavers International Presence');
	$('shavers_presence').show();
	$('pres_nav_3').addClassName('sel');
}

function initialize()
{
	$$('.historyLink').each(function (el) {
		Event.observe(el, 'click', showHistoryPop, false);
		
		var timeBox = el.up();
		if (timeBox.id == "") {
			timeBox = el.up(1);
		}
		var boxID = timeBox.id;
		
		//pre cache background images
		bgImage= new Image(230,224);
		if(IE6){ bgImage.src = '/img/history/'+boxID.sub('year', '')+'.gif'; }
		else{ bgImage.src = '/img/history/'+boxID.sub('year', '')+'.png'; }
		
	});	
	if ($('histPopClose') != null) {Event.observe('histPopClose', 'click', hideHistoryPop, false)};
	
	
	if ($('pres_nav_1') != null) {Event.observe('pres_nav_1', 'click', showStationary, false)};
	if ($('pres_nav_2') != null) {Event.observe('pres_nav_2', 'click', showLighters, false)};
	if ($('pres_nav_3') != null) {Event.observe('pres_nav_3', 'click', showShavers, false)};
	
}

Event.observe(window, 'load', initialize, false);
