window.addEvent('domready', function() 
{	
	if($('searchterm'))
	{
		$('searchterm').addEvent('focus', function()
		{
			$('searchterm').value = '';
		});
	}
	
	$$('a.checkbox').addEvent('click', function(e)
	{
		var evt = new Event(e);
		if(evt.target.className == 'checkbox')
			evt.target.className = 'checkbox-active';
		else
			evt.target.className = 'checkbox';
		updateSolutions();
		evt.stop();
	});
	
	$$('.exp_img a').addEvent('click', function(e)
	{
		var evt = new Event(e);
		evt.stop();
		//var text = evt.target.getParent().getNext().getChildren()[1].getText();
		//evt.target.getParent().setProperty('title','hi!');
	});
	
	$('modal').setStyle('top', '-600px');
	
});

window.addEvent('load', function()
{
	new SlideList($E('#menu ul'), {transition: Fx.Transitions.quadOut, duration: 400});
});

window.addEvent('resize', function()
{
	$('modal').setStyle('left', ((window.getScrollWidth()/2)-220)+'px');
});

function getModalContent(content,playlist)
{
	new Ajax('modalcontent.php', {method: 'post', data: 'playlist='+playlist+'&clip='+content+'&clipid='+currentItem, update: $('modal'), evalScripts: true, 
	onComplete:function()
	{
		overlayOn();
	}
	}).request();
}

function overlayOn()
{
	$('modal').setStyle('left', ((window.getScrollWidth()/2)-230)+'px');
	
	$('overlay').effect('opacity', {duration: 150, 
	onStart: function()
	{
		$('overlay').setStyle('height', window.getScrollHeight()+'px'); 
		$('modal').setStyles({top: '-600px', visibility: 'visible'});
	}, 
	onComplete: function()
	{
		$('modal').effect('top', {duration: 500, transition: Fx.Transitions.Cubic.easeOut}).start(-600, 180);
	}
	}).start(0,0.5);
}

function overlayOff()
{
	$('overlay').effect('opacity', {duration: 150, 
	onStart: function()
	{
			$('modal').setStyles({top: '-600px', visibility: 'hidden'});
	}
	}).start(0);
}

function sendafriend()
{
	new Ajax('sendafriend.php', {method: 'post', data: $('sendtoafriendform'), onComplete:overlayOff}).request();
}

function toggleTab(tab)
{
	$$('#tabs li').each(function(el)
	{
		el.removeClass('current');
	});
	
	$('t'+tab).className = 'current';
	
	$$('#mediabox .content div.show').each(function(el)
	{
		el.className = 'hide';
	});
	
	$('c'+tab).className = 'show';
	
	if($('submenus'))
	{
		$$('#submenu1, #submenu2, #submenu3').each(function(el)
		{
			el.className = 'hide';
		});
		
		$('submenu'+tab).className = 'show';
	}
}

function toggleTab2(tab)
{
	$$('#tabs2 li').each(function(el)
	{
		el.removeClass('current');
	});
	
	$('t'+tab).className = 'current';
	
	$$('#mediabox2 .content div.show').each(function(el)
	{
		el.className = 'hide';
	});
	
	$('c'+tab).className = 'show';
	
	if($('submenus'))
	{
		$$('#submenu1, #submenu2, #submenu3').each(function(el)
		{
			el.className = 'hide';
		});
		
		$('submenu'+tab).className = 'show';
	}
}

function validateContact(form)
{
	var form_error = false;
	var fields = $$('form#'+form+' input[type=text]');
	fields.each(function(el)
	{
		if(el.alt != null)
		{
			if(el.alt == 'name')
			{
				if(el.validName() == false)
				{
					el.addClass('invalid');
					form_error = true;
				}
				else
					el.removeClass('invalid');
			}
				
			if(el.alt == 'phone')
			{
				if(el.validPhone() == false)
				{
					el.addClass('invalid');
					form_error = true;
				}
				else
					el.removeClass('invalid');
			}
			
			if(el.alt == 'email')
			{
				if(el.validEmail() == false)
				{
					el.addClass('invalid');
					form_error = true;
				}
				else
					el.removeClass('invalid');
			}
		}
	});
	
	if(!form_error)
		$(form).submit();
	else
		alert('Some fields are missing or incorrect.\nPlease complete all required fields and try again.');
}

function validateForm()
{
	var form_error = false;
	var form_items = document.forms[1].getElementsByTagName('input');
	for(i = 0; i < form_items.length; i++)
	{
		var temp = form_items[i].id.split("-");
		if(temp[1] == "required")
		{
			if(form_items[i].value == '')
			{
				form_items[i].addClass('invalid');
				form_error = true;
			}
			else
				form_items[i].removeClass('invalid');
		}
	}
	if(!form_error)
		document.forms[1].submit();
	else
		alert('Please complete all required fields.');
}

var selected_solutions = '';
function updateSolutions()
{
	selected_solutions = '';
	$$('.solution_finder a').each(function(el)
	{
		if(el.className == 'checkbox-active')
			selected_solutions += el.getProperty('alt')+'|';
	});
	$('chosen_solutions').value = selected_solutions;
}

function generateEmail(p1,p2)
{
	window.location.replace('mailto:'+p1+'@'+p2,false);
}

function gid(name)
    {
      return document.getElementById(name);
    };

    /*-------------------------------------------------------------------
    Player javascript API
    -------------------------------------------------------------------*/
    function sendEvent(swf, typ, prm)
    {
      thisMovie(swf).sendEvent(typ, prm); 
    };

	var currentItem;
	var currentState;
	var startNumber;
	var playingFlag=false;
    function getUpdate(typ, pr1, pr2, swf)
    {
	  if(typ == "item") { currentItem = pr1; }
      if((typ == 'state') && (swf == 'jstest'))
      {
        gid('stateshow').innerHTML = pr1;
      }
      if (typ == 'time')
      {
        gid('time').innerHTML = pr1;
	  }
	  if(swf != "null") {
		if((typ == "state")&&(pr1 != undefined)) { 
			currentState = pr1; 
			if((currentState=="0")&&( ! playingFlag) && (startNumber != '')) {				
				playingFlag = true;
				sendEvent('player', 'playitem',  startNumber); 					
			}
		}
	}
    };

    function loadFile(swf, obj)
    {
      thisMovie(swf).loadFile(obj); 
    };

    function getLength(swf)
    {
      var len = thisMovie(swf).getLength();
      alert('the length of the playlist is: ' + len);
    };

    function addItem(swf, obj, idx)
    {
      thisMovie(swf).addItem(obj, idx);
    };

    function removeItem(swf, idx)
    {
      thisMovie(swf).removeItem(idx);
    };

    function itemData(swf, idx)
    {
      var obj = thisMovie(swf).itemData(idx);
      var txt = "";
      for(var i in obj)
      {
        txt += i + ": " + obj[i] + "\n";
      }
      return obj.title;
    };

    function thisMovie(movieName)
    {
      if(navigator.appName.indexOf("Microsoft") != -1)
      {
        return window[movieName];
      }
      else
      {
        // return gid(movieName);
        return document[movieName];
      }
    };
	
function createPlayer(theFile, arg)
{
	startNumber=arg;
	var so = new SWFObject("/mediaplayer.swf", "player", "860", "386", "8", "#FFFFFF");
	so.addVariable("file", theFile);
	//so.addVariable("image", "");
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addVariable("displayheight", "386");
	so.addVariable("displaywidth", "680");
	so.addVariable("thumbsinplaylist", "true");
	so.addVariable("shuffle", "false");
	so.addVariable("autoscroll", "true");
	so.addVariable("overstretch", "false");
	so.addVariable("showdigits", "true");
	so.addVariable("callback", "http://www.paragonmediaone.com/blog/wordpress/wp-content/plugins/wordtube/wordtube-statistics.php");
	so.addVariable("backcolor", "0xFFFFFF");
	so.addVariable("frontcolor", "0x14156F");
	so.addVariable("lightcolor", "0x0C0C48");
	so.addVariable("volume", "80");
	so.addVariable("bufferlength", "5");
	so.addVariable("width", "860");
	so.addVariable("height", "386");
	so.addVariable('javascriptid','player');
	so.addVariable('enablejs','true');
	so.addVariable('usefullscreen','false');
	so.addVariable("autostart", "false");
	so.addParam("wmode", "transparent");
	so.write("vidplayer");	
}

// JavaScript Document
var SlideList = new Class({
	initialize: function(menu, options) {
		this.setOptions(this.getOptions(), options);
		
		this.menu = $(menu), this.current = this.menu.getElement('li.current');
		
		this.menu.getElements('li').each(function(item){
			item.addEvent('mouseover', function(){ this.moveBg(item); }.bind(this));
			item.addEvent('mouseout', function(){ this.moveBg(this.current); }.bind(this));
			item.addEvent('click', function(event){ this.clickItem(event, item); }.bind(this));
		}.bind(this));
				
		this.back = new Element('li').addClass('background').adopt(new Element('div').addClass('left')).injectInside(this.menu);
		this.back.fx = this.back.effects(this.options);
		if(this.current) this.setCurrent(this.current);
	},
	
	setCurrent: function(el, effect){
		this.back.setStyles({left: (el.offsetLeft)+'px', width: (el.offsetWidth)+'px'});
		(effect) ? this.back.effect('opacity').set(0).start(1) : this.back.setOpacity(1);
		this.current = el;
	},
	
	getOptions: function(){
		return {
			transition: Fx.Transitions.sineInOut,
			duration: 500, wait: false,
			onClick: Class.empty
		};
	},

	clickItem: function(event, item) {
		if(!this.current) this.setCurrent(item, true);
		this.current = item;
		this.options.onClick(new Event(event), item);
	},

	moveBg: function(to) {
		if(!this.current) return;
		this.back.fx.custom({
			left: [this.back.offsetLeft, to.offsetLeft],
			width: [this.back.offsetWidth, to.offsetWidth]
		});
	}
});

SlideList.implement(new Options);