function homeVideoModal() {

	var blackout = $('<div id="blackout" />');
	blackout.width($(window).width());
	blackout.height($(window).height());

	var outerContainer = $('<div id="OuterContainer" />');

	var innerContainer = $('<div id="InnerContainer" />');
	innerContainer.html('<object id="myExperience794133958001" class="BrightcoveExperience"><param name="bgcolor" value="#FFFFFF" /><param name="width" value="710" /><param name="height" value="402" /><param name="playerID" value="782523916001" /><param name="playerKey" value="AQ~~,AAAAtjTNaYk~,8tm2VJH1hnpyKPeFgYu2ru1VVzYqnMqR" /><param name="isVid" value="true" /><param name="dynamicStreaming" value="true" /><param name="@videoPlayer" value="794133958001" /></object>');
	
	var closeModal = $('<a href="javascript:void(0);" id="closeModal" class="play" onClick="closeModal()" />')

	$('body').append(outerContainer);
	outerContainer.append(innerContainer);
	innerContainer.append(closeModal);
	blackout.insertBefore(outerContainer);
	
	outerContainer.css('top', ($(window).height() - outerContainer.height()) / 2);
	brightcove.createExperiences();
}

function closeModal() {
	$('#blackout').remove();
	$('#OuterContainer').remove();
	supersize.start();
}

$(document).ready(function(){

	var supersize = $(function(){
		if($.fn.supersized){
			$.fn.supersized.options = {  
			startwidth: 4,  
			startheight: 3,
			vertical_center: 1,
			slideshow: 1,
			navigation:1,
			transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
			pause_hover: 0,
			slide_counter: 0,
			slide_captions: 0,
			slide_interval: 6000
			};
		    $('#supersize').supersized(); 
	    }
	});
	
	var bgImage = $('#fullbg img');		
 
    function resizeImg() {
      var imgwidth = bgImage.width(),
		   imgheight = bgImage.height(),
		   winwidth = $(window).width(),
		   winheight = $(window).height(),
		   widthratio = winwidth / imgwidth,
		   heightratio = winheight / imgheight,
		   widthdiff = heightratio * imgwidth,
		   heightdiff = widthratio * imgheight;
 
      if(heightdiff>winheight) {
        bgImage.css({
          width: winwidth+'px',
          height: heightdiff+'px'
        });
      } else {
        bgImage.css({
          width: widthdiff+'px',
          height: winheight+'px'
        });		
      }
	 
	 $("#fullbg img").show();
	 $("#fullbg").show();
	  
    } 
    resizeImg();
    $(window).resize(function() {
      resizeImg();
    }); 	
	
	$(".lightbox").lightbox();
		
	function pagerFactory(idx, slide) {
		var total = $("#slideshow img").length;	
		alert((idx+1)+'/'+total);
	    return (idx+1)+'/'+total;//'<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
	};
	
	function onAfter(curr, next, opts) {
		var index = opts.currSlide;
		var total = $("#slideshow img").length;	
		$("#slidenav").html((index+1)+"/"+total);
	
		var zoom_link = $("#slideshow a:nth-child("+index+")").attr("href");
		$("#view_large").attr("href", zoom_link);
	}
	
	$(".toggle_container").hide();
	

	$("h2.trigger").click(function(){

		$(this).toggleClass("active").next().slideToggle("slow");
		
		if ($(this).hasClass("active")) {
			$("a", this).html("Read Less");							
		} else {
			$("a", this).html("Read More");							
		}
	});
	
	$("span.trigger").click(function(){

		$(this).toggleClass("active").parent().next().slideToggle("slow");
		
		if ($(this).hasClass("active")) {
			$("a", this).html("Read Less");							
		} else {
			$("a", this).html("Read More");							
		}
	});
	
	$('.button a').click(function() {	
		homeVideoModal();
		return false;	
	});
	
	if ($('#slideshow').length) {
		$('#slideshow').cycle({
			fx:      'fade',
			prev:    '#prevBtn',
			next:    '#nextBtn',
		 	after:   onAfter
		});	
	}			
});
