 $(document).ready(function(){load();});

  
   //sectionrollover = new jsGraphics("sectionrollover");
    //sectionhighlight = new jsGraphics("sectionhighlight");


filtercriteria = Array();
function load() {		
	/* This is basic - uses default settings */
			// default to exact
			
		   $(".pricechart").tablesorter(); 


			$('#map_general').show();

			$('#map').supersleight({shim: '/packers/tickets/x.gif'});
			$('#map_general').supersleight({shim: '/packers/tickets/x.gif'});
			
			
			//toggleIETrans();
			
			if ($('.featured').length < 1) {
				$('.featuredinchart').hide();
			}


			if (lambeaufield) switchtickettype('exact_tab','set');
			
			filtercriteria = Array();
			
			  $('#lambeau_field_seating_nav a').each(function() {
					
								
				$(this).hover(
							  function() { 
							  	var current = $(this).attr('id');
								var selectedTab = ($('.selected').children().attr('id')); 
								switchtickettype(current);
								},
							  
							  function() {
								  var current = $(this).attr('id');
								  var selectedTab = ($('.selected').children().attr('id'));
								  switchtickettype(selectedTab)  }
							  );
				
				$(this).click(function(event) { 
								 var current = $(this).attr('id');
								  var selectedTab = ($('.selected').children().attr('id'));
								switchtickettype(current,'set');
								event.preventDefault();
								});	
							  				
			});
			  
	
	$("a#single_image").fancybox();

		//$('#filtermin').keyup(function() { alert('down') });
		//$('#filtermax').keyup(function() { alert('down') });

		//$('.pricechart a').click(function() { alert('sorting by' + $(this).text()); });

		$('area').each(
	
	function() {
		
		$(this).attr('unselectable','on'); // IE
				$(this).attr('hidefocus','true'); // IE

		  var n = $(this).attr('alt');
		  
		  if (n) {
			  $(this).qtip({
				   content: showsection(this),
				   show: {delay:0 },
				   style: { backgroundColor: '#bcdee6' }
			  });
				//sectionrollover = new jsGraphics("sectionrollover");
		// mouseover
		$(this).mouseover(function() {
			// possibily preload this stuff		
			
			
			if ($('#rollovers .s' + n).length == 0) {

			$('#rollovers').append('<div style="display:none;" class="sectionhighlight s' + n + 
						   					'"><img src="/packers/tickets/sections/' + n + '.gif" width="500" height="587" alt="" /></div>');
			}
			/*
			var coords = $(this).attr('coords').split(",");
			sectionrollover.setColor("#bcdee6"); // blue
 
			 if ($(this).attr('shape') == 'rect') {
			  sectionrollover.fillRect(coords[0],coords[1],coords[2]-coords[0],coords[3]-coords[1]);
			 } else {
				 coordsX = new Array(Number(coords[0]),Number(coords[2]),Number(coords[4]),Number(coords[6]));
				 coordsY = new Array(Number(coords[1]),Number(coords[3]),Number(coords[5]),Number(coords[7]));
			  sectionrollover.fillPolygon(coordsX,coordsY);
			 }
			  sectionrollover.paint();
			  */
		});
		
		// mouseout
		$(this).mouseout(function() {
								 // sectionrollover = new jsGraphics("sectionrollover");
								//sectionrollover.clear(); 
								});
		
		// click 
		$(this).click(
		
			function(event) {
				event.preventDefault();

				var section = $(this).attr('alt');
				//var coords = $(this).attr('coords').split(",");
				//alert(section);
			
				// filter by section
				filtersection(section);
				this.blur();
				
				}) // end click
		  } // end if
		}); // jquery each function
 } // end load



function in_array (needle, haystack) {
    var key = '';
        for (key in haystack) {
            if (haystack[key] == needle) {
                return key;
            }
        }
 
    return false;
}

function clearsection(s) {
	//alert('clearing: ' + s);
}

function toggleIETrans() {
	
			$('#map_premium').toggleClass('mapbg');
						$('#map_general').toggleClass('mapbg');
						$('#map').toggleClass('mapbg');
					
					
}

function filtersection(section) {
	
	
	if (eval('SectionData.s' + section) != undefined) {		
				 
		
		var a = in_array(section,filtercriteria);
								  
				 if (a) {
					 // remove section
					// alert('removing section ' + section);
					 filtercriteria.splice(a,1);
					 //hidehighlight(section);
					 $('#rollovers .s' + section).hide();
					 //toggleIETrans();
						 
				 } else { 
				 //toggleIETrans();
					filtercriteria.push(section);
								
					var sectionhighlight = new Image(500,587);
					sectionhighlight.src = '/packers/tickets/sections/' + section + '.gif';
					
					if ($('#rollovers .s' + section).length > 0) {
						$('#rollovers .s' + section).show();
					} else {

						$('#rollovers').append('<div class="sectionhighlight s' + section + 
						   					'"><img src="/packers/tickets/sections/' + section + '.gif" width="500" height="587" alt="" /></div>');
					}

		
				 }
				 
				 
		if (filtercriteria.length>0) {
			// set up the filter
			

					$('.tickets').hide();
							
					var makediv = '<div id="filter"><h2>Only showing tickets that match the following:<br><span>(<a onclick="switchtickettype()">clear all filters</a>)</span></h2><ul id="criterialist">';
					for(i=0;i<filtercriteria.length;i++) {
						var sec = '.section' + filtercriteria[i];
						//alert(sec);
						$(sec).show();
						
						var count = eval("SectionData.s" + filtercriteria[i] +  ".count");
		
						var area = eval('ViewData.s' + filtercriteria[i] + '.name');
						
						var tix = "ticket"; 
						if (count > 1) tix += "s";
						
						// which tab are we on
						if ($('.selected').children().attr('id') == 'exact_tab') {
							// dont' show section
							var area = 'Section ' + filtercriteria[i];
						} 
					
						
						
						makediv  += '<li class="s' + filtercriteria[i] + '">Located in <strong>' + area + '</strong> (' + count + ' ' + tix + ')&nbsp;/ <a onclick="filtersection(\'' + filtercriteria[i] + '\')">clear</a></li>';
					}
					makediv += '</ul></div>';
					$('#tickets').html(makediv); 

								//$('#sectionrolloverimg').attr('src',sectionhighlight.src);
								//pic1.src="http://someplace.com/image1.gif"; 			
															//$("a#single_image").fancybox({'speedIn':200,'speedOut':200,'transitionIn':'elastic','transitionOut':'elastic'});
		} else {
			// nothing left to filter so show everything
			
				switchtickettype();					
				 }
				

					 //sectionhighlight.clear();
					 //sectionhighlight = new jsGraphics("sectionhighlight");
					 //sectionhighlight.setColor("#ff9999"); // red

							//if ($(this).attr('shape') == 'rect') {
							//	  sectionhighlight.fillRect(coords[0],coords[1],coords[2]-coords[0],coords[3]-coords[1]);
							 //} else {
								//	var coordsX = new Array(Number(coords[0]),Number(coords[2]),Number(coords[4]),Number(coords[6]));
								//	var coordsY = new Array(Number(coords[1]),Number(coords[3]),Number(coords[5]),Number(coords[7]));
									//sectionhighlight.fillPolygon(coordsX,coordsY);
						//	 }
							//  sectionhighlight.paint();
						
								
				} 
				
					//else {
						//		$('#tickets').html('<p>Click on where you would like to sit on the map to only show available tickets in that section.</p>');
							  // sectionhighlight.clear();
								//$('tr').show();
					//} // end if
	
}


function hidehighlight(sec) {
	$('.sectionhighlight .s' + sec).hide();
}


function showresponse(e) {
var el =  document.getElementById("tickets");
el.innerHTML = e;
}


function switchtickettype(which,set) {			
					
			// figure out which is the current one.
						var current = ($('.selected').children().attr('id'));			

				if (which == undefined) { which = current; set = 'set' }
			
			
			
			//$('.tickets').show();

						
			if (set == 'set') {
				
				//toggleIETrans();
				// turn off current one
				$('#' + current).parent().removeClass('selected');
				
				// set the new one 
				$('#' + which).parent().addClass('selected');
				maketab = which;
				$('#filter').hide();
				$('#rollovers div').hide();
				filtercriteria = Array();
				
				if (lambeaufield) $('#tickets').html('<p>Click on where you would like to sit on the map to only show available tickets in that section.</p>');

			
			} else {
				maketab = false;
			}
			
			switch(which) {
				
				case 'premium_tab':
					$('#premium').show();
					$('#exact').hide();
					$('#general').hide();
					//$('#tailgate').hide();
					if (set = 'set' && maketab != false) {
						$('#map_premium').show();
						//$('#map_premium').fadeIn(500);
						$('#map_general').hide();
						$('#map').hide();
						$('.tickets').hide();
						$('.premium').show();

					}
				break;
				
				case 'exact_tab':
					$('#exact').show();
					$('#general').hide();
					$('#premium').hide();
					//$('#tailgate').hide();
					
					if (set = 'set' && maketab != false) {
						//$('#map_premium').fadeOut(500);
						$('#map_premium').hide();
						
						$('#map_general').hide();
					
						$('#map').show();
						
						$('.tickets').hide();
						$('.exact').show();

					}
				break;
				
				case 'general_tab':
					$('#general').show();
					$('#exact').hide();
					$('#premium').hide();
					//$('#tailgate').hide();
					if (set == 'set' && maketab != false) {
						var dir = current == 'exact_tab' ? 'right' : 'left';
						
						$('#map_premium').hide();					
						$('#map_general').show();
						$('#map').hide();

						$('.tickets').hide();
						$('.general').show();
						
					}
				break;
				
				case 'tailgate_tab':
					$('#tailgate').show();
					$('#exact').hide();
					$('#general').hide();
					$('#premium').hide();
				break;
				
				
				
				
			}
}


function showseatingview(s) {
	// get the filename
	var fi = eval('ViewData.s' + s + ".file");
	return '<a href="views/' + fi + '" id="single_image">Show Seating View</a>';
}



function showsection(sec) {  

 var section = $(sec).attr('alt');


switch(section) {
	
	
	case 'Bowl':	
			var low = SectionData.bowl.low;
			var high = SectionData.bowl.high;
			var count = SectionData.bowl.count;
			var thestring = "<p><strong>Bowl Seating</strong><br />Sections 100 to 334<br />" + count + ' tickets from<br />$' + low + ' to $' + high + '</p>';
			break;
	case 'IndoorClub':	
			var low = SectionData.indoor.low;
			var high = SectionData.indoor.high;
			var count = SectionData.indoor.count;
			var thestring = "<p><strong>Indoor Club Seating</strong><br />Sections 470 to 694<br />" + count + ' tickets from<br />$' + low + ' to $' + high + '</p>';
			break;
	case 'OutdoorClub':	
			var low = SectionData.outdoor.low;
			var high = SectionData.outdoor.high;
			var count = SectionData.outdoor.count;
			var thestring = "<p><strong>Outdoor Clubs</strong><br />Sections 403 to 435<br />" + count + ' tickets from<br />$' + low + ' to $' + high + '</p>';
			break;
	case 'Skyboxes':	
			var low = SectionData.bowl.low;
			var high = SectionData.bowl.high;
			var count = SectionData.bowl.count;
			var thestring = "<p><strong>Skybox Seating</strong><br />Boxes 4000 to 7000<br />" + count + ' tickets from<br />$' + low + ' to $' + high + '</p>';
			break;
			
     default:
	 	if (section) {
			var longname = eval("ViewData.s" + section +  ".name");
			if (longname == undefined) longname = '';
			
			if ($(sec).parent().attr('id') == 'lambeaumapgeneral') {
					// general seating
					var thestring = '<p><strong>' + longname + '</strong><br />';
			} else {
					// exact
					var thestring = "<p><strong>Section " + section + '</strong> / ' + longname + '<br />';
			}
			
			
			if (eval('SectionData.s' + section) != undefined) {
				var low = eval("SectionData.s" + section +  ".low");
				var high = eval("SectionData.s" + section +  ".high");
				var count = eval("SectionData.s" + section +  ".count");
										
	
				thestring += (count == 1) ?  '1 set of tickets at $' + low + '</p>' :  count + ' sets of tickets from<br />$' + low + ' to $' + high + '</p>';
				
			} else {
			  	thestring += '<em>no tickets currently in this section</em></p>';
			}
		}
} // end switch

			return thestring;


}

