// 2.0 Static invite-core-production.js
/*************
** GLOBAL VARS
**************/
var InviteBrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
InviteBrowserDetect.init();
//all we really care about is trapping for ie.
var inviteIE = false;
var inviteIE6 = false;
if(InviteBrowserDetect.browser == "Explorer") {
	inviteIE = true;
	if(InviteBrowserDetect.version == "6") {
		inviteIE6 = true;
	}
}

var inviteAddedToOnloadInIE = false; //track whether we've added the onload in ie.
var inviteModalInDom = false; //track whether we've written the modal or not.
// holds a reference to all the inviteButton objects on the page.
var inviteButtons = new Array();
var inviteAutoLaunch = ( document.location.href.indexOf("invite-launch=true") > 0 );
var inviteCacheBust = "&noCache=" + (new Date()).getTime();

/*************
** MISC FUNCTIONS
**************/
function i_addLoadEvent(func) { 
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
    window.onload = func; 
  } else { 
    window.onload = function() { 
      if (oldonload) { 
        oldonload(); 
      } 
      func(); 
    } 
  } 
}
function i_addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}
function i_removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
} 
function i_getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function i_getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}
function i_getScrollTop() {
	if (self.pageYOffset) { // all except Explorer
		return self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
		return document.documentElement.scrollTop;
	} else if (document.body) { // all other Explorers 
		return document.body.scrollTop;
	}
}
function i_getScrollLeft() {
	if (self.pageXOffset) { // all except Explorer
		return self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollLeft) { // Explorer 6 Strict
		return document.documentElement.scrollLeft;
	} else if (document.body) { // all other Explorers
		return document.body.scrollLeft;
	}
}
//a click on a widget calls this function.
function loadInviteInModal(which) {
	if(!which) which = 0;
	if(which < inviteButtons.length) {
		inviteButtons[which].loadInviteInModal();
	}
}
function i_hideFlash() {
	if(InviteBrowserDetect.OS=="Windows") {
		return true;
	}
	if(InviteBrowserDetect.browser == "Firefox" && InviteBrowserDetect.version < 3) {
		return true;
	}
	return false;
}
/************
** INVITE MODAL OBJECT
*************/

function InviteModal(modalOptions) {
		
	this.width = this.DEFAULT_WIDTH = 400;
	this.height = this.DEFAULT_HEIGHT = 470;
	this.defaultPage = this.DEFAULT_PAGE = "http://widget.iggli.com/widgets/invite-loading.2.0.iggli";
	this.altText = this.DEFAULT_ALT_TEXT = "Invite friends, RSVP, coordinate tickets, share your experience";
	this.modalOptions = modalOptions || {};
	if(modalOptions) {
			this.width=typeof modalOptions.width=='string'?modalOptions.width:'';
			this.height=typeof modalOptions.height=='string'?modalOptions.height:'';
			this.defaultPage=typeof modalOptions.defaultPage=='string'?modalOptions.defaultPage:'';
			this.altText=typeof modalOptions.altText=='string'?modalOptions.altText:'';
	}	

	this.modalMask = null;
	this.modalContainer = null;//this DOM object also has a reference to this
	this.modalFrame = null;
	this.returnFunc = null;
	this.modalIsShown = false;
	this.hideSelects = false;
	this.returnVal = null;
	this.currentInvite = null;
	
	this.iTabIndexes = new Array();
	// Pre-defined list of tags we want to disable/enable tabbing into
	this.iTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");
	
	//closures to keep track of, remove leaks
	this.resizeFunc = null; 
	this.scrollFunc = null; 
	
	// remember and restore these
	this.restoreKeyPress = null;
	this.restoreOnScroll = null;
	
	this.open = function(invite) {
		this.hideFlash();
		
		if(!this.modalMask) { this.write(); }	//somehow, not written yet.
		this.currentInvite = invite;
		
		this.startObserveWhileModal();	
		this.modalIsShown = true;
		
		this.disableTabIndexes();
		this.modalMask.style.display = "block";
		this.modalContainer.style.display = "block";
		this.centerModal();

		var titleBarHeight = parseInt(document.getElementById("modalTitleBar").offsetHeight, 10);

		this.modalContainer.style.width = this.width + "px";
		this.modalContainer.style.height = (this.height+titleBarHeight) + "px";
		this.setModalMask();
	
		// need to set the width of the iframe to the title bar width because of the dropshadow
		// some oddness was occuring and causing the frame to poke outside the border in IE6
		this.modalFrame.style.width = parseInt(document.getElementById("modalTitleBar").offsetWidth, 10) + "px";
		this.modalFrame.style.height = (this.height) + "px";
		
		// set the url
		//var doc = this.modalFrame.contentDocument || this.modalFrame.contentWindow; // DOM || IE
		//if (doc) {
		//try to change the location without adding an entry in history.
		//	doc.location.replace(invite.DEFAULT_IFRAME_SRC+invite.fullQuery());
		//} else {
		//fail gracefully.
		this.modalFrame.src = invite.DEFAULT_IFRAME_SRC+invite.fullQuery();
		//alert(this.modalFrame.src);
		//}
		
		//WON"T NEED THIS this.returnFunc = returnFunc;
		if (this.hideSelects == true) {
			this.hideSelectBoxes();
		}

		//MIGHT NEED THIS?window.setTimeout("this.setPopTitle();", 600);
	}

	//Close the modal
	this.close = function() {
		
		if (this.currentInvite) this.currentInvite.reload();
		this.currentInvite = null;
		this.stopObserveCloseModal();
		this.modalIsShown = false;
		var theBody = document.getElementsByTagName("BODY")[0];
		theBody.style.overflow = "";
		this.restoreTabIndexes();
		if (this.modalMask == null) {
			return;
		}
		this.modalMask.style.display = "none";
		this.modalContainer.style.display = "none";
		// FUTURE - include the ability to return a value.
		if (this.returnFunc != null) {
			// Set the return code to run in a timeout.
			// Was having issues using with an Ajax.Request();
			this.returnVal = window.frames["modalFrame"].returnVal;
			window.setTimeout('this.returnFunc(this.returnVal);', 1);
		}
		this.modalFrame.src = this.defaultPage;
		// display all select boxes
		if (this.hideSelects == true) {
			this.displaySelectBoxes(); 
		}
		this.displayFlash();
	}
	
	this.setModalMask = function() {
		var theBody = document.getElementsByTagName("BODY")[0];
				
		var fullHeight = i_getViewportHeight();
		var fullWidth = i_getViewportWidth();
		
		// Determine what's bigger, scrollHeight or fullHeight / width
		if (fullHeight > theBody.scrollHeight) {
			theHeight = fullHeight;
		} else {
			theHeight = theBody.scrollHeight;
		}
		
		if (fullWidth > theBody.scrollWidth) {
			theWidth = fullWidth - 17; // 17 is scrollbar width.
		} else {
			theWidth = theBody.scrollWidth; 
		}
		
		this.modalMask.style.height = theHeight + "px";
		this.modalMask.style.width = theWidth + "px";
	}
	
	this.centerModal =	function() {
		if (this.modalIsShown == true) {
			if (this.width == null || isNaN(this.width)) {
				this.width = this.modalContainer.offsetWidth;
			}
			if (this.height == null) {
				this.height = this.modalContainer.offsetHeight;
			}
			var theBody = document.getElementsByTagName("BODY")[0];
			var scTop = parseInt(i_getScrollTop(),10);
			var scLeft = parseInt(theBody.scrollLeft,10);
		
			this.setModalMask();
			
			var titleBarHeight = parseInt(document.getElementById("modalTitleBar").offsetHeight, 10);
			
			var fullHeight = i_getViewportHeight();
			var fullWidth = i_getViewportWidth();
			
			this.modalContainer.style.top = (scTop + ((fullHeight - (this.height+titleBarHeight)) / 2)) + "px";
			this.modalContainer.style.left =  (scLeft + ((fullWidth - this.width) / 2)) + "px";
		}
	}
	
	this.write = function() {
		theBody = document.getElementsByTagName('BODY')[0];
		
		theMask = document.createElement('div');
		theMask.id = 'modalMask';
		theMask.style.position="absolute";
		theMask.style.zIndex="200";
		theMask.style.top="0px";
		theMask.style.left="0px";
		theMask.style.width="100%";
		theMask.style.height="100%";
		theMask.style.opacity=".4";
		theMask.style.filter="alpha(opacity=40)";
		//theMask.style.backgroundColor="transparent !important";
		//theMask.style.backgroundColor="transparent";
		theMask.style.backgroundColor="#333333";
		theMask.style.display="none";
		theContainer = document.createElement('div');
		theContainer.id = 'modalContainer';
		theContainer.style.position="absolute";
		theContainer.style.zIndex="201";
		theContainer.style.top="0px";
		theContainer.style.left="0px";
		theContainer.style.width=this.width+"px";
		theContainer.style.height=this.height+"px";
		theContainer.style.padding="0px";
		theContainer.style.display="none";
		var pngOrGif = "png";
		if (inviteIE6) pngOrGif = "gif";//ie6
		theContainer.innerHTML = '' +
			'<div id="modalInner" style="background: url(http://widget.iggli.com/images/litevite/litevite-bg.' + pngOrGif + ') top center no-repeat;width:100%;height:100%;">' +
				'<div id="modalTitleBar" style="position:relative; z-index:203; width:100%;">' +
					'<div id="modalControls" style="cursor:pointer; cursor:hand; position:relative; text-align:left;">' +
						'<img src="http://widget.iggli.com/images/litevite/close.gif" onclick="inviteModal.close();" id="modalCloseBox" style="position:absolute; top:8px; left:378px;" />' +
					'</div>' +
				'</div>' +
				'<div id="modalContent" style="width:100%;height:100%;">' +
					'<iframe src="'+ this.defaultPage +'" style="margin:0px;width:100%;height:100%;background-color:transparent;position:relative;z-index:202;" scrolling="auto" frameborder="0" allowtransparency="true" id="modalFrame" name="modalFrame" width="100%" height="100%"></iframe>' +
				'</div>' +
			'</div>';
			
		//add a reference to this javascript object.
		theContainer.inviteModal = this;
		
		theBody.appendChild(theMask);
		theBody.appendChild(theContainer);
		
		this.modalMask = document.getElementById("modalMask");
		this.modalContainer = document.getElementById("modalContainer");
		this.modalFrame = document.getElementById("modalFrame");	
		
		// check to see if this is IE. hide select boxes if so
		if (inviteIE) {
			this.hideSelects = true;
		}
	}
	
	//Observe the modal
	this.startObserveWhileModal = function() {		
		var resize = function() { 
			document.getElementById("modalContainer").inviteModal.centerModal();
		}
		this.resizeFunc = this.scrollFunc = resize;
		i_addEvent(window, "resize", resize );
		i_addEvent(window, "scroll", resize );
		if(typeof window.onscroll == "function") {
			this.restoreOnScroll = window.onscroll;
		}
		window.onscroll = resize;
		//store the original reference so we can replace it.
		if(typeof document.onkeypress == "function") {
				this.restoreKeyPress = document.onkeypress;
		}
		document.onkeypress = this.keyDownHandler; 
		
	}
	
	//Stop observing the modal
	this.stopObserveCloseModal = function() {
		i_removeEvent(window, "resize", this.resizeFunc );
		this.resizeFunc = null;
		i_removeEvent(window, "scroll", this.scrollFunc );
		this.scrollFunc = null;
		//restore the original reference
		if(typeof this.restoreOnScroll == "function") {
			window.onscroll = this.restoreOnScroll;
			this.restoreOnScroll = null;
		} else {
			window.onscroll = null;
		}
		//restore the original reference
		if(typeof this.restoreKeyPress == "function") {
				document.onkeypress = this.restoreKeyPress;
				this.restoreKeyPress = null; 
		} else {
			document.onkeypress = null;
		}
	}
	
	// Tab key trap. iff popup is shown and key was [TAB], suppress it.
	// @argument e - event - keyboard event that caused this function to be called.
	this.keyDownHandler = function(e) {
	    if (this.modalIsShown && e.keyCode == 9) { return false; }
	}
	
	// For IE.  Go through predefined tags and disable tabbing into them.
	this.disableTabIndexes = function() {
		if (document.all) {
			var i = 0;
			for (var j = 0; j < this.iTabbableTags.length; j++) {
				var tagElements = document.getElementsByTagName(this.iTabbableTags[j]);
				for (var k = 0 ; k < tagElements.length; k++) {
					this.iTabIndexes[i] = tagElements[k].tabIndex;
					tagElements[k].tabIndex="-1";
					i++;
				}
			}
		}
	}
	
	// For IE. Restore tab-indexes.
	this.restoreTabIndexes = function() {
		if (document.all) {
			var i = 0;
			for (var j = 0; j < this.iTabbableTags.length; j++) {
				var tagElements = document.getElementsByTagName(this.iTabbableTags[j]);
				for (var k = 0 ; k < tagElements.length; k++) {
					tagElements[k].tabIndex = this.iTabIndexes[i];
					tagElements[k].tabEnabled = true;
					i++;
				}
			}
		}
	}
	
	this.hideSelectBoxes = function() {
	  var x = document.getElementsByTagName("SELECT");
	  for (i=0;x && i < x.length; i++) {
	    x[i].style.visibility = "hidden";
	  }
	}

	this.displaySelectBoxes = function() {
	  var x = document.getElementsByTagName("SELECT");
	  for (i=0;x && i < x.length; i++){
	    x[i].style.visibility = "visible";
	  }
	}
	
	this.hideFlash = function() {
		if(i_hideFlash()) {
			var o, e;
			o = document.getElementsByTagName("OBJECT");
			e = document.getElementsByTagName("EMBED");
			for (i=0;i < o.length; i++) {
				o[i].style.visibility = "hidden";
			}
			for (i=0;i < e.length; i++) {
				e[i].style.visibility = "hidden";
			}	
		}
	}
	
	this.displayFlash = function() {
		if(i_hideFlash()) {
			var o = e = new Array();
			o = document.getElementsByTagName("OBJECT");
			e = document.getElementsByTagName("EMBED");
			for (i=0;i < o.length; i++) {
				o[i].style.visibility = "visible";
			}
			for (i=0;i < e.length; i++) {
				e[i].style.visibility = "visible";
			}	
		}
	}
	
	// need a better implementation here.
	this.toString = function() {
		var properties = "";
		for (var propertyName in this) {
			// Check if it's NOT a function
			if (!(this[propertyName] instanceof Function)) {
				properties += propertyName + ", ";
			}
		}
		if(properties.length > 100) properties = properties.substring(0, 100) + "...";
		return "Properties : " + properties;
	}

}

/***************
** INVITE BUTTON OBJECT
***************/
//InviteButton default properties

function InviteButton(inviteModal, inviteOptions) {
	this.buttonNumber = inviteButtons.length;
	this.container = null;
	this.element = null;
	//this.badge = null;
	this.invite = this;
	//alert( inviteModal + " - " + inviteOptions);
	this.modal = inviteModal;
	this.inviteOptions = inviteOptions || {};
	this.skin = this.DEFAULT_SKIN = "button_large";
	this.DEFAULT_IMAGE_SRC = "http://widget.iggli.com/widgets/invite-widget-image.2.0.iggli?";
	//this.DEFAULT_BADGE_SRC = "http://widget.iggli.com/widgets/invite-badge-image.2.0.iggli?";
	this.DEFAULT_IFRAME_SRC = "http://iggli.com/litevite-modal-start.iggli?";
	this.FORWARD_IFRAME_SRC = "http://iggli.com/litevite-modal.iggli?";
	this.DEFAULT_ALT_TEXT = "Invite Friends";
	//try to get a meaningful eventUrl if one not passed in.
	this.setDefaultEventUrl = function() {
		//let's try to set eventUrl to ticketUrl if eventUrl is null
	    if ( (!this.eventUrl || this.eventUrl.length == 0) && this.ticketUrl && this.ticketUrl.length > 0) {
	    	this.eventUrl = this.ticketUrl;
	    }
	    if ( !this.eventUrl ) {
	    	this.eventUrl = this.url;//set it to the page url.
	    }
	}
	//the initial options
	if(inviteOptions) {
		this.version=typeof inviteOptions.version=='string'?inviteOptions.version:'';
		this.inviteId=typeof inviteOptions.inviteId=='string'?inviteOptions.inviteId:'';
		this.partnerId=typeof inviteOptions.partnerId=='string'?inviteOptions.partnerId:'';
		this.url=window.location.href;
	    this.title=typeof inviteOptions.title=='string'?inviteOptions.title:'';
	    this.location=typeof inviteOptions.location=='string'?inviteOptions.location:''; 
	    this.date=typeof inviteOptions.date=='string'?inviteOptions.date:'';
	    this.eventUrl=typeof inviteOptions.eventUrl=='string'?inviteOptions.eventUrl:''; 
	    this.artist=typeof inviteOptions.artist=='string'?inviteOptions.artist:'';
	    this.venue=typeof inviteOptions.venue=='string'?inviteOptions.venue:'';
	    this.venueUrl=typeof inviteOptions.venueUrl=='string'?inviteOptions.venueUrl:'';
	    this.timeStart=typeof inviteOptions.timeStart=='string'?inviteOptions.timeStart:'';
	    this.timeEnd=typeof inviteOptions.timeEnd=='string'?inviteOptions.timeEnd:'';
	    this.timeShow=typeof inviteOptions.timeShow=='string'?inviteOptions.timeShow:'';
	    this.timeDoors=typeof inviteOptions.timeDoors=='string'?inviteOptions.timeDoors:'';
	    this.imageUrl=typeof inviteOptions.imageUrl=='string'?inviteOptions.imageUrl:'';
	    this.seating=typeof inviteOptions.seating=='string'?inviteOptions.seating:'';
	    this.audience=typeof inviteOptions.audience=='string'?inviteOptions.audience:'';
	    this.ticketsRequired=typeof inviteOptions.ticketsRequired=='string'?inviteOptions.ticketsRequired:'';
	    this.ticketUrl=typeof inviteOptions.ticketUrl=='string'?inviteOptions.ticketUrl:'';
	    this.ticketsGeneral=typeof inviteOptions.ticketsGeneral=='string'?inviteOptions.ticketsGeneral:'';
	    this.ticketsReserved=typeof inviteOptions.ticketsReserved=='string'?inviteOptions.ticketsReserved:'';
	    this.minPrice=typeof inviteOptions.minPrice=='string'?inviteOptions.minPrice:'';
	    this.maxPrice=typeof inviteOptions.maxPrice=='string'?inviteOptions.maxPrice:'';
	    this.presaleDate=typeof inviteOptions.presaleDate=='string'?inviteOptions.presaleDate:'';
	    this.presaleCode=typeof inviteOptions.presaleCode=='string'?inviteOptions.presaleCode:'';
	    this.onsaleDate=typeof inviteOptions.onsaleDate=='string'?inviteOptions.onsaleDate:'';
	    this.ticketAvailability=typeof inviteOptions.ticketAvailability=='string'?inviteOptions.ticketAvailability:'';
	    this.audioUrl=typeof inviteOptions.audioUrl=='string'?inviteOptions.audioUrl:'';
	    this.skin=typeof inviteOptions.skin=='string'?inviteOptions.skin:this.DEFAULT_SKIN;
	    this.setDefaultEventUrl();
	}
	//called externally to set any values after init.
	this.setOptions = function(inviteOptions) {
		if(inviteOptions) {
			//we support both camel case and underscore versions of the options.
			this.version=inviteOptions.widgetVersion||this.version;
			 this.version=inviteOptions.widget_version||this.version;
			this.inviteId=inviteOptions.inviteId||this.inviteId;
			 this.inviteId=inviteOptions.invite_id||this.inviteId;
			this.partnerId=inviteOptions.partnerId||this.partnerId;
			 this.partnerId=inviteOptions.partner_id||this.partnerId;
			this.url=inviteOptions.url||this.url;
		    this.title=inviteOptions.title||this.title;
		    this.location=inviteOptions.location||this.location;
		    this.date=inviteOptions.date||this.date;
		    this.eventUrl=inviteOptions.eventUrl||this.eventUrl;
		     this.eventUrl=inviteOptions.event_url||this.eventUrl;
		    this.artist=inviteOptions.artist||this.artist;
		    this.venue=inviteOptions.venue||this.venue;
		    this.venueUrl=inviteOptions.venueUrl||this.venueUrl;
		     this.venueUrl=inviteOptions.venue_url||this.venueUrl;
		    this.timeStart=inviteOptions.startTime||this.timeStart;
		     this.timeStart=inviteOptions.start_time||this.timeStart;
		    this.timeEnd=inviteOptions.endTime||this.timeEnd;
		     this.timeEnd=inviteOptions.end_time||this.timeEnd;
		    this.timeShow=inviteOptions.showTime||this.timeShow;
		     this.timeShow=inviteOptions.show_time||this.timeShow;
		    this.timeDoors=inviteOptions.doorTime||this.timeDoors;
		     this.timeDoors=inviteOptions.door_time||this.timeDoors;
		    this.imageUrl=inviteOptions.imageUrl||this.imageUrl;
		     this.imageUrl=inviteOptions.image_url||this.imageUrl;
		    this.seating=inviteOptions.seating||this.seating;
		    this.audience=inviteOptions.audience||this.audience;
		    this.ticketsRequired=inviteOptions.ticketsRequired||this.ticketsRequired;
		     this.ticketsRequired=inviteOptions.tickets_required||this.ticketsRequired;
		    this.ticketUrl=inviteOptions.ticketUrl||this.ticketUrl;
		     this.ticketUrl=inviteOptions.ticketsUrl||this.ticketUrl;
		      this.ticketUrl=inviteOptions.tickets_url||this.ticketUrl;
		    this.ticketsGeneral=inviteOptions.ticketsGeneralAdmission||this.ticketsGeneral;
		     this.ticketsGeneral=inviteOptions.tickets_general_admission||this.ticketsGeneral;
		    this.ticketsReserved=inviteOptions.ticketsReserved||this.ticketsReserved;
		     this.ticketsReserved=inviteOptions.tickets_reserved||this.ticketsReserved;
		    this.minPrice=inviteOptions.ticketsMinPrice||this.minPrice;
		     this.minPrice=inviteOptions.tickets_min_price||this.minPrice;
		    this.maxPrice=inviteOptions.ticketsMaxPrice||this.maxPrice;
		     this.maxPrice=inviteOptions.tickets_max_price||this.maxPrice;
		    this.presaleDate=inviteOptions.ticketsPresaleDate||this.presaleDate;
		    this.presaleDate=inviteOptions.tickets_presale_date||this.presaleDate;
		    this.presaleCode=inviteOptions.ticketsPresaleCode||this.presaleCode;
		     this.presaleCode=inviteOptions.tickets_presale_code||this.presaleCode;
		    this.onsaleDate=inviteOptions.ticketsOnsaleDate||this.onsaleDate;
		     this.onsaleDate=inviteOptions.tickets_onsale_date||this.onsaleDate;
		    this.ticketAvailability=inviteOptions.ticketsAvailability||this.ticketAvailability;
		     this.ticketAvailability=inviteOptions.tickets_availability||this.ticketAvailability;
		    this.audioUrl=inviteOptions.audioSampleUrl||this.audioUrl;
		     this.audioUrl=inviteOptions.audio_sample_url||this.audioUrl;
		    this.skin=inviteOptions.widgetSkin||this.skin;
		     this.skin=inviteOptions.widget_skin||this.skin;
		    this.setSize();
		    this.setDefaultEventUrl();
		}
	}
    this.type='litevite';
    this.rotate=0;//we don't rotate in the static js file.
    //need to add logic here for sizes.
	this.h=48;
	this.w=120;
	this.setSize = function() {
		if(this.skin=='chiclet'){this.h=16;this.w=16;}
		else if(this.skin=='button_large'){this.h=48;this.w=120;}
		else if(this.skin=='button_medium'){this.h=36;this.w=80;}
		else if(this.skin=='button_small'){this.h=24;this.w=40;}
		else if(this.skin=='button_square'){this.h=48;this.w=51;}
		else if(this.skin=='button_square_large'){this.h=48;this.w=48;}
		else if(this.skin=='button_square_medium'){this.h=36;this.w=36;}
		else if(this.skin=='button_square_small'){this.h=24;this.w=24;}
		else {this.skin=='button_large';this.h=48;this.w=120;}
	}
	this.setSize();
	this.maxLength = (window.navigator.userAgent.indexOf("MSIE") > -1)?2000:10000; //should use InviteBrowserDetect here.
	this.imageQueryCache = null;
	this.miscQueryCache = null;
	if(this.inviteId)this.DEFAULT_IFRAME_SRC = this.FORWARD_IFRAME_SRC; //this is a forward...different url.
	
	//CLASS FUNCTIONS
	this.loadInviteInModal = function() {
		this.modal.open(this);
	}
	
	this.imageQuery = function() {
		//if(this.imageQueryCache) {
		//	return this.imageQueryCache;
		//} else {
			var str = "version="+this.version+
			"&type="+this.type+
			"&skin="+this.skin+
			"&skinFile=invite-button-120x48.png";
			if(this.inviteId && str.length < this.maxLength) str+="&inviteId="+this.inviteId;
			if(this.rotate && str.length < this.maxLength) str+="&rotate="+this.rotate;
			if(this.partnerId && str.length < this.maxLength) str+="&p="+this.partnerId;
			if(this.title && str.length < this.maxLength) str+="&title="+encodeURIComponent(this.title).replace(/\+/g,'%2b');
			if(this.location && str.length < this.maxLength) str+="&location="+escape(this.location).replace(/\+/g,'%2b');
			if(this.date && str.length < this.maxLength) str+="&date="+escape(this.date);
			if(this.venue && str.length < this.maxLength) str+="&venue="+encodeURIComponent(this.venue).replace(/\+/g,'%2b');
			if(this.eventUrl && str.length < this.maxLength) str+="&eventUrl="+escape(this.eventUrl).replace(/\+/g,'%2b');
			if(this.ticketUrl && str.length < this.maxLength) str+="&ticketUrl="+escape(this.ticketUrl).replace(/\+/g,'%2b');
			if(this.artist && str.length < this.maxLength) str+="&artist="+encodeURIComponent(this.artist).replace(/\+/g,'%2b');
			if(this.url && str.length < this.maxLength) str+="&url="+escape(this.url).replace(/\+/g,'%2b');
			this.imageQueryCache = str;
			return str;
		//}
	}
	
	this.miscQuery = function() {
		//if(this.miscQueryCache) {
		//	return this.miscQueryCache;
		//} else {
			var str = "";
			var len = this.imageQuery().length;
			if(this.timeStart && ((str.length + len) < this.maxLength)) str+="&timeStart="+escape(this.timeStart);
	        if(this.timeShow && ((str.length + len) < this.maxLength)) str+="&timeShow="+escape(this.timeShow);
	        if(this.timeDoors && ((str.length + len) < this.maxLength)) str+="&timeDoors="+escape(this.timeDoors);
	        if(this.timeEnd && ((str.length + len) < this.maxLength)) str+="&timeEnd="+escape(this.timeEnd);
	        if(this.ticketsRequired && ((str.length + len) < this.maxLength)) str+="&ticketsRequired="+escape(this.ticketsRequired);
	        if(this.ticketsGeneral && ((str.length + len) < this.maxLength)) str+="&ticketsGeneral="+escape(this.ticketsGeneral).replace(/\+/g,'%2b');
	        if(this.ticketsReserved && ((str.length + len) < this.maxLength)) str+="&ticketsReserved="+escape(this.ticketsReserved).replace(/\+/g,'%2b');
	        if(this.imageUrl && ((str.length + len) < this.maxLength)) str+="&imageUrl="+escape(this.imageUrl).replace(/\+/g,'%2b');
	        if(this.venueUrl && ((str.length + len) < this.maxLength)) str+="&venueUrl="+escape(this.venueUrl).replace(/\+/g,'%2b');
	        if(this.presaleDate && ((str.length + len) < this.maxLength)) str+="&presaleDate="+escape(this.presaleDate).replace(/\+/g,'%2b');
	        if(this.presaleCode && ((str.length + len) < this.maxLength)) str+="&presaleCode="+escape(this.presaleCode).replace(/\+/g,'%2b');
	        if(this.onsaleDate && ((str.length + len) < this.maxLength)) str+="&onsaleDate="+escape(this.onsaleDate).replace(/\+/g,'%2b');
	        if(this.minPrice && ((str.length + len) < this.maxLength)) str+="&minPrice="+escape(this.minPrice).replace(/\+/g,'%2b');
	        if(this.maxPrice && ((str.length + len) < this.maxLength)) str+="&maxPrice="+escape(this.maxPrice).replace(/\+/g,'%2b');
	        if(this.ticketAvailability && ((str.length + len) < this.maxLength)) str+="&ticketAvailability="+escape(this.ticketAvailability).replace(/\+/g,'%2b');
			if(this.seating && ((str.length + len) < this.maxLength)) str+="&seating="+escape(this.seating).replace(/\+/g,'%2b');
			if(this.audience && ((str.length + len) < this.maxLength)) str+="&audience="+escape(this.audience).replace(/\+/g,'%2b');
			if(this.audioUrl && ((str.length + len) < this.maxLength)) str+="&audioUrl="+escape(this.audioUrl).replace(/\+/g,'%2b');
			this.miscQueryCache = str;
			return str;
		//}
	}
	
	
	this.fullQuery = function() {
		var full = this.imageQuery() + this.miscQuery();
		if( full.length > this.maxLength) {
			full = full.substring(0, full.lastIndexOf('&'));
		}
		//alert("length=" + full.length + "\n" + full.replace(/&/g,"\n"));
		return full; 
	}
	
	this.getButtonHtml = function() {
		var str = "";
		str += "<img id='litevite-"+this.buttonNumber+"' src='"+this.DEFAULT_IMAGE_SRC+this.imageQuery()+"' onclick='loadInviteInModal(" + this.buttonNumber + ");' height='"+this.h+"' width='"+this.w+"' alt='"+this.DEFAULT_ALT_TEXT+"' title='"+this.DEFAULT_ALT_TEXT+"' style='cursor:pointer;position:relative;top:0px;left:0px;' />";
		//var style="";
		//if (inviteIE6 || this.skin=="chiclet" || this.skin=="button_small" || this.skin=="button_square_small") style = "none"; //hide badge for smaller widgets
		//str += "<img id='litevite-badge-"+this.buttonNumber+"' src='"+this.DEFAULT_BADGE_SRC+"eventUrl="+ escape(this.eventUrl).replace(/\+/g,'%2b') +"' onclick='loadInviteInModal(" + this.buttonNumber + ");' height='16' width='16' alt='"+this.DEFAULT_ALT_TEXT+"' title='# of invites' style='cursor:pointer;position:absolute;top:0px;left:0px;display:" + style + "' />";
		//alert(str);
		return str;
	}
	
	//call after write/refresh to dom.
	this.registerDomElements = function() {
		//query the dom here and link the html button to the javascript object.
		this.container = this.container || document.getElementById("invite-container-" + this.buttonNumber);
		this.element = this.element || document.getElementById("litevite-" + this.buttonNumber);
		this.element.invite = this;
		//this.badge = this.badge || document.getElementById("litevite-badge-" + this.buttonNumber);
	}
	
	this.write = function() {
		var holder = "";
		holder += "<div id='invite-container-"+this.buttonNumber+"' class='invite-button' style='position:relative;'>";
		holder += this.getButtonHtml();
		holder += "</div>";
		document.write(holder);
		this.registerDomElements();
	}
	
	this.refresh = function() {
		if (!this.container) {
			this.container = document.getElementById("invite-container-" + this.buttonNumber);
		}
		if (this.container) {
			this.container.innerHTML = this.getButtonHtml();
			this.registerDomElements();
		} else {
			//error 
			throw("there is no invite in the DOM.  I can't refresh it.");
		}
	}
	
	this.reload = function() {
		//this.badge.src=this.DEFAULT_BADGE_SRC + "eventUrl=" + escape(this.eventUrl).replace(/\+/g,'%2b') + "&noCache=" + (new Date()).getTime();
	}

	// need a better implementation here.
	this.toString = function() {
		var properties = "";
		for (var propertyName in this) {
			// Check if it's NOT a function
			if (!(this[propertyName] instanceof Function)) {
				properties += propertyName + ", ";
			}
		}
		if(properties.length > 100) properties = properties.substring(0, 100) + "...";
		return "Properties : " + properties;
	}
	
}


/*************
** LOAD THE MODAL
**************/
var inviteModal = new InviteModal();
var inviteModalInDom = false;


/***************
** PRELOAD IMAGE
***************/

function invitePreload() {
	
	var i_preload = new Image();
	i_preload.src = "http://widget.iggli.com/images/litevite/litevite-bg.png";
}

invitePreload();

/**************
** ONLOAD / LAUNCH MODAL
***************/
//called onload only for ie
function inviteOnLoad() {
	if(!inviteModalInDom) {
		inviteModal.write();
		inviteModalInDom = true;
	}
}
//used in autoload case for ie.
function inviteAutoLaunchIE() {
	inviteOnLoad();
	loadInviteInModal(0);
}



