jQuery(initPPVideo)

function initPPVideo() {

	
	vd = jQuery("#ppVideoContainer");
	
	//create div that disables all other interaction below video popup;
	
	hw = jQuery("html").width();
	hh = jQuery("html").height();
	vd.before('<div id="ppVideoCover" style="display: none"></div>')
	vc = jQuery("#ppVideoCover");
	vc.width(hw).height(hh).fadeTo(0,.8);
	
	
	detectAnchor();
	
	
	vc.click( function(event){
		event.preventDefault();
		vd.hide();
		vc.hide();
		
		mv = jQuery("#ppMeatVideo");
		vv = jQuery("#ppVegetableVideo");
		
		//stop all youtube videos by removing the inner html, and reapplying it
		vvHtml = vv.html();
		vv.html(vvHtml);
		mvHtml = mv.html();
		mv.html(mvHtml);
		
	});
	
	jQuery("#watch-videos").click( function(event){
		event.preventDefault();
		
		//center the video div
		bw = jQuery("html").width();
		bh = jQuery("html").height();
		vw = vd.width();
		vh = vd.height();
		vl = ((bw - vw)/2) + 60;
		vd.css("left",vl + "px")
		
		vd.show();
		vc.show();
		
		
		jQuery(window).resize(function(){
			bw = jQuery("html").width();
			bh = jQuery("html").height();
			vw = vd.width();
			vh = vd.height();
			vl = ((bw - vw)/2) + 60;
			vd.css("left",vl + "px")
			
			hw = jQuery("html").width();
			hh = jQuery("html").height();
			vc.width(hw).height(hh);
		});
	});
	
	jQuery("#ppVideoClose").click(function(event) {
		//event.preventDefault();
		
		vd.hide();
		vc.hide();
		
		mv = jQuery("#ppMeatVideo");
		vv = jQuery("#ppVegetableVideo");
		
		//stop all youtube videos by removing the inner html, and reapplying it
		vvHtml = vv.html();
		vv.html(vvHtml);
		mvHtml = mv.html();
		mv.html(mvHtml);
		
		//curUrl = document.location.href.split("#");
		//document.location = curUrl[0];
		
	});
	
	jQuery("#ppVideoMeat").click(function(event) {
		event.preventDefault();
		mv = jQuery("#ppMeatVideo");
		vv = jQuery("#ppVegetableVideo");
		
		if(!mv.is(':visible'))
		{
			vvHtml = vv.html();
			vv.hide();
			vv.html(vvHtml);
			
			mv.show();
			
			jQuery("#ppVideoMeat").addClass("ppButtonSelected");
			jQuery("#ppVideoVegetables").removeClass("ppButtonSelected")
		}
	});
	jQuery("#ppVideoVegetables").click(function(event) {
		event.preventDefault();
		mv = jQuery("#ppMeatVideo");
		vv = jQuery("#ppVegetableVideo");
		
		if(!vv.is(':visible'))
		{
			mvHtml = mv.html();
			mv.hide();
			mv.html(mvHtml);
			vv.show();
			
			jQuery("#ppVideoMeat").removeClass("ppButtonSelected");
			jQuery("#ppVideoVegetables").addClass("ppButtonSelected")
		}
	});
}

function detectAnchor()
{
	//check for anchor tags that need action
	var thisURL = document.location.toString();
	if(thisURL.match('#'))
	{
		matchedAnchor = thisURL.split('#')[1];
		if(matchedAnchor == "video")
		{
			
			//alert("showvideo")
			//show video
			bw = jQuery("html").width();
			bh = jQuery("html").height();
			vw = vd.width();
			vh = vd.height();
			vl = ((bw - vw)/2) + 60;
			vd.css("left",vl + "px")
			
			vd.show();
			vc.show();
		}
	}
}