
var flashvars = {};
var currentVideo = '../videos/demo_2009_sd.mp4';
var videoTime = 106;
flashvars.video = currentVideo;
flashvars.videoTime = videoTime;
var params = {};
params.scale = "noScale";
params.salign = "tl";
var attributes = {};
attributes.id = "VideoPlayer";
attributes.styleclass = "FlashVideo";
attributes.align = "left";
swfobject.embedSWF("flash/VideoPlayerQuick.swf", "alt", "100%", "100%", "9.0.24", "flash/expressInstall.swf", flashvars, params, attributes);

$(function(){
	$('#gallery a').lightBox();
	$('a.lightbox').lightBox();
	var currentStill = null;
	$('#VideoContainer').css('width','640px');
	$('#VideoContainer').css('height','270px');
	$('#rural_cabin').click( function() {
		playVideo('rural_cabin','640','360',274);
		thumbClicked($(this).attr('id'));
	});
	$('#demo_2009').click( function() {
		playVideo('demo_2009','640','270',106);
		thumbClicked($(this).attr('id'));
	});
	$('#aduddell').click( function() {
		playVideo('aduddell','640','270',220);
		thumbClicked($(this).attr('id'));
	});
	$('#c2s').click( function() {
		playVideo('c2s','640','270',174);
		thumbClicked($(this).attr('id'));
	});
	$('#midtown').click( function() {
		playVideo('midtown','640','270',201);
		thumbClicked($(this).attr('id'));
	});
	$('#usbc').click( function() {
		playVideo('usbc','640','360',175);
		thumbClicked($(this).attr('id'));
	});
	$('#maps_3').click( function() {
		playVideo('maps_3','640','360',175);
		thumbClicked($(this).attr('id'));
	});
	$('#texas_tech').click( function() {
		playVideo('texas_tech','640','360',175);
		thumbClicked($(this).attr('id'));
	});
	$('#stills').children('div').each( function(i) {
		
		$(this).click( function() {
			alert($(this).children('div').children('img').attr('alt'));
		});
	});
	/*
	$('#rural_cabin').click( function() {
		playVideo('rural_cabin','1280','720',true);
	});
	$('#2009_demo').click( function() {
		playVideo('2008_demo','1280','540',true);
	});
	$('#aduddell').click( function() {
		playVideo('aduddell','1280','540',true);
	});
	$('#c2s').click( function() {
		playVideo('c2s','1280','540',true);
	});
	$('#midtown').click( function() {
		playVideo('midtown','1280','540',true);
	});
	$('#flatiron').click( function() {
		playVideo('flatiron','1280','720',true);
	});*/
	$('#Video').click( function() {
		unDim();
	});
});
function thumbClicked(thumbId)
{
	$('#title').text($('#' + thumbId).children('div').children('img').attr('alt'));
	$('#' + thumbId).animate({
		opacity: .35
	}, 800 , 'linear', function(){
		hiddenId = $('#nowhere').children('div').attr('id');
		$('#' + hiddenId).appendTo('#videothumbs');
		$('#' + hiddenId).animate({
				opacity: 1
			}, 800 , 'linear', function(){
		});
		$('#' + thumbId).appendTo('#nowhere');
	});
}
function next() {
	
}
function dim() {
	$('#Video').addClass('hdVideo');
	$('#VideoContainer').addClass('hdVideoContainer');
	$('#VideoContainer').center(true);
}
function unDim() {
	var ratio = $('#VideoContainer').width() / $('#VideoContainer').height();
	var height = 640 / ratio;
	$('#VideoContainer').css('height', height + 'px');
	$('#VideoContainer').css('width', 640 + 'px');
	$('#Video').removeClass('hdVideo');
	$('#VideoContainer').removeClass('hdVideoContainer');
	$('#VideoContainer').uncenter();
}
function playVideo(video_name,width,height,videoTime,hd) {
	if(hd)
	{
		currentVideo = '../videos/' + video_name + '_hd.mp4';
	} else {
		currentVideo = '../videos/' + video_name + '_sd.mp4';
	}
//			alert($('#VideoPlayer param:last').val());
//			$('#VideoPlayer param:first').val('video=' + currentVideo);
	$('#VideoPlayer param:last').val('video=' + currentVideo + '&videoTime=' + videoTime);
	$('#VideoContainer').css('width',width + 'px');
	$('#VideoContainer').css('height',height + 'px');
	if(hd) {
		dim();
	} else if(width > 640) {
		dim();
	} else {
		unDim();
	}
	document.getElementById('VideoPlayer').changeVideo(currentVideo);
}
function MM_validateForm() { //v4.0
  if (document.getElementById){
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
	  if (val) { nm=val.name; if ((val=val.value)!="") {
		if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
		  if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
		} else if (test!='R') { num = parseFloat(val);
		  if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
		  if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
			min=test.substring(8,p); max=test.substring(p+1);
			if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	  } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
	} if (errors) alert('The following error(s) occurred:\n'+errors);
	document.MM_returnValue = (errors == '');
  }
}