var dialogIdPrefix = "dialog-"
var dialogCount = 0;
/**
 * $URL$
 * $Author: vashira $
 * $Date: 2010/06/07 08:54:22 $
 * Description:	Virgin Gaming common script
 */

/**
 * Global instance
 **/
var VirginGamingSite = {
	staticVGUrl: ''
};

// synonym to reduce namespace size  
var $VG = VirginGamingSite;

/**
 * $VG.Form handle Form related scripts
 **/
$VG.Form = {
	// Use in all pages with html:form
	initForm: function() {
		// Increase accessibility to form elements
		$("label.dynamic").each(function(i, obj) {
			// control must be in front of label
			var control = $(obj).prev().get(0);
			var controlName = $(control).attr("name");
			$(control).attr("id", controlName + i);
			$(obj).attr("for", controlName + i);
		});
		
		// Auto Focus first error field
		var errorMsgElem = $(".msg .error");
		if($(errorMsgElem).length) {
			$(errorMsgElem).parents(".yui3-g").find("input:first").focus();
		} else {
			// skip hidden fields
			$("fieldset input:first").focus();
		}
		
		// Transform
		this._createDropDownLists();
	}, 
	
	_createDropDownLists: function () {
		// TODO: use jQuery replace <select> with div-based styled select
	}
};

/**
 * $VG.Ajax handle Request/Response related scripts
 **/
$VG.Ajax = {
	// Use in registration
	retrieveSubNationCode: function(nationId, idName) {
		$.post($VG.Ajax.getAjaxPath() + 'getSubNationCode.do', {nationCodeId:nationId}, 
		function(data) {
			document.getElementById(idName).options.length = 0;
			var subCategory = document.getElementById(idName);
			var root = data.documentElement.getElementsByTagName('subnation');
			if (root.length > 0) {
				subCategory.options[0] = new Option('Select a State/Province', '');
				for (var iNode = 0; iNode < root.length; iNode++) {
					var node = root.item(iNode);
					subCategory.options[iNode+1] = new Option($VG.Xml.getData(node, 'name'),
							$VG.Xml.getData(node, 'id'));
				}
				// This is tie to UI
				$(subCategory).parent().parent().fadeIn();
			} else {
				subCategory.options[0] = new Option('No States', '0');
				// This is tie to UI
				$(subCategory).parent().parent().fadeOut();
			}
		});
	},

	// Use in registration
	retrieveTimezone: function(nationId, idName) {
		$.post($VG.Ajax.getAjaxPath() + 'getTZForCountry', {nationCodeId:nationId}, 
		function(data) {
			var root = data.documentElement.getElementsByTagName('timezone');
			if (root.length > 0) {
				var subCategory = document.getElementById(idName);
				var offset = 0;
				subCategory.options.length = 0;
				if (root.length > 1) {
					subCategory.options.length = root.length+1;
					offset = 1;
					subCategory.options[0] = new Option('Select your Time Zone', '');
				} else {
					subCategory.options.length = root.length;
				}
				for (var iNode = 0; iNode < root.length; iNode++) {
					var node = root.item(iNode);
					subCategory.options[iNode+offset] = new Option($VG.Xml.getData(node, 'name'), 
							$VG.Xml.getData(node, 'id'));
				}
				//$('#'+idName+'').prev().text($('option:selected','#'+idName+'').text());
			}
		});
	}, 
	
	// Common
	getAjaxPath: function() {
		var ajaxPath = $VG.Ajax._getActionPath() + '/ajax/';
		return ajaxPath;
	}, 
	
	_getActionPath: function() {
		return location.href.substring(0, location.href.lastIndexOf('/'));
	}
};

$VG.Ajax.Message = {
	
	/**
	 * params:
	 * - to : screenname of recipient (string)
	 *	- subject:  subject of msg (string)
	 * - content: body of msg, accept new line and other escaped chars (string)
	 * - onSuccess: delegate of success called
	 * - onError: delegate of failure called
	 */
	compose: function(to, subject, content, onSuccess, onError) {
		$.getJSON('composeMessage.do', {"screenname": to, "subject": subject, "body": content}, function(data) {
			if(data.success == 'true') {
				if($.isFunction(onSuccess)) {
					onSuccess.call(this, data);
				}
			} else {
				if($.isFunction(onError)) {
					onError.call(this, data);
				}
			}
		});
	}, 
	
	/**
	 * params:
	 * - msgId : ID of message to reply (string)
	 * - content: body of reply msg, accept new line and other escaped chars (string)
	 * - onSuccess: delegate of success called
	 * - onError: delegate of failure called
	 */
	reply: function(msgId, content, onSuccess, onError) {
		$.getJSON('replyToMessage.do', {"id": msgId, "body": content}, function(data) {
			if(data.success == 'true') {
				if($.isFunction(onSuccess)) {
					onSuccess.call(this, data);
				}
			} else {
				if($.isFunction(onError)) {
					onError.call(this, data);
				}
			}
		});
	}, 
	
	/**
	 * params:
	 * - msgIdsArray : Array of ID of message to delete (Array of string)
	 * - onSuccess: delegate of success called
	 * - onError: delegate of failure called
	 */
	deletes: function(msgIdsArray, onSuccess, onError) {
		var msgIdsCV = msgIdsArray.join(",");
		$.getJSON('deleteMessages.do', {"id": msgIdsCV}, function(data) {
			if(data.success == 'true') {
				if($.isFunction(onSuccess)) {
					onSuccess.call(this, data);
				}
			} else {
				if($.isFunction(onError)) {
					onError.call(this, data);
				}
			}
		});
	}
};

$VG.Xml = {
	getData: function(myNode, myNodeName) {
		var subNodes = myNode.childNodes;
		for ( j=0; j < subNodes.length; j++ ){
			var subNode = subNodes.item(j);
			if ( subNode.nodeName == myNodeName ){
				// this is cross browser ( ie and firefox ) compatible
				return subNode.childNodes.item(0).nodeValue;
			}
		}
		return "";
	}
};

$VG.UI = {
	parent: $VG,

	debugLayoutFor: function(elem) {
		var debugGridStyle = {
				'border': '1px dashed red' 
		};
		$(elem).css(debugGridStyle);
		$(elem).find('div').css(debugGridStyle);
		$(elem).find('h2').css(debugGridStyle);
	}, 
	
	showLoading: function(elem) {
		var elemWidth = $(elem).width();
		var elemHeight = $(elem).height();
		$(elem).empty().html('<div class="loading-container" style="width:'+ elemWidth + 'px; height:' + elemHeight + 'px"><img src="' + this.parent.staticVGUrl + 'web_app/vg/images/common/loader.gif" alt="Now Loading..." /></div>');
	},
	
	/**
	 * Create modal dialog with given content and open. This dialog can be access programmatically using $VG.UI.modalDialogInstance
	 * Note that there is ONLY ONE $VG.UI.modalDialogInstance at a time, current value will be override if $VG.UI.openModalDialog is called with different content
	 *
	 * @params opts
	 *	- content: jQuery selector for content of modal dialog : required -- if content is string, need css class name = "modal-dialog-content" to be set explicitly
	 *	- parent: jQuery selector for parent of modal dialog : optional, when this value is set the dialog will center on its parent ELSE will center fixed on window 
	 *	- modal : boolean, true if modal, false otherwise : optional, default is true
	 *	- movable : boolean, true if movable, false otherwise : optional, default is false
	 *	- closable : boolean, true if need close button on top right, false otherwise : optional, default is true
	 *	- closeButtons : array of jQuery selector for buttons : optional -- if this options is set, $VG.UI.closeDialog() will be called. Beware, if you use non modal, the content must has class="dialog-content"
	 *
	 * Sample Usage:
	 * HTML markup
	 * <div id="test-dialog-content">content go here... <button id="bt1" value="ok" /><button id="bt2" value="cancel" /></div>
	 *
	 * JS
	 * // Modal, centered at window
	 * var dialog1 = $VG.UI.openDialog({
	 * 		content: $('#test-dialog-content')
	 * });
	 * // Non modal, centered at window
	 * var dialog2 = $VG.UI.openDialog({
	 *		content: $('#test-dialog-content'),
	 *		modal : false
	 * });
	 * // Non modal, centered at parent
	 * var dialog3 = $VG.UI.openDialog({
	 * 		content: $('#test-dialog-content'),
	 * 		parent: $('.game-status-container'),
	 * 		modal : false
	 * });
	 * // Non modal, centered at parent, movable
	 * var dialog4 = $VG.UI.openDialog({
	 * 		content: $('#test-dialog-content'),
	 * 		parent: $('.game-status-container'),
	 * 		modal : false,
	 * 		movable : true
	 * });
	 * // You don't need to call close dialog if given 'buttons' option
	 * var dialog5 = $VG.UI.openDialog({
	 * 		content: $('#test-dialog-content'),
	 * 		parent: $('.game-status-container'),
	 * 		modal : false,
	 * 		movable : true,
	 * 		closeButtons: [ $('#test-dialog-btn1'), $('#test-dialog-btn2') ]
	 * });
	 * // Set position
	 * var dialog6 = $VG.UI.openDialog({
	 * 		content: $('#test-dialog-content'),
	 * 		parent: $('.game-status-container'),
	 * 		modal : false,
	 * 		movable : true,
	 * 		position : { left: -20, top: 30 }
	 * });
	 * // Custom events - onDialogClosed
	 * dialog6.bind('onDialogClosed', function() {
	 *		alert('This will be called when dialog closed');
	 *		dialog6.unbind('onDialogClosed'); // important, unbind it after finish use
	 * });
	 */
	openDialog: function(opts) {		
		// Validate options
		if((typeof(opts) == 'undefined') || (typeof(opts.content) == 'undefined')) {
			return false;
		}
		var isContentHtml = typeof(opts.content) == 'string';
		if(isContentHtml) {
			throw('content must be jquery selector, not text/html');
		}
		if((typeof(opts.parent) != 'undefined')  && (typeof(opts.modal) != 'undefined') && (opts.modal == true)) {
			throw('Not support, modal dialog cannot has parent element...');
		}
		
		var modalDialogContainerClass = 'vgModalContainer';
		var dialogCloseButtonClass = 'dialog-close-btn';
		var dialogInstance = null;
		
		// Adjust dialog based on given options
		var isModalDialog = true;
		if(typeof(opts.modal) != 'undefined') isModalDialog = opts.modal;
		var dialogParent = null;
		if(typeof(opts.parent) != 'undefined') dialogParent = opts.parent;
		var dialogMovable = false;
		if(typeof(opts.movable) != 'undefined') dialogMovable = opts.movable;
		var dialogClosable = true;
		if(typeof(opts.closable) != 'undefined') dialogClosable = opts.closable;
		var dialogPosition = null;
		if(typeof(opts.position) != 'undefined') dialogPosition = opts.position;
		
		
		// Inject modalDialogContainer if it is the first time
		if($(opts.content).parent('.' + modalDialogContainerClass).length < 1) {
			var dialogTemplate = '<div class="{0}"></div>';
			var dialogInnerTemplate = '<div class="{0}"><img src="{1}" /></div>';
			
			// Wrap content with container then setup styles
			$(opts.content).wrap($.format(dialogTemplate, modalDialogContainerClass));
			if(dialogClosable && $(opts.content).children('.' + dialogCloseButtonClass).length < 1) {
				$(opts.content).append($.format(dialogInnerTemplate, 
					dialogCloseButtonClass,
					$VG.staticVGUrl + 'web_app/vg/images/series/icons/stClose.png'));
			}
			dialogInstance = $(opts.content).parent('.' + modalDialogContainerClass);
			
			// Move to body
			dialogCount++; // Increase the id for dialogs
			dialogId = dialogIdPrefix + dialogCount;
			dialogInstance.attr('id', dialogId);
			dialogInstance.appendTo($('body'));
			// Setup close dialog button
			if(dialogClosable) {
				$(opts.content).find('.' + dialogCloseButtonClass).click(function() {
					// find dialog instance on run-time
					var currentDialogInstance = $(this).parents('.' + modalDialogContainerClass).length < 1 ? $(this).parent() : $(this).parents('.' + modalDialogContainerClass);
					$VG.UI.closeDialog(currentDialogInstance);
					// trigger custom event to observer
					$(currentDialogInstance).trigger('onDialogClosed');
					$('.vgModalContainer').hide();
				});
			}
			
			// If buttons is set, setup close dialog here too
			if((typeof(opts.closeButtons) != 'undefined') && (opts.closeButtons.length > 0)) {
				$.each(opts.closeButtons, function(i, button) {
					var buttonOnClick = (button.onlick) ? button.onclick : function(){ };
					button.click(function() {
						buttonOnClick();
						// find dialog instance on run-time
						var currentDialogInstance = $(this).parents('.' + modalDialogContainerClass).length < 1 ? $(this).parents('.dialog-content') : $(this).parents('.' + modalDialogContainerClass);
						$VG.UI.closeDialog(currentDialogInstance);
						// trigger custom event to observer
						$(currentDialogInstance).trigger('onDialogClosed');
						$('.vgModalContainer').hide();
					});
				});
			}
		}
		
		// Modal or NonModal
		if(isModalDialog) {
			dialogInstance = $(opts.content).parent('.' + modalDialogContainerClass);
			// Setup overlay for modal dialog
			$(dialogInstance).css({
				 'display': 'none'
			});
		} else {
			// Non modal dialog not need container, remove it.	
			$(opts.content).unwrap();
			$(opts.content).css({
				'z-index' : 103
			});
			dialogInstance = $(opts.content);
			
			// However if it has parent, need to relocate DOM to that parent for the sake of positioning
			if(dialogParent != null) {
				$(opts.content).appendTo($(dialogParent));
				
				// Find most z-index value from parent and increment by 1 to lay dialog on top of parent
				var mostZIndexValue = $VG.UI.findMostZIndexValueSince(dialogParent);
				if(mostZIndexValue > 0) {
					mostZIndexValue += 1;
				} else {
					mostZIndexValue = 103; // magic number
				}
				$(opts.content).css({
					'z-index' : mostZIndexValue
				});
			} 
		}
		// Centered on element?
		if(dialogPosition != null) {		
			// Centered on parent element
			var initX, initY;
			if(typeof(opts.position.left) != 'undefined') {
				initX = opts.position.left
			} else {
				initX = ($(dialogParent).width() - $(opts.content).outerWidth()) * 0.5;
			}
			if(typeof(opts.position.top) != 'undefined') {
				initY = opts.position.top
			} else {
				initY = ($(dialogParent).height() - $(opts.content).outerHeight()) * 0.5;
			}
			$(opts.content).css({
				'left' : initX,
				'top' : initY,
				'position' : 'absolute'
			});
		} else {
			// Centered content fixed
			$(opts.content).center();
		}
		// Movable?
		if(dialogMovable) {
			$(opts.content).draggable({ cursor: 'move', opacity: 0.7 });
		}
		
		// Display,  if it is set to display:none, show it now
		$(opts.content).show();
		dialogInstance.fadeIn('fast');
		$('.' + modalDialogContainerClass).css({'z-index' : 9999999}); // DBR-318
		return dialogInstance;
	}, 
	
	/**
	 * Close dialog 
	 *
	 * @params dialogInstance : instance given from $VG.UI.openDialog
	 */
	closeDialog: function(dialogInstance) {
		if(dialogInstance != null) {
			$(dialogInstance).fadeOut('fast', function() {
 				$(this).hide();
			});
		}
		
		$('.vgModalContainer').hide();
	}, 
	
	findMostZIndexValueSince: function(parentElem) {
		var mostZIndexValue = ($(parentElem).css('z-index') > 0) ? $(parentElem).css('z-index')  : 0;
		// Find only 1 level, not recursive for performance
		$(parentElem).children().each(function() { 
			var currentZIndexValue = isNaN(parseInt($(this).css('z-index'))) ? 0 : parseInt($(this).css('z-index'));
			if(currentZIndexValue > mostZIndexValue) { 
				mostZIndexValue = currentZIndexValue;
			}
		});
		return mostZIndexValue;
	},

	confirmDialog : function(options) {
		/*
		   Lasciate ogne speranza, voi ch'entrate.
		   Qui si convien lasciare ogne sospetto;
		   ogne vilt convien che qui sia morta.
		*/
		
    	var hardcodedDialogContent = $('\
					<div class="dialog-content" id="confirm-dialog-content" style="left: 639px; top: 381px; position: absolute; z-index: 9999999999999; display: block;">\
						<p>' + options.message + '</p>\
						\
						<div class="dialog-actions" style="margin-left: 14px">\
							<div style="float: left; cursor: pointer;" class="black-action-btn" id="btn-time-cancel">\
								<span class="action-button-font">' + options.buttons.no + ' </span>\
							</div>\
							<div style="float: left; cursor: pointer;" class="black-action-btn-red" id="btn-time-accept">\
								<span class="action-button-font">' + options.buttons.yes + '</span>\
							</div>\
							<div class="clear"></div>\
						</div>\
					</div>');
					
		function closeConfirmationDialog() {
			(hardcodedDialogContent);
			/*hardcodedDialogContent.fadeOut('fast');
			$('.vgModalContainer').hide();*/
			//DBR-493
			options.callbacks.declined.call(); 
			$VG.UI.closeDialog($(this).closest('.vgModalContainer'));
		};
		
		hardcodedDialogContent.find('#btn-time-cancel').click(function() { options.callbacks.declined.call(); $VG.UI.closeDialog($(this).closest('.vgModalContainer')); } );
		hardcodedDialogContent.find('#btn-time-accept').click(function() { options.callbacks.confirmed.call(); $VG.UI.closeDialog($(this).closest('.vgModalContainer')); } );
		
		var dialog = $VG.UI.openDialog({content:hardcodedDialogContent});
		$('.vgModalContainer').hide();
		$(dialog).css({'z-index':'99999'}).fadeIn('fast');
		
	},
	
	promptDialog : function(options) {
		/*
		   Lasciate ogne speranza, voi ch'entrate.
		   Qui si convien lasciare ogne sospetto;
		   ogne vilt convien che qui sia morta.
		*/
		
		var optionsHtml = '<div id="dialog-options" style="margin-top: -19px; padding-left: 15px; text-align: left;">';
		for(o in options.options) {
			optionsHtml = optionsHtml + '<br /><label><input type="radio" name="response" value="' + options.options[o] + '" />' + options.options[o] + ' </label>'; 
		}
		
		optionsHtml = optionsHtml + '</div>';
		
    	var hardcodedDialogContent = $('\
					<div class="dialog-content" id="confirm-dialog-content" style="left: 639px; top: 381px; position: absolute; z-index: 9999999999999; display: block;">\
						<p style="text-align: left;">' + options.message + '</p> ' + optionsHtml + '\
						\
						<div class="dialog-actions" style="margin-left: 14px">\
							<div style="margin-top: 5px; margin-left: 125px; cursor: pointer;" class="black-action-btn-red" id="btn-time-accept">\
								<span class="action-button-font">' + options.buttons.ok + '</span>\
							</div>\
							<div class="clear"></div>\
						</div>\
					</div>');
					
		function closeConfirmationDialog() { 
			hardcodedDialogContent.fadeOut('fast');
			$('.vgModalContainer').hide();
		};
		
		hardcodedDialogContent.find('#btn-time-cancel').click(function() { options.cancel.call(); closeConfirmationDialog(); } );
		hardcodedDialogContent.find('#btn-time-accept').click(function() {			
			options.callbacks.ok($('#dialog-options input:checked[type=radio]').val());
			closeConfirmationDialog(); 
		});
		
		var dialogInstance = $VG.UI.openDialog({content:hardcodedDialogContent, closable: false});
		$('.vgModalContainer').css({'z-index':'99999'}).fadeIn('fast');
		
	}
};

VirginGamingSite.HTTP = {
    getPage : function() {
	    var pathPieces = window.location.pathname.split('/');
	    var pn = pathPieces[pathPieces.length - 1];
	    return pn.substring(0, pn.length - 3);
    },
	getUrlVars : function() {
	    var vars = [], hash;
	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	    for(var i = 0; i < hashes.length; i++)
	    {
	        hash = hashes[i].split('=');
	        vars.push(hash[0]);
	        vars[hash[0]] = hash[1];
	    }
	    return vars;
	}
};

VirginGamingSite.survey = {
	// event surveys
	trigger : function(e) {
		if ($VG.HTTP && $VG.HTTP.surveyJSON && $VG.HTTP.surveyJSON.event[e]) {
		    _kiq.push(['showSurvey', $VG.HTTP.surveyJSON.event[e]]);
		}
    },
    // page surveys
    show : function() {
		if ($VG.HTTP && $VG.HTTP.surveyJSON && $VG.HTTP.surveyJSON.page[$VG.HTTP.getPage()]) {
		    _kiq.push(['showSurvey', $VG.HTTP.surveyJSON.page[$VG.HTTP.getPage()]]);
		}
    }
};

/*Snippet from http://snipplr.com/view/26662/get-url-parameters-with-jquery--improved*/
$.urlParam = function(name) {
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	if (!results) { 
		return 0; 
	}
	return results[1] || 0;
};

$('document').ready(function() {
	var oly = '<div class="mini-overlay"><div class="spacer"></div><div class="visit-profile-button"><div>Visit</div><div>Profile</div></div></div>';
	
	// mini-profiles
	$('.widget-mini-profile, .widget-mini-team-profile').live('mouseenter', function() {
		var $$ = $(this);
		var obj = $$.attr('formObject');
		var next = $$.next();
		
		// reset any 'stuck' widgets (happens when you move around really quick)
		$('.mini-overlay').trigger('resetwidget');
		
		if (!next.hasClass('mini-overlay')) {
			$$.wrap('<div class="widget-mini-overlay-container"></div>');
			$$.after(oly);
			next = $$.next();
			var p = $$.css('position');
			var w = $$.attr('widthSelector') != null ? $$.find($$.attr('widthSelector')).width() : $$.width();
			var h = $$.attr('heightSelector') != null ? $$.find($$.attr('heightSelector')).height() : $$.height();
			var c = $$.attr('widgetClass');
			
			if (c != null) {
				next.addClass(c);
			}
			
			if (p === 'absolute') {
				next.css('position', p).css('top', $$.css('top')).css('left', $$.css('left')).css('bottom', $$.css('bottom')).css('right', $$.css('right'));
			}

			next.css('width', w).css('height', h).bind('resetwidget', function() {
				var prev = $(this).prev();
				$(this).remove();
				prev.stop(true, true);
				$(this).stop(true, true);
				prev.show();
				prev.unwrap();
		    }).bind('mouseleave', function() {
                $(this).trigger('resetwidget');
		    });
			
			$('.visit-profile-button', next).bind('click', function() {
				document.location = ($$.hasClass('widget-mini-profile') ? 'displayPlayerHome' : 'displayViewTeam') + '.do?formObjectId=' + obj;
			});
			
			$$.fadeOut('fast', function() {next.show();});
		} 
	});
	
	// clickable names and avatars
	$('.widget-player-info, .widget-team-info').live('click', function() {
		var obj = $(this).attr('formObject');

		if (obj == null) {
			$(this).removeClass('widget-player-info');			
		} else {
			document.location = ($(this).hasClass('widget-player-info') ? 'displayPlayerHome' : 'displayViewTeam') + '.do?formObjectId=' + obj;
		}
	});
});

//Sponsorship related functionality
$VG.Sponsor = {
	//gets skinnable data if there is any 
    changeGameSkin : function(gid, path) {
		//reset any pre-existing bindings, to avoid async callbacks messing 
		//  the process.
		$('html').unbind('click');
    	var paramsGetSkin = {
			url : 'sponsorshipDetails.do?gameId=' + gid + '&sponsorPath=' + path,
			type: 'GET',
			dataType : 'json',
			cache : false,
			success : function (jsonData) {
				//when we have sposorship skin set the targeted elements
        		if(jsonData.bckg != null) {
        			//we have the bckg image, set it
        			$('body').css({'background': 'url("' + jsonData.bckg +'") no-repeat scroll center top ' + jsonData.color,
        				           'cursor': 'default'});
        			//IF there is a gotourl for the sponsor, bind the click
        			//  and show the appropriate cursor
        			if(jsonData.gotourl != null && jsonData.gotourl !== '') {
        				$('html').css('cursor', 'pointer');
        				//binding the background to a click
						$('html').click(function (e) {
							
							//get the width of the content
							var page_width = $('div#doc').width();
							//if some error occured, just return
							if (page_width == null) { return; }
							
							//get mouse coordinates
							var x_pos = e.pageX;
							var y_pos = e.pageY;
							//get the document's width
							var doc_width = $(document).width();								
							
							//get the left range of a valid mouse click
							var min_w = (doc_width - 960) / 2;
							//get the right range of a valid mouse click
							var max_w = min_w + 960 + 1;
							//if the click was on the left or right of content
							if(x_pos < min_w || x_pos > max_w) {
								//and the click was at hte right height
								if(y_pos > 56) {
									//redirect to the sponsor's url
									window.open('' + jsonData.gotourl);
								}
							}
						});//end binding the background to click
					} // endif "if(jsonData.gotourl != null && jsonData.gotourl !== '')"
					
        		} else {
        			//reset
        			$('html').unbind('click');
        			$('html').css('cursor', 'default');
        			$('body').css('background', '');
        			//after reset, get old style
        			//this is tightly-coupled now to the dashboardWidgets,
        			//  which is also a file that gets included everywhere(why?)
        			if(gid != null && gid > 0) {
	        			var fn = $VG.dashboardWidgets.gameListWidget.staticUrl + '/web_app/vg/css/skin/userhome/' + gid + '.css';
		                var e = document.createElement('link');
		                e.setAttribute('rel', 'stylesheet');
		                e.setAttribute('type', 'text/css');
		                e.setAttribute('href', fn);
		                e.setAttribute('game', gid);
		                $('link[game]').remove();
		                $('head')[0].appendChild(e);
		            }
        		}
			},
			error : function(request, status, error) {
				//error flow for non 200 response
			}
		}
		$.ajax(paramsGetSkin);
    }
};

/*!
 * Copyright (c) 2009 Joe Mastey
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
(function($){$.fn.easter=function(fn,params){params=$.extend({},$.fn.easter.params,params);this.each(function(){var tgt=$(this);tgt.bind('easter',fn).bind('keyup',function(event){$.fn.easter.checkCode(event,params,tgt);});});return this;};$.fn.easter.params={'code':[38,38,40,40,37,39,37,39,66,65],'step':0};$.fn.easter.checkCode=function(event,params,tgt){if(event.keyCode==params.code[params.step]){params.step++;}else{params.step=0;}
if(params.step==params.code.length){tgt.trigger('easter');params.step=0;}};})(jQuery);$(document).easter(function(){try{var st=$('script[src*="site.js"]').attr('src');$vgeaster={burl:st.substring(0,st.indexOf('site.js'))+'widgets/misc/'}
var s=document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.src=$vgeaster.burl+'asteroids.min.js';}catch(e){}});
