// ---- ready manager for jquery 

$.readyRegistry = [];

$.readyRegister = function(f) {
	$.readyRegistry.push(f);
}

// --- start

var subMenuActive = false;

var step2visible = false;
var step3visible = false;

$.readyRegister(function(){
    $("#nav li").hover(
        function(){ 
			subMenuActive = true;
			$("ul", this).show(); 
			$(this).addClass('active');
		}, 
        function() { 
			subMenuActive = false;
			$(this).removeClass('active');	
		} 
    );
    if (document.all) {
        $("#nav li").hoverClass("sfhover");
    }
});

$.fn.hoverClass = function(c) {
   return this.each(function(){
       $(this).hover( 
           function() { 
				$(this).addClass(c); 
    			$('select').addClass('ie6selectfix');
			},
           function() { 
				$(this).removeClass(c); 
				$('select').removeClass('ie6selectfix');
			}
       );
   });
};


var dateCount = 0;
var selectionMenusShown = false;
var clickPurchaseDate = function(){
    if (!step2visible) {
		$('#seat-map').hide();

		$('#performance-purchase-step2').show();
		$('#seat-map').show();
	}
	$('#seat-map').show();
	
	// next 5 lines added by PAG to populate performance-step-2 div
	var val = '';
	$('input[@name=\'purchase-date\']').each(function() {
	    dateCount++;
		if (this.checked)
				val = this.value;
	});

//		temporarily disabled so i can lay stuff out
	getseatingavailability(val);

//	    window.location.hash = 'buy';

	// robb, this needed to be done each time after each reload
	$('input.purchase-sections').click(function(){
	
		// this added to to track selected section
		$('input[@name=\'purchase-section\']').each(function() {
			if (this.checked)
				selected_zone = this.value;
		});
		
		// this try/catch added by PAG 2007-04-05 to add menus to panel
		try
		{
			if ( ! selectionMenusShown )
			{
				var src = document.getElementById("pricetypeselectors_src");
				var dest = document.getElementById("pricetypeselectors_dest");
				if (src && dest )
				{
					dest.innerHTML = src.innerHTML;
					src.innerHTML = ""; // in essence to 'move' the code
					selectionMenusShown = true;
					$('#performance-purchase-step3').show();
					var omitSYOS = document.getElementById("omitSYOS");
					if (omitSYOS != null)
					{
						$('#button_selectseats').attr("src", "/assets/images/button_purchase.png");
					}
				}
			}
		}
		catch(err)
		{
			alert("iso_details 128: " + err.description);
		}
		
		// window.location.hash = 'seats';
	});
		
	step2visible = true;
};	



$.readyRegister(function(){
        
	$('input[@name=\'purchase-date\']').each(function() {
	    dateCount++;
	});
	
    //pre-check if there's only one date
	if (dateCount == 1) {
        $('input[@name=\'purchase-date\']').get(0).checked = true;
        clickPurchaseDate();
	}
	
	$('input.purchase-dates').click(clickPurchaseDate);
	
});

function showSectionInfo(section) {
    if (section == 'main floor front') {
        $('#map-wrapper').css('backgroundPosition', (84*7)+'px 0px')        
    }
    
    if (section == 'main floor') {
        $('#map-wrapper').css('backgroundPosition', (84*6)+'px 0px')        
    }

    if (section == 'orchestra box side') {
        $('#map-wrapper').css('backgroundPosition', (84*5)+'px 0px')        
    }

    if (section == 'orchestra box center') 
        $('#map-wrapper').css('backgroundPosition', (84*4)+'px 0px')        

    if (section == 'dress circle') 
        $('#map-wrapper').css('backgroundPosition', (84*3)+'px 0px')        

    if (section == 'first mezzanine') 
        $('#map-wrapper').css('backgroundPosition', (84*2)+'px 0px')        

    if (section == 'second mezzanine') 
        $('#map-wrapper').css('backgroundPosition', (84*1)+'px 0px')        

 
 //   $('#map-wrapper').css('backgroundPosition', '84px 0px')
// 	var sectionInfo = section + ' means: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla nec tellus. In pharetra lorem auctor ligula.';
// 	$('#section-explanation').html(sectionInfo).show();
    //alert(section);
}

function hideSectionInfo() {
//	$('#section-explanation').html(' ').hide();	
    $('#map-wrapper').css('backgroundPosition', '0px 0px')        
}

function changeSeats() {
	var anyValue = false;
//	var allSeats = []; 
	var v;
//	var stripID;
	
	$('select.seats').each(function() {
		v = $(this).val();
//		stripID = $(this).get(0).id.substring(5);
//		allSeats[stripId] = v;
		if (v != '')	
			anyValue = true;
	});
		
	if (anyValue) {
		$('#reserve-button').show();		
	}
	else {
		$('#reserve-button').hide();
	}
}

function reserveSeats() {
	$('#performance-purchase-loader').show();
	
	var allSeats = []; 
	var stripID;

	$('select.seats').each(function() {
		stripID = $(this).get(0).id.substring(5);
		allSeats[stripID] = $(this).val();
	});
		
	// this.style.cursor = "wait";
	document.body.style.cursor = "wait";
	complete_purchase_begin(); // in dw_performance.js: async ajax call
}

var activeSection = '';

var explanations = {
	'main-floor-a-e':'Main floor A-E explanation goes here.',
	'dress-circle':'Dressing Circle explanation goes here.'
};

function overSection(section) {
//     aler(section);
// 	if(explanations[section])
// 		var ex = explanations[section];
// 	else
// 		var ex = 'This section has no description';
// 
// 	$("#section_explanation").html(ex).show();
}

function outSection(section) {
// 	$("#section_explanation").hide();
}

function openMap() {
    var mapWindow = showModalWindow('map-modal-panel', 'Seating detail view', 340, 260, 400, 483+32+32);

	var modalContent = '<a href="#" onclick="hideModalWindow(\'map-modal-panel\'); return false;"><img src="/assets/images/seating_large.gif" width="400" height="483" style="position: absolute; left: 0; top: 0;" /></a>';

	modalContent += '<form style="padding-top: 4px"><table cellspacing="0" cellpadding="0" border="0"><tr><td><label for="tbx_login">Username</label></td><td><input type="text" name="tbx_login" id="tbx_login" /></td></tr><tr><td><label for="tbx_password">Password</label></td><td><input type="password" name="tbx_password" id="tbx_password" /></td></tr><tr><td><label for="tbx_promo_code">Promo code</label></td><td><input type="text" name="tbx_promo_code" id="tbx_promo_code" /></td></tr></table></form>';

	mapWindow.find('.modal-content').html(modalContent);

	mapWindow.find('.bottombar .button').html('<a href="#" onclick="hideModalWindow(\'map-modal-panel\'); return false;"><img src="/assets/images/button_close.png" width="108" height="32" alt="Close" title="Close" /></a>');
	mapWindow.find('.bottombar .content').html('');
}

window.onload = function() {
	var w= document.body.clientWidth;
	 if (w<905)
	 	$('#main-nav').css('margin-left', '0px');
};

window.onresize = function() {
	var w= document.body.clientWidth;
	 if (w<905)
	 	$('#main-nav').css('margin-left', '0px');
	else
		$('#main-nav').css('margin-left', '0px');
};