/*
MFG and Subfeature Controller - 0.9.20101103
*/


/*(function($) {
if(!document.defaultView||!document.defaultView.getComputedStyle){var oldCurCSS=jQuery.curCSS;jQuery.curCSS=function(a,b,c){if(b==='background-position'){b='backgroundPosition'}if(b!=='backgroundPosition'||!a.currentStyle||a.currentStyle[b]){return oldCurCSS.apply(this,arguments)}var d=a.style;if(!c&&d&&d[b]){return d[b]}return oldCurCSS(a,'backgroundPositionX',c)+' '+oldCurCSS(a,'backgroundPositionY',c)}}var oldAnim=$.fn.animate;$.fn.animate=function(a){if('background-position'in a){a.backgroundPosition=a['background-position'];delete a['background-position']}if('backgroundPosition'in a){a.backgroundPosition='('+a.backgroundPosition}return oldAnim.apply(this,arguments)};function toArray(a){a=a.replace(/left|top/g,'0px');a=a.replace(/right|bottom/g,'100%');a=a.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");var b=a.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);return[parseFloat(b[1],10),b[2],parseFloat(b[3],10),b[4]]}$.fx.step.backgroundPosition=function(a){if(!a.bgPosReady){var b=$.curCSS(a.elem,'backgroundPosition');if(!b){b='0px 0px'}b=toArray(b);a.start=[b[0],b[2]];var c=toArray(a.options.curAnim.backgroundPosition);a.end=[c[0],c[2]];a.unit=[c[1],c[3]];a.bgPosReady=true}var d=[];d[0]=((a.end[0]-a.start[0])*a.pos)+a.start[0]+a.unit[0];d[1]=((a.end[1]-a.start[1])*a.pos)+a.start[1]+a.unit[1];a.elem.style.backgroundPosition=d[0]+' '+d[1]};
})(jQuery);*/

var MFGArray = new Array();
var subFeaturePosition = new Array();
subFeaturePosition[1] = "0px";
subFeaturePosition[2] = "-110px";
subFeaturePosition[3] = "-220px";
var subFeatureMovement = 350;

if (!mobileDevice){
	try{
	jQuery(".subFeatureContent").mouseenter(function(){
		var sfID = jQuery(this).attr('ID').split("_");
		switch(sfID[1]) {
			case "1":
				if (jQuery(this).css("top") != subFeaturePosition[1]) {
					jQuery("#"+sfID[0]+"_1").stop().animate({
						top: subFeaturePosition[1]
					}, subFeatureMovement);
					jQuery("#"+sfID[0]+"_2").stop().animate({
						top: subFeaturePosition[2]
					}, subFeatureMovement);
				}
				break;
			
			case "2":
				if (jQuery("#"+sfID[0]+"_1").css("top") != subFeaturePosition[1] && jQuery("#"+sfID[0]+"_2").css("top") == subFeaturePosition[2]) {
					break;
				}
				jQuery("#"+sfID[0]+"_1").stop().animate({
					top: "-110px"
				}, subFeatureMovement);
				jQuery("#"+sfID[0]+"_2").stop().animate({
					top: subFeaturePosition[2]
				}, subFeatureMovement);
				break;
			
			case "3":
				if (jQuery("#"+sfID[0]+"_1").css("top") == subFeaturePosition[1] || jQuery("#"+sfID[0]+"_2").css("top") == subFeaturePosition[2]) {
					jQuery("#"+sfID[0]+"_1").stop().animate({
						top: "-110px"
					}, subFeatureMovement);
					jQuery("#"+sfID[0]+"_2").stop().animate({
						top: "-220px"
					}, subFeatureMovement);
				}
				break;
		}
	});
	jQuery('.subFeatureBox').mouseenter(function(){
		jQuery(this).css('background-position', '0px -150px');
		// jQuery(this).stop().animate({
			// backgroundPosition: '0px -10px'
		// }, 400);
	});
	jQuery('.subFeatureBox').mouseleave(function(){
		// jQuery(this).stop().animate({
			// backgroundPosition: '0px -150px'
		// }, 400);
	});
	}
	catch(e){}
}
jQuery(window).ready(function(){
	if (!mobileDevice){
		jQuery('.subFeatureBox').each(function(){
			if (isIE6){
				jQuery(this).css("height", "460px");
			} else {
				jQuery(this).css("height", "420px");
			}
		});
		jQuery('.subFeatureContent').each(function() {
			if (!isIE6){
				jQuery(this).prepend('<div class="subFeatureContentGradient">&nbsp;</div>');
				jQuery(this).mouseenter(function(){
					jQuery(this).children('.subFeatureContentGradient').stop().animate({
						opacity:0.1
					}, 500);
				});
				jQuery(this).mouseleave(function(){
					jQuery(this).children('.subFeatureContentGradient').stop().animate({
						opacity:0
					}, 500);
				});
			}
			
			var sfID = jQuery(this).attr('ID').split("_");
			switch (sfID[1]){
				case "1":
					jQuery("#"+sfID[0]+"_1").css("top", subFeaturePosition[1]);
					break;
				case "2":
					jQuery("#"+sfID[0]+"_2").css("top", subFeaturePosition[2]);
					break;
				case "3":
					jQuery("#"+sfID[0]+"_3").css("top", subFeaturePosition[3]);
					break;
			}
		});
	}
});




var currentMFG = 0;
var oldMFG = 0;
var currentHoverMFG = null;
var mfgFadeTime = 700;
var mfgShowTime = 6000;
var mfgTimer = null;
var mfgIsLoaded = new Array();
var isFlashEnabled = false;
var host = location.hostname;
function playMFG(){
	var mfgSWF = MFGArray[currentMFG].split('/');
	var mfgSWF = mfgSWF.pop();
	var mfgSWF = mfgSWF.split('.');
	var mfgSWF = mfgSWF[0];
	var mfgLink = jQuery("#mfgImages a:nth-child("+currentMFG+")").attr('href');
	var mfgFlashObject = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' viewastext='' width='980' height='540' id='mfgFlashObject' name='mfgFlashObject'><param name='allowScriptAccess' value='always'><param name='movie' value='/content/flash/SWFs/wmfg/mfgpreload.swf?country="+siteRegion+"&mfg="+mfgSWF+"&link="+mfgLink+"'><param name='quality' value='high'><param name='loop' value='false'></param><param name='wmode' value='transparent'><param name='embed' value='transparent'><param name='menu' value='false'><embed src='/content/flash/SWFs/wmfg/mfgpreload.swf?country="+siteRegion+"&mfg="+mfgSWF+"&link="+mfgLink+"' quality='high' loop='false' wmode='transparent' name='mainFeatureGraphic' menu='false' embed='transparent' allowscriptaccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' width='980' height='540' id='mfgFlashObject' name='mfgFlashObject'></object>";
	clearTimeout(mfgTimer);
	jQuery('#mfgSelector').hide();
	jQuery('#mfgFlashPlayButton').hide();
	jQuery('#mfgFlash').show();
	jQuery('#mfgFlash').html(mfgFlashObject);
}
function stopMFG(){
	jQuery('#mfgFlash').fadeOut(mfgFadeTime, function(){jQuery('#mfgSelector').fadeIn(mfgFadeTime); jQuery('#mfgFlashPlayButton').fadeIn(mfgFadeTime);});
	jQuery('#mfgFlash').html = "<p>&nbsp;</p>";
	mfgRotate(currentMFG, true);
}
function clearSwitchers(){
	jQuery("#mfgSelector .mfgBlock img").each(function(){
		if (jQuery(this).attr("id") != currentHoverMFG){
			jQuery(this).removeClass('mfgSelectorSelected');
			jQuery(this).stop().animate({
				opacity:0.5
			});
		}
	});
}
function openMFG(){
	jQuery('#mfg'+currentMFG).show().css("opacity",1);
	jQuery('#mfg'+currentMFG+" img").show().stop().animate({opacity:1},mfgFadeTime,function(){ mfgTimer = setTimeout("clearSwitchers(); clearTimeout(mfgTimer); mfgRotate();",mfgShowTime); });
}
function mfgRotate(passedMFG, returnFromFlash){
	oldMFG = currentMFG;
	if (passedMFG){
		currentMFG = passedMFG;
	} else {
		if (currentMFG == 4){
			currentMFG = 1;
		} else {
			currentMFG++;
		}
	}
	if (!returnFromFlash){
		jQuery('#mfg'+oldMFG).stop().animate({
			opacity:0
		},mfgFadeTime, function(){jQuery(this).hide();})
		jQuery('#mfg'+oldMFG+' img').stop().animate({opacity:0});
	}
	jQuery('#mfgSelect'+currentMFG).addClass('mfgSelectorSelected');
	jQuery('#mfgSelect'+currentMFG).animate({
		opacity:1
	});
	if (!mfgIsLoaded[currentMFG]){
		clearTimeout(mfgTimer);
		jQuery('#mfgFlashPlayButton').fadeOut(200);
		jQuery("#mfg"+currentMFG).append('<div class="mfgLoadAnim">&nbsp;</div>');
		jQuery("#mfg"+currentMFG).show();
		jQuery("#mfg"+currentMFG).animate({opacity:1});
		jQuery("#mfg"+currentMFG+" .mfgLoadAnim").delay(1000).fadeIn(300);
		var thisMFGAlt = jQuery("#mfg"+thisMFG+" img").attr("alt");
		var thisMFG = currentMFG;
		var img = new Image();
		jQuery(img).load(function(){
			mfgIsLoaded[thisMFG] = true;
			jQuery("#mfg"+thisMFG+" img").remove();
			jQuery("#mfg"+thisMFG+" .mfgLoadAnim").fadeOut(100, function(){
				jQuery("#mfg"+thisMFG+" .mfgLoadAnim").remove();
			});
			jQuery("#mfg"+thisMFG).append(this);
			if (currentMFG == thisMFG){
				openMFG();
			} else {
				jQuery("#mfg"+thisMFG).hide().css("opacity","0");
			}
			if (isFlashEnabled){
				jQuery('#mfgFlashPlayButton').fadeIn(200);
			}
		}).attr({
			'src': MFGArray[currentMFG],
			'alt': thisMFGAlt
		}).css("opacity",0);
	} else {
		openMFG();
	}
}
function switchMFG(mfgPosition){
	if (mfgPosition != currentMFG) {
		clearTimeout(mfgTimer);
		clearSwitchers();
		mfgRotate(mfgPosition);
	}
}
if (!isIE6){
	var kode = [], konami = "38,38,40,40,37,39,37,39,66,65";
	jQuery(document).keydown(function(contra) {
		kode.push( contra.keyCode );
		if ( kode.toString().indexOf( konami ) >= 0 ){
			jQuery(document).unbind('keydown',arguments.callee);
			jQuery('body').append('<div id="xandoOverlay"><div id="videoOuter"><div id="videoInner">&nbsp;</div></div></div>');
			jQuery('#xandoOverlay').fadeIn(400, function(){
				jQuery('#xandoOverlay #videoOuter #videoInner').html('<object id="xandoVideo" width="570" height="458"><param name="movie" value="/content/includes/redesign2010/game1.swf"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed id="xandoVideo" src="/content/includes/redesign2010/game1.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="570" height="458"></embed></object><p style="color:#fff; font-weight:bold; text-align:center;">With best wishes from the European Web Dev Team! :)</p>');
			});
			jQuery('#xandoOverlay').click(function(){
				jQuery("#xandoVideo").remove();
				jQuery("#xandoOverlay").fadeOut(400, function(){
					jQuery(this).remove();
				});
			});
		}
	});
}
jQuery("#searchBox input,#search input").click(function() {
	//if (jQuery("#searchBox input").val() == "Search NVIDIA") {
		jQuery("#searchBox input").val('');
	//}
});
jQuery(document).ready(function(){
	if (DetectFlashVer(9, 0, 0)){
		isFlashEnabled = true;
	}
	function initMFG(){
		for (i=1;i<=4;i++){
			if (i==1){
				MFGArray[i] = jQuery("#mfgImages #mfg"+i+" img").attr("src");
			} else {
				MFGArray[i] = jQuery("#mfgImages #mfg"+i+" img").attr("longdesc");
			}
		}
		jQuery("#mfgSelector .mfgBlock img").each(function(){
			jQuery(this).mouseenter(function(){
				currentHoverMFG = jQuery(this).attr("id");
				jQuery(this).stop().animate({
					opacity:1
				});
			});
			jQuery(this).mouseleave(function(){
				currentHoverMFG = null;
				leavingID = jQuery(this).attr("id");
				if (leavingID != ("mfgSelect"+currentMFG)){
					jQuery(this).stop().animate({
						opacity:0.5
					});
				}
			});
		});
		jQuery("#mfg1").hide();
		jQuery("#mfgSelector").show();
		if (isFlashEnabled){
			jQuery("#mfgFlashPlayButton").show();
			jQuery("#mfgFlashPlayButton img").show();
			jQuery("#mfgFlashPlayButton img").css("visibility", "visible");
		}
		mfgIsLoaded[1] = true;
		mfgRotate();
	}
	if (flashOnLoad && isFlashEnabled){
		var mfgFlashObject = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' viewastext='' width='980' height='540' id='mfgFlashObject' name='mfgFlashObject'><param name='allowScriptAccess' value='always'><param name='movie' value='/content/flash/SWFs/wmfg/WMFG.swf'><param name='quality' value='high'><param name='loop' value='false'></param><param name='wmode' value='transparent'><param name='flashvars' value='lang="+siteRegion+"'><param name='embed' value='transparent'><param name='menu' value='false'><embed src='/content/flash/SWFs/wmfg/WMFG.swf' quality='high' loop='false' wmode='transparent' name='mainFeatureGraphic' menu='false' embed='transparent' flashvars='lang="+siteRegion+"' allowscriptaccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' width='980' height='540' id='mfgFlashObject' name='mfgFlashObject'></object>";
		jQuery('#mfgSelector,#mfgFlashPlayButton').hide();
		jQuery('#mfgFlash').show();
/* 		jQuery('#mfgFlash').html('<div id="mfgFlashContainer"></div>');
		var flashVars = {
			lang:siteRegion
		};
		swfobject.embedSWF("/content/flash/SWFs/wmfg/WMFG.swf", "mfgFlashContainer", "980", "540", "9.0.0", "expressinstall.swf", flashVars); */
		jQuery('#mfgFlash').html(mfgFlashObject);
	} else {
		initMFG();
	}
});
