//tab click script
var sourceID;
var clickedTab=null;
var tStr=''; //USED FOR TRACKING, UPDATED WITH EVERY TAB CLICK
function tabClick(e,doTracking) {
	if (doTracking==undefined) {doTracking=true;}
	if (e!=clickedTab) {
		clickedTab=e;
		targetID=false;
		checkTarget=e;
		while (!checkTarget.hasClassName('clickableTab')) {
			checkTarget=checkTarget.up();
		}
		checkTargetStr=checkTarget.id.split('-tab').join('');
		window.location.hash=checkTargetStr;
		$$('.clickableTab').each(function(e){e.addClassName('off').removeClassName('on')});
		checkTarget.addClassName('on').removeClassName('off');
		targetID=checkTargetStr+'-content';
		
		//TRACKING - do tracking
		if (doTracking) {
			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.pageName=window.location.pathname+((window.location.search!='')?window.location.search:'')+((window.location.hash!='')?window.location.hash:'');
			s.t();
		}
		//END TRACKING

		//DEACTIVATE ALL VIDEOPLAYERS
		$$('.vPlayer').each(function(e){
			if (!e.select('img')[0]) {
				$(e).update('');
			}
		});

		//HANDLE MENU BAR AND TRACKING
		$$('#primaryContentMenuBar .tabContent').each(function(e){
			e.style.display=(e.id==targetID)?'block':'none';
		});
		
		//activate main flash animation
		initFlashAnimation($(targetID));
		
		setTimeout(function(){initMediaConsole($(targetID));},250); //delay slightly to give main animation a chance to load first
		
	}
}

// activate selected tab
var selectedTabName=window.location.hash.slice(1);	// Get name of tab from URL
var selectedTab = document.getElementById(selectedTabName);
if (!selectedTab) {	// If there is no DIV with the given name  ...
	selectedTabName += '-tab';	// ... give it another try by appending '-tab'
	selectedTab = document.getElementById(selectedTabName);
}
var firstTab = null;
var divs = document.getElementsByTagName('div');	// Search all DIV elements ...
for (var i=0; i<divs.length; ++i)
	if (divs[i].className.indexOf('clickableTab') != -1) {	// ... for a DIV with the CSS class "clickableTab" ...
		firstTab = divs[i];	// ... and store the first in firstTab.
		break;
	}
if (firstTab) {	// Make sure there was at least one DIV with the class "clickableTab"
	if ((!selectedTab) || (selectedTab.id == firstTab.id)) {	// If we have no tab name or its the name of the first tab ...
		firstTab.className = firstTab.className.replace(/\boff\b/, 'on');	// ... then activate first tab.
		document.getElementById(firstTab.id.split('-tab').join('')+'-content').style.display = 'block';
	} else {	// If a tab other than the first one is selected ...
		firstTab.className = firstTab.className.replace(/\bon\b/, 'off');	// ... then deactivate first tab ...
		document.getElementById(firstTab.id.split('-tab').join('')+'-content').style.display = 'none';
		selectedTab.className = selectedTab.className.replace(/\boff\b/, 'on');	// ... and activate the selected tab.
		document.getElementById(selectedTab.id.split('-tab').join('')+'-content').style.display = 'block';
	}
}

//on load, apply tab click script, "click" first tab
function initTabs() {
	$$('.clickableTab').each(function(e){
		if (e.id.indexOf('-tab')<0) {
			e.id=e.id+'-tab';
		}
		e.onclick=function(){
			tabClick(this,true);
		}
	});
	if (BrowserDetect.browser=='Explorer') { // needed for IE6 weirdness fix
		setInterval(function(){document.title=storedWinTitle;},50);
	}	
	setTimeout(function() {
		if (selectedTabName.indexOf('-tab')<0)
			selectedTabName += '-tab';
		if (document.getElementById(selectedTabName)) {
			tabClick($(selectedTabName),true);
		} else {
			tabClick($$('.clickableTab')[0],true);		
		}
	},50);
	/* IE 6 PNG FIX JS */
	if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) &&
	 document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule) {
		setTimeout(function() {
			var pngFixPath='/_admin/css/png-fix/iepngfix.htc';
			// list all CSS rules that need png fix
			// from vmax.css
			document.styleSheets[0].addRule('#threeBoxModule .top', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#threeBoxModule .middle', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#threeBoxModule .bottom', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('.middleTransparentSection', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('.mediaConsoleImageWrapper .mediaConsolePlayButton', 'behavior: url('+pngFixPath+')');
			//from GCF CSS
			document.styleSheets[0].addRule('#msgHorizModule .top', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#msgHorizModule .bottom', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#msgBoxModule .videoBoxFixTop', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#msgBoxModule .videoBoxFixBot', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#msgBoxModule .shareLinkBox', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#transpLayer709 .top', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#transpLayer709 .middle', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#transpLayer709 .bottom', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#transpLayer948 .bottom ', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#transpLayer948 .middle', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('#transpLayer948 .top', 'behavior: url('+pngFixPath+')');
			//from styles.css
			document.styleSheets[0].addRule('.rrBoxModuleMulti .rrBoxModuleTop', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('.rrBoxModuleMulti .rrBoxModuleBody', 'behavior: url('+pngFixPath+')');
			document.styleSheets[0].addRule('.rrBoxModuleMulti .rrBoxModuleBottom', 'behavior: url('+pngFixPath+')');
		},250);
	}
}

//videoplayer activation code
var storedWinTitle=document.title;
function doVideo(which,autoPlay) {
	if (autoPlay==undefined) {
		autoPlay=false;
	}
	if ($(which).select('.videoURL')[0]) {
		targetVP=$(which).select('.vPlayer')[0];
		var imageURL='';
		if (targetVP.select('img')[0]) {
			imageURL=targetVP.select('img')[0].src;
			$(which).insert({bottom:'<div class="imageURLstored" style="display:none;">'+imageURL+'</div>'});
		} else if ($(which).select('.imageURLstored')[0]) {
			imageURL=$(which).select('.imageURLstored')[0].innerHTML;
		}
		targetVP=targetVP.identify();
		videoURL=$(which).select('.videoURL')[0].innerHTML;
		var so = new SWFObject('/campaign/global/videoplayer/videoplayer.swf', 'vPlayer'+targetVP, '240', '165', '8', '#ffffff');
		so.addVariable('videoURL',videoURL);
		so.addVariable('imageURL',imageURL);
		so.addVariable('videoPlayerCSSID','vPlayer'+targetVP);
		so.addVariable('isExplorer',BrowserDetect.browser=='Explorer');
		so.addVariable('popupVideoRolloverText',$('popupVideoRolloverText').innerHTML);
		so.addVariable('tStr',s.pageName);
		so.addVariable('autoPlay',autoPlay);
		if ($(which).select('.videoTitle')[0]) {
			so.addVariable('tStr2',$(which).select('.videoTitle')[0].innerHTML);
		}
		so.addParam('allowFullscreen','true');
		so.addParam('wmode','transparent');
		so.addParam('quality','autohigh');
		so.addParam('scale','noscale');
		so.addParam('salign','tl');
		so.write(targetVP);
	}
}
//videoplayer resize callback -- called when player resizes for any reason, should be used to adjust HTML container's height to match
function videoPlayerLayoutCallback(vPlayerCSSID,updatedSpecs) {
	$(vPlayerCSSID).style.height=(updatedSpecs.videoHeight+updatedSpecs.interfaceHeight)+'px';
}

//omniture tracking wrapper for videoplayers (taken from /_admin/js/omniture_wrapper.js since this file was not included in the page...)
function emcTrack(tStr,filename,mode) {

	currentPageName=window.location.pathname+((window.location.search!='')?window.location.search:'')+((window.location.hash!='')?window.location.hash:'');

	//download and custom link tracking -- shows up in File Downloads or Custom Links
	if (mode=='d') {
		s.tl(true,'d',filename);
	} else if (mode=='o') {
		s.tl(true,'o',tStr);
	}

	//normal pageName tracking to enable pathing, etc. for both download and normal (but not custom)
	if (mode!='o') {
		s.pageName=currentPageName+': '+tStr;
		s.t();
	}

}


// main animation placement scripts
var fVersion=deconcept.SWFObjectUtil.getPlayerVersion();
var queryStr=String(window.location);
var useFlash=(fVersion['major']>=8) ? ((queryStr.indexOf('?noflash')>=0 && (queryStr.indexOf('isus.emc.com/')>=0 || queryStr.indexOf('http://localhost/')>=0)) ? false : true ) : false ;
var mainAnimations={};
function initFlashAnimation(e) {
	if (useFlash) {
		var targetName;
		if (e.select('.mainFlashAnimation').length>0) {
		    targetName=e.id.split('-')[0];
		    mainAnimations[targetName] = new SWFObject('swf/'+targetName+'.swf?file=swf/'+targetName+'.xml', targetName+'Animation', '689', '232', '8', '#ffffff');
		    mainAnimations[targetName].addParam('scale', 'noscale');
		    mainAnimations[targetName].addParam('wmode', 'transparent');
		    mainAnimations[targetName].addParam('AllowScriptAccess', 'always');
		    mainAnimations[targetName].addVariable('browser', BrowserDetect.browser);
		    mainAnimations[targetName].write(e.select('.mainFlashAnimation')[0]);
		}
	}
}


//media console
function initMediaConsole(el) {
	var idSplit='';
	el.select('.mediaConsoleTab').each(function(e) {
		idSplit=e.id.split('-');
		e.onclick=function(){doMediaConsoleVideo(e,true);};
	});
	doMediaConsoleVideo($(idSplit[0]+'-1-tab'),false);
}
function doMediaConsoleVideo(e,ap) {
	if (ap==undefined) {ap=true;}
	if (e!=null) {
		idSplit=e.id.split('-');
		whichConsole=idSplit[0];
		$$('.mediaConsoleTab').each(function(e) {
			if (e.id.indexOf(whichConsole)>=0) {
				e.setOpacity(1);
				e.style.cursor='pointer';
				e.select('.mediaConsolePlayButton')[0].style.display='block';
			}
		});
		e.setOpacity(0.5);
		e.style.cursor='auto';
		e.select('.mediaConsolePlayButton')[0].style.display='none';
		target=$(idSplit[0]+'-'+idSplit[1]+'-content');
		$$('.mediaConsoleContent').each(function(e) {
			if (e.id.indexOf(whichConsole)>=0) {
				e.style.display='none';
			}
		});
		target.style.display='block';
		var videoTitle=e.select('.videoNav')[0].innerHTML;
		$(whichConsole).update('<div class="vPlayer"></div><div class="videoURL"></div><div class="videoTitle"></div>');
		$$('#'+whichConsole+' .videoURL').first().update(e.select('.videoURL')[0].innerHTML);
		$$('#'+whichConsole+' .vPlayer').first().update(e.select('.videoPlaceholder')[0].innerHTML);
		$$('#'+whichConsole+' .videoTitle').first().update(videoTitle.stripTags().truncate(30));
		doVideo(whichConsole,ap);
	}
}

//dom-ready checking, fires init
var alreadyrunflag=false; //flag to indicate whether target function has already been run
if (/Safari/i.test(navigator.userAgent)) { // safari
  var _timer=setInterval(function(){ if(/loaded|complete/.test(document.readyState)){ clearInterval(_timer); initTabs(); }}, 10);
} else if (document.addEventListener) { // most 'modern' browsers
  document.addEventListener("DOMContentLoaded", function(){ alreadyrunflag=true; initTabs(); }, false);
} else if (document.all && !window.opera) { //IE
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
  var contentloadtag=document.getElementById("contentloadtag");
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete"){
      alreadyrunflag=true;
      initTabs();
    }
  };
}
window.onload=function(){ //catchall for old browsers
  setTimeout('if (!alreadyrunflag) {initTabs();}', 0);
};




// IE5.5+ PNG Alpha Fix v2.0 Alpha: Background Tiling Support
// (c) 2008 Angus Turnbull http://www.twinhelix.com

// This is licensed under the GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

//var IEPNGFix = window.IEPNGFix || {};
//
//IEPNGFix.tileBG = function(elm, pngSrc, ready) {
//	// Params: A reference to a DOM element, the PNG src file pathname, and a
//	// hidden "ready-to-run" passed when called back after image preloading.
//
//	var data = this.data[elm.uniqueID],
//		elmW = Math.max(elm.clientWidth, elm.scrollWidth),
//		elmH = Math.max(elm.clientHeight, elm.scrollHeight),
//		bgX = '0px';//elm.currentStyle.backgroundPositionX,
//		bgY = '0px';//elm.currentStyle.backgroundPositionY,
//		bgR = elm.currentStyle.backgroundRepeat;
//
//	// Cache of DIVs created per element, and image preloader/data.
//	if (!data.tiles) {
//		data.tiles = {
//			elm: elm,
//			src: '',
//			cache: [],
//			img: new Image(),
//			old: {}
//		};
//	}
//	var tiles = data.tiles,
//		pngW = tiles.img.width,
//		pngH = tiles.img.height;
//
//	if (pngSrc) {
//		if (!ready && pngSrc != tiles.src) {
//			// New image? Preload it with a callback to detect dimensions.
//			tiles.img.onload = function() {
//				this.onload = null;
//				IEPNGFix.tileBG(elm, pngSrc, 1);
//			};
//			return tiles.img.src = pngSrc;
//		}
//	} else {
//		// No image?
//		if (tiles.src) ready = 1;
//		pngW = pngH = 0;
//	}
//	tiles.src = pngSrc;
//
//	if (!ready && elmW == tiles.old.w && elmH == tiles.old.h &&
//		bgX == tiles.old.x && bgY == tiles.old.y && bgR == tiles.old.r) {
//		return;
//	}
//
//	// Convert English and percentage positions to pixels.
//	var pos = {
//			top: '0%',
//			left: '0%',
//			center: '50%',
//			bottom: '100%',
//			right: '100%'
//		},
//		x,
//		y,
//		pc;
//	x = pos[bgX] || bgX;
//	y = pos[bgY] || bgY;
//	if (pc == x.match(/(\d+)%/)) {
//		x = Math.round((elmW - pngW) * (parseInt(pc[1]) / 100));
//	}
//	if (pc == y.match(/(\d+)%/)) {
//		y = Math.round((elmH - pngH) * (parseInt(pc[1]) / 100));
//	}
//	x = parseInt(x);
//	y = parseInt(y);
//
//	// Handle backgroundRepeat.
//	var repeatX = { 'repeat': 1, 'repeat-x': 1 }[bgR],
//		repeatY = { 'repeat': 1, 'repeat-y': 1 }[bgR];
//	if (repeatX) {
//		x %= pngW;
//		if (x > 0) x -= pngW;
//	}
//	if (repeatY) {
//		y %= pngH;
//		if (y > 0) y -= pngH;
//	}
//
//	// Go!
//	this.hook.enabled = 0;
//	if (!({ relative: 1, absolute: 1 }[elm.currentStyle.position])) {
//		elm.style.position = 'relative';
//	}
//	var count = 0,
//		xPos,
//		maxX = repeatX ? elmW : x + 0.1,
//		yPos,
//		maxY = repeatY ? elmH : y + 0.1,
//		d,
//		s,
//		isNew;
//	if (pngW && pngH) {
//		for (xPos = x; xPos < maxX; xPos += pngW) {
//			for (yPos = y; yPos < maxY; yPos += pngH) {
//				isNew = 0;
//				if (!tiles.cache[count]) {
//					tiles.cache[count] = document.createElement('div');
//					isNew = 1;
//				}
//				var clipR = (xPos + pngW > elmW ? elmW - xPos : pngW),
//					clipB = (yPos + pngH > elmH ? elmH - yPos : pngH);
//				d = tiles.cache[count];
//				s = d.style;
//				s.behavior = 'none';
//				s.left = xPos + 'px';
//				s.top = yPos + 'px';
//				s.width = clipR + 'px';
//				s.height = clipB + 'px';
//				s.clip = 'rect(' +
//					(yPos < 0 ? 0 - yPos : 0) + 'px,' +
//					clipR + 'px,' +
//					clipB + 'px,' +
//					(xPos < 0 ? 0 - xPos : 0) + 'px)';
//				s.display = 'block';
//				if (isNew) {
//					s.position = 'absolute';
//					s.zIndex = -999;
//					if (elm.firstChild) {
//						elm.insertBefore(d, elm.firstChild);
//					} else {
//						elm.appendChild(d);
//					}
//				}
//				this.fix(d, pngSrc, 0);
//				count++;
//			}
//		}
//	}
//	while (count < tiles.cache.length) {
//		this.fix(tiles.cache[count], '', 0);
//		tiles.cache[count++].style.display = 'none';
//	}
//
//	this.hook.enabled = 1;
//
//	// Cache so updates are infrequent.
//	tiles.old = {
//		w: elmW,
//		h: elmH,
//		x: bgX,
//		y: bgY,
//		r: bgR
//	};
//};
//
//
//IEPNGFix.update = function() {
//	// Update all PNG backgrounds.
//	for (var i in IEPNGFix.data) {
//		var t = IEPNGFix.data[i].tiles;
//		if (t && t.elm && t.src) {
//			IEPNGFix.tileBG(t.elm, t.src);
//		}
//	}
//};
//IEPNGFix.update.timer = 0;
//
//if (window.attachEvent && !window.opera) {
//	window.attachEvent('onresize', function() {
//		clearTimeout(IEPNGFix.update.timer);
//		IEPNGFix.update.timer = setTimeout(IEPNGFix.update, 100);
//	});
//}
//

