/*****
RUNS POPUP RANKING CARD FOR RECRUITS
*****/

com.espn.recruit.scoutrankingcard = Class.create();

com.espn.recruit.scoutrankingcard.list = [];
com.espn.recruit.scoutrankingcard.ajaxRequest = null;
com.espn.recruit.scoutrankingcard.cache = new Object();

com.espn.recruit.scoutrankingcard.PLAYER_LINK_IDENTIFIER = 'scoutrankingcard';
com.espn.recruit.scoutrankingcard.TAB_OVERVIEW = 0;
com.espn.recruit.scoutrankingcard.FULL_HELP = 1;


com.espn.recruit.scoutrankingcard.TABS = [com.espn.recruit.scoutrankingcard.TAB_OVERVIEW, com.espn.recruit.scoutrankingcard.FULL_HELP];

com.espn.recruit.scoutrankingcard.STATUS_HIDDEN = 0;
com.espn.recruit.scoutrankingcard.STATUS_SHOWN = 1;

com.espn.recruit.scoutrankingcard.PNG_HACK_URL = "http://assets.espn.go.com/i/recruiting/recruitTracker/popup/pnghack.png";


com.espn.recruit.scoutrankingcard.formatPNGTag = function(properties) {
	var id = (properties.id) ? ' id="' + properties.id + '"' : '';

	if (document.all) {
		return '<img' + id + ' style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src=\'' + properties.src + '\');" src="' + com.espn.recruit.scoutrankingcard.PNG_HACK_URL + '" border="' + properties.border + '" width="' + properties.width + '" height="' + properties.height + '" />';
	} else {
		return '<img' + id + ' src="' + properties.src + '" border="' + properties.border + '" height="' + properties.height + '" width="' + properties.width + '" />';
	}
};

com.espn.recruit.scoutrankingcard.checkCache = function(playerId, tabId) {
	return (com.espn.recruit.scoutrankingcard.cache[playerId] && com.espn.recruit.scoutrankingcard.cache[playerId][tabId]);
};



com.espn.recruit.scoutrankingcard.prototype = {

	tabId:  com.espn.recruit.scoutrankingcard.TABS[0],

	leagueId: -1,
	teamId: -1,
	playerId: -1,
	status: com.espn.recruit.scoutrankingcard.STATUS_HIDDEN,
	arrow: null,

	parentDiv: null,
	contentDiv: null,

	sourceEvent: null,
	sourceElement: null,

	position: null,

 	height: 200,
 	width: 519,
 	padding: 0,
 	borderSize: 0,

	initialize: function() {

		var _this = this;

		this.position = new com.espn.recruit.scoutrankingcard.Position(this, { y: 0, x: 0 });
		this.parentDiv = document.createElement('DIV');
		this.parentDiv.id = 'pcMain2';
		var styles = {
			display: 'none',
			position: 'absolute',
			height: (this.height - (this.padding*2) - (this.borderSize*2)) + 'px',
			width: (this.width - (this.padding*2) - (this.borderSize*2)) + 'px',
			zIndex: 10000
		};
		Element.setStyle(this.parentDiv, styles);

		// BASIC FORMATTING
		this.renderTabNav();
		this.renderShell();

		this.position.render();

		this.arrow = new com.espn.recruit.scoutrankingcard.Arrow(this);

		com.espn.recruit.scoutrankingcard.list.push(this);

		// ADD RULES TO DOM
		var rules = {
			'.scoutrankingcard' : function(element){
				element.onclick = function(event){
				_this.handleClick(event || window.event);
				}
			}

		};



		//if (com.espn.env.an != com.espn.env.IE) {
			Behaviour.register(rules);

		//}

		com.espn.recruit.scoutrankingcard.list.push(this);

		Behaviour.addLoadEvent(function() { _this._onload() });

	},

	handleClick: function(event) {


		if (event && Event.element(event)) {

			var previousSourceElement = this.sourceElement;

			this.sourceEvent = event;
			this.sourceElement = Event.element(event);

			// SAFARI FIX
			if (!this.sourceElement.getAttribute) {
				this.sourceElement = this.sourceElement.parentNode;
			}
			if (!this.sourceElement.getAttribute) {
				return;
			}

			this.leagueId = this.sourceElement.getAttribute('league_id');
			this.teamId = this.sourceElement.getAttribute('team_id');
			this.gatherSourceElementCoordinates();
			var playerId = this.sourceElement.getAttribute('rank');
			var tabId = this.sourceElement.getAttribute('tab_id');


			if (this.status == com.espn.recruit.scoutrankingcard.STATUS_HIDDEN || previousSourceElement != this.sourceElement) {
				this.show(playerId, tabId);
			} else {
				this.hide();
			}

		}
	},

	gatherSourceElementCoordinates: function() {
		if (this.sourceElement) {
			var sourceElementDimensions = Element.getDimensions(this.sourceElement);
			var sourceElementCumOffsets = Position.cumulativeOffset(this.sourceElement);
			this.sourceElement.x_right = sourceElementCumOffsets[0] + sourceElementDimensions.width; // x of element's right side
			this.sourceElement.x_left = sourceElementCumOffsets[0]; // x of element's left side
			this.sourceElement.y_top = sourceElementCumOffsets[1]; // y of element's top side
			this.sourceElement.y_bottom = sourceElementCumOffsets[1] + sourceElementDimensions.height; // y of element's bottom side
		}
	},


	hide: function() {
		this.playerId = -1;
		Element.update(this.contentDiv, "");
		Element.hide(this.parentDiv);
		this.arrow.hide();
		this.status = com.espn.recruit.scoutrankingcard.STATUS_HIDDEN;

	},

	show: function(playerId, tabId) {



		var _this = this;

		var rules2 = {
				'.pcTab' : function(element){
					element.onclick = function(event){
					_this.changeTab(1);
					}
				}

		};
		Behaviour.register(rules2);
		Behaviour.apply()

		if (!(tabId && com.espn.recruit.scoutrankingcard.TABS[tabId])) tabId = com.espn.recruit.scoutrankingcard.TABS[0];

		if (playerId != null && playerId != -1) {
			this.playerId = playerId;
		}

		this.tabId = tabId;

		// HIDE PRIOR TO UPDATE
		this.arrow.hide();
		this.parentDiv.hide();

		this.arrow.getOrientation();
		this.move()

		// RENDER THE APPROPRIATE TAB
		var options = { _success: function() { _this.finalizeShow(); } }
		this.renderTabChoice();
		this.renderContent(options);
		this.trackCardLoad();

		//this.finalizeShow();
		// WILL PROCEED TO finalizeShow() AFTER COMPLETION OF UPDATE
	},

	finalizeShow: function() {
		this.arrow.show();
		this.parentDiv.show();
		this.status = com.espn.recruit.scoutrankingcard.STATUS_SHOWN;
		showGradeExp(getPlayerClassif(this.playerId));

	},

	changeTab: function(tabId) {
		this.tabId = tabId;
		//this.renderTabChoice();
		this.trackTabChange();
		this.renderContent();
	},

	getOffset: function() {
		return { y: 0, x: this.arrow.width - 12 };
	},


	move: function() {
		this.position.set(this.getOffset().x, this.getOffset().y);
		this.position.render();
	},

	clear: function() {
		this.contentDiv.innerHTML = '';
	},

	renderContent: function(options) {
		switch (parseInt(this.tabId)){
			case com.espn.recruit.scoutrankingcard.TAB_OVERVIEW:
				this.renderContentOverview(options);
				break;
			//case com.espn.recruit.scoutrankingcard.FULL_HELP:
			//	this.renderContentFullHelp(options)
			//	break;
			}

	},

	getCachedData: function() {
		if (com.espn.recruit.scoutrankingcard.cache[this.playerId]) {
			if (com.espn.recruit.scoutrankingcard.cache[this.playerId][this.tab]) {
				return com.espn.recruit.scoutrankingcard.cache[this.playerId][this.tab];
			}
		}
		return null;
	},

	setCachedData: function(data) {
		if (!com.espn.recruit.scoutrankingcard.cache[this.playerId]) {
			com.espn.recruit.scoutrankingcard.cache[this.playerId] = new Object();
		}
		com.espn.recruit.scoutrankingcard.cache[this.playerId][this.tab] = data;
	},



	renderContentOverview: function(options) {

		var _this = this;

		var adToInsert;
		if (com.espn.recruit.useAdServer == true && digAdData && digAdData['PresentedByLogo']) adToInsert = digGetAd('PresentedByLogo', true);

		var _success = function(transport, object) {
			_this.setCachedData(transport.responseText);
			if (options && options._success) { options._success(); }

			if (com.espn.recruit.useAdServer == true && adToInsert && $('adInsertion_PresentedByLogo')) {
				Element.update('adInsertion_PresentedByLogo', adToInsert);
			}



		};

		var cachedData = this.getCachedData();
		if (cachedData) {
			Element.update(this.contentDiv, cachedData);
			this.finalizeShow();

			if (com.espn.recruit.useAdServer == true && adToInsert && $('adInsertion_PresentedByLogo')) {
				Element.update('adInsertion_PresentedByLogo', adToInsert);
			}
		} else {
			var url = 'popup/rankHtml';
			var pars = 'playerId=' + this.playerId;
			var target = this.contentDiv;
			new Ajax.Updater(target, url, {method: 'get', parameters: pars, onComplete: _success});
	 		}
	},

	renderTabInactive: function(tabId) {
	//	var _this = this;
//
	//	var oldTabLink = $('pcTab' + tabId);
	//	Element.removeClassName(oldTabLink, "TabsON");
	//	Element.addClassName(oldTabLink, "TabsOFF");
		//Element.setStyle(oldTabLink, { cursor: 'pointer' });

		//oldTabLink.onclick = function() { _this.changeTab(tabId); };


// DON'T NEED FOR RECRUIT TRACKER POPUPS

		// LEFT SIDE
		//Element.update($('pcTab' + tabId + '_left'), com.espn.recruit.scoutrankingcard.formatPNGTag({ width: 14, height: 36, border: 0, src: 'http://games-ak.espn.go.com/s/ffllm/07/images/design07/playerpop/pctabs_offleft.png' }));

 		// MIDDLE SECTION
	 	//var oldTabBG = $('pcTabBG' + tabId)
		//Element.update(oldTabBG, com.espn.recruit.scoutrankingcard.formatPNGTag({ width: Element.getStyle(oldTabBG, 'width'), height: Element.getStyle(oldTabBG, 'height'), border: 0, src: 'http://games-ak.espn.go.com/s/ffllm/07/images/design07/playerpop/pctabs_offback.png' }));

		// RIGHT SIDE
		//var width = (tabId == com.espn.recruit.scoutrankingcard.TAB_OVERVIEW) ? 14 : 10;
		//var endpiece = (tabId == com.espn.recruit.scoutrankingcard.TAB_OVERVIEW) ? 'end' : '';
		//Element.update($('pcTab' + tabId + '_right'), com.espn.recruit.scoutrankingcard.formatPNGTag({ width: width, height: 36, border: 0, src: 'http://games-ak.espn.go.com/s/ffllm/07/images/design07/playerpop/pctabs_offright' + endpiece + '.png' }));

	},

	renderTabActive: function(tabId) {
	//	var _this = this;

	//	var newTabLink = $('pcTab' + tabId);
	//	Element.removeClassName(newTabLink, "TabsOFF");
	//	Element.addClassName(newTabLink, "TabsON");
	//	Element.setStyle(newTabLink, { cursor: 'default' });
	//	newTabLink.onclick = null;


// DON'T NEED FOR RECRUIT TRACKER POPUPS

		// LEFT SIDE
		//Element.update($('pcTab' + tabId + '_left'), com.espn.recruit.scoutrankingcard.formatPNGTag({ width: 14, height: 36, border: 0, src: 'http://games-ak.espn.go.com/s/ffllm/07/images/design07/playerpop/pctabs_onleft.png' }));

 		// MIDDLE SECTION
 		//var newTabBG = $('pcTabBG' + tabId)
		//Element.update($('pcTabBG' + tabId), com.espn.recruit.scoutrankingcard.formatPNGTag({ width: Element.getStyle(newTabBG, 'width'), height: Element.getStyle(newTabBG, 'height'), border: 0, src: 'http://games-ak.espn.go.com/s/ffllm/07/images/design07/playerpop/pctabs_onback.png' }));

		// RIGHT SIDE
		//var width = (tabId == com.espn.recruit.scoutrankingcard.TAB_OVERVIEW) ? 14 : 10;
		//var endpiece = (tabId == com.espn.recruit.scoutrankingcard.TAB_OVERVIEW) ? 'end' : '';
		//Element.update($('pcTab' + tabId + '_right'), com.espn.recruit.scoutrankingcard.formatPNGTag({ width: width, height: 36, border: 0, src: 'http://games-ak.espn.go.com/s/ffllm/07/images/design07/playerpop/pctabs_onright' + endpiece + '.png' }));
	},

	renderTabChoice: function() {

		var _this = this;

		$A(com.espn.recruit.scoutrankingcard.TABS).each(function(tabId) {

				if (_this.tabId != tabId) {
					_this.renderTabInactive(tabId);
				} else {
					_this.renderTabActive(tabId);
				}
			}
		);
	},

	renderTabNav: function() {

	//	var tabsDiv = document.createElement('DIV');
	//	tabsDiv.id = 'pcTabs';

	//	tabsDiv.innerHTML = '<div id="recruit-tabs">'+
	//		 		'<ul>'+
	//		   		'<li><a id="pcTab' + com.espn.recruit.scoutrankingcard.TAB_OVERVIEW + '"><span>Briefing Room</span></a></li>'+
	//		  		'</ul>'+
	//				'</div>';

	//	this.parentDiv.appendChild(tabsDiv);

	},

	renderShell: function() {
		var bodyDiv = document.createElement('DIV');
		var styles = {
				width: this.width + 'px',
				position: 'absolute',
				top: '26px',
				zIndex: '1'
				};

		Element.setStyle(bodyDiv, styles);

		var iframeBackboard = (com.espn.env.an != com.espn.env.IE) ? '' : '<iframe style="z-index:50;left:0px;position:absolute;top:0px;width:519px;height:170px;filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)" src="javascript:false;" frameBorder="0" scrolling="no" id="diFrame"></iframe>';

		bodyDiv.innerHTML = com.espn.recruit.scoutrankingcard.formatPNGTag({ width: 519, height: 19, border: 0, src: 'http://assets.espn.go.com/i/recruiting/recruitTracker/popup/rt_popup_top2.png' }) + '<br /><div>' +
					'<!-- start Main Overview -->' +
					iframeBackboard +
					'<div id="layer2" style="z-index:50;position:absolute;width:519px;height:388px;top:19px;left:0px;">' + com.espn.recruit.scoutrankingcard.formatPNGTag({  height: 388, width: 519, border: 0, id:'blackBG', src: 'http://assets.espn.go.com/i/recruiting/recruitTracker/popup/rt_popup_middle.png' }) + '</div>' +
					'<div id="inWhite" style="position:relative;z-index:60;width: 480px; height:386px; margin: 0 0 0 20px; background: #fff;">' +
					'<!-- start content div -->' +
					'<div id="pcContent2" style="height:354px;">' +
					'</div>' +
					'<!-- end content div -->' +
					//'<br clear="all">' +
					'<!-- begin close option -->' +
					'<div id="pcCloseBorder2">' +
					'<div id="pcClose2"><img id="pcCloseButton2" src="http://assets.espn.go.com/i/recruiting/recruitTracker/popup/RTclose_btn.gif" border="0" width="71" height="20" style="cursor: pointer;" alt="" /></div>' +
					'</div>' +
					'<!-- end close option -->' +
					'</div>' +
					'<!-- end overview -->' +
					'</div>' +
					com.espn.recruit.scoutrankingcard.formatPNGTag({ width: 519, height: 15, border: 0, src: 'http://assets.espn.go.com/i/recruiting/recruitTracker/popup/rt_popup_btm.png' }) + '</div>' +
					'<!-- end PlayerCard background -->' +
					'</div>' +
					'<!-- end main -->';

		this.parentDiv.appendChild(bodyDiv);
	},

	_onload: function() {
		document.body.appendChild(this.parentDiv);
		this.contentDiv = $('pcContent2');
		this.bindEventListeners();
		this.arrow._onload(this.arrow);
	},

	bindEventListeners: function() {

		var _this = this;

		/*****
		if (com.espn.env.an == com.espn.env.IE) {
			var els = document.getElementsByName(com.espn.recruit.scoutrankingcard.PLAYER_LINK_IDENTIFIER);

			var linkOnClick = function(event) { _this.handleClick(event); };
			for(var n=0;n<els.length;n++) {
				el = els[n];
				if (el.name.indexOf(com.espn.recruit.scoutrankingcard.PLAYER_LINK_IDENTIFIER) == 0) {
					Event.observe(el, 'click', linkOnClick)
				}
			}
		}
		*****/

		var hideCard = function() { _this.hide(); };
		Event.observe($('pcCloseButton2'), 'click', hideCard);

	},

	toggleView: function(name, vCurrent, vNext) {

		Element.setStyle(name+vCurrent, { display: 'none' });
		Element.setStyle(name+vNext, { display: 'block' });

	},

			trackCardLoad: function() {

				var tabName = 'helper';
				var anExec = 0;//set to zero for multiple page views per page, otherwise omit
				var anSiteSection = "insider";
				var anContentSection = "ncf";
				var anContentSubSection = "recruiting";
				var anContentSubSubSection = "";
				var anContentType = "popup"
				var anLeafPageName = "scoutranking-" + tabName;
				var anStoryId = "";
				//alert("Track Card Load "+anExec+ ' ' +anSiteSection+ ' ' +anContentSection+ ' ' +anContentSubSection+ ' ' +anContentSubSubSection+ ' ' +anContentType+ ' ' +anLeafPageName+ ' ' +anStoryId)
				anTrackPageView(anExec,anSiteSection,anContentSection,anContentSubSection,anContentSubSubSection,anContentType,anLeafPageName,anStoryId);

			},

			trackTabChange: function() {
				var tabName = 'scoutranking-helper'
				var anLinkURL = "http://insider.espn.go.com/ncf/player"
				var anSiteSection = "insider";
				var anLinkPos = "ncf_recruiting_popup_tab";
				var anLinkId = "ncf_" + tabName;
				//alert("Track Card Change "+ anLinkURL+ ' ' +anSiteSection+ ' ' +anLinkPos+ ' ' +anLinkId)
				anTrackLink(anLinkURL,anSiteSection,anLinkPos,anLinkId);
	}

}

com.espn.recruit.scoutrankingcard.Arrow = Class.create();

com.espn.recruit.scoutrankingcard.Arrow.prototype = {

	scoutrankingcard: null,
	position: null,

	//height: 229,
	//width: 123,
	height: 110,
	width: 59,
 	padding: 0,
 	borderSize: 0,

	parentDiv: null,
	image: null,
	orientation: null,

	initialize: function(scoutrankingcard) {

		this.scoutrankingcard = scoutrankingcard;
		this.orientation = { y: com.espn.recruit.scoutrankingcard.ORIENTATION_DOWN, x: com.espn.recruit.scoutrankingcard.ORIENTATION_LEFT };
		var positionProperties = { y: 0, x: 0 };
		this.position = new com.espn.recruit.scoutrankingcard.Position(this, positionProperties);

		this.parentDiv = document.createElement('DIV');
		this.parentDiv.id = 'pcArrow2';
		var styles = {
			display: 'none',
			position: 'absolute',
			width: (this.width - (this.padding*2) - (this.borderSize*2)) + 'px',
			height: (this.height - (this.padding*2) - (this.borderSize*2)) + 'px',
			zIndex: 10001
		};
		Element.setStyle(this.parentDiv, styles);

		this.image = new Image();

		this.position.render();
	},

	_onload: function() {
		var _this = this;
		document.body.appendChild(_this.parentDiv);
	},

	hide: function() {
		Element.hide(this.parentDiv);
	},

	show: function() {
		this.move();
		this.render();
		// DON'T DISPLAY ARROW WHEN NOT ENOUGH HORIZONTAL SPACE
		if (this.orientation.x != com.espn.recruit.scoutrankingcard.ORIENTATION_CENTER) {
			Element.show(this.parentDiv);
		}
	},

	move: function() {
		this.position.set(this.getOffset().x, this.getOffset().y);
		this.position.render();

	},

	getOffset: function() {
		return { y: 0, x: 0 };
	},

	getOrientation: function() {
		var x_orientation;
		var y_orientation;

		var widthNeeded = this.scoutrankingcard.width + this.scoutrankingcard.getOffset().x;
		var heightNeeded = this.scoutrankingcard.height + this.scoutrankingcard.getOffset().y;

		// FOR GETTING THE BROWSER SIZE IN STANDARDS-COMPLIANT MODE
		var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;

		var availableHeight = (window.innerHeight) ? window.innerHeight : iebody.clientHeight;
		var availableWidth = (window.innerWidth) ? window.innerWidth : iebody.clientWidth;

		if (availableWidth - (this.scoutrankingcard.sourceElement.x_right - (document.documentElement.scrollLeft || document.body.scrollLeft)) - widthNeeded > 0) {
			x_orientation = com.espn.recruit.scoutrankingcard.ORIENTATION_LEFT;
		} else if ((this.scoutrankingcard.sourceElement.x_left - (document.documentElement.scrollLeft || document.body.scrollLeft)) > widthNeeded) {
			x_orientation = com.espn.recruit.scoutrankingcard.ORIENTATION_RIGHT;
		} else {
			x_orientation = com.espn.recruit.scoutrankingcard.ORIENTATION_CENTER;
		}

		if ((this.scoutrankingcard.sourceElement.y_top - (document.documentElement.scrollTop || document.body.scrollTop)) > heightNeeded) {
			y_orientation = com.espn.recruit.scoutrankingcard.ORIENTATION_DOWN;
		} else if (availableHeight - (this.scoutrankingcard.sourceElement.y_bottom - (document.documentElement.scrollTop || document.body.scrollTop)) - heightNeeded > 0) {
			y_orientation = com.espn.recruit.scoutrankingcard.ORIENTATION_UP;
		} else {
			y_orientation = com.espn.recruit.scoutrankingcard.ORIENTATION_CENTER;
		}

		this.orientation.x = x_orientation;
		this.orientation.y = y_orientation;
	},

	render: function() {
		var y_orientation = (this.orientation.y != com.espn.recruit.scoutrankingcard.ORIENTATION_CENTER) ? this.orientation.y : com.espn.recruit.scoutrankingcard.ORIENTATION_DOWN;
		this.image.src = 'http://assets.espn.go.com/i/recruiting/recruitTracker/misc/popup_arrow_' + this.orientation.x + y_orientation + '.png';
		Element.update(this.parentDiv, com.espn.recruit.scoutrankingcard.formatPNGTag({ width: this.width, height: this.height, border: 0, src: this.image.src }));
	}
}

com.espn.recruit.scoutrankingcard.Position = Class.create();

// ORIENTATIONS REFER TO THE DIRECTION THE ARROW IS POINTING -- TYPICALLY IT POINTS DOWN AND TO THE LEFT.
com.espn.recruit.scoutrankingcard.ORIENTATION_DOWN = 0;
com.espn.recruit.scoutrankingcard.ORIENTATION_UP = 1;
com.espn.recruit.scoutrankingcard.ORIENTATION_LEFT = 0;
com.espn.recruit.scoutrankingcard.ORIENTATION_RIGHT = 1;
com.espn.recruit.scoutrankingcard.ORIENTATION_CENTER = 2; // USED IN INSTANCES WHERE THERE ISN'T ROOM ON EITHER SIDE OF THE ELEMENT, SO CENTER THE CARD


com.espn.recruit.scoutrankingcard.Position.prototype = {

	component: null,

	y: 0,
	x: 0,

	hasOrientation: false,

	initialize: function(component, properties) {
		this.component = component;
		for(prop in properties) {
			var value = properties[prop];
			this[prop] = value;
		}
	},

	getCoordinates: function() {
		var x = 0; var y = 0;
		var arrow = (this.component.arrow) ? this.component.arrow : this.component;
		var scoutrankingcard = (this.component.scoutrankingcard) ? this.component.scoutrankingcard : this.component;
		var isArrow = (arrow == this.component);
		switch(arrow.orientation.x) {
			case com.espn.recruit.scoutrankingcard.ORIENTATION_LEFT:
				x = scoutrankingcard.sourceElement.x_right;
				break;
			case com.espn.recruit.scoutrankingcard.ORIENTATION_RIGHT:
				x = scoutrankingcard.sourceElement.x_left;
				break;
			case com.espn.recruit.scoutrankingcard.ORIENTATION_CENTER:
				x = Event.pointerX(scoutrankingcard.sourceEvent);
				break;
		}
		switch(arrow.orientation.y) {
			case com.espn.recruit.scoutrankingcard.ORIENTATION_DOWN:
				y = scoutrankingcard.sourceElement.y_top;
				break;
			case com.espn.recruit.scoutrankingcard.ORIENTATION_UP:
				y = scoutrankingcard.sourceElement.y_bottom;
				break;
			case com.espn.recruit.scoutrankingcard.ORIENTATION_CENTER:
				y = (!isArrow) ? Event.pointerY(scoutrankingcard.sourceEvent) : scoutrankingcard.sourceElement.y_top;
				break;
		}

		return { x: x, y: y };
	},

	set: function(x_offset, y_offset) {

		var coordinates = this.getCoordinates();

		var arrow = (this.component.arrow) ? this.component.arrow : this.component;
		var orientation = arrow.orientation;

		var isArrow = (arrow == this.component);

		if (orientation.y == com.espn.recruit.scoutrankingcard.ORIENTATION_DOWN || (orientation.y == com.espn.recruit.scoutrankingcard.ORIENTATION_CENTER && isArrow)) {
			this.y = coordinates.y - y_offset - this.component.height;
		} else if (orientation.y == com.espn.recruit.scoutrankingcard.ORIENTATION_UP) {
			this.y = coordinates.y + y_offset;
		} else {	// ORIENTATION_CENTER
			this.y = coordinates.y - (this.component.height/2);
		}

		if (orientation.x == com.espn.recruit.scoutrankingcard.ORIENTATION_LEFT) {
			this.x = coordinates.x + x_offset;
		} else if (orientation.x == com.espn.recruit.scoutrankingcard.ORIENTATION_RIGHT) {
			this.x = coordinates.x - x_offset - this.component.width;
		} else {	// ORIENTATION_CENTER
			this.x = 0
			//this.x = coordinates.x - (this.component.width/2);
		}

	},

	render: function() {
		Element.setStyle(this.component.parentDiv, { top: this.y +'px', left: this.x +'px' });


	}

}

com.espn.recruit.scoutrankingcard.instance = new com.espn.recruit.scoutrankingcard();

/*****
END POP PLAYER CARD
*****/

//Shows and displays different layers of the popup

var rankId
function toggleFan(toggle) {
	rankId ='bucket'
	if (toggle == 1){
		document.getElementById('toggleoff').style.display = 'block';
		document.getElementById('toggleon').style.display = 'none';
		for (i=1; i < 9; i++){
			document.getElementById(rankId+i).style.display = 'block';
		}
		changeSize('big');
	}
	else {
		document.getElementById('toggleoff').style.display = 'none';
		document.getElementById('toggleon').style.display = 'block';
		for (i=1; i < 9; i++){
			if(document.getElementById(rankId+i).className != 'aRank')
				document.getElementById(rankId+i).style.display = 'none';
		}
		changeSize('small');
	}

}

function showGradeExp(rank) {
	if(rank==0){toggleFan(1);}
	else{
		rankId = 'bucket'+rank;
		document.getElementById(rankId).className ='aRank'
		document.getElementById(rankId).style.display = 'block'
		changeSize('small');
	}
}

function getPlayerClassif(rank) {
	classif = 0
	if (rank >= 90 && rank <= 100){classif = 1;}
	if (rank >= 80 && rank <= 89){classif = 2;}
	if (rank >= 70 && rank <= 79){classif = 3;}
	if (rank >= 60 && rank <= 69){classif = 4;}
	if (rank >= 50 && rank <= 59){classif = 5;}
	if (rank == 45){classif = 6;}
	if (rank == 40){classif = 7;}
	if (rank > 100 || rank == -1){classif = 8;}

	return classif;

	}

function changeSize(sSize){
	if(sSize=='small'){
		//document.getElementById('diFrame').style.height = "170px";
		document.getElementById('pcMain2').style.height = "200px";
		document.getElementById('layer2').style.height = "192px";
		document.getElementById('blackBG').style.height = "192px";
		document.getElementById('inWhite').style.height = "192px";
		document.getElementById('pcContent2').style.height = "160px";
		document.getElementById('rContent3').style.height = "140px";
		document.getElementById('rContent3').style.scroll = "hidden";

		}
	else{
		//document.getElementById('diFrame').style.height = "420px";
		document.getElementById('pcMain2').style.height = "450px";
		document.getElementById('layer2').style.height = "388px";
		document.getElementById('blackBG').style.height = "388px";
		document.getElementById('inWhite').style.height = "386px";
		document.getElementById('pcContent2').style.height = "354px";
		document.getElementById('rContent3').style.height = "320px";
		}

	}

