// == QUERYSTRING PARSER ==================================
function querystring(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function validate_for(type, string)
{
	// cc check is generic.  use full `isValidCreditCard` function for more control.
	
	var re;
	if(type=='url') { re = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/; }
	else if(type=='email') { re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/ }
	else if(type=='phone') { re = /^\(\d{3}\) ?\d{3}( |-)?\d{4}|^\d{3}( |-)?\d{3}( |-)?\d{4}/ }
	else if(type=='zip') { re = /^((\d{5}-\d{4})|(\d{5})|([AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d))$/ }
	else if(type=='money') { re = /^\$?(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})?|\d{1,3}(\.\d{0,2})?|\.\d{1,2}?)$/ }
	else if(type=='cc') { re = /^((4\d{3})|(5[1-5]\d{2}))(-?|\040?)(\d{4}(-?|\040?)){3}|^(3[4,7]\d{2})(-?|\040?)\d{6}(-?|\040?)\d{5}/ }
	return (re.test(string));
}

function strip_tags(string)
{
	return string.replace(/(<([^>]+)>)/ig,""); 
}

// == INCLUDE DEBUG CSS ===================================
if (window.location.href.indexOf('debug')>0)
{
	document.write('<link rel="stylesheet" type="text/css" media="screen" href="css/debug.css" />');
}





// ========================================================

jQuery.fn.equalizeCols = function(){
  var height = 0;
  return this.css("height","auto").each(function(){
    height = Math.max( height, jQuery(this).outerHeight() );
  }).css("height", height);

};


var info_shown = false;
$(document).ready(function(){

	$(".hover").hover(
      function () {
        $(this).addClass('over');
      }, 
      function () {
        $(this).removeClass('over');
      }
    );

//  equalize the left and right columns if one is longer than the other.
	var min_height = $('.column.bordered').height();
	$('.column').each(function(){
		if($(this).height() < min_height)
		{
//			$(this).height(min_height);
		}
	});
	
	$("#footer ul li.visit").click(function(){ window.location.href='visit.html'; });
	$("#footer ul li.exhibition").click(function(){ window.location.href='exhibition.html'; });
	$("#footer ul li.explore").click(function(){ window.location.href='explore.html'; });
	$("#footer ul li.events").click(function(){ window.location.href='events.html'; });
	
	

	// homepage clickable area
	$("#home #content div.rivalry").click(function(){ window.location.href='exhibition.html'; });
	$("#home #content div.restoration").click(function(){ window.location.href='explore.html'; });
	$("#home #content div.highlights").click(function(){ window.location.href='#'; });


	// homepage press quotes - turn one on
	r = Math.floor(Math.random()*3)
	$('#home #content div#press blockquote:eq('+ r +')').show();

});

// CHECK THE CELL PHONE FIELD(S) FOR CORRECTNESS

function format_cell()
{
	$('#cell')[0].value = $('#exchange')[0].value + "" + $('#prefix')[0].value + "" + $('#suffix')[0].value
	if(validate_for('phone', $('#cell')[0].value))
	{
		return true;
	} else {
		alert('Please enter a valid phone number!');
		return false;
	}
}