var pictures = new Array();
var pictureIndex = 0;
var PICTURE_TIMER = 5000;


var posters = new Array();
var poster_link = new Array();
var posterIndex = 0;
var POSTER_TIMER = 5500;

$(document).ready(function() {
	$(".menu-bar").buttonset();
	$(".button").button();
	$(".datepicker").datepicker();
  $(".defaultPop").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600,
		'speedOut'		:	200,
		'overlayShow'	:	true
	});
  loadPictures();
  loadPosters();
	startPictureCarouselTimer();
	startPosterCarouselTimer();
	setupFrames();
	setupMenuDropDown();
});

function loadPictures(){
  $("#carousel_images").find("input").each(function(index){
    pictures[index] = $(this).val();
  });
}

var blur = 0;
function setupMenuDropDown() {
	$('#pub-drop-down').hide();
	$('#main-menu').mouseover(function(){
		$('#pub-drop-down').show();
	});
	$('#menu-bar').hover( function(){
	}, function(){
		$('#pub-drop-down').hide();
	} );
}

function setupFrames() {
	$(".menuIframe").fancybox({
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'speedIn' : 600,
		'speedOut' : 200,
		'height' : '90%',
		'width' : '60%',
		'overlayShow' : true
	});
	$(".mapIframe").fancybox({
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'speedIn' : 600,
		'speedOut' : 200,
		'height' : '90%',
		'width' : '90%',
		'overlayShow' : true
	});
	$(".tourIframe").fancybox({
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'speedIn' : 600,
		'speedOut' : 200,
		'height' : 520,
		'width' : 730,
		'overlayShow' : true
	});
	$(".feedbackPop").fancybox({
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'speedIn' : 600,
		'speedOut' : 200,
		'height' : 470,
		'width' : 730,
		'overlayShow' : true
	});
	$(".defaultPop").fancybox({
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'speedIn' : 600,
		'speedOut' : 200,
		'overlayShow' : true
	});
	$("a.iframe").click(function() {
		$("a.iframe").resize();
	});
	$(".time-slider").slider({
		value : 1800,
		min : 800,
		max : 2300,
		step : 50,
		slide : function(event, ui) {
			var val = parseInt(ui.value);
			$("#amount").val(convertTimeString(val));
		}
	});
	var val = $(".time-slider").slider("value");
	$("#amount").val(convertTimeString(parseInt(val)));
	clickButton($('.menu_button:first'));
}

function convertTimeString(timeVal) {
	var minutes = (timeVal % 100) * .6;
	if (minutes == 0) {
		minutes = '00';
	}
	var hours = parseInt(timeVal / 100);
	var timestr = hours + ":" + minutes + "am";
	var daySplit = "am";
	if (hours >= 12) {
		daySplit = "pm";
	}
	if (hours > 12) {
		hours = hours - 12;
	}
	return hours + ":" + minutes + daySplit;
}

function clickButton(button) {
	button.attr('checked', true);
	button.button("refresh");
	button.click();
}

function startPictureCarouselTimer() {
	$('.pictures #image2').hide();
	setTimeout('nextPicture()', PICTURE_TIMER);
}

function nextPicture() {

	$('.pictures #image1').effect('drop', null, 500, function() {
		var nextImage = pictures[nextPictureIndex()];

		$('.pictures #image1 img').attr("src", nextImage);
		$('.pictures #image1').removeAttr("style").hide().fadeIn();

		pictureIndex = nextPictureIndex();
		startPictureCarouselTimer();
	});
}

function nextPictureIndex() {
	return (pictureIndex + 1) % pictures.length;
}


function loadPosters(){
  $("#eventPosters_small").find("input").each(function(index){
    posters[index] = $(this).val();
  });

  $("#eventPosters_large").find("input").each(function(index){
    poster_link[index] = $(this).val();
  });
}

function startPosterCarouselTimer() {
	$('.posters #image2').hide();
	setTimeout('nextPoster()', POSTER_TIMER);
}

function nextPoster() {

	$('.posters #image1').effect('fade', null, 500, function() {
		var nextImage = posters[nextPosterIndex()];
		var nextLink = poster_link[nextPosterIndex()];

		$('.posters #image1 img').attr("src", nextImage);
		$('.posters #image1 a').attr("href", nextLink);
		$('.posters #image1').removeAttr("style").hide().fadeIn();

		posterIndex = nextPosterIndex();
		startPosterCarouselTimer();
	});
}

function nextPosterIndex() {
	return (posterIndex + 1) % posters.length;
}
