 // JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function clearChildren(element) {
	if(element.firstChild) {
		while(element.childNodes[0]) {
			element.removeChild(element.childNodes[0]);
		}
	}
}

var lipservice = {
			
	__construct: function () {
		MM_preloadImages('images/buttonBlogf2.gif','images/buttonBookf2.gif','images/buttonCompanyf2.gif','images/buttonContactf2.gif','images/buttonFriendf2.gif','images/buttonHomef2.gif','images/buttonJobsf2.gif','images/buttonLinksf2.gif','images/buttonShowsf2.gif','images/buttonAccessf2.gif','images/slideShow1.jpg','images/slideShow2.jpg','images/slideShow3.jpg','images/slideShow4.jpg','images/slideShow5.jpg');
		this.replaceText();
		this.navswap();
		this.patron();
		this.podcasts();
		this.wlvideo();
		this.linksBlur();
		this.jsLink();
	},
	
	replaceText: function() {
		Cufon.replace('.cufon');
	},
	
	linksBlur: function () {
		$('a').focus(function () {
			$(this).blur();
		})
	},
	
	jsLink: function () {
		$('#test').click(function () {
			var link = prompt("Please enter the full url of the page you want to link to");
			if(!link) {
				return false;
			}
			var title = prompt("Please enter a title for the link, this will be the text that is displayed");
			if(!title) {
				return false;
			}
			var atag = '<a href="'+link+'" target="_blank">'+title+'</a>';
			textarea = document.getElementById('testText');
			insertText(textarea, atag);
			
		})
	},
	
	navswap: function () {
		var nav_images = $('#navigation').find('img');
		nav_images.mouseover(function () {
			var imageId = $(this).attr('id');
			var arg = 'images/' + imageId + 'f2.gif';
			MM_swapImage(imageId,'',arg,0);
		})
		
		nav_images.mouseout(function () {
			MM_swapImgRestore();
		})
	},
		
	patron: function() {
		$('#patronmail').find('a').click(function (e) {
			var href = $(this).attr('href');
			var popUp = window.open(href,'patron_signup','height=500,width=644,scrollBars=1,resizable=0');
			if(popUp) {
				e.preventDefault();
				popUp.focus();
			}
		});
	},
	
	podcasts: function() {
		var events = $('.podcast_popup');
		for(var i=0; i<events.length; i++){
			events.eq(i).click(function() {
			var url = 'youtube.php?url=' + $(this).attr('name');
			var popUp = window.open(url,'podcast','height=414,width=495,scrollBars=0,resizable=0');
			popUp.focus;
			return false;
			});
		}
	},
	
	wlvideo: function () {
		if(!document.getElementById('wlvideo')){return false;}
		var link = document.getElementById('wlvideo');
		var event = link.getElementsByTagName('a');
		event[0].onclick = function(){
			popUp = window.open(this.href,'wlvideo','height=200,width=420,scrollBars=0,resizable=0');
			popUp.focus;
			return false;
		}
	}
}

var DOMNews = {

	/*
		DOMnews 1.0 
		homepage: http://www.onlinetools.org/tools/domnews/
		released 11.07.05
	*/
	
	/* Variables, go nuts changing those! */
	// initial position 
	dn_startpos: 0, 			
	// end position
	dn_endpos: 0, 			
	// Speed of scroller higher number = slower scroller 
	dn_speed: 1,				
	// ID of the news box
	dn_newsID: 'news',			
	// class to add when JS is available
	dn_classAdd: 'hasJS',		
	// Message to stop scroller
	dn_stopMessage: 'Stop scroller',	
	// ID of the generated paragraph
	dn_paraID: 'DOMnewsstopper',
	dn_interval: null,
	dn_scrollpos: 0,

	__construct: function () {
		if($('#news').length == 0) {
			return false;
		}
		this.dn_endpos = $('#news').find('ul').eq(0).outerHeight(true) * -1;
		this.dn_startpos = $('#news').height();
		this.dn_scrollpos = this.dn_startpos;
		this.initDOMnews();
	},
	
	__destruct: function () {
		clearInterval(this.dn_interval);
	},
	
	initDOMnews: function () {
		var n = $('#'+this.dn_newsID);
		n.attr('className', this.dn_classAdd);
		this.dn_interval = setInterval(this.scrollDOMnews, this.dn_speed);
		var newa = document.createElement('a');
		var newp = document.createElement('p');
		newp.setAttribute('id',this.dn_paraID);
		newa.href='#';
		newa.appendChild(document.createTextNode(this.dn_stopMessage));
		newa.onclick = function () {
			DOMNews.stopDOMnews();
			return false;
		}
		newp.appendChild(newa);
		var stopper = document.getElementById('scrollstop');
		stopper.appendChild(newp);
		n.mouseover(function () {		
			clearInterval(DOMNews.dn_interval);
		});
		n.mouseout(function () {
			DOMNews.dn_interval = setInterval(DOMNews.scrollDOMnews,DOMNews.dn_speed);
		});
	},

	stopDOMnews: function () {
		clearInterval(this.dn_interval);
		var n=document.getElementById('news');
		n.className='';
		var remove = document.getElementById('DOMnewsstopper');
		remove.style.visibility = 'hidden';
	},
	
	scrollDOMnews: function () {
		var n=document.getElementById(DOMNews.dn_newsID).getElementsByTagName('ul')[0];
		n.style.top=DOMNews.dn_scrollpos+'px';
		//var debug = document.getElementById('scrollstop');
		//debug.firstChild.firstChild.firstChild.nodeValue = 'height: ' + n.offsetHeight + ' pos:' + DOMNews.dn_scrollpos;
		if(DOMNews.dn_scrollpos==DOMNews.dn_endpos){DOMNews.dn_scrollpos=DOMNews.dn_startpos;}
		DOMNews.dn_scrollpos--;	
	}
}

$(document).ready(function() {
	lipservice.__construct();
});

window.onload = function () {
	//we only want the news to scroll when everything is loaded so it gets the right height
	DOMNews.__construct();
}
