var Popup = Class.create( {
    initialize: function( params ) {
		this.settings = params;
		
		//add eventlistener for the close button
		$(this.settings.close_id).observe('click', this.hide.bind(this));
	},
	
	show: function() {
		//Calc position for the anchor div
		this._position();
		if (this.settings.widgetDisable)
			$('FlashOpaquePopupLayer').show();
		$(this.settings.popup_id).show();
		
		if (this.settings.pageDisable)
			$('full-opaque').show();
	},
	
	hide: function() {
		if (this.settings.widgetDisable)
			$('FlashOpaquePopupLayer').hide();
		
		if (this.settings.pageDisable)
			$('full-opaque').hide();
		
		$(this.settings.popup_id).hide();	
	},
	
	setContent: function(html) {
		var content = $$('#' + this.settings.popup_id +' .popup-content');
		content[0].update(html);
	},
	
	setTitle: function(html) {
		var title = $$('#' + this.settings.popup_id +' .highlight');
		title[0].update(html);
	},
	
	setUnderTitle: function(html) {
		var underTitle = $$('#' + this.settings.popup_id +' .underTitle');
		underTitle[0].update(html);
	},
	

	
	addPriceTypeListeners: function(seat) {
		//Add eventlisteners to all buttons in the popup
		$$(".ticketType-table .button").each(function(s) {
			s.observe("click", function() {
				
				// in case the click comes from ga button "add"
				if (this.getAttribute("ptNumber") == null)
					return;
				
				//set the priceType(stored in the rel attribute of the button) of the seat
				seat.setPriceTypeNumber(this.getAttribute("ptNumber"));
				seat.setPriceTypeCode(this.getAttribute("ptCode"));
				
				seatmap.addSeatToCart(seat);
				
				seatmap.popups['pricetypePopup'].hide();
				//Perhaps we should remove the eventlisteners??
			});
		});
		
	},
	
	_position: function() {
		//var anchor = $(this.settings.anchor_id).cumulativeOffset();
		var anchor = $(this.settings.anchor_id).positionedOffset();
		$(this.settings.popup_id).style.left = this.settings.offset.x + anchor[0] +'px';
		$(this.settings.popup_id).style.top = this.settings.offset.y + anchor[1] +'px';
		
		if(this.settings.width >0)
			$(this.settings.popup_id).style.width = this.settings.width +'px';
		else
			$(this.settings.popup_id).style.width = this.settings.width;
		
		if (this.settings.height > 0) {
			$('scrollable').style.maxHeight = this.settings.height +'px';
			$('scrollable').style.overflow = 'auto';
		}
	} 

});

Popup.createDropDownHTML = function(maxNum, priceTypeNumber, priceTypeCode, priceCategoryNumber){
	var dropdown = "";
	var options = "";
	for(var i = 0 ; i<=maxNum; i++)
		options += "<option value='"+i+"'>"+i+"</option>"

	dropdown = '<select class="gaPriceTypeSelect" ptCode="' + priceTypeCode +'" ptNumber="'+ priceTypeNumber +'" pcNumber="' + priceCategoryNumber + '">'+options+'</select>';
	return dropdown;
}


//Disable and Enable the Add button in GA ticket type popup based on chosen quantity 
Popup.gaDisableButton = function () {
	var sum = 0;
	$$(".gaPriceTypeSelect").each(function(s){
		sum += parseInt(s.getValue());			
	});
		
	if(sum == 0)
		$$(".ticketType-span .button")[0].disable();
	else
		$$(".ticketType-span .button")[0].enable();
}

