$(document).ready(function(){
	$('div.answer').hide();
	$('p.question').css('color','#457E00').css('textDecoration','underline').css('cursor','pointer');
	$('p.question').hover(function() {
		$(this).css('color','#036');
	}, function() {
		$(this).css('color','#457E00');
	});
	$('p.question').click(function() {
		$(this).next('div').slideToggle()
		.siblings('div.answer:visible').slideUp('fast');	
	});
	
	
	$('a.custom_fb_iframe').fancybox({
       type:'iframe', 
       centerOnScroll: true, 
       width:440,
       height: 390,
       hideOnOverlayClick: false,
	   titleShow: false
	});
	if ($('body').hasClass("design_tab")){
		/*Override styles that were set for when javascript is disabled*/
		$('#northParkPhotos').css({'overflow': 'hidden'});
		$('.prevNorthPark').css('display', 'inline').css('cursor','default');
		$('.nextNorthPark').css('display', 'inline').css('cursor','pointer');
				
		$('#northParkPhotos').serialScroll({
			items:'li',
			prev:'.prevNorthPark',
			next:'.nextNorthPark',
			axis:'x',
			step:1,
			duration:1000,
			offset:-5,
			force:true,
			stop:true,
			lock:false,
			exclude:2,
			cycle:false, //don't pull back once you reach the end
			onBefore:function( e, elem, $pane, $items, pos ){
				$('.prevNorthPark').removeClass('disabledPrev');
				$('.nextNorthPark').removeClass('disabledNext');
				//if at the beginning of the strip
				if( pos == 0 ){ 
					//gray out the prev arrow
					$('.prevNorthPark').addClass('disabledPrev');
					//set the cursor to an arrow when over the prev arrow
					$('.prevNorthPark').css('display', 'inline').css('cursor','default');
					/*set the cursor to a pointer when over the next arrow so the user knows its clickable*/
					$('.nextNorthPark').css('display', 'inline').css('cursor','pointer');
				}
				//if at the end of the strip
				else if( pos == $items.length-3){
					//gray out the next arrow
					$('.nextNorthPark').addClass('disabledNext');	
					//set the cursor to an arrow when over the next arrow
					$('.nextNorthPark').css('display', 'inline').css('cursor','default');
					/*set the cursor to a pointer when over the prev arrow so the user knows its clickable*/
					$('.prevNorthPark').css('display', 'inline').css('cursor','pointer');
				}
				//if anywhere in the middle
				else {
					/*set the cursor to a pointer when over the prev arrow so the user knows its clickable*/
					$('.prevNorthPark').css('display', 'inline').css('cursor','pointer');
					/*set the cursor to a pointer when over the next arrow so the user knows its clickable*/
					$('.nextNorthPark').css('display', 'inline').css('cursor','pointer');
				}
			}
		});
		/*Override styles that were set for when javascript is disabled*/
		$('#schmulParkPhotos').css({'overflow': 'hidden'});
		$('.prevSchmulPark').css('display', 'inline').css('cursor','default');
		$('.nextSchmulPark').css('display', 'inline').css('cursor','pointer');
				
		$('#schmulParkPhotos').serialScroll({
			items:'li',
			prev:'.prevSchmulPark',
			next:'.nextSchmulPark',
			axis:'x',
			step:1,
			duration:1000,
			offset:-5,
			force:true,
			stop:true,
			lock:false,
			exclude:2,
			cycle:false, //don't pull back once you reach the end
			onBefore:function( e, elem, $pane, $items, pos ){
				$('.prevSchmulPark').removeClass('disabledPrev');
				$('.nextSchmulPark').removeClass('disabledNext');
				//if at the beginning of the strip
				if( pos == 0 ){ 
					//gray out the prev arrow
					$('.prevSchmulPark').addClass('disabledPrev');
					//set the cursor to an arrow when over the prev arrow
					$('.prevSchmulPark').css('display', 'inline').css('cursor','default');
					/*set the cursor to a pointer when over the next arrow so the user knows its clickable*/
					$('.nextSchmulPark').css('display', 'inline').css('cursor','pointer');
				}
				//if at the end of the strip
				else if( pos == $items.length-3){
					//gray out the next arrow
					$('.nextSchmulPark').addClass('disabledNext');	
					//set the cursor to an arrow when over the next arrow
					$('.nextSchmulPark').css('display', 'inline').css('cursor','default');
					/*set the cursor to a pointer when over the prev arrow so the user knows its clickable*/
					$('.prevSchmulPark').css('display', 'inline').css('cursor','pointer');
				}
				//if anywhere in the middle
				else {
					/*set the cursor to a pointer when over the prev arrow so the user knows its clickable*/
					$('.prevSchmulPark').css('display', 'inline').css('cursor','pointer');
					/*set the cursor to a pointer when over the next arrow so the user knows its clickable*/
					$('.nextSchmulPark').css('display', 'inline').css('cursor','pointer');
				}
			}
		});
		/*Override styles that were set for when javascript is disabled*/
		$('#owlHollowPhotos').css({'overflow': 'hidden'});
		$('.prevOwlHollow').css('display', 'inline').css('cursor','default');
		$('.nextOwlHollow').css('display', 'inline').css('cursor','pointer');
				
		$('#owlHollowPhotos').serialScroll({
			items:'li',
			prev:'.prevOwlHollow',
			next:'.nextOwlHollow',
			axis:'x',
			step:1,
			duration:1000,
			offset:-5,
			force:true,
			stop:true,
			lock:false,
			exclude:2,
			cycle:false, //don't pull back once you reach the end
			onBefore:function( e, elem, $pane, $items, pos ){
				$('.prevOwlHollow').removeClass('disabledPrev');
				$('.nextOwlHollow').removeClass('disabledNext');
				//if at the beginning of the strip
				if( pos == 0 ){ 
					//gray out the prev arrow
					$('.prevOwlHollow').addClass('disabledPrev');
					//set the cursor to an arrow when over the prev arrow
					$('.prevOwlHollow').css('display', 'inline').css('cursor','default');
					/*set the cursor to a pointer when over the next arrow so the user knows its clickable*/
					$('.nextOwlHollow').css('display', 'inline').css('cursor','pointer');
				}
				//if at the end of the strip
				else if( pos == $items.length-3){
					//gray out the next arrow
					$('.nextOwlHollow').addClass('disabledNext');	
					//set the cursor to an arrow when over the next arrow
					$('.nextOwlHollow').css('display', 'inline').css('cursor','default');
					/*set the cursor to a pointer when over the prev arrow so the user knows its clickable*/
					$('.prevOwlHollow').css('display', 'inline').css('cursor','pointer');
				}
				//if anywhere in the middle
				else {
					/*set the cursor to a pointer when over the prev arrow so the user knows its clickable*/
					$('.prevOwlHollow').css('display', 'inline').css('cursor','pointer');
					/*set the cursor to a pointer when over the next arrow so the user knows its clickable*/
					$('.nextOwlHollow').css('display', 'inline').css('cursor','pointer');
				}
			}
		});
		/*Override styles that were set for when javascript is disabled*/
		$('#southParkPhotos').css({'overflow': 'hidden'});
		$('.prevSouthPark').css('display', 'inline').css('cursor','default');
		$('.nextSouthPark').css('display', 'inline').css('cursor','pointer');
				
		$('#southParkPhotos').serialScroll({
			items:'li',
			prev:'.prevSouthPark',
			next:'.nextSouthPark',
			axis:'x',
			step:1,
			duration:1000,
			offset:-5,
			force:true,
			stop:true,
			lock:false,
			exclude:2,
			cycle:false, //don't pull back once you reach the end
			onBefore:function( e, elem, $pane, $items, pos ){
				$('.prevSouthPark').removeClass('disabledPrev');
				$('.nextSouthPark').removeClass('disabledNext');
				//if at the beginning of the strip
				if( pos == 0 ){ 
					//gray out the prev arrow
					$('.prevSouthPark').addClass('disabledPrev');
					//set the cursor to an arrow when over the prev arrow
					$('.prevSouthPark').css('display', 'inline').css('cursor','default');
					/*set the cursor to a pointer when over the next arrow so the user knows its clickable*/
					$('.nextSouthPark').css('display', 'inline').css('cursor','pointer');
				}
				//if at the end of the strip
				else if( pos == $items.length-3){
					//gray out the next arrow
					$('.nextSouthPark').addClass('disabledNext');	
					//set the cursor to an arrow when over the next arrow
					$('.nextSouthPark').css('display', 'inline').css('cursor','default');
					/*set the cursor to a pointer when over the prev arrow so the user knows its clickable*/
					$('.prevSouthPark').css('display', 'inline').css('cursor','pointer');
				}
				//if anywhere in the middle
				else {
					/*set the cursor to a pointer when over the prev arrow so the user knows its clickable*/
					$('.prevSouthPark').css('display', 'inline').css('cursor','pointer');
					/*set the cursor to a pointer when over the next arrow so the user knows its clickable*/
					$('.nextSouthPark').css('display', 'inline').css('cursor','pointer');
				}
			}
		});
	}

});

$(window).load(function () {
 	$currentText = new Array();
	$dateArray = new Array();	
	$dateArrayUnique = new Array();	
	$sortedDateArray = new Array();
	$textArray = new Array();
	$textString = "";
	$('.find_me').each(function(){
		$html = $(this).html();
		$currentText.push($html);
	});	
	
	$('.date').each(function(){
		$date = $(this).html();
		$dateArray.push($date);		
	});
	
	for (i in $dateArray){
		$dateArray[i] = Date.parse($dateArray[i]);
		if (i == 0){
			$dateArrayUnique.push($dateArray[i]);	
		}
		else {
			$flag = 0;
			for(j in $dateArrayUnique){
				if ($dateArrayUnique [j] == $dateArray[i]){
					$flag++;	
				}
			}
			if ($flag == 0){
				$dateArrayUnique.push($dateArray[i]);	
			}
		}
	}
	
	
	function sortNumber(a,b) {	return a - b; }
	$sortedDateArray = $dateArrayUnique.sort(sortNumber);

	for (j in $sortedDateArray){		
		for (k in $dateArray){			
			if ($sortedDateArray[j] == $dateArray[k]){
				$textArray.push ($currentText[k]);			
			}		
		}	
	}

	for (m in $textArray){
		$textString = $textString + " " + $textArray[m];	
	}
	$('div#fk_tours_events').html($textString);
	
	var num_events = $('.upcoming_event').length;
	if(num_events > 3) {
		$('.upcoming_event:gt(2)').hide();
		$('.upcoming_event:last').after('<p id="more_events_link"><a href="#">See more events</a></p>');
		$('#more_events_link').click(function(){
			$('.upcoming_event').show();
			$('#more_events_link').remove();
			return false;
		});
	}
});
