// JavaScript Document

var vidArray = new Array;
vidArray[16] = "<div class='videoLink' onclick=\"javascript:loadVideo('GTyDriIWKCQ')\"> <div class='videoImage rat-0'> <img src='images/vidThumb_009.gif' /> </div> <div class='videoDescription'><span class='videoTitle'>The Dark Black Night Knight</span><br /><p>2011 48 Hour Film Project winner of 'Best Film' and 'Best Acting' awards. Showing at 2012 Filmapalooza, NM.</p></div></div>";
vidArray[15] = "<div class='videoLink' onclick=\"javascript:loadVideo('4a5X99q_uE4')\"> <div class='videoImage rat-0'> <img src='images/vidThumb_008.gif' /> </div> <div class='videoDescription'><span class='videoTitle'>Spooky Spooktacular</span><br /><p>Will Kegen and Wilson find their way or will they be doomed to drive aimlessly forever into oblivion.  Watch and find out.</p></div></div>";
vidArray[14] = "<div class='videoLink' onclick=\"javascript:loadVideo('e5N79h5eSL8')\"><div class='videoImage rat-1'><img src='images/vidThumb_007.gif' /></div><div class='videoDescription'><span class='videoTitle'>I Mow the Lawn</span><br /><p>An epic rap about the trials and tribulations of mowing the lawn every week.  With original music by ShortPants.</p></div></div>";
vidArray[13] = "<div class='videoLink' onclick=\"javascript:loadVideo('zOpszVXPO1Q')\"><div class='videoImage rat-0'><img src='images/vidThumb_011.gif' /></div><div class='videoDescription'><span class='videoTitle'>Other Side</span><br /><p>There are messy eaters and then there's Jason.  Luckily Kurtis is a good enough friend to say something.</p></div></div>";
vidArray[12] = "<div class='videoLink' onclick=\"javascript:loadVideo('yunx_pBqKH4')\"><div class='videoImage rat-0'><img src='images/vidThumb_006.gif' /></div><div class='videoDescription'><span class='videoTitle'>The Snowball Fight</span><br /><p>Boys will be boys but a person can only take so much abuse and I wouldn't want to be in the way when this one snaps.</p></div></div>";
vidArray[5] = "<div class='videoLink' onclick=\"javascript:loadVideo('ZnQ-ypCvN0w')\"><div class='videoImage rat-0'><img src='images/vidThumb_005.gif' /></div><div class='videoDescription'><span class='videoTitle'>Stairs</span><br /><p>Josh is super excited because today is 'package day'.  He's been waiting for this one for a while... but there's a catch.</p></div></div>";
vidArray[10] = "<div class='videoLink' onclick=\"javascript:loadVideo('fFz4J73XjIs')\"><div class='videoImage rat-0'><img src='images/vidThumb_012.gif' /></div><div class='videoDescription'><span class='videoTitle'>Butterfinger Commercial</span><br /><p>ShortPants's entry into the 2009 Butterfinger commercial contest.  If you ask if we won we'll make you eat a Butterfinger.</p></div></div>";
vidArray[11] = "<div class='videoLink' onclick=\"javascript:loadVideo('oGGQC5dMW6s')\"><div class='videoImage rat-1'><img src='images/vidThumb_014.gif' /></div><div class='videoDescription'><span class='videoTitle'>Time Machine</span><br /><p>Josh and Wilson get candy bars but Josh isn't happy with his choice.  He could either walk back to the store... or...</p></div></div>";
vidArray[8] = "<div class='videoLink' onclick=\"javascript:loadVideo('WKWWc1btVNA')\"><div class='videoImage rat-1'><img src='images/vidThumb_004.gif' /></div><div class='videoDescription'><span class='videoTitle'>Ghost Friend</span><br /><p>Wilson and his cat had a little accident and now find themselves waiting for a table to open up in heaven.</p></div></div>";
vidArray[7] = "<div class='videoLink' onclick=\"javascript:loadVideo('ifpRkQs6f4U')\"><div class='videoImage rat-0'><img src='images/vidThumb_003.gif' /></div><div class='videoDescription'><span class='videoTitle'>Pizza Video</span><br /><p>A video about a night in the life of a slice of pizza.</p></div></div>";
vidArray[6] = "<div class='videoLink' onclick=\"javascript:loadVideo('d-jmFHC2cu8')\"><div class='videoImage rat-2'><img src='images/vidThumb_002.gif' /></div><div class='videoDescription'><span class='videoTitle'>The Monolith</span><br /><p>Wilson has something to show Josh in his basement... he just isn't sure how to turn it on.</p></div></div>";
vidArray[1] = "<div class='videoLink' onclick=\"javascript:loadVideo('rKPBfL08pvs')\"><div class='videoImage rat-0'><img src='images/vidThumb_013.gif' /></div><div class='videoDescription'><span class='videoTitle'>Game Night</span><br /><p>Wilson thinks the group is playing poker tonight and he is getting down to business.  At least he was right about it being game night.</p></div></div>";
vidArray[3] = "<div class='videoLink' onclick=\"javascript:loadVideo('xuueU-RoO-I')\"><div class='videoImage rat-1'><img src='images/vidThumb_016.gif' /></div><div class='videoDescription'><span class='videoTitle'>Roommate Test 2</span><br /><p>For some reason Kegen's last roommate didn't work out.  He's got another prospective prospect... but he's still not sure...</p></div></div>";
vidArray[4] = "<div class='videoLink' onclick=\"javascript:loadVideo('e5JGCuVkvVE')\"><div class='videoImage rat-2'><img src='images/vidThumb_015.gif' /></div><div class='videoDescription'><span class='videoTitle'>Roommate Test</span><br /><p>Kegen is about to get a new roommate, but how will he ever know whether or not he is trustworthy?  Better test him...</p></div></div>";
vidArray[2] = "<div class='videoLink' onclick=\"javascript:loadVideo('_u2BKra-R8g')\"><div class='videoImage rat-0'><img src='images/vidThumb_017.gif' /></div><div class='videoDescription'><span class='videoTitle'>Forcefield</span><br /><p>Kurtis clearly doesn't know where the line is, and Tony clearly doesn't know what a joke is.</p></div></div>";
vidArray[0] = "<div class='videoLink' onclick=\"javascript:loadVideo('jcZStBiyngY')\"><div class='videoImage rat-1'><img src='images/vidThumb_001.gif' /></div><div class='videoDescription'><span class='videoTitle'>Ninja Poofs</span><br /><p>Josh demonstrates his new toy to Kurtis.  Kurtis wants to try but hasn't read the directions yet.</p></div></div>";
vidArray[9] = "<div class='videoLink' onclick=\"javascript:loadVideo('ESCCfhAsdEo')\"><div class='videoImage rat-0'><img src='images/vidThumb_010.gif' /></div><div class='videoDescription'><span class='videoTitle'>9 Ball Blues</span><br /><p>Winner of the 2009 48 Hour Film Project, 'Audience Choice' award.  Tony takes his 8 ball for granted and learns a valuable life lesson.</p></div></div>";
vidArray.reverse();
var currentPage = 1;
var itemsPerPage = 5;
var TotalPages = Math.ceil(vidArray.length/itemsPerPage);
var vidTitle = "<img src='images/ourVideos.gif' /><br /><br />";
var currentVideo = "";
var pageHTML = "";
var ratingIcon 	= [
					"/images/pg.gif", 
					"/images/13.gif", 
					"/images/r.gif"];
var ratingWords = [
					"No earmuffs required", 
					"Mild swearing", 
					"You kiss your mother with that mouth!?"];
$(document).ready(function() {
	
	/*theURL = window.location.search.substring(1);
	//theVidURL = theURL.split("=");
	//if (theVidURL[0] == "theVideo") {
	//var toLoad = "'" + theVidURL[1] + "'";
	//loadVideo(toLoad);
	*/	 
   
   for(i=0; i < vidArray.length; i++){
	   document.getElementById("videoLinks").innerHTML = document.getElementById("videoLinks").innerHTML + vidArray[i];
   }
   
   for(j=0; j<TotalPages; j++){
	   pageHTML = pageHTML + "<a style='cursor:pointer;' onclick='javascript:gotoPage(" + j + ");' >&nbsp;&nbsp;" + (j + 1) + "&nbsp;&nbsp;</a>";
   }
   
   document.getElementById("paging").innerHTML = "<p>PAGE <span id=\"spncp\">" + currentPage + "</span> of " + TotalPages + "&nbsp;&nbsp;-&nbsp;&nbsp;" + pageHTML;
   jasonissolazy();
 });
 function jasonissolazy(){
	var ratingsDiv = "<div class=\"ratings\"></div>";
	var ratingsDivPH = "<div class=\"ratingsPH\"></div>";
	/*var ratingsImg = "<img src=\"/somepathtosomeimage/andthensomeimage.jpg\" />";*/	
	var tObj = null;
	
	$(".videoLink").css("display","none");
	tObj = $(".videoLink:first");	
	$(tObj).css("display","block");
	
	for (i = 1; i < itemsPerPage; i++){
		tObj = $(tObj).next();
		$(tObj).css("display","block");
	}	
	
	$(".videoImage").each(function(intIndex, objCaller){
		$(objCaller).html(ratingsDiv + $(objCaller).html());
		var ratingCount = 0;
		var ratingsList = "";
		var workerBee = null;
		
		ratingsList = $(objCaller).attr("class");		
		workerBee = ratingsList.split(" ");
		
		for (i = 0; i < workerBee.length; i++){
			var sotemporary = workerBee[i];
			
			sotemporary = sotemporary.split("-");
			
			if (sotemporary.length == 2){
				if (sotemporary[0] == "rat"){
					if (sotemporary[1] != "0"){
						var rememberme = "";					
						if (ratingIcon[sotemporary[1]].charAt(0) == "#"){			
							rememberme = ratingsDivPH;
							if($(objCaller).children(".ratings").children(".ratingsPH").length != 0){
								$(objCaller).children(".ratings").html($(objCaller).children(".ratings").html() + rememberme);
								$(objCaller).children(".ratings").children(".ratingsPH:last").css("background-color",ratingIcon[sotemporary[1]]);
							}else{
								$(objCaller).children(".ratings").html(rememberme);
								$(objCaller).children(".ratings").children(".ratingsPH").css("background-color",ratingIcon[sotemporary[1]]);							
								$(objCaller).children(".ratings").children(".ratingsPH").css("margin-left","0px");
							}						
						}else{							
							rememberme = "<img src=\""+ ratingIcon[sotemporary[1]] +"\" />";
							if($(objCaller).children(".ratings").children("img").length != 0){
								$(objCaller).children(".ratings").html($(objCaller).children(".ratings").html() + rememberme);
							}else{
								$(objCaller).children(".ratings").html(rememberme);					
								$(objCaller).children(".ratings").children("img").css("margin-left","0px");
							}		
						}
						$(objCaller).siblings(".videoDescription").append("<p style=\"margin:2px 0px 0px 0px; font-size:8px\"><span style=\"color:#a96666;\">*</span>" + ratingWords[sotemporary[1]] + "</p>");
						ratingCount++;
					}
				}
			}			
		}		
		$(objCaller).children(".ratings").css("width", (ratingCount * 24) + "px");
	});	
 }
 function gotoPage(number){
 
	$("#spncp").html(number + 1);
	$(".videoLink").css("display","none");
	tObj = $(".videoLink:first");	
 
	for (i = 0; i < number; i++){
		for (j = 0; j < itemsPerPage; j++){
			tObj = $(tObj).next();
		}
	}	
	for (i = 1; i < itemsPerPage; i++){
		$(tObj).css("display","block");
		tObj = $(tObj).next();
	} 
	$(tObj).css("display","block");
	
/*
	 var theIndex = number*4;
	 currentPage = number+1;
	 var remainder = 4;
	 if(number == Math.floor(vidArray.length/4)){
		remainder = (vidArray.length%4);
	 }
	 
	 document.getElementById("videoLinks").innerHTML = vidTitle;
	 for(k=0; k < remainder; k++){
	 	document.getElementById("videoLinks").innerHTML = document.getElementById("videoLinks").innerHTML + vidArray[theIndex + k];
 	 }
	 document.getElementById("paging").innerHTML = "<p>PAGE " + currentPage + " of " + TotalPages + "&nbsp;&nbsp;-&nbsp;&nbsp;" + pageHTML;
*/
}

function useHttpResponse(){
if (xmlhttp.readyState == 4) {
    var textout = xmlhttp.responseText;
    alert(textout);
  }
}

 function sendmyemail(){
 if ($("#txtemail").val() != ""){
	 xmlhttp=new XMLHttpRequest();
	  xmlhttp.open("GET", "maillist.php?email=" + $("#txtemail").val(), true);
	  xmlhttp.onreadystatechange = useHttpResponse;
	  xmlhttp.send();
	 }
	 else{
		alert("We need you to at least pretend to give us your email by putting something in the box.");
	 }
 }

 function loadVideo(theOne){
	/*setCurrent(theOne);*/
	loadNewVideo(theOne, 0); 
 }
 
 function vvPlaylist(){
	 loadNewPlaylist("0135B725C07141BC", 1, 0, "large");
 }
 
 
 
 function showShare(which){
	if(which == "facebook"){
		$("#facebookShare").fadeIn("slow");	
	}
	if(which == "twitter"){
		$("#twitterShare").fadeIn("slow");	
	}
 }
 
 function hideShare(){
		$("#facebookShare").fadeOut("slow");	
		$("#twitterShare").fadeOut("slow");	
 }
 
 function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}
