var loggedIn = 0;
var panels = new Array();
var delayedObject;
var selected_subnav = "mvp_share_panel_about";
var videoTitle = "";
var currentPanel = "";
var lastPanel = "";
var reloadPlayer = false;
var continuousPlay = true;
if ( ( typeof mode != 'undefined' ) ) {
	if ( mode == 'svp' ) {
		continuousPlay = false;
	}
}

function cancelLogin() {
	$('submit_login_btn').src = '/decor/buttons/signin_small.gif';
	Effect.BlindUp('signup_section');
	$('mvp_login_mode').value = 'signup';
	$('mvp_login_title').innerHTML = "Sign In";
	if ( lastPanel ) {
		showPanel(lastPanel);
	} else {
		new Effect.Fade('magnify_widget_playlist_item_' + currentPanel + '_container', {duration: .1});
		currentPanel = "";
	}
}

function showLogin() {
	showPanel('login');
}

function requireLogin() {
	showLogin();;
	reloadPlayer = true;
}

function logIn(url, form, target) {
	new Ajax.Updater(target, toolRoot + url, {
		method: 'post', 
		parameters: Form.serialize( form ), 
		evalScripts: true
	});		
}

function destroyContainers() {
	var createdContainers = $$('.magnify-widget-playlist-item-content-container-created');
	createdContainers.each(function(element) {
		Element.remove(element);
	});
}

function reloadPanels() {
	for ( var i=0; i < panels.length; i++ ) {
		
		if ( panels[i] != 'shop' ) {
			new Ajax.Updater('magnify_player_overlay_' + panels[i], toolRoot +  + panels[i] + '.minc', {
				method: 'get', 
				parameters: 'content_item_cid=' + currentCID + '&width=' + width, 
				evalScripts: ( panels[i] == 'shop' ? false : true )
			});
		}
	}
}

function showPage(id) {
	Element.hide('magnify_player_overlay_' + selectedTab);
	Element.show(id);
}

function sendEmail(url, form, target) {
	new Ajax.Updater(target, toolRoot + url, {
		method: 'post', parameters: Form.serialize( form ), evalScripts: true
	});
}

function sendEmail2(url, form, target) {
	new Ajax.Updater(target, url, {
		method: 'post', parameters: Form.serialize( form ), evalScripts: true
	});
}

function checkEmail(email) {
	new Ajax.Request( '/login/email?email=' + escape( email ), { 
		onSuccess: function( transport ) { 
			if ( transport.responseText.indexOf('Please') > -1 ) {
				$('submit_login_btn').className = 'mvp-register-button';
				Effect.BlindDown('signup_section');
				$('mvp_login_mode').value = 'signup';
				$('mvp_login_title').innerHTML = "New User Registration";
				Element.hide('submit_button_reset');
			} else {
				$('submit_login_btn').className = 'mvp-signin-button';
				Effect.BlindUp('signup_section');
				$('mvp_login_mode').value = 'signin';
				$('mvp_login_title').innerHTML = "Sign In";	
				Element.show('submit_button_reset');		
			}
		} 
	});
}

function resetPassword(url, email, target) {
	new Ajax.Updater(target, toolRoot + url, {
		method: 'get', parameters: 'reset_password=1&email=' + email, evalScripts: true
	});	
}

function showIndicator(bool) {
	// this is disabled for now
	return;
	if ( bool ) {
		Element.show('magnify_widget_indicator_container');
	} else {
		Element.hide('magnify_widget_indicator_container');	
	}
}

function saveObject(url, form, target) {
	new Ajax.Request(toolRoot + 'get_login.minc', {	
		onCreate: function() {
			showIndicator(true);
		},
		onSuccess: function(transport) { 
			loggedIn = transport.responseText; 
			finishSave(url, form, target); 
		}
	});
}

function finishSave(url, form, target) {
	if ( !url || !form || !target ) {
		showIndicator(false);
		return;
	}
	if ( loggedIn > 0 ) {
		var params = "";
		if ( typeof(form) == 'object' ) { 
			params = Form.serialize( form );
		} else {
			params = form;
		}
		new Ajax.Updater(target, toolRoot + url, {
			method: 'post', 
			parameters: params, 
			evalScripts: true, 
			onSuccess: function() { 
				showIndicator(false); 
			}
		});	
	} else {
		showIndicator(false);
		delayedObject = new Array(url, Form.serialize( form ), target);
		if ( isSSO ) {
			window.open(toolRoot + 'sso_login', 'sso_login', '');			
			new Ajax.Updater(target, toolRoot + 'sso_login_msg.minc?content_item_cid=' + currentCID + '&amp;width=' + width, {
				method: 'get', evalScripts: true
			});
		} else {
			showLogin();	
		}
	}
}

function saveObject2(url, form, target) {
	new Ajax.Request(toolRoot + 'get_login.minc', {	
		onCreate: function() {
			showIndicator(true);
		},
		onSuccess: function(transport) { 
			loggedIn = transport.responseText; 
			finishSave2(url, form, target); 
		}
	});
}

function finishSave2(url, form, target) {
	if ( !url || !form || !target ) {
		showIndicator(false);
		return;
	}
	if ( loggedIn > 0 ) {
		new Ajax.Updater(target, url, {
			method: 'post', 
			parameters: Form.serialize( form ), 
			evalScripts: true, 
			onSuccess: function() { 
				showIndicator(false); 
			}
		});	
	} else {	
		showIndicator(false);
		delayedObject = new Array(url, form, target);
		if ( isSSO ) {
			window.open(toolRoot + 'sso_login', 'sso_login', '');			
			new Ajax.Updater(target, toolRoot + 'sso_login_msg.minc?content_item_cid=' + currentCID + '&amp;width=' + width, {
				method: 'get', evalScripts: true
			});
		} else {
			showLogin();	
		}
	}
}



function add_user_tag(tag) {
	new Ajax.Updater('magnify_widget_playlist_item_tag_content', toolRoot + 'tag.minc?content_item_cid=' + currentCID + '&amp;width=' + width + '&amp;add_tags=' + escape( tag ), {
		method: 'get'
	}); 
}

function drop_user_tag(tag_nid) {
	new Ajax.Updater('magnify_widget_playlist_item_tag_content', toolRoot + 'tag.minc?content_item_cid=' + currentCID +'&amp;width=' + width + '&amp;drop_tag=' + tag_nid, {
		method: 'get'
	}); 
}

function selectTab(id) {	
	$$('.magnify-player-tab-selected').each( function(tab, index) {
		Element.removeClassName(tab.id, 'magnify-player-tab-selected');
		Element.addClassName(tab.id, 'magnify-player-tab');
	});
	Element.removeClassName(id, 'magnify-player-tab');
	Element.addClassName(id, 'magnify-player-tab-selected');
	if ( $('magnify_player_overlay_login') ) {
		Element.hide('magnify_player_overlay_login');
	}
	getContent(id.gsub('magnify_player_tab_', ''));
}

function getContent(id) {
	Element.hide('magnify_player_overlay_' + selectedTab);
	if ( $('magnify_player_overlay').style.display == 'none' ) {
		Effect.BlindDown('magnify_player_overlay', { duration: 0.5 } );
	} else if ( id == selectedTab ) {	
		Effect.BlindUp('magnify_player_overlay', { duration: 0.5 });	
		Element.removeClassName('magnify_player_tab_' + id, 'magnify-player-tab-selected');
		Element.addClassName('magnify_player_tab_' + id, 'magnify-player-tab');
	}
	Element.show('magnify_player_overlay_' + id);		
	selectedTab = id;
}

function initOverlay(id) {
	Element.hide('magnify_player_overlay');
	Effect.BlindUp('magnify_player_overlay', { duration: 0.5 });
	$('magnify_player_overlay').style.zIndex = 1;
	Element.hide('magnify_player_overlay_rate_it');
}

function showSubnav(id) {
	if ( id != selected_subnav ) {
		Element.show(id);
		Element.hide(selected_subnav);
		selected_subnav = id;
	}
}

function showOverlay(element, id) {
	var control_indicator = element.firstChild.nextSibling;
	var regex = /-on/;
	var is_on = regex.test(control_indicator.className);
	if ( is_on ) {
		Effect.BlindUp(id, { scope: 'tabs', duration: 0.5 });
	} else {
		Effect.BlindDown(id, { scope: 'tabs', duration: 0.5 });	
	}
	//Effect.toggle(id, 'blind');
	control_indicator.className = is_on ? 'mvp-title-control-off' : 'mvp-title-control-on';
}

function hidePanel() {
	new Effect.Fade('magnify_widget_playlist_item_' + currentPanel + '_container', { duration: .1 });
	currentPanel = "";
}

function showPanel(panel) {
	if ( (mode == 'svp') && (panel == currentPanel) ) {
		if ( $('magnify_widget_playlist_item_' + currentPanel + '_container') ) new Effect.Fade('magnify_widget_playlist_item_' + currentPanel + '_container', {duration: .1});
		lastPanel = currentPanel;
		currentPanel = '';
		return;
	}

	if ( panel == 'playlists' ) {	
		if ( !$('magnify_widget_playlist_container') ) {
			var navContainer = $('magnify_widget_playlist_nav_container');
			var container = document.createElement('div');
			container.id = 'magnify_widget_playlist_container';
			navContainer.appendChild(container);
			playlistCallback(currentPlaylist, currentCID);
		}
		hideAd();
		if ( (currentPanel == 'playlists') && (numPlaylists > 1) ) {
			restorePlaylist('', currentPlaylist);
		}
		if ( $('magnify_widget_playlist_item_' + currentPanel + '_container') ) new Effect.Fade('magnify_widget_playlist_item_' + currentPanel + '_container', {duration: .1});
	} else {
		if ( panel != currentPanel ) {
			if ( currentPanel && currentPanel != 'playlists' ) {	
				if ( $('magnify_widget_playlist_item_' + currentPanel + '_container') ) new Effect.Fade('magnify_widget_playlist_item_' + currentPanel + '_container', {duration: .1, queue: { position: 'start', scope: 'content' }});					
			}
			if ( $('magnify_widget_playlist_item_' + panel + '_container') ) {
				new Element.show('magnify_widget_playlist_item_' + panel + '_container');
			} else {
				var navContainer = $('magnify_widget_playlist_nav_container');
				var drawer = document.createElement('div');
				drawer.className = 'magnify-widget-playlist-item-content-container-created';
				drawer.id = 'magnify_widget_playlist_item_' + panel + '_container';
				drawer.style.zIndex = 499;
				drawer.style.position = "absolute";
				drawer.style.left = "0px";
				var container = document.createElement('div');
				container.className = 'magnify-widget-playlist-item-content';
				container.id = 'magnify_widget_playlist_item_' + panel + '_content';
				drawer.appendChild(container);
				navContainer.appendChild(drawer);
				new Ajax.Updater('magnify_widget_playlist_item_' + panel + '_content', toolRoot +  panel + '.minc?content_item_cid=' + currentCID + ( queryString ? '&' + queryString : '' ), {
					evalScripts: true,
					method: 'get',
					asynchronous: true,
					onComplete: function() {
						hideAd();
						if ( mode != 'ivp' ) {
							$('magnify_widget_playlist_item_' + panel + '_content').insert( { top: '<div class="magnify-player-overlay-close"><a href="#" onclick="hidePanel();" class="magnify-player-overlay-close-link">close</a></div>' } );
						}
						if ( $('magnify_widget_playlist_item_' + panel + '_container').style.display == 'none' ) {
							new Effect.Appear('magnify_widget_playlist_item_' + panel + '_container', {duration: .1, queue: { position: 'end', scope: 'content' }});
						}
					}	
				});
			}
		}
	}
	lastPanel = currentPanel;
	currentPanel = panel;
}

function makeSelected(el, class1, class2) {
	$$('.' + class1).each( function( element ) {
		element.removeClassName(class1);
		element.addClassName(class2);
	});
	if ( el ) {
		Element.removeClassName(el, class2);
		Element.addClassName(el, class1);
	}
}

function scrollToTab(tabContainer, tab) {	
	var tabLoc = tab.positionedOffset()[0];
	new Effect.Move(tabContainer, {x: tabLoc*-1, y: 0, queue: { position: 'end', scope: 'pager' } });
	pageCounter = Math.ceil(tabLoc/pageWidth);
}

var lastScrollDistance = "";
function scrollToListItem(listContainer, listItem) {	
	var itemLoc = listItem ? listItem.positionedOffset()[1] : 0;
	var containerLoc = listContainer ? parseInt(listContainer.style.top) : 0;
	lastScrollDistance = (-1*containerLoc)-itemLoc;
	new Effect.Move(listContainer, {x: 0, y: (-1*containerLoc)-itemLoc, queue: { position: 'end', scope: 'scroller' } });
}

function restoreListScroll(listContainer) {
	new Effect.Move(listContainer, {x: 0, y: -1*lastScrollDistance, queue: { position: 'end', scope: 'scroller' } });
}
	
function playerCallback(videoCID, autoplay) {
	currentCID = videoCID;
	var playerURL;
	var hostname = window.location.hostname;
	if ( mode == 'ivp' ) {
		playerURL = 'http://' + hostname + '/item/' + videoCID;
		window.location.href = playerURL;	
	} else {
		playerURL = 'http://' + hostname + componentRoot + 'player_content?content_item_cid=' + videoCID + '&autoplay=' + (autoplay ? '1' : '') + ( queryString ? '&' + queryString : '' );				
		//$('magnify_video_player').innerHTML = '<div style="text-align: center; margin-top:' + parseInt($('magnify_video_player').offsetHeight/2 - 20) + 'px;" class="mvp-loading-message">Loading video...</div>';
		
		new Ajax.Updater('magnify_video_player', playerURL, {
			evalScripts: true,
			method: 'get',
			asynchronous: true,
			onComplete: function() {
				continuousPlay = true;
				destroyContainers();
			}
		});
	}
}

playlistCallback = function(playlistCID, itemCID) {
	var hostname = window.location.hostname;
	var playlistURL = 'http://' + hostname + componentRoot + 'playlists?playlist=' + playlistCID + '&content_item_cid=' + itemCID + ( queryString ? '&' + queryString : '' );
	$('magnify_widget_playlist_container').innerHTML = '<div style="text-align: center; margin-top: ' + parseInt($('magnify_widget_playlist_container').offsetHeight/2 - 20) + 'px;" class="mvp-loading-message">Loading playlists...</div>';
	new Ajax.Updater('magnify_widget_playlist_container', playlistURL, {
		evalScripts: true,
		method: 'get',
		asynchronous: true,
		onComplete: function() {
			scrollToListItem($('magnify_widget_playlist_items'), $('magnify_widget_playlist_item_' + playlistCID));
		}
	});
}

restorePlaylist = function(el, playlistCID, itemCID) {
	if ( currentPlaylist && (currentPlaylist != '') ) {
		currentPlaylist = '';
		new Effect.Fade('magnify_widget_playlist_wrapper_' + playlistCID);
		new Effect.BlindUp( 'magnify_widget_playlist_items_container_' + playlistCID);
		$('magnify_widget_playlist_' + playlistCID).addClassName('magnify-widget-playlist');
		$('magnify_widget_playlist_' + playlistCID).removeClassName('magnify-widget-playlist-selected');
		if ( $('magnify_widget_playlists').offsetHeight > $('magnify_widget_playlist_container').offsetHeight ) {
			$('magnify_widget_playlists').addClassName('magnify-widget-playlists');
			Element.show('magnify_widget_playlist_scrollbar');
		}
		restoreListScroll($('magnify_widget_playlists'));
	}
}


activatePlaylist = function(el, playlistCID, itemCID) {
	if ( currentPlaylist != playlistCID ) {
		makeSelected(el, 'magnify-widget-playlist-selected', 'magnify-widget-playlist'); 
		playlistItemsCallback(playlistCID, itemCID);
		currentPlaylist = playlistCID;
	} else {
		if ( currentPlaylist && (currentPlaylist != '') ) { restorePlaylist(el, currentPlaylist); }
		currentPlaylist = '';
	}
}

playlistItemsCallback = function(playlistCID, itemCID, autoplay) {
	var hostname = window.location.hostname;
	var playlistItemsURL = 'http://' + hostname + componentRoot + 'playlist_items?playlist=' + playlistCID + '&content_item_cid=' + itemCID + ( queryString ? '&' + queryString : '' );
	playlistCID = playlistCID.gsub(/\'/, '');
	
	scrollToListItem($('magnify_widget_playlists'), $('magnify_widget_playlist_' + playlistCID)); 
	
	if ( $('magnify_widget_playlist_items_container_' + playlistCID) ) {
		$('magnify_widget_playlist_items_container_' + playlistCID).innerHTML = '<div style="text-align: center; margin-top: 50px;" class="mvp-loading-message">Loading playlist...</div>';
		
		new Effect.BlindDown( 'magnify_widget_playlist_items_container_' + playlistCID );
		if ( $('magnify_widget_playlist_scrollbar') ) {
			Element.hide('magnify_widget_playlist_scrollbar');
		}
		$('magnify_widget_playlists').removeClassName('magnify-widget-playlists');
				
		new Ajax.Updater('magnify_widget_playlist_items_container_' + playlistCID, playlistItemsURL, {
			evalScripts: true,
			method: 'get',
			asynchronous: true,
			onComplete: function() {
				new Effect.Appear('magnify_widget_playlist_wrapper_' + playlistCID); 
			}
		});
	}
}

stopContinuousPlay = function() {
	continuousPlay = false;
}

loadNext = function() {
	var videoCID = 'undefined';
	var maxIndex = currentPlaylistCIDs.length;
	currentPlaylistCIDs.each(function(el, index) {
		if ( el == currentCID ) {
			var nextIndex = index + 1;
			if ( maxIndex > nextIndex ) {
				videoCID = currentPlaylistCIDs[nextIndex];
			} else {
				videoCID = 'undefined';
			}
			$break;
		}
	});
	if ( (videoCID != 'undefined') && continuousPlay ) {
		playerCallback(videoCID, 1);
		var playlistItem = $('magnify_widget_playlist_item_' + videoCID);
		makeSelected(playlistItem, 'magnify-widget-playlist-item-selected', 'magnify-widget-playlist-item');
		scrollToPlaylistItem(playlistItem);
	}
	
	if ( typeof(StatsObject) != 'undefined' ) {	
		StatsObject.ajaxy = true;
		StatsObject.packLog();
	}
}

scrollToPlaylistItem = function(playlistItem) {
	var list = $('magnify_widget_playlist_wrapper_' + currentPlaylist);
	var listContainer = $('magnify_widget_playlist_items_container_' + currentPlaylist);
	var listHeight = list.offsetHeight;
	var listContainerHeight = listContainer.offsetHeight;
	var currentLocation = Math.abs(parseInt(list.style.top));
	var itemLocation = playlistItem.offsetTop
	var scrollHandle = $('magnify_widget_playlist_items_scrollbar_handle_' + currentPlaylist);
	var moveAmount = (listContainerHeight/listHeight) * listContainerHeight;
	if ( (itemLocation - currentLocation) > (listContainerHeight-50) ) {
		new Effect.Move(list, {x: 0, y: -1* ( itemLocation - currentLocation ) });
		new Effect.Move(scrollHandle, {x: 0, y: moveAmount });
	}
}


var showAds = 0;
var adDelay;
var adShowing = false;
var adDist = 0;
var hideInterval;
function showAd(manual) {
	if ( !adShowing && $('magnify_widget_playlist_item_companion') ) {
		manual = manual ? manual : 0;
		if ( mode == 'svp' ) {
			adDist = $('magnify_player_content').offsetHeight;		
		} else {
			adDist = $('magnify_widget_playlist_container').offsetHeight;
		}
		//adDist = $('magnify_widget_playlist_item_companion').offsetHeight;
		//new Effect.Opacity('magnify_widget_playlist_container', { from: 1.0, to: 0.4 });
		
		new Effect.Move($('magnify_widget_playlist_item_companion'), {x: 0, y: -1*adDist, duration: 0.75, queue: { position: 'start', scope: 'ad_rect' }});
		if ( !manual ) {
			hideInterval = setTimeout(hideAd, adDelay);
		}
		
		$('magnify_widget_rect_handle').onclick = hideAd;
		$('magnify_widget_rect_handle').innerHTML = 'close';
		Effect.Appear( $('magnify_widget_rect_frame'), {duration: .1, queue: { position: 'end', scope: 'ad_rect'}} );
		adShowing = true;
	}
}

function hideAd() {
	if ( adShowing ) {
		Effect.Fade( $('magnify_widget_rect_frame'), {duration: .1, queue: { position: 'start', scope: 'ad_rect'}} );
		clearTimeout(hideInterval);
		adShowing = false;
		$('magnify_widget_rect_handle').onclick = function() {
			showAd(1);
		}
		$('magnify_widget_rect_handle').innerHTML = 'advertisement';
		new Effect.Move($('magnify_widget_playlist_item_companion'), {x: 0, y: adDist, duration: 0.75, queue: { position: 'end', scope: 'ad_rect' }});
		adDist = 0;		
	}
}

function refreshAds(adArray, videoCID) {
	adArray.each( function(el) {
		if ( el ) {
			el.src = toolRoot + 'ad.mason?loc=' + el.id + '&amp;content_item_cid=' + videoCID + ( queryString ? '&amp;' + queryString : '' );;
		}
	});
}

function showEmbedCode(link, el) {
	if ( el.style.display == 'none' ) {
		Effect.Appear(el, {queue: { scope: 'embed_link'}} );
		link.innerHTML = "hide embed code";
	} else {	
		Effect.Fade(el, {queue: { scope: 'embed_link'}} );
		link.innerHTML = "embed this player";
	}
	return false;
}

/*
moo.fx, simple effects library built with prototype.js (http://prototype.conio.net).
by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE.
for more info (http://moofx.mad4milk.net).
Saturday, February 11, 2006
v 1.2.1
*/

var fx = new Object();
//base
fx.Base = function(){};
fx.Base.prototype = {
	setOptions: function(options) {
	this.options = {
		duration: 500,
		onComplete: '',
		transition: fx.sinoidal
	}
	Object.extend(this.options, options || {});
	},

	go: function() {
		this.startTime = (new Date).getTime();
		this.timer = setInterval (this.step.bind(this), 13);
	},

	step: function() {
		var time  = (new Date).getTime();
		if (time >= this.options.duration+this.startTime) {
			this.now = this.to;
			clearInterval (this.timer);
			this.timer = null;
			if (this.options.onComplete) setTimeout(this.options.onComplete.bind(this), 10);
		}
		else {
			var Tpos = (time - this.startTime) / (this.options.duration);
			this.now = this.options.transition(Tpos) * (this.to-this.from) + this.from;
		}
		this.increase();
	},

	custom: function(from, to) {
		if (this.timer != null) return;
		this.from = from;
		this.to = to;
		this.go();
	},

	hide: function() {
		this.now = 0;
		this.increase();
	},

	clearTimer: function() {
		clearInterval(this.timer);
		this.timer = null;
	}
}

//stretchers
fx.Layout = Class.create();
fx.Layout.prototype = Object.extend(new fx.Base(), {
	initialize: function(el, options) {
		this.el = $(el);
		this.el.style.overflow = "hidden";
		this.el.iniWidth = this.el.offsetWidth;
		this.el.iniHeight = this.el.offsetHeight;
		this.setOptions(options);
	}
});

// scrolling div
// added 3/22/2006 by kkp, clue inc
// http://www.clueinc.net
fx.ScrollDiv = Class.create();
fx.ScrollDiv.prototype = Object.extend(new fx.Base(), {
	initialize: function(container, el, handle, options) {
		this.container = $(container);
    	this.el = $(el);
    	this.handle = $(handle);
    	this.setOptions(options);
    	this.totalHeight = this.el.offsetHeight;
    	this.handleHeight = parseInt(this.handle.style.height);
    	this.containerHeight = this.container.offsetHeight;
    	this.now = parseInt(this.el.style.top);
    	this.scrollLimit = this.totalHeight;
    	this.dest = -1*(this.totalHeight-this.containerHeight);
	},
	
	scrollUp: function() {
    	this.clearTimer();
    	if ( this.now < 0 ) {
    		this.custom(this.now, 0);
    	}
	},
	
	scrollDown: function() {
    	this.clearTimer();
    	this.dest = -1*(this.el.offsetHeight-this.container.offsetHeight);
    	if ( this.now > this.dest ) {
    		this.custom(this.now, this.dest);
    	}
	},
	
	stopScroll: function() {
		this.clearTimer();
	},

	increase: function() {
		var handleLimit = this.handle.parentNode.offsetHeight - this.handleHeight;
		var movePercent = ( Math.abs(this.now) / (this.el.offsetHeight-this.container.offsetHeight) ) * handleLimit;
    	this.el.style.top = this.now + "px";
		this.handle.style.top = movePercent + "px";
		//$('debug').innerHTML = "handle top: " + this.handle.style.top + ", handle limit: " + handleLimit + ", handle height: " + this.handleHeight + ", scroll height: " + this.handle.parentNode.offsetHeight + ", now: " + this.now + ", dest: " + this.dest + ", total height: " + this.el.offsetHeight;
	}	
});

fx.Height = Class.create();
Object.extend(Object.extend(fx.Height.prototype, fx.Layout.prototype), {	
	increase: function() {
		this.el.style.height = this.now + "px";
	},

	toggle: function() {
		if (this.el.offsetHeight > 0) this.custom(this.el.offsetHeight, 0);
		else this.custom(0, this.el.scrollHeight);
	}
});

fx.Width = Class.create();
Object.extend(Object.extend(fx.Width.prototype, fx.Layout.prototype), {	
	increase: function() {
		this.el.style.width = this.now + "px";
	},

	toggle: function(){
		if (this.el.offsetWidth > 0) this.custom(this.el.offsetWidth, 0);
		else this.custom(0, this.el.iniWidth);
	}
});

//fader
fx.Opacity = Class.create();
fx.Opacity.prototype = Object.extend(new fx.Base(), {
	initialize: function(el, options) {
		this.el = $(el);
		this.now = 1;
		this.increase();
		this.setOptions(options);
	},

	increase: function() {
		if (this.now == 1 && (/Firefox/.test(navigator.userAgent))) this.now = 0.9999;
		this.setOpacity(this.now);
	},
	
	setOpacity: function(opacity) {
		if (window.ActiveXObject) this.el.style.filter = "alpha(opacity=" + opacity*100 + ")";
		this.el.style.opacity = opacity;
		if (opacity == 0) this.el.style.visibility = "hidden";
		else this.el.style.visibility = "visible";
	},

	toggle: function() {
		if (this.now > 0) this.custom(1, 0);
		else this.custom(0, 1);
	}
});

//transitions
fx.sinoidal = function(pos){
	return ((-Math.cos(pos*Math.PI)/2) + 0.5);
	//this transition is from script.aculo.us
}
fx.linear = function(pos){
	return pos;
}
fx.cubic = function(pos){
	return Math.pow(pos, 3);
}
fx.circ = function(pos){
	return Math.sqrt(pos);
}

addthis_pub = "PI7WS6CWKKERFRJ5";
addthis_brand = 'Magnify.net';
addthis_logo = 'http://www.magnify.net/decor/trim/page-logo-180.gif';
function getAddThis(link, title, container) {
	var content_url = encodeURIComponent(link);
	var content_title = encodeURIComponent(title);
	var container = $(container);
	
	injectScript('http://s7.addthis.com/js/152/addthis_widget.js');
	
	var link = document.createElement('a');
	link.href = "http://www.addthis.com/bookmark.php";
	link.onmouseover = function() { return addthis_open(this, '', content_url, content_title); }
	
	link.onmouseout = function() {
		addthis_close();
	}
	link.onclick = function() {
		return addthis_sendto();
	}
	
	var img = document.createElement('img');
	img.src = "http://s7.addthis.com/button1-bm.gif";
	img.border = 0;
	img.style.width = "125px";
	img.style.height = "16px";
	link.appendChild(img);
	container.appendChild(link);

}

// swap images for 5-star ratings
function swapRate(level, img_on, img_off) {
	for ( var i=1; i <= 5; i++ ) {
		$('mvp_rating_' + i).src = ( i <= level ? img_on : img_off );
	}
}


///// positioning functions
function getPosleft(elm) {
	var left = elm.offsetLeft;
	while((elm = elm.offsetParent) != null) {
		left += elm.offsetLeft;
	}
	return left;
}

function getPostop(elm) {
	var top = elm.offsetTop;
	while((elm = elm.offsetParent) != null) {
		top += elm.offsetTop;
	}
	return top;
}


function getPageOffsetLeft(menuDiv) {
var x;
x = menuDiv.offsetLeft;
  if (menuDiv.offsetParent != null) {
    x += getPageOffsetLeft(menuDiv.offsetParent);
   }
return x;
}


function getPageOffsetTop(menuDiv) {
var y;
y = menuDiv.offsetTop;
  if (menuDiv.offsetParent != null)
    y += getPageOffsetTop(menuDiv.offsetParent);
return y;
}

function injectScript(url) {
	var oScript = document.createElement("script"); 
	var dtRf = new Date(); 
	oScript.setAttribute("src", url + "?rf=" + dtRf.getTime()); 
	var head = document.getElementsByTagName('head')[0];
	head.appendChild(oScript);
}


// Safari can't load css via ajax
// It must be attached to the head tag
// takes the id of your stylesheet in th ajax file
function injectCSS(css_string) {
	var ss = document.createElement('style');
	var def = css_string;
	ss.setAttribute("type", "text/css");
	if (ss.styleSheet) {   // IE
		ss.styleSheet.cssText = def;
	} else {                // the world
		var tn = document.createTextNode(def);
		ss.appendChild(tn);
	}
	var head = document.getElementsByTagName('head')[0];
	head.appendChild(ss);
}