;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

function PalmerScroll(stuff, myobj){
	jQuery(myobj).text('More video loading below...');
	if (stuff.indexOf('?') != -1) {
		var things = stuff.substr(1).split("&");
	} else {
		var things = stuff.split("&");
	}
	var ar = [];
	var t = [];
	for (var i=0; i < things.length; i++) {
		t = things[i].split("=");
		ar[t[0]] = parseInt(t[1]);
	}
	var i = Math.round(10000*Math.random());
	jQuery.ajax({
		url: "/oncampus/includes/palmerscroll.php?cat="+ar['cat']+"&off="+ar['off']+"&num="+ar['num'],
		data: "iefix="+i,
		cache: false,
		success: function(xml){
			var onum = ar['off']+ar['num'];
			var newmore = '<div id="seemore_'+onum+'" style="text-align: center; padding-bottom: 5px">';
			if (ar.cat_cnt > onum) {
				newmore += '<a id="seemore" href="'+window.location.pathname+'?';
				newmore += 'cat='+ar['cat']+'&amp;num='+ar['num']+'&amp;off='+onum+'&amp;cat_cnt='+ar['cat_cnt']+'" ';
				newmore += 'onclick="return PalmerScroll(\'';
				newmore += 'cat='+ar['cat']+'&amp;num='+ar['num']+'&amp;off='+onum+'&amp;cat_cnt='+ar['cat_cnt']+'\',this);"';
				newmore += '>See more video...</a>';
			}
			newmore += '</div>';
			jQuery('#palmerscroll').append(xml).slideDown('slow');
			jQuery('#seemore_'+onum).replaceWith(newmore);
			jQuery("a.onVidFix,a.onVidFix2").each( function(i) {
				this.className = (this.href.indexOf("o="+ar['off']) != -1 ? 'onVidFix2' : 'onVidFix');
			});
			jQuery(myobj).animate({opacity: 1.0},2500,0,function(){ jQuery(myobj).fadeOut('slow', function() { jQuery(myobj).remove() }) });
			var old_off = (ar['off']-ar['num']+23);
			jQuery.scrollTo(jQuery('#vt'),2000);
			jQuery('#othervideos').scrollTo(jQuery('p').eq(old_off),2000);
		}
	});
	return false;
}

jQuery(document).ready(function(){
	jQuery.ajaxSetup({ timeout: 15000, datatype: 'html', type: "POST", complete: function() { doScroll(); } });
	jQuery("#seeless").remove();
	jQuery("#seemore").click( function(e) {
		e.preventDefault();
		e.returnValue = false;
		var stuff = this.href.substr(this.href.indexOf('?'));
		PalmerScroll(stuff,this);
		return false;
	});
	if (location.href.indexOf('calendar') != -1){
		calAjaxSearchDo('form#searchform_s','#calendar_items');
		calAjaxDo('a.smrust','no','#calendar_items');
		calAjaxDo('#swapReturn,a.month_sm', 1, '#calendar_meat');
		calAjaxDo('a.larger', 'no', '#calendar_items');
		calAjaxDo('#bottom_columns a', 'no', '#calendar_items');
		calAjaxCats('a.cat_href', '#calendar_items');
	}
	if (document.getElementById('rac_contain') ) {
		rac_setup_binds();
	}
});

function calAjaxDo(findWhat, full, putWhere){
	jQuery(findWhat).click(function(e){
		e.preventDefault(); 
		e.returnValue = false;
		var the_url = jQuery(this).attr("href").replace(/oncampus\/calendar/i,"oncampus/includes/calswap");
		var hist_url = jQuery(this).attr("href");
		jQuery.ajax({
			data: 'easy=check&full='+full,
			url: the_url,
			success: function(xml){
					jQuery(putWhere).html(xml);
					calAjaxDo('a.smrust,a.lgrust','no','#calendar_items');
					calAjaxDo('#swapReturn,a.month_sm', 1, '#calendar_meat');
					calAjaxSearchDo('form#searchform_s','#calendar_items');
					calAjaxCats('a.cat_href', '#calendar_items'); }
		});
		return false;
	});
}

function calAjaxSearchDo(findWhat, putWhere) {
	jQuery(findWhat).submit(function(e){
		e.preventDefault();
		e.returnValue = false;
		form_vars = 'easy=check';
		jQuery(findWhat + " :input:not(#exp_events)").each( function(i){ 
			if (jQuery(this).attr('value')) form_vars += '&'+jQuery(this).attr('name')+'='+jQuery(this).attr('value');
		});
		jQuery(findWhat + " :checkbox").each( function(i){ 
			if (jQuery(this).is(':checked')) form_vars += '&'+jQuery(this).attr('name')+'=on';
		});
		jQuery.ajax({
			url: "/oncampus/includes/calswap/search.php",
			data: form_vars,
			success: function(msg){
					jQuery(putWhere).html( msg );
					calAjaxSearchDo('form.searchform_pag','#calendar_items'); }
		});
		return false;
	});
}

function calAjaxCats(findWhat, putWhere){
	jQuery(findWhat).each( function(i){
		var the_url = this.href;
		jQuery(this).click( function(e){
			e.preventDefault();
			e.returnValue = false;
			jQuery.ajax({
				url: "/oncampus/includes/calswap/search.php",
				data: the_url.substr((the_url.indexOf('?')+1))+"&easy=check",
				success: function(msg){
						jQuery(putWhere).html( msg );
						calAjaxSearchDo('form#searchform_s,form.searchform_pag','#calendar_items'); }
			});
			return false;
		});
	});
}

function doScroll(){
	jQuery.scrollTo(jQuery("#calendar_meat"),1500);
}

function URLDecode(str){
	str.replace(/&quot;/,'"');
	str.replace(/&apos;/,'\'');
	str.replace(/&nbsp;/,' ');
	return str;
}

String.prototype.ucFirst = function () { return this.substr(0,1).toUpperCase() + this.substr(1,this.length); };

function monum2txt(monthnum){
	var months = new Array(13);
	months[1]  = "January"; months[2]  = "February"; months[3]  = "March"; months[4]  = "April"; months[5]  = "May"; months[6]  = "June";
	months[7]  = "July"; months[8]  = "August"; months[9]  = "September"; months[10]  = "October"; months[11] = "November"; months[12] = "December";
	monthnum = monthnum.replace(/^0/,"");
	return months[monthnum];
}

function rac_setup_binds() {
	jQuery("div.rac_helpful").children().unbind();
	jQuery("div.rac_helpful").mouseout(function() {
		rac_revert();
	});

	var rac_arr = [ "1", "2", "3", "4", "5" ];

	jQuery.each(rac_arr, function() {
		var rac_s_val = this;
		jQuery("div.rac_helpful a#rac_star" + this).mouseover(function() {
			for (i = 1; i <= 5; i++) {
				jQuery("div.rac_helpful a#rac_star" + i + " img").attr('src',jQuery("div.rac_helpful a#rac_star" + i + " img").attr('src').replace((rac_s_val >= i ? 'fade' : 'full'), (rac_s_val >= i ? 'full' : 'fade') ).replace('half', (rac_s_val >= i ? 'full' : 'fade')));
			}
		}).mouseout(function() {
			for (var i = 5; i >= rac_s_val; i--) {
				jQuery("div.rac_helpful a#rac_star" + i +" img").attr('src',jQuery("div.rac_helpful a#rac_star" + i +" img").attr('src').replace('full','fade').replace('half', 'fade') );
			}
		});
		var rac_inputs = [];
		jQuery("div.rac_helpful a#rac_star" + this).click(function() {
			rac_destroy_binds(rac_s_val);
			jQuery.ajax({
				data: 'rac_star_val='+rac_s_val+'&rac_cur_page='+location.href.replace('http://www.utexas.edu',''),
				url: 'http://www.utexas.edu/oncampus/includes/rate.php',
				type: "POST",
				timeout: 2000,
				error: function() {},
				success: function(r) { rac_ajax_do(r); },
				complete: function() {}
			});
			return false;
		});
	});
}

function rac_destroy_binds(s_val) {
	jQuery("div.rac_helpful").mouseout(function() { rac_revert(s_val); });
	jQuery("div.rac_helpful a#rac_star" + s_val).unbind('mouseout');
	rac_revert(s_val);
}

function rac_revert(cur_star) {
	if (typeof cur_star != "object") { cur_star = jQuery("#rac_avg_star").text(); }
	for (var i = 1; i <= 5; i++) {
		if (typeof jQuery("div.rac_helpful a#rac_star" + i +" img").attr('src') != 'undefined') {
			jQuery("div.rac_helpful a#rac_star" + i +" img").
				attr('src', jQuery("div.rac_helpful a#rac_star" + i +" img").
				attr('src').replace(
				(i <= cur_star ? 'fade' : 'full'),
				(i <= cur_star ? 'full' : 'fade')).
				replace('half', (cur_star >= i ? 'full' : 'fade'))
			);
			if (cur_star >= (i-.75) && cur_star < (i-.25)) {
				jQuery("div.rac_helpful a#rac_star" + i +" img").
				attr('src', 
					jQuery("div.rac_helpful a#rac_star" + i +" img").
					attr('src').replace( (i <= cur_star ? 'fade' : 'full'),
					(i <= cur_star ? 'full' : 'fade') ).
					replace( 'fade' , 'half')
				);
			}
		}
	}
}

// This is the general AJAX response handler
function rac_ajax_do(stuff) {
	jQuery(stuff).find("id").each(function() {
		if (jQuery(this).text() != '0') {
			// If the id is -1 or 1, the submission was either
			// successful, or the person is somehow trying to
			// repost their rating.  Either way, the "rac_msg
			// gets swapped, and the JS is unbound.
			jQuery(".rac_helpful a").unbind('click');
			jQuery("#rac_msg").html(jQuery("msg",stuff).text());

			jQuery("div.rac_helpful").unbind();
			// Revert the star level to the average
			// Comment out the following line to keep the
			// star level at the user's rating level until the page
			// is re-loaded.
			 jQuery("div.rac_helpful").mouseout(function() { rac_revert(); });

		} else if (jQuery(this).text() == '0') {
			alert(jQuery("msg",stuff).text());
		}
	});
}

/**
 * jQuery history event v0.1
 */
(function($) {
    var currentHash, previousNav, timer, hashTrim = /^.*#/;

    var msie = {
        iframe: null,
        getDoc: function() {
            return msie.iframe.contentWindow.document;
        },
        getHash: function() {
            return msie.getDoc().location.hash;
        },
        setHash: function(hash) {
            var d = msie.getDoc();
            d.open();
            d.close();
            d.location.hash = hash;
        }
    };

    var historycheck = function() {
        var hash = msie.iframe ? msie.getHash() : location.hash;
        if (hash != currentHash) {
            currentHash = hash;
            if (msie.iframe) {
                location.hash = currentHash;
            }
            var current = $.history.getCurrent();
            $.event.trigger('history', [current, previousNav]);
            previousNav = current;
        }
    };

    $.history = {
        add: function(hash) {
            hash = '#' + hash.replace(hashTrim, '');
            if (currentHash != hash) {
                var previous = $.history.getCurrent();
                location.hash = currentHash = hash;
                if (msie.iframe) {
                    msie.setHash(currentHash);
                }
                $.event.trigger('historyadd', [$.history.getCurrent(), previous]);
            }
            if (!timer) {
                timer = setInterval(historycheck, 100);
            }
        },
        getCurrent: function() {
            return currentHash.replace(hashTrim, '');
        }
    };

    $.fn.history = function(fn) {
        $(this).bind('history', fn);
    };

    $.fn.historyadd = function(fn) {
        $(this).bind('historyadd', fn);
    };

    $(function() {
        currentHash = location.hash;
        if ($.browser.msie) {
            msie.iframe = $('<iframe style="display:none" src="javascript:false;"></iframe>').prependTo('body')[0];
            msie.setHash(currentHash);
            currentHash = msie.getHash();
        }
    });
})(jQuery);
