var LetsGetStarted = '<a href="mailto:&#103;&#101;&#116;&#115;&#116;&#97;&#114;&#116;&#101;&#100;&#64;&#109;&#105;&#110;&#100;&#97;&#105;&#109;&#46;&#99;&#111;&#109;?subject=I want to Get Started" title="&#69;&#109;&#97;&#105;&#108; Mind Aim to get things started">&#103;&#101;&#116;&#115;&#116;&#97;&#114;&#116;&#101;&#100; |at| &#109;&#105;&#110;&#100;&#97;&#105;&#109; |dot| &#99;&#111;&#109;</a>'

//Stop CSS Background Flickering in Internet Explorer 6
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}

function showExample(category,example,resize) {
	extCat = category;
	extFile = example;
	window.prevOpt = String("#"+category+example);
	var prevOpt = window.prevOpt;
	var techtut = new Array(
		["file","xwidth","ywidth","description"],
		["Securing_Industrial_Networks.swf",912,570,"<strong>Scope &nbsp; </strong>&nbsp; Content research, user interface design, script/copy writing, storyboarding, illustration, and Flash animation/coding."],
		["Data-over-Cellular_Tutorial.swf",800,600,"<strong>Scope &nbsp; </strong>&nbsp; Flash animation/coding, content script writing, storyboarding, design, user interface, and illustration."],
		["How_KVM_via_IP_Works.swf",800,600,"<strong>Scope &nbsp; </strong>&nbsp; Design, content research, storyboarding, user interface, copy writing illustration, and Flash animation/coding."],
		["How_Serial_Encap _Works.swf",800,600,"<strong>Scope &nbsp; </strong>&nbsp; User interface design, script/copy writing, storyboarding, illustration, and Flash animation/coding."],
		["How_Video_Over_IP_Works.swf",800,600,"<strong>Scope &nbsp; </strong>&nbsp; Illustration, content research, copy writing, storyboarding, user interface design, and Flash animation/coding."],
		["How_Simulation_SW_Works.swf",800,600,"<strong>Scope &nbsp; </strong>&nbsp; Storyboarding, content research, script writing, user interface design, illustration, and Flash animation/coding."],
		["Ring_Redundancy_RS2-4R.swf",800,600,"<strong>Scope &nbsp; </strong>&nbsp; Content research, script/copy writing, storyboarding, design, user interface, illustration, and Flash animation/coding."]
	);
	var prodtour = new Array(
		["file","xwidth","ywidth","description"],
		["G408M Product Tour v1.swf",912,570,"<strong>Scope &nbsp; </strong>&nbsp; User interface design, isometric illustration, Flash animation/coding, product benefit messsaging, and copywriting."],
		["ControlNet SHR-DSHR Module Product Tour-2009-01.swf",912,570,"<strong>Scope &nbsp; </strong>&nbsp; Product benefit analysis, market differentiation messaging, copywriting, storyboarding, design, photography, user interface, illustration, and Flash animation/coding."],
		["Hirschmann-Power_in_MICE_en.swf",800,600,"<strong>Scope &nbsp; </strong>&nbsp; Key market feature research/competitive analysis, script writing, copywriting, storyboarding, design, user interface, illustration, and Flash animation/coding."],
		["StoryBox_DVD.swf",800,600,"<strong>Scope &nbsp; </strong>&nbsp; Illustration, message development strategy, storyboarding, design, user interface, and Flash animation/coding."],
		["EOTec_2104-rev2007-12.swf",800,600,"<strong>Scope &nbsp; </strong>&nbsp; Improved existing user interface and user experience, Flash animation/coding."],
		["WinterBlast.swf",600,800,"<strong class='alt'>Game Demo &nbsp; </strong>&nbsp; <strong>Scope &nbsp; </strong>&nbsp; Game concept, user interface design, illustration, and Flash animation/coding."],
		["Toonals Concept-Process Overview.swf",800,600,"<strong class='alt'>Business Concept &nbsp; </strong>&nbsp; <strong>Scope &nbsp; </strong>&nbsp; Logo design, content discovery, user interface design, illustration, and Flash animation/coding."]
	);
	$(prevOpt).addClass("current").fadeTo(0, 1.0);
	var category = eval(category);
	var example = eval(example);
	var fileN = category[example][0];
	var fileX = category[example][1];
	var fileY = category[example][2];
	var fileD = category[example][3];
	var offset = ($("#headerZone").height())+($("#shadow-bott").height())+($("#footZone").height());
	// Let's check the viewport and resize if needed
	if (holeSize()[0] < fileX) {
		minH = Math.round(fileX*.4);
 		sizeDiff = fileX-(holeSize()[0]-30);
 		fileXn = fileX-sizeDiff;
		if (fileXn < minH) { // minH in the min height
			fileXn = minH;
		}
		var scale = (fileXn/fileX);
		var fileY = Math.round(fileY*scale);
		var fileX = fileXn;
	}
	var bodyY = fileY+offset+50; // 40 is approximate y padding
	if (holeSize()[1] < bodyY) {
		minV = Math.round(fileY*.4);
 		sizeDiff = bodyY-holeSize()[1];
 		fileYn = fileY-sizeDiff;
		if (fileYn < minV) { // minV in the min height
			fileYn = minV;
		}
		var scale = (fileYn/fileY);
		var fileX = Math.round(fileX*scale);
		var fileY = fileYn;
	}
	if (resize == true) {
		$("#swf").attr("width", fileX).attr("height", fileY).css("width",fileX+"px").css("height",fileY+"px");
	} else {
		var flashvars = {};
		var attributes = {};
		var params = {
		  menu: "false",
		  scale: "exactfit",
		  quality: "autohigh",
		  allowScriptAccess: "sameDomain"
		};
		swfobject.embedSWF("/work/interactive/swf_files/"+fileN, "swf", fileX, fileY, "8.0.0","expressInstall.swf", flashvars, params, attributes);
		$("#descriptionArea").html(fileD);
	}
	$("#swfZone").css("width",fileX+"px");
	$("#descriptionArea").css("width",fileX+"px");
	$("#shadow-bott").attr("width", fileX).css("width",fileX+"px");
}
function loadExample() {	
	if (extFile !== "" && extCat !== "") {
		showExample(extCat,extFile,false);
	} else {
		showExample("prodtour","01");
	}
}

var blank = new Image();
blank.src = '/images/image.gif';

function fixPng(png) {
	// get src
	var src = png.src;
	// set width and height
	if (!png.style.width) { png.style.width = $(png).width(); }
	if (!png.style.height) { png.style.height = $(png).height(); }
	// replace by blank image
	png.onload = function() { };
	png.src = blank.src;
	// set filter (display original image)
	png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}

// Returns the width and height of viewport (browser window)
function holeSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  var myWH = new Array(myWidth,myHeight)
	return (myWH);
}

//function to get random number from 1 to n (maxVal)
function randomToN(maxVal,floatVal) {
   var randVal = Math.random()*maxVal;
   return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}

var thoughts = [ ];
var mindaimers = [ ];

function bubbleLoop (val) {
	window.countBubble++
	if (window.countBubble > val) {
		window.countBubble = 0;
	}
	return (window.countBubble);
}

function bubbleTimer() {
	if (!window.loopCount) {
		window.loopCount = 0;
	}
	$.doTimeout('bubbler', 8000, function(){
		window.loopCount++;
		if (window.loopCount < 7) {
			showMindBubble(mindaimers[bubbleLoop((mindaimers.length-1))]);
			return true;
		}
		else {
			$.doTimeout('bubbler');
		}
	});
}

function thoughtsLoop () {
	window.countThought++
	if (window.countThought >= thoughts.length) {
		window.countThought = 0;
	}
	return (window.countThought);
}

function showMindBubble (obj,start) {
	$("#bubble").hide().removeClass();
	$(".mindaimer").removeClass("enabled");
	var _id = $(obj).attr("id");
	var _thought = thoughts[thoughtsLoop()];
	var _title = $(obj).attr("title");
	//$("#output").append(_title+"<br>");
	$("#"+_id).addClass("enabled");
	var _elems = _title.split("|");
	//$("#output").append(_title+"<br><br>");
	var offsetL = _elems[1];
	if (!offsetL || offsetL == "") {
		var offsetL = 0;
	}
	var offsetT = _elems[2];
	//$("#output").append("T: "+offsetT+"<br>");
	if (!offsetT || offsetT == "") {
		var offsetT = 0;
	}
	var offsetL = offsetL+"px";
	var offsetT = offsetT+"px";
	$("#bubble p").html(_thought);
	$("#bubble").css("left",offsetL).css("top",offsetT);
	$("#bubble").addClass(_id).fadeIn(300, function() {
		if (($("#bubble p").html()) == "") {
			$("#bubble").css("display","none");
		}
	});
	if (start) {
		bubbleTimer();
		if (!window.countBubble) {
			window.countBubble = 0;
		}
		if (!window.countThought) {
			window.countThought = 0;
		}
	}
	var TT = $("#bubble").css("top");
	var LL = $("#bubble").css("left");
	//$("#output").append("offsetT: "+offsetT+"<br>");
	//$("#output").append("left: "+LL+" top: "+TT+"<br>");
}

function hideMindBubble (obj) {
	var _id = $(obj).attr("id");
	$("#"+_id).removeClass("enabled");
	$("#bubble").css("display","none").removeClass();
	$("#bubble p").empty();
}

// JQUERY READY
$(document).ready(function() {

//$("#output").show();

$('#LetsGetStarted').html(LetsGetStarted);

$('#ValidHTML5').html('<img src="/images/valid_html5.gif" alt="valid_html5" width="80" height="15" />');

if ($('.mindaimer').length > 0) {
	var set1 = $(".set1");
	var set1L = ((set1.length)-1);
	$(".set1").hide();
	$(set1[randomToN(set1L)]).show();
	
	var set2 = $(".set2");
	var set2L = ((set2.length)-1);
	$(".set2").hide();
	$(set2[randomToN(set2L)]).show();
	
	var set3 = $(".set3");
	var set3L = ((set3.length)-1);
	$(".set3").hide();
	$(set3[randomToN(set3L)]).show();
	
	$(".mindaimer").removeClass("enabled").each(function (i) {
		var _title = $(this).attr("title");
		var elems = _title.split("|");
		var _t = elems[0];
		var _id = $(this).attr("id");
		if ( $(this).is(":visible") ) {
			mindaimers.push($(this));
			//$("#output").append("<b>visible</b>: "+_id+"<br>");
			//$("#output").append("<b>title</b>: "+_t+"<br>");
		}
		thoughts[i] = _t;
	});
	$("#bubble").hide().removeClass();
	showMindBubble(mindaimers[0],true);
	
	$(".mindaimer").mouseover(function () {
		showMindBubble ($(this));
		window.thisTitle = $(this).attr("title");
		$(this).attr("title","");
		$.doTimeout('bubbler'); //stops timer
		$.doTimeout('outbub'); //stops timer
	});
	$(".mindaimer").mouseout(function () {
		hideMindBubble ($(this));
		$(this).attr("title",window.thisTitle);
		$.doTimeout( 'outbub', 2500, function(){
			showMindBubble(mindaimers[window.countBubble], true);
		});
	});
}

$('.external').attr("target","_blank");

$('#lab, #birdie, .core-item').click(function() {
	var link = $(this).find('a').attr('href');
	document.location.href = link;
});

$('.core-item').hover(
	function () {
		$(this).addClass('over');
	},
	function () {
		$(this).removeClass('over');
	}
);

$('#moreWeb').click(function() {
	$('.section2').toggle();
});

$('#btn-getstarted a').hover(
	function () {
		$(this).addClass('over');
	},
	function () {
		$(this).removeClass('over');
	}
);

$('#moreWeb').toggle(
	function () {
		$('.section2').show("slow");
		$(this).html('<span>&ndash;</span>LESS');
	},
	function () {
		$('.section2').hide("fast");
		$(this).html('<span>+</span>MORE');
	}
);

var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
if (badBrowser) {
	// get all pngs on page
	$('img[src$=.png]').each(function() {
		if (!this.complete) {
			this.onload = function() { fixPng(this) };
		} else {
			fixPng(this);
		}
	});
}


$('#GetStartedForm').validate({
  rules: {
    firstname: {
      required: true,
      minlength: 2
    },
    lastname: {
      required: true,
      minlength: 2
    },
    email: {
      required: true,
      email: true
    },
    phone: {
      required: true,
      minlength: 7
    }
  }
});

// Only for interactive samples page
if ($('#swfZone').length > 0) {
	$(".option").fadeTo(250, 0.5);
	
	loadExample();
	
	$(".option").hover(function() {
		if (this.id !== window.prevOpt.slice(1)) {
			$(this).fadeTo(100, 1.0);
		}
	}, function() {
		if (this.id !== window.prevOpt.slice(1)) {
			$(this).fadeTo(250, 0.5);
		}
	});
		
	$(".option").click(function() {
		if (window.prevOpt) {
			$(window.prevOpt).removeClass("current").fadeTo(10, 0.5);
		}
		theID=this.getAttribute('id');
		category= theID.slice(0, -2);
		example= theID.slice(-2);
		window.prevOpt = "#"+theID;
		$(this).addClass("current");
		showExample(category,example);
		return false;
	});
	
	var resizeTimer = null;
	$(window).bind('resize', function() { 
	    if (resizeTimer) clearTimeout(resizeTimer); 
	    resizeTimer = setTimeout("showExample(extCat,extFile,true)", 70);
	});
}

// Only for page error
if ($('#errorMsg').length > 0) {
	$.doTimeout(10000, function(){
		$('#errorMsg').slideUp("slow");
	});
}

}); // JQUERY END