var D = YAHOO.util.Dom;

MEESH = {
	menu_items : [],
	init : function(strPage) {
			// check Flash version for Demo Reel page:
		MM_CheckFlashVersion('8,0,0,0','Content on this page requires a newer version of Adobe Flash Player. Do you want to download it now?')
		var a = document.getElementsByTagName('a');
		for (var i=0; i<a.length; i++) {
			if (a[i].className=='ext') {
				a[i].onclick = function() {
					window.open(this.href);
					return false;
				}
			}
		}
		// add listener to right colum, which will link to Contact page
		D.get('right_side').onclick = function() { window.location = '/contact.php'; };
		// activate contact form
		if (document.forms['contact']) {
			document.forms['contact'].onsubmit = function() {
				MEESH.sendContactForm();
				return false;
			};
		}
	},
	sendContactForm : function() {
		var form = document.forms['contact'];
		if (D.get('contact_error')) {
			form.removeChild(D.get('contact_error'));
		}
		YAHOO.util.Connect.setForm(form);
		YAHOO.util.Connect.asyncRequest('POST', 'content/contact_send.php', MEESH.callbackContactForm); 
	},
	callbackContactForm : {
		success : function(o) {
			var response = o.responseText;
			if (response=='sent') {			
				var confirmation = '<h2>Message sent!</h2>';
				confirmation += '<p>Thank you for taking the time to contact me! :)</p>';
				confirmation += '<p><br/>-Michelle</p>';
				D.get('contact').innerHTML = confirmation;
			// in case of missing field, this handler expects the name of the form field as the response:
			} else {
				var form = document.forms['contact'];
				var p = document.createElement('p');
				p.id = 'contact_error';
				p.innerHTML = 'Please fill out the highlighted (required) field below:';
				form.insertBefore(p,form.firstChild);
				var input = form.getElementsByTagName('input');
				for (var i=0; i<input.length; i++) {
					if (input[i].name==response) {
						D.addClass(input[i],'missing');
						input[i].focus();
					} else {
						D.removeClass(input[i],'missing');
					}
				}
			}
		},
		failure : function(o) {
			alert('Sending the message failed. Please try again.');
		},
	  	timeout : 5000
	}
};


// code necessary for Flash Video Player (Demo Reel):
function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

window.onload = MEESH.init();