// JavaScript Document

var eThumbNail = null;
var nVideo;
var videos = new Array();
videos[0] = { title: "What did you just post?", file:"websafety_OnAir.flv", link: "", thumbnail: "#thumb_video1" };
videos[1] = { title: "Who is on your friend's list?", file: "peer.flv", link: "http://www.nsteens.org/videos/social-networking/", thumbnail: "#thumb_video2" };
videos[2] = { title: "Post-To-Be Private", file: "terrible_text.flv", link: "http://www.nsteens.org/videos/social-networking/", thumbnail: "#thumb_video3" };
videos[3] = { title: "Attitude Overdrive", file: "attitude_overdrive.flv", link: "http://www.nsteens.org/videos/gaming/index.html", thumbnail: "#thumb_video4" };

var so = new SWFObject("media/mediaplayer.swf?v=3.16", "player", "300", "260", "7", "0x000000", true);
so.addParam('allowscriptaccess', 'always');
so.addParam('allowfullscreen','false');
so.addParam('wmode', 'transparent');
so.addParam('menu', 'false');
so.addVariable('autostart', 'false');
so.addVariable('enablejs','true');

// Functions to support the FLV Media Player (http://www.jeroenwijering.com/?item=Javascript_interaction)
function sendEvent(swf,typ,prm) { 
  thisMovie(swf).sendEvent(typ,prm); 
};
function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
};
function loadFile(swf,obj) { 
	thisMovie(swf).loadFile(obj); 
};

function playVideo(n) {
		$("#video > h3").html(videos[n].title);
		if (videos[n].link != "") {
			$("#lnk_video").html("<a href='" + videos[n].link + "' target='_blank'>Full Video</a>");
		} else {
			$("#lnk_video").html("&nbsp;");
		}
		so.addVariable('javascriptid','video1');
		so.addVariable('file', videos[n].file);
		so.addVariable('autostart', 'true');
		so.write('video_player');

		// 'active' is not initially set
		if (eThumbNail)
			eThumbNail.removeClass("active");
			
		eThumbNail = $(videos[n].thumbnail);
		eThumbNail.addClass("active");						
		return false;
}

function getUpdate(typ,pr1,pr2,swf) { 
  if (typ == 'state') {
		if (pr1 == 3) {
			if (nVideo < 3) {
				nVideo++;
				playVideo(nVideo);
			}
		}
	}
}

function playAll() {
	nVideo = 0;
	playVideo(nVideo);
}

if (document.images) {
	 img1 = new Image();
	 img2 = new Image();
	 img3 = new Image();
	 img4 = new Image();
	 img5 = new Image();
	 img6 = new Image();
	 img7 = new Image();
	 img8 = new Image();
	 img9 = new Image();
	 img10 = new Image();
	 img11 = new Image();
	 
	 img1.src = "style/images/tab_about_on.png";
	 img2.src = "style/images/tab_parent_on.png";
	 img3.src = "style/images/tab_teens_on.png";
	 img4.src = "style/images/tab_educator_on.png";
	 img5.src = "style/images/tab_community_on.png";
	 
	 img6.src = "style/images/tab_about_roll.png";
	 img7.src = "style/images/tab_parent_roll.png";
	 img8.src = "style/images/tab_teens_roll.png";
	 img9.src = "style/images/tab_educator_roll.png";
	 img10.src = "style/images/tab_community_roll.png";
	 
	 img11.src = "style/images/hdr_contactus_on.png";
}

$(document).ready(function(){
	$("#site_nav").tabs({ 
		fx: { opacity: 'toggle' },
    select: function(e, ui) {
			if (ui.panel.id == "tab_about") {
				so.addVariable('autostart', 'false');
				so.write('video_player');
			}
		},
    show: function(e, ui) {
    }
	});

	$("#dialog_contact").dialog({ 
		autoOpen: false,
		autoResize: true,
		modal: true, 
		width: 400,
		height: 500,
		overlay: { 
				opacity: 0.5, 
				background: "black" 
		} 
	});
	$('#link_contact a').click(function(){
		$("#dialog_contact").dialog('open');
	});

/*
	$("#sidebar > ul > li").fadeTo("fast", 0.75);
	$("#sidebar > ul > li").hover(
		function () {
			$(this).fadeTo("fast", 1.0);
		},
		function () {
			$(this).fadeTo("fast", 0.75);
		}
	);
*/
	$("#sidebar > ul > li > a > img").fadeTo("normal", 0.0);
	$("#sidebar > ul > li > a").hover(
		function () {
			// alert($(this).find("img").attr("src"));
			$(this).find("img").fadeTo("normal", 1.0);
		},
		function () {
			$(this).find("img").fadeTo("normal", 0.0);
		}
	);

	$("#thumbnail_list > li > a > img").fadeTo("fast", 0.0);
	$("#thumbnail_list > li > a").hover(
		function () {
			// alert($(this).find("img").attr("src"));
			$(this).find("img").fadeTo("fast", 1.0);
		},
		function () {
			$(this).find("img").fadeTo("fast", 0.0);
		}
	);

/*
	$("#global_footer > ul > li").fadeTo("normal", 0.75);
	$("#global_footer > ul > li").hover(
		function () {
			$(this).fadeTo("fast", 1.0);
		},
		function () {
			$(this).fadeTo("fast", 0.75);
		}
	);
*/

	$(".lnk_promo > img").hover(
		function () {
			$(this).fadeTo("normal", 0.0);
		},
		function () {
			$(this).fadeTo("normal", 1.0);
		}
	);
	
	$("#thumbnail_list > li#thumb_video1 > a").click(function () {
		so.addVariable('enablejs','false'); // Stop getUpdate from being called
		return playVideo(0);
	}); 
	$("#thumbnail_list > li#thumb_video2 > a").click(function () {
		so.addVariable('enablejs','false'); // Stop getUpdate from being called
		return playVideo(1);
	}); 
	$("#thumbnail_list > li#thumb_video3 > a").click(function () {
		so.addVariable('enablejs','false'); // Stop getUpdate from being called
		return playVideo(2);
	}); 
	$("#thumbnail_list > li#thumb_video4 > a").click(function () {
		so.addVariable('enablejs','false'); // Stop getUpdate from being called
		return playVideo(3);
	}); 
	playAll();
});	

function isValidEmail(s) {
	 return (s.indexOf(".") > 2) && (s.indexOf("@") > 0);
}
function IsEmpty(aTextField) {
	 if ((aTextField.value.length==0) || (aTextField.value==null)) {
			return true;
	 }
	 else { return false; }
}	
function myValidate() {
	var f = document.forms[0];
	if (IsEmpty(f.first_name) || IsEmpty(f.last_name) || IsEmpty(f.email) || IsEmpty(f.subject) || IsEmpty(f.comments) || !isValidEmail(f.email.value)) {
		$("#error_box").show();
		return false;
	}
	$("#error_box").hide();
	return true;
}
