/**
 * 
 * ML WEBCAST PAGE
 * v0.1
 * by Bob Budd
 * bbudd@boathouseinc.com
 *
 */

var elem, myInterval, initHeight, addHeight, finalHeight, objIframe = '';

// setting up listeners for clicks on the two subscribe buttons
Event.observe(window, 'load', function() {
	if(Element.getStyle('long-modal-information', 'display') == 'block' || Element.getStyle('short-modal-signup', 'display') == 'block') return;
	$('notify-me').observe('click', function(event){
		Event.stop(event);
		subscribeModalCall(event);
	});
	$('next-webcast').observe('click', function(event){
		Event.stop(event);
		subscribeModalCall(event);
	});
});

// called by flash to resize its parent div for the bios 
function resizeFlash(num) {
	finalHeight = num;
	elem = $('webcast-hero-container');
	initHeight = parseInt(elem.style.height);
	addHeight = (num - initHeight) / 7.5;
	myInterval = (addHeight < 0 ? setInterval(makeSmaller, 30) : setInterval(makeBigger, 30));
}


function makeBigger(){
	if(initHeight <= finalHeight) {
		initHeight += addHeight;
		elem.style.height = initHeight + "px";
	} else {
		elem.style.height = finalHeight + "px";
		clearInterval(myInterval);
	}
}


function makeSmaller(){
	if(initHeight >= finalHeight) {
		initHeight += addHeight;
		elem.style.height = initHeight + "px";
	} else {
		elem.style.height = finalHeight + "px";
		clearInterval(myInterval);
	}
}




// open the "important information" modal 
function importantModalCall() {
	if(Element.getStyle('long-modal-information', 'display') == 'block' || Element.getStyle('short-modal-signup', 'display') == 'block') return;
	pageTrack("/webcasts/2010/outlook/importantinfo");
	Element.setStyle('long-modal-information', {'display':'block'});
	Element.setOpacity('long-modal-information', 0)
	new Effect.Opacity('long-modal-information', { duration: 1.0, from: 0, to: 1 });
	Event.observe(window, 'keydown', function(e){
		if(e.keyCode == 27 || e.keyCode == "KEY_ESC") {
			new Effect.Opacity('long-modal-information', { duration: 1.0, from: 1, to: 0, afterFinish: function(e){
				Element.setStyle('long-modal-information', {'display':'none'});
				} 
			});
		}
	});
	// click listener to close modal
	$('important-close').observe('click', function (e) {
		new Effect.Opacity('long-modal-information', { duration: 1.0, from: 1, to: 0, afterFinish: function(e){
			Element.setStyle('long-modal-information', {'display':'none'});
			} 
		});
	});
	$('important-close-lower').observe('click', function (e) {
		new Effect.Opacity('long-modal-information', { duration: 1.0, from: 1, to: 0, afterFinish: function(e){
			Element.setStyle('long-modal-information', {'display':'none'});
			} 
		});
	});
}



// open the "subscribe" modal 
function subscribeModalCall(e) {
	if(!objIframe){
new Insertion.Top('short-modal-signup', "<iframe src='Outlook_2010_Ch2.aspx' scrolling='no' width='100%' height='105%' style='border:none;'></iframe>");	}
	if(Event.element(e).id == 'notify-me') pageTrack("/webcasts/2010/outlook/signup/?src=btn-top"); // coming from the top link
	else pageTrack("/webcasts/2010/outlook/signup/?src=btn-bottom"); // coming from the bottom link
	Element.setStyle('short-modal-signup', {display:'block'});
	Element.setOpacity('short-modal-signup', 0)
	//Effect.scrollTo('pseudoBody').animate;
	new Effect.Opacity('short-modal-signup', { duration: 1.0, from: 0, to: 1 });
}

// called from flash to tell when the bio panel is opened
function getPanel(item) {
	var axel = Math.random()+"";
	var a = axel * 10000000000000;
	fncWriteFloodlightTag("footer", "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=outlo173;ord=1;num=" + a + "?");
	pageTrack(item);
}

// called from inside the flash as well as outside, google analytics call
function pageTrack(item) {
	var pt = _gat._getTracker('UA-3395701-2');
	//pt._initData();
	try{
		pt._trackPageview(item);
	} catch (e) { trace("FAIL"); }
}

// called from inside the flash only, google analytics call - mostly for video events
function eventTrack(one, two, three, four) { 
	var pt = _gat._getTracker('UA-3395701-2');
	pt._initData();
	//trace(one +" >>>>> " + two +" >>>>> " + three +" >>>>> " + (four ? four : "DEAD")); 
	try{
		pt._trackEvent(one, two, three);  
	} catch (e) { 
		console.log(e); 
	}
	var axel = Math.random()+"";
	var a = axel * 10000000000000;
	//trace(four);
	if (four !== undefined) fncWriteFloodlightTag("footer", four + a + "?");
}



// dart floodlight call code
function fncWriteFloodlightTag(container, url) {
	//is url valid
	if (url != "" && url != null) {
		//does browser support DOM scripting?
		if (document.getElementById) {
			//find the container
			var _con = document.getElementById(container);
			if (_con != null) {
				//create a new <image> element
				var _iframe = document.createElement('iframe');
				
				_iframe.setAttribute('alt', 'DoubleClick Spotlight tracking image');
				_iframe.setAttribute('src', url);
				_iframe.setAttribute('width', "1");
				_iframe.setAttribute('height', "1");
				
				//attach <img> to container
				_con.appendChild(_iframe);
			}			
		}
		//does browser support document.images?
		else if (document.images) {
			var _iframe = new Image();
			_iframe.src = url;
		}
		//does browser support document.write?
		else if (document.write) {
			document.write("<iframe src=\"" + url + "\" alt=\"\" width=\"1\" height=\"1\" frameborder=\"0\" />");
		}
	}
}


// QA documentation code
function trace(item) {
	if(console.log) console.log(item);
}

