/**
 *  corner() takes a single string argument:  $('#myDiv').corner("effect corners width")
 *
 *  effect:  name of the effect to apply, such as round, bevel, notch, bite, etc (default is round). 
 *  corners: one or more of: top, bottom, tr, tl, br, or bl. 
 *           by default, all four corners are adorned. 
 *  width:   width of the effect; in the case of rounded corners this is the radius. 
 *           specify this value using the px suffix such as 10px (and yes, it must be pixels).
 *
 * @name corner
 * @type jQuery
 * @param String options Options which control the corner style
 * @cat Plugins/Corner
 * @return jQuery
 * @author Dave Methvin (http://methvin.com/jquery/jq-corner.html)
 * @author Mike Alsup   (http://jquery.malsup.com/corner/)
 * 
 * documentation -  http://www.malsup.com/jquery/corner/
 */
;(function($){var expr=(function(){if(!$.browser.msie)return false;var div=document.createElement('div');try{div.style.setExpression('width','0+0')}catch(e){return false}return true})();    
function sz(el,p){return parseInt($.css(el,p))||0};
function hex2(s){var s=parseInt(s).toString(16);return(s.length<2)?'0'+s:s};
function gpc(node){for(;node&&node.nodeName.toLowerCase()!='html';node=node.parentNode){var v=$.css(node,'backgroundColor');if(v=='rgba(0, 0, 0, 0)')continue;if(v.indexOf('rgb')>=0){var rgb=v.match(/\d+/g);return'#'+hex2(rgb[0])+hex2(rgb[1])+hex2(rgb[2])}if(v&&v!='transparent')return v}return'#ffffff'};
function getWidth(fx,i,width){switch(fx){case'round':return Math.round(width*(1-Math.cos(Math.asin(i/width))));case'cool':return Math.round(width*(1+Math.cos(Math.asin(i/width))));case'sharp':return Math.round(width*(1-Math.cos(Math.acos(i/width))));case'bite':return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));case'slide':return Math.round(width*(Math.atan2(i,width/i)));case'jut':return Math.round(width*(Math.atan2(width,(width-i-1))));case'curl':return Math.round(width*(Math.atan(i)));case'tear':return Math.round(width*(Math.cos(i)));case'wicked':return Math.round(width*(Math.tan(i)));case'long':return Math.round(width*(Math.sqrt(i)));case'sculpt':return Math.round(width*(Math.log((width-i-1),width)));case'dog':return(i&1)?(i+1):width;case'dog2':return(i&2)?(i+1):width;case'dog3':return(i&3)?(i+1):width;case'fray':return(i%2)*width;case'notch':return width;case'bevel':return i+1}};
$.fn.corner=function(o){if(this.length==0){if(!$.isReady&&this.selector){var s=this.selector,c=this.context;$(function(){$(s,c).corner(o)})}return this}o=(o||"").toLowerCase();var keep=/keep/.test(o);var cc=((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);var sc=((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);var width=parseInt((o.match(/(\d+)px/)||[])[1])||10;var re=/round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;var fx=((o.match(re)||['round'])[0]);var edges={T:0,B:1};var opts={TL:/top|tl/.test(o),TR:/top|tr/.test(o),BL:/bottom|bl/.test(o),BR:/bottom|br/.test(o)};if(!opts.TL&&!opts.TR&&!opts.BL&&!opts.BR)opts={TL:1,TR:1,BL:1,BR:1};var strip=document.createElement('div');strip.style.overflow='hidden';strip.style.height='1px';strip.style.backgroundColor=sc||'transparent';strip.style.borderStyle='solid';return this.each(function(index){var pad={T:parseInt($.css(this,'paddingTop'))||0,R:parseInt($.css(this,'paddingRight'))||0,B:parseInt($.css(this,'paddingBottom'))||0,L:parseInt($.css(this,'paddingLeft'))||0};if(typeof this.style.zoom!=undefined)this.style.zoom=1;if(!keep)this.style.border='none';strip.style.borderColor=cc||gpc(this.parentNode);var cssHeight=$.curCSS(this,'height');for(var j in edges){var bot=edges[j];if((bot&&(opts.BL||opts.BR))||(!bot&&(opts.TL||opts.TR))){strip.style.borderStyle='none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');var d=document.createElement('div');$(d).addClass('jquery-corner');var ds=d.style;bot?this.appendChild(d):this.insertBefore(d,this.firstChild);if(bot&&cssHeight!='auto'){if($.css(this,'position')=='static')this.style.position='relative';ds.position='absolute';ds.bottom=ds.left=ds.padding=ds.margin='0';if(expr)ds.setExpression('width','this.parentNode.offsetWidth');else ds.width='100%'}else if(!bot&&$.browser.msie){if($.css(this,'position')=='static')this.style.position='relative';ds.position='absolute';ds.top=ds.left=ds.right=ds.padding=ds.margin='0';if(expr){var bw=sz(this,'borderLeftWidth')+sz(this,'borderRightWidth');ds.setExpression('width','this.parentNode.offsetWidth - '+bw+'+ "px"')}else ds.width='100%'}else{ds.margin=!bot?'-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px':(pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px'}for(var i=0;i<width;i++){var w=Math.max(0,getWidth(fx,i,width));var e=strip.cloneNode(false);e.style.borderWidth='0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';bot?d.appendChild(e):d.insertBefore(e,d.firstChild)}}}})};
$.fn.uncorner=function(){$('div.jquery-corner',this).remove();return this};    
})(jQuery);
/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 2/19/2008
 * @author Ariel Flesler
 * @version 1.3.3
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function($){var o=$.scrollTo=function(a,b,c){o.window().scrollTo(a,b,c)};o.defaults={axis:'y',duration:1};o.window=function(){return $($.browser.safari?'body':'html')};$.fn.scrollTo=function(l,m,n){if(typeof m=='object'){n=m;m=0}n=$.extend({},o.defaults,n);m=m||n.speed||n.duration;n.queue=n.queue&&n.axis.length>1;if(n.queue)m/=2;n.offset=j(n.offset);n.over=j(n.over);return this.each(function(){var a=this,b=$(a),t=l,c,d={},w=b.is('html,body');switch(typeof t){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(t)){t=j(t);break}t=$(t,this);case'object':if(t.is||t.style)c=(t=$(t)).offset()}$.each(n.axis.split(''),function(i,f){var P=f=='x'?'Left':'Top',p=P.toLowerCase(),k='scroll'+P,e=a[k],D=f=='x'?'Width':'Height';if(c){d[k]=c[p]+(w?0:e-b.offset()[p]);if(n.margin){d[k]-=parseInt(t.css('margin'+P))||0;d[k]-=parseInt(t.css('border'+P+'Width'))||0}d[k]+=n.offset[p]||0;if(n.over[p])d[k]+=t[D.toLowerCase()]()*n.over[p]}else d[k]=t[p];if(/^\d+$/.test(d[k]))d[k]=d[k]<=0?0:Math.min(d[k],h(D));if(!i&&n.queue){if(e!=d[k])g(n.onAfterFirst);delete d[k]}});g(n.onAfter);function g(a){b.animate(d,m,n.easing,a&&function(){a.call(this,l)})};function h(D){var b=w?$.browser.opera?document.body:document.documentElement:a;return b['scroll'+D]-b['client'+D]}})};function j(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
/**
 * jQuery[a] - Animated scrolling of series
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/20/2008
 * @author Ariel Flesler
 * @version 1.2.1
 *
 * http://flesler.blogspot.com/2008/02/jqueryserialscroll.html
 */
;(function($){var a='serialScroll',b='.'+a,c='bind',C=$[a]=function(b){$.scrollTo.window()[a](b)};C.defaults={duration:1e3,axis:'x',event:'click',start:0,step:1,lock:1,cycle:1,constant:1};$.fn[a]=function(y){y=$.extend({},C.defaults,y);var z=y.event,A=y.step,B=y.lazy;return this.each(function(){var j=y.target?this:document,k=$(y.target||this,j),l=k[0],m=y.items,o=y.start,p=y.interval,q=y.navigation,r;if(!B)m=w();if(y.force)t({},o);$(y.prev||[],j)[c](z,-A,s);$(y.next||[],j)[c](z,A,s);if(!l.ssbound)k[c]('prev'+b,-A,s)[c]('next'+b,A,s)[c]('goto'+b,t);if(p)k[c]('start'+b,function(e){if(!p){v();p=1;u()}})[c]('stop'+b,function(){v();p=0});k[c]('notify'+b,function(e,a){var i=x(a);if(i>-1)o=i});l.ssbound=1;if(y.jump)(B?k:w())[c](z,function(e){t(e,x(e.target))});if(q)q=$(q,j)[c](z,function(e){e.data=Math.round(w().length/q.length)*q.index(this);t(e,this)});function s(e){e.data+=o;t(e,this)};function t(e,a){if(!isNaN(a)){e.data=a;a=l}var c=e.data,n,d=e.type,f=y.exclude?w().slice(0,-y.exclude):w(),g=f.length,h=f[c],i=y.duration;if(d)e.preventDefault();if(p){v();r=setTimeout(u,y.interval)}if(!h){n=c<0?0:n=g-1;if(o!=n)c=n;else if(!y.cycle)return;else c=g-n-1;h=f[c]}if(!h||d&&o==c||y.lock&&k.is(':animated')||d&&y.onBefore&&y.onBefore.call(a,e,h,k,w(),c)===!1)return;if(y.stop)k.queue('fx',[]).stop();if(y.constant)i=Math.abs(i/A*(o-c));k.scrollTo(h,i,y).trigger('notify'+b,[c])};function u(){k.trigger('next'+b)};function v(){clearTimeout(r)};function w(){return $(m,l)};function x(a){if(!isNaN(a))return a;var b=w(),i;while((i=b.index(a))==-1&&a!=l)a=a.parentNode;return i}})}})(jQuery);
/**
 * jQuery - Ticker
 * Copyright (c) 2009 Mike Slater
 * @author Mike Slater
 *
 */
;(function($){
  $.fn.ticker = function(options) 
  {
  	var settings = $.extend({
  		moverSpeed : 10,
  		feedURL : 'feed.xml',
  		easeType : 'linear'
  	},options||{});
		var $container = $(this);
		$container.empty();
		var $mover = 
		$('<div></div>')
			.addClass('headline-mover')
			.appendTo($container);		
		
		$.get(settings.feedURL, function(data)
		{
			$('rss item', data).each(function()
			{
				var $link = $('<a></a>')
					.attr('href', $('link', this).text())
					.text($('title', this).text());
				var $headline = $('<h4></h4>').append($link);
				$('<div></div>')
					.append($headline)
					.addClass('headline')
					.appendTo($mover);
			});
			var containerWidth = $container.width();
			var pause = false;
			var headlineCount = $('div.headline').length;
			var moverWidth = 0;
			var extraPadding = ($mover.find('div.headline').eq(0).innerWidth()) - ($mover.find('div.headline').eq(0).width());
			for(var num = 0; num < headlineCount; num++)
			{
				moverWidth += $mover.find('div.headline').eq(num).innerWidth();
			}
			$mover.width(moverWidth + 1);
			var moverDistance = moverWidth - extraPadding;
			$mover.css('left', containerWidth);
			var xpos = containerWidth;
			
			var headlineRotate = function()
			{
				pause = false;
				xpos = parseInt($mover.css('left'));
				$mover.animate(
					{left: -moverDistance},
					((xpos + moverDistance) * settings.moverSpeed),
					settings.easeType,
					function()
					{
						$(this).css('left', containerWidth);
						headlineRotate();
					});
			};

			if(!pause)
			{
				headlineRotate();
			}
						
			$container.hover(function()
			{
				$mover.stop();
				pause = true;
			}, function()
			{
				if(pause)
				{
					pause = false;
					headlineRotate();
				}
			});
			
		});
		
	};
})(jQuery);
  
 $(function() {  
		
 	$('#news-feed').ticker(
 		{feedURL : '/ajax/feed.xml', moverSpeed : 13}
 	);

	$('#navbar ul li').mouseover(function(){
		if ($(this).find('.submenu').length){
			$(this).find('.submenu').show().end()
			       .addClass('tab');
		} else {
			$(this).addClass('active');
		}
	});
	
	$('#navbar ul li').mouseout(function(){
		$('#navbar > ul > li').removeClass('active');
		$(this).find('.submenu').hide().parent().removeClass('tab');
	});
		
	//SET SUBNAV WIDTH
	var pages = $('#navbar ul li.nav_new div.submenu .subnav_section').size();
	var pagewidth = 220;
	var total = pages * pagewidth;
	$('#navbar ul li.nav_new div.submenu').width(total);
		
	$('#chickenScroller').serialScroll({
		items:'li',
		prev:'#back',
		next:'#forth',
		cycle:true
	});
	
	$('#ip_rightcol .poster').hide();

	//INITIATE MIKE COMMENT
	var $mikes = $('span.mike');
	$mikes.each(function(){
		$(this).mikeComment();
	});
	
	//ADMIN SECTION CONTROLS
	$('#admin_controls li.subnav').hide();
	$('#admin_controls li.top_level').addClass('inactive').find('a').mouseover(controlOn);
	
	$('#pageContent').corner();

});

function controlOn(e) {
	if ( $(this).parent().hasClass('inactive') ) {
		$('#admin_controls li.top_level').removeClass('active').addClass('inactive');
		$(this).parent().stop().removeClass('inactive').addClass('active')
				.animate(
					{
						left: 0
					}, 250, showSubControl(($(this).parent()))
				).siblings('.top_level').stop().animate(
					{
						left: -60
					}, 250);
	}
	e.stopPropagation;
}

function showSubControl(list) {
	$('#admin_controls li.subnav').stop().hide();
	$(list).next().stop().show();
}


//STUFF TO DO AFTER ALL IMAGES ON PAGE ARE LOADED
$(window).load(function() {
	$('#ip_rightcol .poster').slideDown(1500);
	
	//MAKE ALL ARCHIVE LIST ITEMS THE SAME HEIGHT
	var tallestLI = 0;
	$('ul.archiveList > li').add('#search_results > li').each(function() {
		if ($(this).height() > tallestLI ) {
			tallestLI = $(this).height();
		}
	});
	
	$('ul.archiveList > li').add('#search_results > li').height(tallestLI);
	
	var hpHeight = $('#hp_leftcol').height();
	var hpRailHeight = $('#hp_rightcol').height();
	if (hpRailHeight < hpHeight)
	{
		$('#hp_rightcol').height(hpHeight);
	}
		
});

//JAVASCRIPT FUNCTIONS

function validateAdmin(frm) {
	var errors = new Array();
	if (frm.username.value == '') {
		errors.push("Username is a required field");
	}		
	if (frm.username.value.length > 20) {
		errors.push("Max Username is 20 characters");
	}		
	if (frm.password.value == '') {
		errors.push("Password is a required field");
	}	
	if (frm.password.value.length > 20) {
		errors.push("Max Password is 20 characters");
	}		
	if (errors.length>0) {
		var msg = "The following errors occured:\n";
		for (var i=0; i<errors.length; i++){
			msg+=errors[i] + "\n";
		}
		alert(msg);
		return false;
	}	
	else {
		return true;
	}
}

function handleFocus(element)  
{  
 if (element.value == element.defaultValue)   
 {  
    element.value = '';  
 }  
}  

function handleBlur(element)  
{  
 if (element.value == '')  
 {  
    element.value = element.defaultValue;  
 }  
}     



//TEMPORARILY DEVELOPING MIKE COMMENT FUNCTION HERE
jQuery.fn.mikeComment = function()
{
	$(this).bind("mousemove", function(e)
	{
	    mikeText = $(this).attr('rel');
		$('#mike_area').text(mikeText);
		$("#mike_area").css({"left": e.pageX + 15, "top" : e.pageY + 15}).show();
	}).bind("mouseout", function()
	{
	    $("#mike_area").hide().css({"left": 0, "top" : 0});
	});
}
