function posWin(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function showVideo() {
  if (document.getElementById('video')) {
	  fLayer = document.getElementById('video')
	  fLayer.style.visibility = "visible"; 
  }
}

function hideVideo() {
	$(document).ready(function() {
		$('#video').hide();
		$('#tintLayer').hide();
	});
}

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.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

$(document).ready(function() {

	$('a.videoLink').click(function(){
		$('#tintLayer').show();
		var mid = $(window).scrollTop() + Math.floor($(window).height() / 2);
		var top = mid - 200;
		$('#flash2').css('top', top);
		$('#flash2').show();
		var filePath = $(this).attr('href');
		$('#flash2 .flashContent').html("");
		
    	$('#flash2 .flashContent').flash(
        	{ src: filePath,
          	width: 470,
          	height: 390 },
        	{ version: 8 }
    	);
    	return false;
	});

	$('p.closeBox a').click(function(){
		$('#flash2').hide();
		$('#tintLayer').hide();
		$('#flash2 .flashContent').html("");
    	return false;
	});
	
	$('p.featurettes a').click(function(){
		showVideo();
		var mid = $(window).scrollTop() + Math.floor($(window).height() / 2);
		var top = mid - 250;
		$('#video').css('top', top);
		$('#tintLayer').show();
    	return false;
	});
			
	$('#subForm #hhouy-hhouy').focus(function() {
		$(this).attr('value', '');
		$(this).css('color', '#000');
	});

	$('.signUpWrap label a').click(function() {
		$(this).blur();
		$('.signUpWrap form').toggleClass('display');
//		$('.signUpWrap label').toggleClass('background', 'transparent');
//		$('.signUpWrap label a').css('color', '#000000');
		
		return false;
	});

	$("#options").change(function(e){
	  window.location = $(this).val();
	});


	$('#sign_up').validate({
	  rules: {
		'Email': {
		  required: true,
		  email: true
		},
	  	'event[]' : {
	  	  required: true,
		  minlength: 1
	  	}
	  },
		messages: {
            'First_Name': "First name is a required field",
            'Last_Name': "Last name is a required field",
            'Email': "Please enter a valid email address",
 //          	'Zipcode': "Zip code is a required field"
           	'Phone': "Please enter your phone number",
           	'event[]' : "Please check at least one event or campus tour"
       }
 	});

	$('.home #col1 h2.intro a.more').click(function() {
		$('.home .extra').slideToggle();
		$('.home #col1 h2.intro a.more').toggle();
		
		return false;
	});

	$('.boardPhotos td img').mouseover(function() {
		var words = $(this).attr('alt');
		var offset = $(this).offset();
		var divTop = offset.top + 'px';
		var divLeft = offset.left - 210 + 'px';
		$('.words').css('top', divTop);
		$('.words').css('left', divLeft);
		$('.words').html(words);
		$('.words').show();
	});

	$('.boardPhotos td img').mouseout(function() {
		$('.words').hide();
	});

	$('.mapWrap .linkspots a').click(function() {
		$(this).blur();
		return false;
	});

	$('.mapWrap .linkspots a').mouseenter(function() {
		var title = $(this).attr('title');
		var image = "/media/" + $(this).attr('rel');
		var text = $(this).attr('alt');
		var link = $(this).attr('href');

	 	$('#mapFeature img').attr('src', '');
		$('#mapFeature img').attr('src', image);
		$('#mapFeature h4').html(title);
		$('#mapFeature p.text').html(text);
		
		if(link == '' || link == 'undefined') {
			$('#mapFeature p a.learn').attr('href', '');
			$('#mapFeature p a.learn').hide();
		} else {
			$('#mapFeature p a.learn').attr('href', link);
			$('#mapFeature p a.learn').show();
		};

		var divTop = $(this).css('top');
		var divLeft = $(this).css('left');
		
		divTop = parseInt(divTop.substring(0, divTop.indexOf('px')));
		divLeft = parseInt(divLeft.substring(0, divLeft.indexOf('px')));
		
//		divTop = (divTop + 18) + 'px';
//		divLeft = (divLeft - 137) + 'px';
//		divTop = (divTop - 105) + 'px';
		divTop = (divTop + 25) + 'px';
		divLeft = (divLeft - 50) + 'px';

		$('#mapFeature').css('top', divTop);
		$('#mapFeature').css('left', divLeft);
		$('#mapFeature').show();
	});
	
	$('#mapFeature').mouseleave(function() {
//	 	$(this).hide();
//	 	$('#mapFeature img').attr('src', '');
	});
	
	$('#mapFeature a.close').click(function() {
		$(this).blur();
		$('#mapFeature').hide();
//	 	$('#mapFeature img').attr('src', '');
		return false;
	});

	$('#subForm #hhouy-hhouy').focus(function() { $(this).css('color', '#000') });

	$('#subForm').submit(function (e) {
		e.preventDefault();
		$.getJSON(
		this.action + "?callback=?",
		$(this).serialize(),
		function (data) {
			if (data.Status === 400) {
	//			$('#subForm .msg').html("Error: " + data.Message);
				alert("Error: " + data.Message);
	//			alert('test');
			} else { // 200
			//	$('#subForm .msg').html("<span>Success:</span> " + data.Message);
				//	alert("Success: " + data.Message);
					alert("Within the next few minutes, you should receive a confirmation email at the address you just entered. To confirm your subscription, simply the click the link in that email and you'll be all set. If you don't see an email in the next 15 minutes, please check your junk folder. And thanks again.");
			}
		}); 
	});


// 	swaps submit inputs with <a href=""> link for easier button styling with CSS
// 	Degrades nicely for browsers w/o javascript and retains enter key submit trigger
// 	Nested in livequery plugin to bind AJAX added content. Works on current non-AJAX too.

	$('#sign_up :submit, .signUpWrap :submit').livequery('', function() { 
//			alert('test');
      		var $this = $(this);
      		var f = this.form;
      		var link = $('<a class="gfxBtn" href="#">' + $this.val() + '</a>')
         		.bind('click',function() {
              	 		$(f).trigger('submit');
               			return false;
            		});
      		$this.after(link).css({position:'absolute', top:'-20000px'});
    });	


});  // closing of jQuery load function

		

