
//building the div to display only if a user has javascript and not for search engine crawlers and such
var datediv = jQuery('<div id="caldiv"><form action="/" method="get" accept-charset="utf-8"><div id="calwrap"><input type="hidden" name="date" value="date" id="date">' +
'<h3 class="date">By Date</h3><p id="nav-prev"><a href="#" id="month-prev">&lt;</a></p><h2></h2>' +
'<p id="nav"-next"><a href="#" id="month-next">&gt;</a></p><div id="calendar"></div></div><div id="opts"><h3 class="audience">By Audience</h3><select name="audience"><option value="1">Children</option></select>' +
'<h3 class="loc">By Location</h3><select name="location"><option value="1">Guggenheim NY</option></select><input type="image" src="/templates/guggenheim/images/go-button.gif" value="Go"></div></form>' +
'</div>');
//calendar stuff
var Calendar = new Object();
var month, prevMonth, nextMonth, year = (new Date).getFullYear();

Calendar.toggleCal = function(){
  // jQuery(".calendar a").toggle(function() {
  //    jQuery("#caldiv").slideDown("slow");
  //    jQuery(this).css("background-image" , "url(images/cal-open.gif)");
  // }, function() {
  //  jQuery("#caldiv").slideUp("slow");
  //  jQuery(this).css("background-image" , "url(images/calendar.gif)");
  // });;
  if(!jQuery("#caldiv").is(":visible")){
     jQuery("#caldiv").slideDown("slow");
     }else{
        jQuery("#caldiv").slideUp("slow");
     }
  
  
}

Calendar.generateDay = function(jQuerytd, thisDate, month, year)
	{
		if (jQuerytd.is('.current-month')) {
			var d = thisDate.getDate();
			jQuery("#caldiv h2").html(thisDate.getMonthName() + " " + thisDate.getFullYear());
			month = Number(month)+1;
			prevMonth = month - 2;
			nextMonth = month;
			jQuerytd.bind(
				'click',
				function()
				{
					//console.log('You clicked on ' + (Number(month)+1) + '/' + d + '/' + year);
					jQuery(".selected").removeClass("selected");
					jQuery(this).addClass("selected");
					jQuery("#date").val((Number(month)+1) + '/' + d + '/' + year)
					
				}
			);
		}
	}
	
jQuery(document).ready(function() {
  jQuery(datediv).insertAfter("#header").hide();
  jQuery("#caldiv form #calendar").renderCalendar({renderCallback: Calendar.generateDay});
  jQuery("a#month-prev").bind('click', function(){
  	if(prevMonth < 0){
  	  year -= 1
  	  prevMonth = 11
  	} 
  	  jQuery("#caldiv form #calendar").renderCalendar({month:prevMonth, renderCallback: Calendar.generateDay, year: year});
  		jQuery("tbody tr").not(":first").find(":first-child.other-month").parent().remove();
  	  return false;
  })
  jQuery("a#month-next").bind('click', function(){
  	if(nextMonth >= 12){
      year += 1
      nextMonth = 0
  	}	
  		jQuery("#caldiv form #calendar").renderCalendar({month:nextMonth, renderCallback: Calendar.generateDay, year: year});
  		jQuery("tbody tr").not(":first").find(":first-child.other-month").parent().remove();
  		return false;
  	})
  jQuery(".calendar a").css("background-repeat", "no-repeat")
  jQuery("tbody tr").not(":first").find(":first-child.other-month").parent().remove();
});	



/* sifr Stuff */

function RGBtoHex(rgb) {
if(rgb != "transparent"){
	var R = rgb.split("(")[1].split(")")[0].split(",")[0]
	var G = rgb.split("(")[1].split(")")[0].split(",")[1].substr(1)
	var B = rgb.split("(")[1].split(")")[0].split(",")[2].substr(1)
	return toHex(R)+toHex(G)+toHex(B)
	}	else {
		return "ffffff"
	}
}
function toHex(N) {
 if (N==null) return "00";
 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
 return "0123456789ABCDEF".charAt((N-N%16)/16)
      + "0123456789ABCDEF".charAt(N%16);
}
     
jQuery(document).ready(function() {
			jQuery("#callouts h3").each(function(){
			var selector =	jQuery(this).parent()[0].className.substr(4)
						p = RGBtoHex(jQuery(this).parent().css("backgroundColor"))
			  		sIFR.replaceElement(named({sSelector: "." + selector + " h3" , sFlashSrc:"http://www.guggenheim-deployment.com/templates/guggenheim/flash/guggenheim-bold.swf",nPaddingBottom: -15, sFlashVars:"textalign=left&offsetTop=6", sBgColor: "#" + p }));
			})
      sIFR.replaceElement(named({sSelector:"#content h1", sFlashSrc:"http://www.guggenheim-deployment.com/templates/guggenheim/flash/guggenheim-bold.swf",nPaddingBottom: -10, sFlashVars:"textalign=left&offsetTop=6"}));

/*Expandable content by adding the class title to an element. hides the next html element after the one with the class title on page load
converts the element with the class title to a clickable toggle switch that hides/shows the hidden element
*/
      jQuery(".title").addClass("arrow-off").next().hide();
      jQuery(".title").click(function() {
        if(jQuery(this).next().is(":visible")){
          jQuery(this).addClass("arrow-off").next().slideUp();
        } else {
          jQuery(this).removeClass("arrow-off").next().slideDown();
        }
      });
      
      
});
