top.ShortTailD30 = function(p_VAST) {

// =========================================
// INITIALIZATION CODE	(07-22-09)	

// ************************************
// ** DEFINE EXTERNAL FILE URLS // ************************************
this.URL_JQUERY = 'http://shorttailmedia.com/wp-content/themes/shortTailMedia/style/js/jquery.js';
this.URL_SWFOBJECT = 'http://shorttailmedia.com/wp-content/themes/shortTailMedia/style/js/jquery.swfobject.min.js';
this.URL_D30 = 'http://www.shorttailmedia.com/images/d30/shortTail_D30.swf';

this.VAST = p_VAST;	
this.initialized = false;
this.scriptsWritten = false;top
this.zMax = 9999;

// add JQUERY script to top level if it doesn't exist
if(top.jQuery == undefined)
	write_script(this.URL_JQUERY);   
shortTailD30_initTimer = setInterval(function(){
	// enforce swfobject gets written once jquery exists
	if (!top.shortTail_D30.scriptsWritten && top.jQuery != undefined && top.jQuery.hasFlashPlayerVersion == undefined) {
		write_script(top.shortTail_D30.URL_SWFOBJECT);
		top.shortTail_D30.scriptsWritten = true;
	}
	// both scripts are ready start the D30
	if(top.jQuery != undefined && top.jQuery.hasFlashPlayerVersion != undefined)
	{
		clearInterval(shortTailD30_initTimer);
		top.shortTail_D30.modalInit();}
	}, 	100
);
// =========================================

function write_script(p_src) {
	var tag;
	var container = top.document.getElementsByTagName("head").length > 0 		? top.document.getElementsByTagName("head")[0] : top.document.getElementsByTagName("body")[0];
	
	tag = top.document.createElement('script');
	tag.setAttribute('src', p_src);
	tag.setAttribute('type', 'text/javascript');
	tag.setAttribute('language', 'JavaScript');
	container.appendChild(tag);
	void(tag);
}


this.modalInit = function () {

	if(!top.jQuery.hasFlashPlayerVersion("9.0.115")) {
	  alert('Please install the latest version of Flash player');
	  return;
	  }
  var hostPage, hostReferrer;

  try{
      hostPage = top.location.href
      hostReferrer = top.document.referrer;
  }catch(err){
      hostPage = "";
      hostReferrer = "";
  }

  shortTail_D30Modal = top.jQuery('<div id="shortTail_D30_modal" ></div>');
  shortTail_D30Content = top.jQuery('<div id="shortTail_D30_content" ></div>');
	shortTail_D30Content.css({position:'absolute', top:'0px', left:'0px', width:'1px', height:'1px', 'margin-top':0, 'margin-left':0, 'z-index':top.shortTail_D30.zMax + 2});
	top.shortTail_D30.positionAtZMax();
	
	top.jQuery(top.document.body).append(shortTail_D30Modal);
	top.jQuery(top.document.body).append(shortTail_D30Content);

  //append flash
 	shortTail_D30Content.flash
	(
		{
	        swf: top.shortTail_D30.URL_D30,
			hasVersion:'9.0.115',
	        width: '100%',
	        height: '100%',
	        params: 			{
	            bgcolor: "#000000",
	            allowScriptAccess: "always",
	            wmode: "transparent",
	            flashvars: 				{
	                hostPage: escape(hostPage),
	                hostReferrer:escape(hostReferrer),
	                VastXML: top.shortTail_D30.VAST 	            }
	        }
		}      );
}
	

this.showModal = function () { 	top.shortTail_D30.positionAtZMax();
 	shortTail_D30Modal.css({opacity:0, display:"inline", filter:"alpha(opacity=0)", position:"absolute", top:0, left:0, width:Math.max(top.jQuery(top.document).width(), top.jQuery(top).width()), height:Math.max(top.jQuery(top.document).height(), top.jQuery(top).height()), background:"#000000"});
  shortTail_D30Modal.fadeTo(525, 0.70, top.shortTail_D30.onFadeInCompleted);
	// bind to load of page
	top.jQuery(top).load(top.shortTail_D30.onResized);
}


this.onFadeInCompleted = function() {
	if(top.shortTail_D30.initialized) return;

	top.shortTail_D30.initialized = true;
	
  shortTail_D30Content.width('800px');
	shortTail_D30Content.height('524px');	
 	shortTail_D30Content.css({
		'top': Math.round((top.jQuery(top).height() - shortTail_D30Content.outerHeight()) / 2) + 'px',
		'left': Math.round((top.jQuery(top).width() - shortTail_D30Content.outerWidth()) / 2) + 'px'
	});
	shortTail_D30Content.show();
	
	// bind to resize of window
  top.jQuery(top).resize(top.shortTail_D30.onResized);
	
	top.shortTail_D30.positionAtZMax();
}

this.onResized = function(){
	var winWidth = top.jQuery(top).width();
	var winHeight  = top.jQuery(top).height();
	
	shortTail_D30Content.css({'left': Math.round((winWidth - 800) / 2) + 'px', 'top': Math.round((winHeight - 525) / 2) + 'px'});
	shortTail_D30Modal.width(Math.max(top.jQuery(top.document).height(), winWidth));
	shortTail_D30Modal.height(Math.max(top.jQuery(top.document).width(), winHeight));
}

this.modalFadeOut = function () {    shortTail_D30Modal.fadeOut();
}


this.closeModal = function () {
	
	top.shortTail_D30 = false; //added by JP on 10/16/09
	// stop binds
  top.jQuery(top).unbind('resize', top.shortTail_D30.onResized);
	top.jQuery(top).unbind('load', top.shortTail_D30.onResized);
	// clear out content
  shortTail_D30Modal.height('0px');
  shortTail_D30Modal.width('0px');	
	shortTail_D30Modal.empty();
  shortTail_D30Content.height('0px');
  shortTail_D30Content.width('0px');
	// SAFARI throws an error if attempting to kill out from an ExternalInterface call
	setTimeout("shortTail_D30Content.empty();", 250);
  try{
      shortTail_D30_onClose();
		
  }catch(err){
  }
}

this.positionAtZMax = function(){
	top.jQuery('*').each(function(){
		var cur = parseInt(top.jQuery(this).css('zIndex'));
		top.shortTail_D30.zMax = cur > top.shortTail_D30.zMax ? top.jQuery(this).css('zIndex') : top.shortTail_D30.zMax;
	});
	shortTail_D30Content.css({'z-index':top.shortTail_D30.zMax + 2});
	shortTail_D30Modal.css({'z-index': top.shortTail_D30.zMax + 1});
}	


}




/*
* The VASTXML string var that is passed into the constructor as VAST string
* Ad servers should template this string so that it creates a valid VAST document within the one line string.
* The D30 JavaScript will the embed the VAST string into the D30 Flash module when the ad is run.
*/

//top.VASTXML = '<?xml version="1.0" encoding="UTF-8"?><VideoAdServingTemplate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd"><Ad id="D30"><InLine><AdSystem>BURST</AdSystem><AdTitle>Trailer</AdTitle><Description>video trailer</Description><Survey></Survey><Error></Error><Impression></Impression><TrackingEvents></TrackingEvents><Video><Duration>00:00:15</Duration><AdID>AdID</AdID><AdParameters apiFramework="adParams"/><VideoClicks><ClickThrough><URL id="myadsever"><![CDATA[http://www.filminfocus.com/focusfeatures/film/taking_woodstock/]]></URL></ClickThrough><ClickTracking></ClickTracking><CustomClick></CustomClick></VideoClicks><MediaFiles><MediaFile id="myMediaFile" delivery="progressive" bitrate="250" width="200" height="200" type="video/x-flv"><URL><![CDATA[RETW3011H_1.flv]]></URL></MediaFile></MediaFiles></Video><CompanionAds><Companion id="sponsor" width="270" height="40" resourceType="static" creativeType="PNG"><AltText>Taking Woodstock</AltText><URL><![CDATA[/images/d30/88x31_nowplaying.jpg]]></URL></Companion><Companion id="social" width="16" height="16" resourceType="static" creativeType="PNG"><URL><![CDATA[/images/d30/d30_twitter_logo.png]]></URL><CompanionClickThrough><URL><![CDATA[http://twitter.com/]]></URL></CompanionClickThrough></Companion><Companion id="social" width="16" height="16" resourceType="static" creativeType="PNG"><URL><![CDATA[/images/d30/d30_facebook_logo.png]]></URL><CompanionClickThrough><URL><![CDATA[http://www.facebook.com/TakingWoodstock]]></URL></CompanionClickThrough></Companion></CompanionAds><NonLinearAds></NonLinearAds><Extensions><Extension type="D30Config"><BaseColor>000000</BaseColor><FontColor>FFFFFF</FontColor><ProgressColor>0066CC</ProgressColor><SecsRequiredToView>5</SecsRequiredToView></Extension></Extensions></InLine></Ad></VideoAdServingTemplate>';

top.CNNXML = '<?xml version="1.0" encoding="UTF-8"?><VideoAdServingTemplate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd"><Ad id="D30"><InLine><AdSystem>BURST</AdSystem><AdTitle>Trailer</AdTitle><Description>video trailer</Description><Survey></Survey><Error></Error><Impression></Impression><TrackingEvents></TrackingEvents><Video><Duration>00:00:15</Duration><AdID>AdID</AdID><AdParameters apiFramework="adParams"/><VideoClicks><ClickThrough><URL id="myadsever"><![CDATA[http://cnn.com]]></URL></ClickThrough><ClickTracking></ClickTracking><CustomClick></CustomClick></VideoClicks><MediaFiles><MediaFile id="myMediaFile" delivery="progressive" bitrate="250" width="200" height="200" type="video/x-flv"><URL><![CDATA[CNN_spot/CNN_spot3.flv]]></URL></MediaFile></MediaFiles></Video><CompanionAds><Companion id="sponsor" width="270" height="40" resourceType="static" creativeType="PNG"><AltText>CNN</AltText><URL><![CDATA[/images/d30/CNN_spot/CNN_88x31_nowplaying.jpg]]></URL></Companion><Companion id="social" width="16" height="16" resourceType="static" creativeType="PNG"><URL><![CDATA[/images/d30/d30_twitter_logo.png]]></URL><CompanionClickThrough><URL><![CDATA[http://twitter.com/cnnbrk]]></URL></CompanionClickThrough></Companion><Companion id="social" width="16" height="16" resourceType="static" creativeType="PNG"><URL><![CDATA[/images/d30/d30_facebook_logo.png]]></URL><CompanionClickThrough><URL><![CDATA[http://www.facebook.com/cnn]]></URL></CompanionClickThrough></Companion></CompanionAds><NonLinearAds></NonLinearAds><Extensions><Extension type="D30Config"><BaseColor>000000</BaseColor><FontColor>FFFFFF</FontColor><ProgressColor>0066CC</ProgressColor><SecsRequiredToView>5</SecsRequiredToView></Extension></Extensions></InLine></Ad></VideoAdServingTemplate>';

top.BEETXML = '<?xml version="1.0" encoding="UTF-8"?><VideoAdServingTemplate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd"><Ad id="D30"><InLine><AdSystem>BURST</AdSystem><AdTitle>Trailer</AdTitle><Description>video trailer</Description><Survey></Survey><Error></Error><Impression></Impression><TrackingEvents></TrackingEvents><Video><Duration>00:00:15</Duration><AdID>AdID</AdID><AdParameters apiFramework="adParams"/><VideoClicks><ClickThrough><URL id="myadsever"><![CDATA[http://beet.tv]]></URL></ClickThrough><ClickTracking></ClickTracking><CustomClick></CustomClick></VideoClicks><MediaFiles><MediaFile id="myMediaFile" delivery="progressive" bitrate="250" width="200" height="200" type="video/x-flv"><URL><![CDATA[BeetTV_DAP/BeetTvInterview.flv]]></URL></MediaFile></MediaFiles></Video><CompanionAds><Companion id="sponsor" width="270" height="40" resourceType="static" creativeType="PNG"><AltText>BeetTV</AltText><URL><![CDATA[/images/d30/BeetTV_DAP/BeetTV_88x31.jpg]]></URL></Companion><Companion id="social" width="16" height="16" resourceType="static" creativeType="PNG"><URL><![CDATA[/images/d30/d30_twitter_logo.png]]></URL><CompanionClickThrough><URL><![CDATA[http://twitter.com]]></URL></CompanionClickThrough></Companion><Companion id="social" width="16" height="16" resourceType="static" creativeType="PNG"><URL><![CDATA[/images/d30/d30_facebook_logo.png]]></URL><CompanionClickThrough><URL><![CDATA[http://www.facebook.com]]></URL></CompanionClickThrough></Companion></CompanionAds><NonLinearAds></NonLinearAds><Extensions><Extension type="D30Config"><BaseColor>000000</BaseColor><FontColor>FFFFFF</FontColor><ProgressColor>0066CC</ProgressColor><SecsRequiredToView>5</SecsRequiredToView></Extension></Extensions></InLine></Ad></VideoAdServingTemplate>';

top.jQuery(document).ready(function () {
	top.jQuery('.page-item-47,.viewDemo').click(function () {
	  launchDemo( $( this ).attr("rel") );
	  return false;
	});
});

//flash and html links can call this function to launch the demo
function launchDemo( strFLV ){
	if( ! top.shortTail_D30 ){
		
		if( strFLV == 'CNN'  ){
			top.shortTail_D30 = new top.ShortTailD30(top.CNNXML);
		}else if( strFLV == 'BEET'  ){
			top.shortTail_D30 = new top.ShortTailD30(top.BEETXML);
		}else{
			top.shortTail_D30 = new top.ShortTailD30(top.VASTXML);
		}
		
	}
}

