var fVersion=deconcept.SWFObjectUtil.getPlayerVersion();
var queryStr=String(window.location);
var useFlash=(fVersion['major']>=8) ? ((queryStr.indexOf('?noflash')>=0) ? false : true ) : false ;

var isAnimating=true;
var setupComplete=false;
var cTab;
var cSubTab;
var config=new Object();
config['introDelay']=1;
config['fps']=20;
config['introDuration']=2;
config['animTime']=0.3;
config['animTimeLong']=0.7;
config['subtabDisplayTime']=5;

var playbackTimer;

function doFlash(whichTarget,whichSwf,txtContent) {
	var so = new SWFObject(whichSwf, 'flash', '300', '200', '8', '#ffffff');
	so.addVariable('xmlTxtStr',txtContent);
	so.addParam('wmode','transparent');
	so.write(whichTarget.select('.pageFlash')[0]);
}

function switchMainTab(which) {
	if (!isAnimating && (cTab!=which)) {
				
		isAnimating=true;
		cTab=which;
		cSubTab=1;
		playbackTimer.stop();
		$$('.tab').each(function(e){$(e).style.backgroundPosition=$(e).readAttribute('originalBgPos');});
		$$('.buttonSmall').each(function(e){
			$(e).select('.smallButtonLeft')[0].style.backgroundPosition='0px 0px';
			$(e).select('.smallButtonCenter')[0].style.backgroundPosition='0px -50px';
			$(e).select('.smallButtonRight')[0].style.backgroundPosition='-14px 0px';
		});
		if (cTab!='page0') {$(cTab.replace('page','tab')).style.backgroundPosition='0px -320px';}
		switch (cTab) {
			case 'page0':
			case 'page5':
				$(cTab.replace('page','tab')).select('.smallButtonLeft')[0].style.backgroundPosition='0px -25px';
				$(cTab.replace('page','tab')).select('.smallButtonCenter')[0].style.backgroundPosition='0px -75px';
				$(cTab.replace('page','tab')).select('.smallButtonRight')[0].style.backgroundPosition='-14px -25px';
				break;
			default :
				$(cTab.replace('page','tab')).style.backgroundPosition='0px -320px';
			break;
		}
		$$('.pagesForAnims').each(function(e){
			if (cTab!=e.id) {
				new Effect.Opacity(e,{
					framerate: config['fps'],
					duration: config['animTime'],
					to: 0
				});
			}
		});
		setTimeout(function(){
			if (cTab=='page0') {
				$('pageTop').style.display='none';
				$('pageBody').style.display='none';
			} else {
				$('pageTop').style.display='block';
				$('pageBody').style.display='block';
				if ($(cTab).select('.subtabPlayPause').length>0) {
					$(cTab).select('.subtabPlayPause')[0].removeClassName('subtabPlay').addClassName('subtabPause');
				}
				switchSubTab('subtab1');
			}
			$$('.pagesForAnims').each(function(e){$(e).style.display='none';});
			$(cTab).style.display='block';
			if (cTab=='page0') { //resize page to match content (wouldn't have to do this if it weren't for that meddling IE6!)
				$('bgTabs').style.height='329px'; 
			} else {
				$('bgTabs').style.height=$(cTab).getHeight()+'px';
			}
			if (parseInt($('bgTabs').style.height)<329) {
				$('bgTabs').style.height='329px';
			}
		},config['animTime']*1000);
		new Effect.Opacity(cTab,{
			delay: config['animTime'],
			framerate: config['fps'],
			duration: config['animTime'],
			to: 1,
			afterFinish: function() {
				isAnimating=false;
			}
		});
	}
}

function switchSubTab(subTabName) {
	
		//TRACKING
		//make tracking string
		tStr='';
		//main tab
		if ($(cTab.replace('page','tab')).select('div').length) {
			$(cTab.replace('page','tab')).select('div').each(function(e){
				if (e.innerHTML!='') {tStr+=e.innerHTML.stripTags()+' ';}
			});
		} else {
			$(cTab.replace('page','tab')).select('td').each(function(e){
				if (e.innerHTML!='') {tStr+=e.innerHTML.stripTags()+' ';}
			});
		}
		//sub tab
		if ($$('#'+cTab+' .subTabs .'+subTabName+' a').length) {
			tStr+=': '+$$('#'+cTab+' .subTabs .'+subTabName+' a')[0].innerHTML;
		}
		//do tracking
		var s=s_gi('emc-emccom');
		s.dynamicAccountSelection=true
		s.dynamicAccountList="emc-lithuania=lithuania.emc.com;emc-latvia=latvia.emc.com;emc-estonia=estonia.emc.com;emc-slovakia=slovakia.emc.com;emc-slovenia=slovenia.emc.com;emc-argentina=argentina.emc.com;emc-australia=australia.emc.com;emc-austria=austria.emc.com;emc-belgium=belgium.emc.com;emc-brazil=brazil.emc.com;emc-canada=canada.emc.com;emc-chile=chile.emc.com;emc-china=china.emc.com;emc-colombia=colombia.emc.com;emc-czech=czech.emc.com;emc-denmark=denmark.emc.com;emc-venezuela=venezuela.emc.com;emc-finland=finland.emc.com;emc-france=france.emc.com;emc-germany=germany.emc.com;emc-greece=greece.emc.com;emc-hk=hk.emc.com;emc-hungary=hungary.emc.com;emc-india=india.emc.com;emc-israel=israel.emc.com;emc-italy=italy.emc.com;emc-japan=japan.emc.com;emc-korea=korea.emc.com;emc-mexico=mexico.emc.com;emc-middleeast=middle-east.emc.com;emc-netherlands=netherlands.emc.com;emc-norway=norway.emc.com;emc-peru=peru.emc.com;emc-poland=poland.emc.com;emc-portugal=portugal.emc.com;emc-puertorico=puertorico.emc.com;emc-russia=russia.emc.com;emc-singapore=singapore.emc.com;emc-singapore=southasia.emc.com;emc-southafrica=southafrica.emc.com;emc-spain=spain.emc.com;emc-suisse=suisse.emc.com;emc-sweden=sweden.emc.com;emc-switzerland=switzerland.emc.com;emc-taiwan=taiwan.emc.com;emc-turkey=turkey.emc.com;emc-uk=uk.emc.com;emc-indonesia=indonesia.emc.com;emc-thailand=thailand.emc.com;emc-malaysia=malaysia.emc.com;emc-philippines=philippines.emc.com;emc-dev2008=.isus.emc.com;emc-emccom=."
		s.tl(true,'o',window.s.pageName+': '+tStr);
		//END TRACKING

	cSubTab=Number(subTabName.slice(subTabName.indexOf('subtab')+6));
	$(cTab).select('td').each(function(e){
		temp=$(e).className;
		temp=temp.replace('on','off');
		$(e).className=temp;
	});
	$(cTab).select('a').each(function(e){
		e.style.color='#6c6c6c';
	});
	$$('.'+subTabName).each(function(e){
		temp=$(e).className;
		temp=temp.replace('off','on');
		$(e).className=temp;
		if ($(e).hasClassName('onCenter')) {
			$(e).select('a')[0].style.color='#ca9217';
		}
	});
	$(cTab).select('.pageContent').each(function(e){$(e).style.display='none';});
	$(cTab).select('div.'+subTabName)[0].style.display='block';
	if (($(cTab).select('div.'+subTabName+' .pageFlash').length>0) && useFlash) {
		doFlash($(cTab).select('div.'+subTabName)[0],$(cTab).select('div.'+subTabName+' .pageFlash')[0].readAttribute('flashurl'),$(cTab).select('div.'+subTabName+' .pageFlash')[0].readAttribute('flashxmltxt'));
	}
}

var gateAnimations=new Array();
function doIntro() {
	new Effect.Morph($('gateLeft'),{
		delay: config['introDelay'],
		framerate: config['fps'],
		duration: config['introDuration'],
		style: {
			width: '0px'
		}
	})
	new Effect.Morph($('gateLeftHandle'),{
		delay: config['introDelay'],
		framerate: config['fps'],
		duration: config['introDuration'],
		style: {
			left: '0px'
		}
	})
	new Effect.Morph($('gateRight'),{
		delay: config['introDelay'],
		framerate: config['fps'],
		duration: config['introDuration'],
		style: {
			width: '0px',
			left: '599px'
		}
	})
	$('gateRight').select('img')[0].style.position='relative';
	new Effect.Morph($('gateRight').select('img')[0],{
		delay: config['introDelay'],
		framerate: config['fps'],
		duration: config['introDuration'],
		style: {
			left: '-289px'
		}
	})
	new Effect.Morph($('gateRightHandle'),{
		delay: config['introDelay'],
		framerate: config['fps'],
		duration: config['introDuration'],
		style: {
			left: '589px'
		},
		afterFinish: function() {
			$('gateLeft').style.display='none';
			$('gateRight').style.display='none';
			new Effect.Opacity('gateLeftHandle',{ from: 1, to: 0, duration: config['animTime'] });
			new Effect.Opacity('gateRightHandle',{ from: 1, to: 0, duration: config['animTime'] });
		}
	})
	
	cumulativeDelay=config['introDuration']+config['introDelay']+config['animTime'];
	$$('.tab').each(function(e){
		new Effect.Opacity($(e),{
			delay: cumulativeDelay,
			framerate: config['fps'],
			duration: config['animTime'],
			to: 1
		});
		cumulativeDelay+=config['animTime'];
	});
	$$('.buttonSmall').each(function(e){
		new Effect.Opacity($(e),{
			delay: cumulativeDelay,
			framerate: config['fps'],
			duration: config['animTime'],
			to: 1
		});
		cumulativeDelay+=config['animTime'];
	});

	//final setup and interaction enabler
	setTimeout(function() {
		
		isAnimating=false;
		
		//'click' the first gallery image
		clickedThumb=$$('.galleryThumb')[0].identify();
		$$('.galleryThumb')[0].style.border='1px solid #e39300';
		$('galleryLargeWrapper').insert({bottom:'<img id="galleryLarge" src="'+$$('.galleryThumb')[0].src.replace(/thumb/,'large')+'" onload="this.style.display=\'block\';"/>'});

	},cumulativeDelay);
}

function setup() {
	cTab='page0';
	$(cTab).select('.titleText')[0].style.display='block';
	$(cTab).style.backgroundPosition='0px 10px';
	$('bgTabs').style.height='329px'; 
	playbackTimer=new PeriodicalExecuter(function(){},1000); //dummy to prevent errors
	$$('.tab').each(function(e){
		$(e).writeAttribute('originalBgPos',e.style.backgroundPosition);
		$(e).setOpacity(0);
		$(e).style.visibility='visible';
	});
	$$('.buttonSmall').each(function(e){
		$(e).setOpacity(0);
		$(e).style.visibility='visible';
	});
	$(cTab.replace('page','tab')).select('.smallButtonLeft')[0].style.backgroundPosition='0px -25px';
	$(cTab.replace('page','tab')).select('.smallButtonCenter')[0].style.backgroundPosition='0px -75px';
	$(cTab.replace('page','tab')).select('.smallButtonRight')[0].style.backgroundPosition='-14px -25px';
	
	setupComplete=true;

	setTimeout(doIntro, 500); // had to do this because of IE refusing to do scriptaculous when called in onload events
}
Event.observe(window, 'load', setup);

/* COMPRESSED VERSION OF BEHAVIOUR */
/* Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work of Simon Willison http://ripcord.co.nz/behaviour/ */   
var Behaviour={list:new Array,register:function(_1){Behaviour.list.push(_1);},start:function(){Behaviour.addLoadEvent(function(){Behaviour.apply();});},apply:function(){for(h=0;sheet=Behaviour.list[h];h++){for(selector in sheet){list=document.getElementsBySelector(selector);if(!list){continue;}for(i=0;element=list[i];i++){sheet[selector](element);}}}},addLoadEvent:function(_2){var _3=window.onload;if(typeof window.onload!="function"){window.onload=_2;}else{window.onload=function(){_3();_2();};}}};Behaviour.start();function getAllChildren(e){return e.all?e.all:e.getElementsByTagName("*");};document.getElementsBySelector=function(_5){if(!document.getElementsByTagName){return new Array();}var _6=_5.split(" ");var _7=new Array(document);for(var i=0;i<_6.length;i++){token=_6[i].replace(/^\s+/,"").replace(/\s+$/,"");if(token.indexOf("#")>-1){var _9=token.split("#");var _a=_9[0];var id=_9[1];var _c=document.getElementById(id);if(_a&&_c.nodeName.toLowerCase()!=_a){return new Array();}_7=new Array(_c);continue;}if(token.indexOf(".")>-1){var _9=token.split(".");var _a=_9[0];var _d=_9[1];if(!_a){_a="*";}var _e=new Array;var _f=0;for(var h=0;h<_7.length;h++){var _11;if(_a=="*"){_11=getAllChildren(_7[h]);}else{_11=_7[h].getElementsByTagName(_a);}for(var j=0;j<_11.length;j++){_e[_f++]=_11[j];}}_7=new Array;var _13=0;for(var k=0;k<_e.length;k++){if(_e[k].className&&_e[k].className.match(new RegExp("(\\s+|^)"+_d+"(\\s+|$)"))){_7[_13++]=_e[k];}}continue;}if(token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)){var _a=RegExp.$1;var _15=RegExp.$2;var _16=RegExp.$3;var _17=RegExp.$4;if(!_a){_a="*";}var _e=new Array;var _f=0;for(var h=0;h<_7.length;h++){var _11;if(_a=="*"){_11=getAllChildren(_7[h]);}else{_11=_7[h].getElementsByTagName(_a);}for(var j=0;j<_11.length;j++){_e[_f++]=_11[j];}}_7=new Array;var _13=0;var _18;switch(_16){case "=":_18=function(e){return (e.getAttribute(_15)==_17);};break;case "~":_18=function(e){return (e.getAttribute(_15).match(new RegExp("(^|\\s+)"+_17+"(\\s+|$)")));};break;case "|":_18=function(e){return (e.getAttribute(_15).match(new RegExp("^"+_17+"-?")));};break;case "^":_18=function(e){return (e.getAttribute(_15).indexOf(_17)==0);};break;case "$":_18=function(e){return (e.getAttribute(_15).lastIndexOf(_17)==e.getAttribute(_15).length-_17.length);};break;case "*":_18=function(e){return (e.getAttribute(_15).indexOf(_17)>-1);};break;default:_18=function(e){return e.getAttribute(_15);};}_7=new Array;var _13=0;for(var k=0;k<_e.length;k++){if(_18(_e[k])){_7[_13++]=_e[k];}}continue;}if(!_7[0]){return;}_a=token;var _e=new Array;var _f=0;for(var h=0;h<_7.length;h++){var _11=_7[h].getElementsByTagName(_a);for(var j=0;j<_11.length;j++){_e[_f++]=_11[j];}}_7=_e;}return _7;};

var clickedThumb='';

Behaviour.register({
	'.pageFlash' : function (e) { //set up flash URLs and text
		txtStr='<xml>';
		$(e).select('div').each(function(e2){
			txtPieceClasses=$w(e2.className).each(function(e3){
				txtStr+='<textlabel id="'+e3+'">'+e2.innerHTML+'</textlabel>';
			});
		});
		txtStr+='<textlabel id="replay">'+replayTextLabel+'</textlabel>';
		txtStr+='</xml>';
		// double quote compatibility, this f/r will be reversed in flash
		changeArray=new Array();
		processedText=txtStr.split('"').join('[[DQ]]').split('<br>').join('[[BR]]').split('<br/>').join('[[BR]]').split('<BR>').join('[[BR]]').split('<BR/>').join('[[BR]]').split('<b>').join('[[B]]').split('</b>').join('[[/B]]').split('<B>').join('[[B]]').split('</B>').join('[[/B]]').split('<i>').join('[[I]]').split('</i>').join('[[/I]]').split('<I>').join('[[I]]').split('</I>').join('[[/I]]');
		txtStr=processedText;//escape(processedText);
		$(e).writeAttribute('flashxmltxt',txtStr);
		$(e).writeAttribute('flashurl',$(e).select('img')[0].src.split('-noflash').join('').split('.gif').join('.swf').split('.jpg').join('.swf'));
	},
	'a.tab' : function(e) { // main tabs
		e.onmouseover=function() {
			if (!isAnimating) {
				e.style.backgroundPosition='0px -320px';
			}
		};
		e.onmouseout=function() {
			if (cTab!=e.id.replace('tab','page')) {
				e.style.backgroundPosition=$(e).readAttribute('originalBgPos');
			}
		};
		e.onclick=function() {
			if (!isAnimating) {
				e.style.backgroundPosition='0px -320px';
				switchMainTab(e.id.replace('tab','page'));
				return false;
			}
		};
	},
	'.subTabs a' : function(e) { // sub tabs
		e.onmouseover=function() {
			if (!isAnimating && $(e).parentNode.hasClassName('offCenter')) {
				e.style.color='#000000';
			}
		};
		e.onmouseout=function() {
			if (!$(e).parentNode.hasClassName('onCenter')) {
				e.style.color='#6c6c6c';
			}
		};
		e.onclick=function() {
			if (!isAnimating) {
				switchSubTab($w($(e).parentNode.className)[1]);
				e.style.color='#ca9217';
				return false;
			}
		};
	},
	'a.buttonSmall' : function (e) {
		e.onmouseover=function() {
			if (!isAnimating) {
				$(e).select('.smallButtonLeft')[0].style.backgroundPosition='0px -25px';
				$(e).select('.smallButtonCenter')[0].style.backgroundPosition='0px -75px';
				$(e).select('.smallButtonRight')[0].style.backgroundPosition='-14px -25px';
			}
		};
		e.onmouseout=function() {
			if (cTab!=e.id.replace('tab','page')) {
				$(e).select('.smallButtonLeft')[0].style.backgroundPosition='0px 0px';
				$(e).select('.smallButtonCenter')[0].style.backgroundPosition='0px -50px';
				$(e).select('.smallButtonRight')[0].style.backgroundPosition='-14px 0px';
			}
		};
		e.onclick=function() {
			if (!isAnimating) {
				$(e).select('.smallButtonLeft')[0].style.backgroundPosition='0px -25px';
				$(e).select('.smallButtonCenter')[0].style.backgroundPosition='0px -75px';
				$(e).select('.smallButtonRight')[0].style.backgroundPosition='-14px -25px';
				switchMainTab(e.id.replace('tab','page'));
				return false;
			}
		};
	},
	'.galleryThumb' : function (e) {
		e.onclick=function() {
			if ($(e).identify()!=clickedThumb) {
				$('galleryLarge').remove();
				$$('.galleryThumb').each(function(othere){
					othere.style.border='1px solid #666666';
				});
				clickedThumb=$(e).identify();
				e.style.border='1px solid #e39300';
				$('galleryLargeWrapper').insert({bottom:'<img id="galleryLarge" src="'+$(e).src.replace(/thumb/,'large')+'" onload="this.style.display=\'block\';"/>'});
			}
		}
		e.onmouseover=function() {
			if ($(e).identify()!=clickedThumb) {
				e.style.border='1px solid #2e89d5';
			}
		}
		e.onmouseout=function() {
			if ($(e).identify()!=clickedThumb) {
				e.style.border='1px solid #666666';
			}
		}
	},
	'#galleryLargeWrapper' : function (e) {
		e.onclick=function() {
			window.open($('galleryLarge').src.replace(/large/,'hires'),'cx4hires');
		}
		e.onmouseover=function() {
			$('galleryHiresLink').style.backgroundImage='url(/microsites/cx4/images/link_hires_bullet_on.gif)';
		}
		e.onmouseout=function() {
			$('galleryHiresLink').style.backgroundImage='url(/microsites/cx4/images/link_hires_bullet_off.gif)';
		}
	}
});