// Email window popup with disclaimer static text.
// use: when user clicks and attorney email link
//
function emailWindow(email)
{
        window.open("email-popup.html?email=" + email, "EmailNotice", "toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes,width=500,height=220");
}

// Bookmark page link, IE only.
// all other browsers displays an alert box.  not sure how detailed we
// want to make this, eg NS, Firefox 'press ctrl+d' message, Mozilla ??
//
function addToFavorites()
{
	var ua = navigator.userAgent.toLowerCase(); 
	
	// browser engine name
	this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
	this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

	// browser name
	this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
	this.isSafari      = (ua.indexOf('safari') != - 1);
	this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
	this.isOpera       = (ua.indexOf('opera') != -1); 
	this.isIcab        = (ua.indexOf('icab') != -1); 
	this.isAol         = (ua.indexOf('aol') != -1); 
	this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
	this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
	this.isFirebird    = (ua.indexOf('firebird/') != -1);
	this.isFirefox    = (ua.indexOf('firefox/') != -1);
	this.isChrome    = (ua.indexOf('chrome/') != -1);
	this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );

	this.versionMajor = parseInt(this.versionMinor);
	this.isMac    = (ua.indexOf('mac') != -1);

	this.isIE5x = (this.isIE && this.versionMajor == 5);
	
	if (window.external && !this.isMac && !this.isFirefox && !this.isChrome)
	{
		var url=window.location.href;
		var title=document.title;
		window.external.AddFavorite(url,title)
	} 
	else if (!this.isMac && (this.isNS || this.isFirefox || this.isMozilla || this.isChrome))
	{
		alert("Press Ctrl+D to bookmark this page."); 
	} 
	else if (this.isMac && (this.isSafari || this.ie5x || this.isMozilla || this.isFirefox || this.isChrome ))
	{
		alert("Press \u2318D to bookmark this page."); 
	} else {
		alert("Sorry! Your browser doesn't support this function.\nUse your browser's bookmark feature to add a bookmark."); 
	}
}

// Place holder for the 'print this page' link
// s/b replaced when we do the html templates
//
function printPage()
{
	window.print();  
}

// 
// NS only
//
function findOnThisPage()
{
	window.find();  
}


// preload images
function preloadImages()
{
	var imagesToLoad = new Array('i/navAbout_on.jpg', 'i/navPractice_on.jpg', 'i/navAttorney_on.jpg', 'i/navNews.jpg', 'i/navDiversity.jpg', 'i/navCareers.jpg', 'i/navContact.jpg');

	// Don't bother if there's no document.images
	if (document.images)
	{
		if (typeof(document.WM) == 'undefined')
		{
			document.WM = new Object();
		}

		document.WM.loadedImages = new Array();

		// Loop through all the arguments.
		var argLength = imagesToLoad.length;

		for(arg=0;arg<argLength;arg++) 
		{
			// For each arg, create a new image.
			document.WM.loadedImages[arg] = new Image();
			// Then set the source of that image to the current argument.
			document.WM.loadedImages[arg].src = imagesToLoad[arg];
		}
	}
}

// goto page
// skip if default value
// see featured.html (zelle)
function gotoPage(url)
{
	if (url != '**')
		window.location = url;
}

function showQuote( quoteNum ) {
	
	if( quoteNum != 0 )
		hideQuote( 0 );
	
	if( quoteBox = document.getElementById("quoteBox_"+quoteNum) )
		quoteBox.style.display='block';
}

function hideQuote( quoteNum ) {
	
	if( quoteBox = document.getElementById("quoteBox_"+quoteNum) )
		quoteBox.style.display='none';
		
	if( quoteNum != 0 )
		showQuote( 0 );
}

function setOptionsText( newText )
{
	if( arguments.length < 1 )
		newText='Options';
		
	document.getElementById('optionsText').innerHTML = newText+':';
}

// VIDEO POPUP 
//
var popupStatus = 0;
function loadPopup(video_id, forced)
{
	//loads popup only if it is disabled
	if(popupStatus==0){
		$(".backgroundPopup").css({
			opacity: "0.7"
		});
		
		if(forced)
		{
			$(".backgroundPopup").show();
			$('#popupContact_').show();
		} else {
			$(".backgroundPopup").fadeIn("slow");
			$('#popupContact_'+video_id).fadeIn("slow");
		}
		
		popupStatus = 1;
		
	}
}

// disabling popup
function disablePopup(video_id)
{
	//disables popup only if it is enabled
	if(popupStatus==1){
		
		$(".backgroundPopup").fadeOut("slow");
		$(".popupContact").fadeOut("slow");
		
		// stop jwplayer, or IE will keep playing the audio
		// uses the makeOuterHtml() function for Firefox to work right
		// We also use this popup for a form, so in some instances might
		// not need to worry about destroying the jwplayer.
		if(video_id)
			jwplayer('contactArea_'+video_id).remove();
		
		popupStatus = 0;
	}
}

// positioning popup
function centerPopup(video_id)
{

	var windowHeight = $(window).height();
	var windowWidth = $(window).width();
	var popupHeight = $(".popupContact").height();
	var popupWidth = $(".popupContact").width();
	var popupOffset = $("#body").offset();
	
	var positionTop = windowHeight/2-popupHeight/2;
	
	if(video_id)
		var positionLeft =  windowWidth/2-popupWidth/2 - 60;
	else
		var positionLeft =  windowWidth/2-popupWidth/2 - 26;
	
	var positionLeft =  positionLeft-popupOffset.left;

	//centering
	$(".popupContact").css({
		"position": "absolute",
		"top": positionTop,
		"left": positionLeft
	});
	
	//only need force for IE6
	$(".backgroundPopup").css({
		"height": windowHeight
	});
}

var player_started = false;
var video_playing = null;
function createPlayer(full_video_file, video_id)
{
	
	if(video_playing != video_id)
	{
		player_started = false;
	}
	
	if(!player_started)
	{
		jwplayer('contactArea_'+video_id).setup({
		file: 'http://media.dh.firmseek.com/'+full_video_file,
		height: '100%',
		width: '100%',
		autostart: true,
		players: [
			{ type: 'flash', src: 'flash/player.swf' },
			{ type: 'html5' }
			]
		});
	
	} 
	
	video_playing = video_id;
}	


// function for Firefox to remove video correctly
// for some reason, we can't reinitialize remove/reinitiallize jwplayer
// in FF or we get crossdomain error
// http://www.longtailvideo.com/support/forums/jw-player/javascript-interaction/14969/firefox-throws-javascript-error-when-setting-listeners-after-ajax-replacement

var _emptyTags = {
"IMG": true,
"BR": true,
"INPUT": true,
"META": true,
"LINK": true,
"PARAM": true,
"HR": true
};

function makeOuterHtml()
{
	
	if(typeof(HTMLElement) != 'undefined'){ // prevents IE from seeing the rest
		HTMLElement.prototype.__defineGetter__("outerHTML", function () {
			var attrs = this.attributes;
			var str = "<" + this.tagName;
			for (var i = 0; i < attrs.length; i++)
				str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";
			if (_emptyTags[this.tagName])
				return str + ">";
			return str + ">" + this.innerHTML + "</" + this.tagName + ">";
		});
		HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
			var r = this.ownerDocument.createRange();
			r.setStartBefore(this);
			var df = r.createContextualFragment(sHTML);
			this.parentNode.replaceChild(df, this);
		});
	}
}

$(document).ready(function() {
	makeOuterHtml();
});


	
// run various stuff on document ready	
jQuery(function(){
	
	var video_id = null;
	// click to load popup
	$(".popVideo").click(function(){
		
		idnum = this.id;
		video_id = idnum.substring(9);
		full_video_file = $('#popupContact_'+video_id+' #contactArea_'+video_id).text();
		
		// load the video into the popup
		// be used if upgraded to latest player with html5 support
		// not doing that just yet
		createPlayer(full_video_file, video_id)
		
		// centering with css
		centerPopup(video_id);
		
		// load popup
		loadPopup(video_id, forced = false);
	});
	
	var form_id = null;
	// click to load popup
	$(".popForm").click(function(){
		
		idnum = this.id;
		form_id = idnum.substring(9);
		
		// centering with css
		centerPopup(form_id);
		
		// load popup
		loadPopup(form_id, forced = false);
	});
				
	// click the x to close popup
	$(".popupContactClose").click(function(){
		disablePopup(video_id);
	});
	
	// click outsite to close popup
	$(".backgroundPopup").click(function(){
		disablePopup(video_id);
	});
	
	// Press escape to close popup
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup(video_id);
		}
	});
	
	// practice-search case animation
    if($('#index').length != 0)
    {
		$('#testimonialSlides').cycle({
			fx: 		'scrollHorz',
			delay:		2000,
			timeout:	5000,
			speed:		700,
			speedIn:	550,  // speed of the 'in' transition
			speedOut:	450,  // speed of the 'out' transition
			easing:		'easeinout',
			easeIn:		null,  // easing for "in" transition
			easeOut:	null,  // easing for "out" transition
			pause: 		true,
			prev:		'#prev',
			next:		'#next',
			//continuous:	true,
			clearType: 	!$.support.opacity
		});
	}
	
	

});


