jQuery(document).ready(function($) {	
	parseURLParams();
	
	//when rolling downwards off a picker, close all bubbles
	$("#miniFooter").mouseover(function(){
	 	if(BrowserDetect.browser=="Explorer"){
 	 		$("#pickerBubbles div.bubble").attr("style", "display: none");
		}else{
		 	$("#pickerBubbles div.bubble").fadeOut('fast');
		}
	});

	
	$('#eventsCarousel').jcarousel({
      	scroll: 8,
       	start: 4,
		wrap: 'circular',
        //initCallback:   mycarousel_initCallback,
  		itemLastInCallback:   mycarousel_itemLastInCallback,
      	itemVisibleInCallback: {onBeforeAnimation: eventsCarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: eventsCarousel_itemVisibleOutCallback}
	});


	//iphone tap to close
	$('#pickerBubbles div.bubble').click(function() {
  		$(this).fadeOut('fast');
	});
		
	if(BrowserDetect.browser=="Explorer"){
 	  	$("#pickerBubbles div.bubble").hover(
			//ie(even 8) can't handle animating the opacity of a png with an alpha channel
      		function () {}, 
      		function () {$(this).attr("style", "display: none");}
    	);
	}else{
		$("#pickerBubbles div.bubble").hover(
			function () {}, 
			function () {$(this).fadeOut('fast');}
		);
	}


	$('img.hover').hover(
		function() {$(this).attr('src', $(this).attr('src').replace( /_off/i, '_over' ));}, 
		function() {$(this).attr('src', $(this).attr('src').replace( /_over/i, '_off' ));}
	);



	//calendar bubbles
	$(".calendarTable a.cBubble","#mainColBody").hover(
		function () {
			var theData = $(this).attr('data-bubble'), theSel= "#" + theData + " div.bubble";
			if(BrowserDetect.browser=="Explorer"){$(theSel).attr("style", "display:block")}else{$(theSel).fadeIn('fast')}
		}, 
		function () {}
	);

});


function   mycarousel_itemLastInCallback(carousel, two,three,state) {
 	//hide any open bubbles
 	$("#pickerBubbles div.bubble:not(.open)").attr("style", "display: none");
 	

	var startLocation = 1;
	//this is not a good place for the page specific start scroll
	if(state=='init'){carousel.scroll(startLocation)}
};


var eventsCarousel_itemList = [

  	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/clowns.jpg', title: 'fall fun', href:'/fun/?picker=homePicker',bubble:"bwFallFun"},
// 	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/bizworks.jpg', title: 'DC Bizworks', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=DC%20BizWorks'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/jammin.jpg', title: 'jammin&rsquo;', href:'http://ostreetmuseumfoundation.org/museum/performing_arts/jammin/'},
	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/livingsocial.jpg', title: 'livingsocial', href:'/social', replaceWith: "#lsFlipContainer" },
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/memberevents.jpg', title: 'member events', href:'/membership/parties/?picker=homePicker'},
//   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/tourbaby.jpg', title: 'tours', href:'/museum/visitor_information/tours/'},
// 	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/brunch.jpg', title: 'brunch &amp; tea', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Brunch',bubble:"bwBrunchTea"},
	{url: 'http://www2.omansion.com/holiday_events/images/picker/chanukah.jpg', title: 'mitzvahs', href:'/bar_mitzvahs_bat_mitzvahs/?picker=homePicker'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/halloween.jpg', title: 'halloween', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Halloween%20Party',bubble:"bwHalloween"},
  	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/martinez.jpg', title: 'boys night out', href:'/girls_night_out/?picker=homePicker'},

	{url: 'http://www2.omansion.com/holiday_events/images/picker/thanksgiving.jpg', title: 'thanksgiving', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Turkey%20Dinner',bubble:"bwThanksgiving"},

	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/books.jpg', title: 'book tour', href:'/museum/visitor_information/tours/'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/strawberries.jpg', title: 'public events', href:'/sundays_mondays/'},
   {url: 'http://www2.omansion.com/holiday_events/images/picker/other/brunch.jpg', title: 'tea', href:'/sundays_mondays/tea/?picker=homePicker'},

   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/penguins.jpg', title: 'fundraising', href:'http://www.omuseum.org/museum/programs/fundraising/'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/girls.jpg', title: 'girls night out', href:'/night_out_parties/?picker=homePicker'},
	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/hat.jpg', title: 'shopping spree', href:'/museum/visitor_information/tours/#Gift%20Shopping%20Tour'},
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/cooking-party.jpg', title: 'cooking class', href:'/cookingclasses/?picker=homePicker'},
	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/xmas-tours.jpg', title: 'tours', href:'/museum/visitor_information/tours/'},
 
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/gift-cert.jpg', title: 'gift certificates', href:'https://www.omansion.com/events/gift-certificates.shtml?picker=homePicker'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/6-days-xmas.jpg', title: 'open house', href:'/christmas_sale/'},
  	{url: 'http://www2.omansion.com/holiday_events/images/picker/snowmen.jpg', title: 'december events', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Dec%20Martini',bubble:"bwXmasEvents"},
   {url: 'http://www2.omansion.com/holiday_events/images/picker/other/uniqueparties.jpg', title: 'unique parties', href:'/fun/?picker=homePicker'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/christmas-in-summer.jpg', title: 'xmas dining', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Xmas%20Eve%20Dinner',bubble:"bwXmas"},
  	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/new-year-picker.jpg', title: 'new year&rsquo;s eve', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=BOTH:%20New%20Year\'s%20Eve%20Dinner%20Party',bubble:"bwNewYear"},
  	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/mlk.jpg', title: 'MLK Lunch', href:"https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=MLK%20Lunch"},

  	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/groundhog.gif', title: 'groundhog day', href:"https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Groundhog's"},
	{url: 'http://www2.omansion.com/holiday_events/images/picker/chinese-newyear.jpg', title: 'chinese new year', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Chinese%20New%20Year\'s%20Party'},
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/valentines-day.jpg', title: 'valentine&rsquo;s day', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Valentine\'s%20Sit-Down%20Dinner',bubble:"bwValentines"},
  	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/sadie.jpg', title: 'sadie hawkins', href:"https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Valentine's%20Party"},
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/mardi-gras.jpg', title: 'mardi gras', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Mardi%20Gras%20Party'},
//   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/numerology.jpg', title: 'numerology', href:'/numerology/?picker=homePicker'},
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/springthink.jpg', title: 'spring fun', href:'/fun/?picker=homePicker',bubble:"bwSpringFun"},

	{url: 'http://www2.omansion.com/holiday_events/images/picker/st-patricks-day.jpg', title: 'st patrick&rsquo;s day', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=St.%20Patrick\'s%20Party'},
//   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/sro.jpg', title: 'sro concerts', href:'/sro/?picker=homePicker'},

	{url: 'http://www2.omansion.com/holiday_events/images/picker/april-fool.jpg', title: 'april fool&rsquo;s day', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=J\'O\'kester%20Martini'},
	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/dandilion.jpg', title: 'earth day', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Earth%20Day'},
  	{url: 'http://www2.omansion.com/holiday_events/images/picker/easter.jpg', title: 'easter', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Easter%20Brunch',bubble:"bwEaster"},
//	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/martini.jpg', title: "o'dinnertini", href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Martini'},
//	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/artleasing.jpg', title: 'art leasing', href:'http://www.omuseum.org/art_leasing/?picker=homePicker'},
//   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/dresscode.jpg', title: 'dress code', href:'/dress_code/?picker=homePicker'},
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/grad-parties.jpg', title: 'grad parties', href:'/affordable_parties/#Graduation%20Party'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/chilis.jpg', title: 'cinco de mayo', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Cinco%20de%20Mayo'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/mothers-day.jpg', title: 'mother&rsquo;s day', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Mother\'s%20Day%20Brunch',bubble:"bwMomsDay"},
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/secretdoor.jpg', title: 'secret door', href:'/its_all_here/secret/?width=610&height=460', thickbox:'yes'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/telescope.jpg', title: 'treasure hunt', href:'/treasure_hunts/?picker=homePicker'},
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/inspireimag.jpg', title: 'monday lunch', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Lunch'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/tourbaby.jpg', title: 'dress code', href:'/dress_code/?picker=homePicker'},


 	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/mondays.jpg', title: 'liquid fun', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Martini',bubble:"bwMonday"},
	{url: 'http://www2.omansion.com/holiday_events/images/picker/fathers-day.jpg', title: 'father&rsquo;s day', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=FD%20Brunch',bubble:"bwDadsDay"},
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/heartgirl.jpg', title: 'summer fun', href:'/fun/?picker=homePicker',bubble:"bwSummerFun"},
   	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/invites-girl.jpg', title: 'kids&rsquo; parties', href:'/museum/programs/kids/'},
	{url: 'http://www2.omansion.com/holiday_events/images/picker/4th-of-july.jpg', title: '4th of july', href:'https://www.omansion.com/events/reservation.shtml?picker=homePicker&Event=Fourth'},
 	{url: 'http://www2.omansion.com/holiday_events/images/picker/other/numerology.jpg', title: 'numerology', href:'/numerology/?picker=homePicker'},
 		{url: 'http://www2.omansion.com/holiday_events/images/picker/other/razzle-dazzle.jpg', title: 'mansion sale', href:'/yard_sale/?picker=homePicker'},

   {url: 'http://www2.omansion.com/holiday_events/images/picker/other/reception.jpg', title: 'champagne tour', href:'/museum/visitor_information/tours/#Champagne%20Tours'}



 
 
];





function eventsCarousel_itemVisibleInCallback(carousel, item, i, state, evt){
 	var idx = carousel.index(i, eventsCarousel_itemList.length);
 	var thisItem = eventsCarousel_itemList[idx - 1];  
 	//	if(window.console){console.log('eventsCarousel_itemVisibleInCallback')};

	 $("a[href*=/forms/]","#eventsCarousel").click(function() {
		//alert('hi');
		var myURL =  this.href;
		var theseParams = parseGetVars(myURL);
		var thisDept = unescape(theseParams['department']);
		var thisSubject = unescape(theseParams['subject']);
		var thisBody = unescape(theseParams['body']);
		//alert(thisDept);

			
		// Pass a value to thickbox window by updating parent page's hidden form field	
		// set the value of the hidden form field id='dept' in the calling page
		// to the 'department' value captured from the link clicked on, that is now stored in the var 'thisDept'
		//document.getElementById("dept").value = thisDept;
		document.globalStorage.field1.value = thisDept;
		document.globalStorage.field2.value = thisSubject;
		document.globalStorage.field3.value = thisBody;
	});	
 	
  	
    var thisItemHTML = eventsCarousel_getItemHTML(thisItem) ;    
    var thisWidth = item.width;
    var thisHeight = item.height;
    // Create an object from HTML
    var DOMitem = jQuery(thisItemHTML).get(0);
	
	
 	
 	//Bubbles
 	if(thisItem.bubble){
		//initialize bubble
		var theSel= "#" + thisItem.bubble + " div.bubble";
		if(BrowserDetect.browser=="Explorer"){
 	 
 	  		$(DOMitem).hover(
				//ie(even 8) can't handle animating the opacity of a png with an alpha channel
      			function () {$(theSel).attr("style", "display:block");}, 
      			function () {}
    		);
  
		}else{
	 	
			$(DOMitem).hover(
				function () {$(theSel).fadeIn('fast');}, 
				function () {}
		);
	}
	}

 	 //Thickboxes
 	if(thisItem.thickbox){
 	
 	if(thisItem.complex!="yes"){
 		//Simple thickboxes
   		tb_init(DOMitem);
  	}else{
       	 //Complex thickboxes
       	if(BrowserDetect.browser=="Safari"||BrowserDetect.browser=="Chrome"){
       		//Safari and Chrome do popup
       		$(DOMitem).click(function () {
       			var thisHref= $(this).attr('href');
   				displayWindow(thisHref, 930,490,0);
   				return false;
   			});
       	}else{
         	//Complex thickboxes, FF, IE
			tb_init(DOMitem);
		}  
  	}
  	}
  	
  	//REPLACE FLIP CONTENTS
	if(typeof(thisItem.replaceWith)!="undefined"){
		newHTML=   $(thisItem.replaceWith).html() ;
    	var DOMitem = jQuery(newHTML).get(0);
	}
  	
  	
	carousel.add(i, DOMitem);
	
	//INIT FLIP
	if(typeof(thisItem.replaceWith)!="undefined"){initFlip();}
	
}

function eventsCarousel_itemVisibleOutCallback(carousel, item, i, state, evt){carousel.remove(i);};

function eventsCarousel_getItemHTML(item){
	var isPopup=item.popup;
	var replaceSelector=item.replaceWith;
	var thisHTML="";
	
	if (isPopup=='bubble'){
	    thisHTML=  '<a href="'+item.href+'">	<img src="' + item.url + '" width="94" height="88" alt="' + item.title + '" /><p>' +item.title+'</p></a>';
	}else{
    	thisHTML=  '<a href="'+item.href+'"><img src="' + item.url + '" width="94" height="88" alt="' + item.title + '" /><p>' +item.title+'</p></a>';
	}
	return thisHTML;
}



function parseURLParams(){
	var tb = unescape($.getURLParam("tb"));
	var width = unescape($.getURLParam("width"));
	var height = unescape($.getURLParam("height"));
	if(width =="null"){width =  "900"}	
	if(height =="null"){height =  "450"}
	
	if(tb !="null"){
		tbURL = tb + "?width="+width+"&height=" + height;
		tb_show("", tbURL, null);
	}
}



function initFlip(){
	$('.contentFlip').bind("click",function(){
		// $(this) point to the clicked .contentFlip element (caching it in elem for speed):
		var elem = $(this);
		
		// data('flipped') is a flag we set when we flip the element:
		if(elem.data('flipped'))
		{
			// If the element has already been flipped, use the revertFlip method
			// defined by the plug-in to revert to the default state automatically:
			elem.revertFlip();
			
			// Unsetting the flag:
			elem.data('flipped',false)
		}
		else
		{
			// Using the flip method defined by the plugin:
			elem.flip({
				direction:'lr',
				speed: 350,
				onBefore: function(){
					// Insert the contents of the .contentData div (hidden from view with display:none)
					// into the clicked .contentFlip div before the flipping animation starts:
					elem.html(elem.siblings('.contentData').html());
				}
			});
			
			// Setting the flag:
			elem.data('flipped',true);
		}
	});
}

