/* ------------
Global Scripts!
Site: inwilmingtonde.com
Author: Mobius New Media
------------ */

// add event to mywilmington
function addToMyWilmington( userID,eventID ) {
	//alert("add To My Wilmington - userID:"+userID + " eventID:"+eventID);
	// add this event to mywilmington 
	var theData = "userID=" + userID + "&eventID=" + eventID;
	
	$.ajax({
	   type: "POST",
	   url: "/includes/ajax_addEventToMyWilmington.php",
	   data: theData,
	   success: function(){
		alert("You have just added this item to myWilmington!");
		
	   }
	 });
}

// set reminder for event
function setEventReminder( userID,eventID ) {
	if ( $('#setReminderDiv:hidden') ) {
		$('#setReminderDiv').dialog('open');
		var theData = "userID=" + userID + "&eventID=" + eventID;
		//alert("setEventReminder: " + userID + " eventID:" + eventID);
	$.ajax({
	   type: "POST",
	   url: "/includes/ajax_getUserAndEventInfo.php",
	   data: theData,
	   dataType:"xml",
	   success: function(result){
		$(result).find("placeEventInfo").each(function() {
			var placeTitle = $(this).find('placeTitle').text();		
			var eventTitle = $(this).find('eventTitle').text();	
			var eventID = $(this).find('eventID').text();
			var nextDate = $(this).find('nextDate').text();
			var smsAddress = $(this).find('smsAddress').text();
			var suggestedReminderDate = $(this).find('suggestedReminderDate').text();
			var mainImageID = $(this).find('mainImageID').text();	
			var mainImageFileType = $(this).find('mainImageFileType').text();	
			
			var imageThumbnail_src = "/media/" + mainImageID +"/" + "thumbnail" + mainImageFileType;
			var reminderMessage = eventTitle  + "\nat " + placeTitle + "\nDate: "+ nextDate;
			var nextDateString = "Date: "+ nextDate;
			
			$("#reminderForm_nextDate").html( nextDateString );
    		//$("#reminderForm_placeName").html( $(this).attr("placeName") );
			//alert("place Title: " + placeTitle + "\n event Title: " +eventTitle + "\n event ID: " + eventID);
			
			$("#reminderForm_placeTitle").html( placeTitle );
			$("#reminderForm_eventID").val( eventID );
			$("#reminderForm_eventTitle").val( eventTitle );
			$("#reminderForm_eventTitleDisplay").html( eventTitle );
			$("#reminderForm_imageThumbnail").attr('src', imageThumbnail_src);
			$("#reminderMessage").val(reminderMessage);
			$("#reminderDate").val(suggestedReminderDate);
			$("#reminderSMS").val(smsAddress);
			
  			});
		
	   }
	 });
		return false;
	} else {
		$('#setReminderDiv').dialog('close');
	}
	return true;
}

/*function addClick(theLink, activity){
	//alert("addClick " + theLink + " : \n activity: " +activity);
	//addClick($userID,$objectID,$objectType,$organizationID,$dateTime,$link,$activity)
	var userID = <?php echo $userID?>;
	var objectID = <?php echo $eventID?>;
	var objectType = <?php echo EVENT?>;
	var organizationID = <?php echo $organizationID?>;
	var dateTime = '<?php echo $dateTime?>';
	var theData= "userID=" + userID + "&objectID=" + objectID + "&objectType=" + objectType + "&organizationID=" + organizationID + "&dateTime=" + dateTime + "&link=" + theLink + "&activity=" + activity;
	
	$.ajax({
	   type: "POST",
	   url: "/includes/ajax_addClick.php",
	   data: theData,
	   success: function(returnMessage){
	  // alert('result: ' + returnMessage);
	   }
	 });	
	return true;
}*/

function truncateTitles() {
	// truncate card titles
	$('.eventList li h3 a, .eventList li h4, .eventList li h2').not('.eventList li.feature h2').truncate({
		width: '157',
		after: '&hellip;',
		center: false,
		addtitle: true // adds title attribute with original content
	}).show( function(){
		$('#loading').remove();
	});
	
}

$(document).ready(function() {
	
	
	// truncate card titles
	truncateTitles();
	
	
	// search result filter
	$('.searchFilter li a').click(function() {
		var theLinkID = $(this).attr('id');
		var theDivID = theLinkID.substr(5);
		$('.searchFilter li').removeClass('current');
		$(this).parent('li').addClass('current');
		if ( theLinkID == 'link_everything' ) {
			// shows everything
			$('div.searchCategory').fadeIn();
		} else {
			// shows selected results
			$('div.searchCategory').hide();
			$('#' + theDivID).fadeIn();
		}
	});
	
	
	// start additional media gallery scroller
	$(".additionalMediaScrollable").scrollable({ 
		speed : 1000, 
		mousewheel: false, 
		circular: false
	});
	
	// lightbox for large images
	$("a.lightbox").fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	300, 
		'overlayShow'	:	true,
		'overlayOpacity':	.5,
		'overlayColor' 	:	'#000',
		'titlePosition'	:	'inside',
		'transitionIn'	: 	'elastic',
		'transitionOut'	: 	'elastic'
	});
	
	// mywilmington dropdown menu animation
	$('#myWilmingtonLink > li, #nav > li, #nav li li').removeClass('hover');
	$('#myWilmingtonLink > li, #nav > li, #nav li li').hoverIntent(function() {
		$(this).children('ul').slideToggle();
	}, function() {
		$(this).children('ul').slideToggle();
	});
	
	// table zebra striping
	$('.listTable tr:even').addClass('alt');
	
	// weather feed from yahoo						
	$('#weather').weatherfeed(
	  ['USDE0055'],
	  {unit: 'f', wind: false, image: false, link: false, highlow: false}
	);//weatherfeed
	
	// tabbed box on detail pages
	$("#tabs").tabs();
	
	// set reminder dialog box
	$('#setReminderDiv').dialog({
		autoOpen: false,
		width: 800,
		height: 500,
		modal: true,
		buttons: {
			"Cancel": function() { 
				$(this).dialog("close"); 
			},
			"Set Reminder" : function() {
				setEventReminderSubmit();
			}
		}
	});
	
	// date picker
	$(".datePicker").datepicker({
		dateFormat: 'yy-mm-dd',
		changeMonth: true,
		//ampm: true
	});
	
	$('.timePicker').timepicker({
		timeFormat: 'hh:mm tt',
		ampm: true,
		stepMinute: 5
	});
	$('.reminderTimePicker').timepicker({
		timeFormat: 'hh:mm tt',
		ampm: true,
		stepHour: 1,
		hour: 6,
		showMinute:false,
		minute: 0
	});
	// set reminder date field to a week before the selected event
	var oneWeekBeforeDate = $('#reminderDate');
	oneWeekBeforeDate.datetimepicker('setDate', (new Date(2011, 05, 11, 20, 00)) );
	
	// form validation - set reminder
	$("#setEventReminderForm").validate({
		rules: {
			reminderDate: "required",
			reminderEmail: {
				required: true,
				email: true
			},
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			reminderDate: "Please select a date.",
			reminderEmail: "Please enter the email address."
		}
	});
	
	// form validation - suggest an event
	$("#suggestEvent_form").validate({
		rules: {
			event_name: "required",
			event_description: "required",
			startDate: "required",
			startTime: "required",
			place_name: "required",
			place_address: "required",
			place_city: "required",
			contact_name: "required",
			contact_email: {
				required: true,
				email: true
			},
			contact_phone: "required",
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			event_name: "Please enter the event name.",
			event_description: "Please enter the event description.",
			startDate: "Please select a start date.",
			startTime: "Please select a start time.",
			place_name: "Please enter the place name.",
			place_address: "Please enter the street address.",
			place_city: "Please enter the city.",
			contact_name: "Please enter your name.",
			contact_email: "Please enter you email address.",
			contact_phone: "Please enter your phone number."
		}
	});
	
	// form validation - contact form
	$("#contact_form").validate({
		rules: {
			contact_name: "required",
			contact_email: {
				required: true,
				email: true
			},
			contact_comments: "required",
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			contact_name: "Please enter your name.",
			contact_email: "Please enter the email address.",
			contact_comments: "Please enter your message."
		}
	});
	
	// form validation - qr contest winner form
	$("#qrWinnerForm").validate({
		rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			phone: "required",
			address: "required",
			//address2: "required",
			city: "required",
			state: "required",
			zip: "required",
			seriesPrizes: "required"
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			name: "Please enter your first and last name.",
			email: "Please enter the email address.",
			phone: "Please enter your phone number.",
			address: "Please enter your address.",
			//address2: "Please enter your",
			city: "Please enter your city.",
			state: "Please select your state.",
			zip: "Please enter your 5-digit zip code.",
			seriesPrizes: "Please select a prize."
		}
	});
	
	// submit function for set event reminder form
	function setEventReminderSubmit() {
		var mediaFormResult = $('#setEventReminderForm').validate().form();
		if ( mediaFormResult == true ) { // if form validates, submit form and close dialog
			//alert('validated');
			$('#setEventReminderForm').submit();
			$('#setReminderDiv').dialog("close"); 
		} else { // if form does not validate, do nothing
			alert ('not validated');
		}
	}
	
	
	
	// event listing page > hide active category's bottom bar link
	var theCurrentEventListing = $('.categoryBar').attr('id');
	//alert( 'the current event listing is ' + theCurrentEventListing );
	if ( theCurrentEventListing == 'music' ) {
		$('#bottomBar_music').hide();
	}
	if ( theCurrentEventListing == 'artsEntertainment' ) {
		$('#bottomBar_arts').hide();
	}
	if ( theCurrentEventListing == 'foodDrink' ) {
		$('#bottomBar_food').hide();
	}
	
	// function to run when you reach the bottom of the page by scrolling
	$(window).scroll(function(){
       if($(document).height()==$(window).scrollTop()+$(window).height()){
           //alert('bottom');
           // show something, load content via ajax etc
       }
    });
	
	// login form validation
	$("#frmLogin").validate({
		rules: {
			txtUserId: {
				required: true,
				email: true
			},
			txtPassword: "required"
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			txtUserId: "Please enter your email address.",
			txtPassword: "Please enter your password."
		}
	});
   
   // advanced search reveal
   $('#advancedSearchLink').toggle(function(){
   		$('#advancedSearchDiv').slideDown('slow');
		$(this).children('span.icon').removeClass('icon-preview').addClass('icon-notick');
		$("#advancedSearchMode").val(1);
   }, function() {
	   $('#advancedSearchDiv').slideUp('slow');
	   $(this).children('span.icon').removeClass('icon-notick').addClass('icon-preview');
	   $("#advancedSearchMode").val(0);
   });
	
   // image caption magic!
   $('.imgCaptionDiv').each(function(){
	   var theImageWidth = $(this).children('img').width() + 1; // + 1 to include border
	   var theImageHeight = $(this).children('img').height() + 1; // + 1 to include border
	   //alert('the image width is ' + theImageWidth + ' and the height is ' + theImageHeight);
	   $(this).width( theImageWidth ).height( theImageHeight );
   });
   
   // footer social media icon animation on hover
   $('#socialMediaIcons li').hoverIntent(function(){
	   $(this).animate({ bottom: '20px' }, 700);
   }, function(){
	   $(this).animate({ bottom: '0px' }, 500);
   });
   
   /* maintenance message box */
   // hide div on click, set cookie
   $('#maintenance-close').click(function(){
	   $('#maintenancemode').fadeOut('slow');
	   $.cookie('maintenance-cookie', 'closed');
	 
   });
   // if cookie is set don't show message again
   if( $.cookie('maintenance-cookie') == "closed" ) {
		 $('#maintenancemode').hide();
	} else {
		$('#maintenancemode').show();
	}
	
	if ( $('.additionalMediaScrollable > ul').children().length == 1 ) {
		 //alert('only one media item!');
		 $('.additionalMedia').hide();
	}

   	
});//close doc ready functions




/* ------------
Homepage Scripts Only!
------------ */


if( $('body').attr('id') == 'body_home' ) {

$(document).ready(function() {
						   
	
	// start music events on homepage
	$("#music .mainBarScrollable").scrollable({ 
		speed : 1000, 
		mousewheel: false, 
		circular: false
	}).autoscroll({ 
		autoplay: true, 
		interval: 5000 
	});
	// start arts events on homepage
	$("#artsEntertainment .mainBarScrollable").scrollable({ 
		speed : 1000, 
		mousewheel: false, 
		circular: false
	}).autoscroll({ 
		autoplay: true, 
		interval: 6000 
	});
	// start food events on homepage
	$("#foodDrink .mainBarScrollable").scrollable({ 
		speed : 1000, 
		mousewheel: false, 
		circular: false
	}).autoscroll({ 
		autoplay: true, 
		interval: 7000 
	});
	// go to first event in scrollable list on homepage
	$('.icon-doubleArrowL').click(function() {
		$(this).parent('.leftBar').next('.mainBarScrollable').data("scrollable").begin(2000);
	});
	// go to last event in scrollable list on homepage
	$('.icon-doubleArrowR').click(function() {
		var eventListSize = $(this).parent('.rightBar').prev('.mainBarScrollable').data("scrollable").getSize();
		var lastEventIndex = eventListSize - 4;
		//alert('my list has ' + eventListSize + ' events');
		$(this).parent('.rightBar').prev('.mainBarScrollable').data("scrollable").seekTo(lastEventIndex,2000);
	});
	// when it reaches the last music event, scroll back to beginning
	$('#music .mainBarScrollable').data("scrollable").onSeek(function(event, index) {
		var musicListSize = $('#music .mainBarScrollable').data("scrollable").getSize();
		var musicLastEventIndex = musicListSize - 1;
		//var musicIndex = $('#music .scrollable').data("scrollable").getIndex();
		if( $('#music .mainBarScrollable').data("scrollable").getIndex() == musicLastEventIndex ) {
			// get more music
			//getNextMusicEvents();
			//alert('Music has reached the last event!');
			//$('#music .mainBarScrollable').data("scrollable").begin(2000);
		}
	});
	// when it reaches the last arts event, scroll back to beginning
	$('#artsEntertainment .mainBarScrollable').data("scrollable").onSeek(function(event, index) {
		var artListSize = $('#artsEntertainment .mainBarScrollable').data("scrollable").getSize();
		var artLastEventIndex = artListSize - 1;
		if( $('#artsEntertainment .mainBarScrollable').data("scrollable").getIndex() == artLastEventIndex ) {
			//getNextArtsEvents();
			//$('#artsEntertainment .mainBarScrollable').data("scrollable").begin(2000);
		}
	});
	// when it reaches the last food event, scroll back to beginning
	$('#foodDrink .mainBarScrollable').data("scrollable").onSeek(function(event, index) {
		var foodListSize = $('#foodDrink .mainBarScrollable').data("scrollable").getSize();
		var foodLastEventIndex = foodListSize - 1;
		if( $('#foodDrink .mainBarScrollable').data("scrollable").getIndex() == foodLastEventIndex ) {
			// get more food and drink
			$('#foodDrink .mainBarScrollable').data("scrollable").begin(2000);
		}
	});
	
	$('#food-pause').toggle(function() {
		$(this).removeClass('icon-pause').addClass('icon-play').attr('title','Play');
		$('#foodDrink > .scrollable').data("scrollable").stop();
	},function(){
		$(this).removeClass('icon-play').addClass('icon-pause').attr('title','Pause');
		$('#foodDrink > .scrollable').data("scrollable").play();
	});
	
	$('#arts-pause').toggle(function() {
		$(this).removeClass('icon-pause').addClass('icon-play').attr('title','Play');
		$('#artsEntertainment > .scrollable').data("scrollable").stop();
	},function(){
		$(this).removeClass('icon-play').addClass('icon-pause').attr('title','Pause');
		$('#artsEntertainment > .scrollable').data("scrollable").play();
	});
	
	$('#music-pause').toggle(function() {
		$(this).removeClass('icon-pause').addClass('icon-play').attr('title','Play');
		$('#music > .scrollable').data("scrollable").stop();
	},function(){
		$(this).removeClass('icon-play').addClass('icon-pause').attr('title','Pause');
		$('#music > .scrollable').data("scrollable").play();
	});
	
});

} // end homepage scripts


/* ------------
myWilmington Scripts Only!
------------ */


if( $('body').attr('id') == 'body_myWilmington' ) {

// hide event instances in cms
function hideEventInstances(){
	$('#eventInstances > .eventInstance').not('#eventInstance1').hide();
	$('#eventInstances').prepend("<a id='eventInstances-show' class='submit' href='javascript:'>Show All Dates &amp; Times</a>");
	$('#eventInstances-show').toggle(function(){
		$('#eventInstances > .eventInstance').show();
		$(this).html('Hide All Dates &amp; Times');
	},function(){
		$('#eventInstances > .eventInstance').not('#eventInstance1').hide();
		$(this).html('Show All Dates &amp; Times');
	});
}

$(document).ready(function() {
	
	// form validation - forgot password
	$("#form_forgotPassword").validate({
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			email: "Please enter the email address."
		}
	});
	
	// form validation - add/edit organization
	$("#form_organization").validate({
		rules: {
			title: "required",
			phone: "required"
			//description: "required"
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			title: "Please enter the name.",
			phone: "Please enter the phone number."
			//description: "Please enter description."
		}
	});
	
	// form validation - add/edit event
	$("#form_event").validate({
		rules: {
			title: "required",
			placeID: "required",
			postDate: "required",
			//description: "required",
			keywords: "required",
			primaryCategory: "required",
			category: "required"
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			title: "Please enter the title.",
			placeID: "Please select the place.",
			postDate: "Please enter the post date.",
			//description: "Please enter the description.",
			keywords: "Please enter the search keywords.",
			primaryCategory: "Please select the primary category.",
			category: "Please select at least one secondary category."
		}
	});
	
	// form validation - add/edit place
	$("#form_place").validate({
		rules: {
			title: "required",
			address: "required",
			city: "required",
			state: "required",
			zip: "required",
			phone: "required",
			//description: "required",
			keywords: "required",
			placeCategory: "required"
			
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			title: "Please enter the title.",
			address: "Please enter the address.",
			city: "Please enter the city.",
			state: "Please select the state.",
			zip: "Please enter the zip code.",
			phone: "Please enter the phone number.",
			//description: "Please enter the description.",
			keywords: "Please enter the search keywords.",
			placeCategory: "Please select at least one category."
			
		}
	});

	// form validation - add/edit parking
	$("#form_parking").validate({
		rules: {
			title: "required",
			address: "required",
			city: "required",
			state: "required",
			zip: "required",
			//description: "required"
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			title: "Please enter the title.",
			address: "Please enter the address.",
			city: "Please enter the city.",
			state: "Please select the state.",
			zip: "Please enter the zip code.",
			//description: "Please enter the description."
		}
	});
	
	// form validation - add/edit user
	$("#form_user").validate({
		rules: {
			theFirstName: "required",
			theLastName: "required",
			email: {
				required: true,
				email: true
			},
			password: {
				required: true,
				minlength: 4
			},
			passwordConfirm: {
				required: true,
				equalTo: "#password"
			}
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
			 //element.val( error );
		},
		messages: {
			theFirstName: "Please enter the first name.",
			theLastName: "Please enter the last name.",
			email: "Please enter a valid email address.",
			password: "Please enter a password of at least 4 characters.",
			passwordConfirm: "Please re-enter the password."
		}
	});

	// dim my past events in mywilmington
	$('.pastEvents .eventList li').fadeTo( 'slow' , 0.5 );
	
	// start upcoming events scrollable on mywilmington
	$(".upcomingEvents .mainBarScrollable").scrollable({ 
		speed : 1000, 
		mousewheel: false, 
		circular: false
	});
	// start past events scrollable on mywilmington
	$(".pastEvents .mainBarScrollable").scrollable({ 
		speed : 1000, 
		mousewheel: false, 
		circular: false
	});
	// start suggested events scrollable on mywilmington
	$(".suggestedEvents .mainBarScrollable").scrollable({ 
		speed : 1000, 
		mousewheel: false, 
		circular: false
		//vertical: true
	});
	
	// go to first event in scrollable list on mywilmington
	$('.icon-doubleArrowL').click(function() {
		$(this).parent('.inlineBarLeft').next('.mainBarScrollable').data("scrollable").begin(2000);
	})
	
	// go to first event in vertical scrollable list on mywilmington
	$('.icon-doubleArrowU').click(function() {
		$(this).parent('.verticalBarLeft').next('.mainBarScrollable').data("scrollable").begin(2000);
	})
	
	// go to last event in scrollable list on mywilmington
	$('.icon-doubleArrowR').click(function() {
		var eventListSize = $(this).parent('.inlineBarRight').prev('.mainBarScrollable').data("scrollable").getSize();
		var lastEventIndex = eventListSize - 4;
		//alert('my list has ' + eventListSize + ' events');
		$(this).parent('.inlineBarRight').prev('.mainBarScrollable').data("scrollable").seekTo(lastEventIndex,2000);
	});
	
	// go to last event in vertical scrollable list on mywilmington
	$('.icon-doubleArrowD').click(function() {
		var eventListSize = $(this).parent('.verticalBarRight').prev('.mainBarScrollable').data("scrollable").getSize();
		var lastEventIndex = eventListSize - 1;
		//alert('my list has ' + eventListSize + ' events');
		$(this).parent('.verticalBarRight').prev('.mainBarScrollable').data("scrollable").seekTo(lastEventIndex,2000);
	});
	
	//currentMainImage
	$('#currentMediaDiv img:first').addClass('currentMainImage').attr('title','This is the main image');
	
	
	
});//close doc ready functions

function vanityURL_Check(objectID,objectType){
var theVanityURL = $("#vanityURL").val();
//alert("checking vanityURL objectID: " + objectID);
if( theVanityURL.length > 0){
	var theData = "vanityURL=" + theVanityURL + "&objectType=" +objectType+ "&objectID=" +objectID;
		
		$.ajax({
		   type: "POST",
		   url: "includes/ajax_checkDuplicateVanityURL.php",
		   data: theData,
		   success: function(resultcode){
			
			if(resultcode > 0){
				//alert("Sorry, that URL is already taken. Please try another one. [ "+ resultcode +"]");
				alert("Sorry, that URL is already taken. Please try another one.");
				$('#vanityURL').val("").focus().prev('label').children('.icon-checkMark').addClass('invisible');
			}else{
				$('#vanityURL').prev('label').children('.icon-checkMark').removeClass('invisible');
				//alert("vanityURL is a good one " + resultcode);
			}
			vanityURL_is_valid = resultcode;
		   }
		 });
}
return ;
}

function checkDuplicateEmail(){
var email = $("#email").val();
var userID = $("#userID").val();
//alert("checkDuplicateEmail : " + email + "\n userID:" + userID);
if( email.length > 0){
	var theData = "email=" + email + "&userID=" +userID;;
		$.ajax({
		   type: "POST",
		   url: "includes/ajax_checkDuplicateEmail.php",
		   data: theData,
		   success: function(resultcode){
			//alert("resultcode" + resultcode);
			if(resultcode > 0){
				alert("Sorry, that Email Address is already taken. Please use another one.");
				//alert("Sorry, that Email Address is already taken. Please use another one. [ "+ resultcode +"]");
				$("#email").val("").focus().prev('label').children('.icon-checkMark').addClass('invisible');
			}else{
			//alert("That email address is available " + resultcode);
			$('#email').prev('label').children('.icon-checkMark').removeClass('invisible');
			}
			
		   }
		 });
}
return ;
}

} // end mywilmington scripts


/* ------------
Splash Page Scripts!
------------ */


if( $('body').attr('id') == 'body_splash' ) {

// open hot picks window
function eventHotPicks() {
	$('#hotPickEvents').animate({ 'top': '90px'}, 2000, 'swing').addClass('open');
	$('#nav_hotPicks').addClass('selected');
}
// scrolling background for clouds
var newleftclouds = 0;
function scrollClouds() {
	$('#clouds').css({
		backgroundPosition: newleftclouds + 'px' + ' 90px' 
	});
	newleftclouds -= 1;
}
// get current scroll position to show details
function getCurrentScrollPosition() {
		
	var currentScrollPosition = $("#subjectsWrap").data("scrollable").getIndex();
	$("#subjects img").removeClass('currentScrollItem').next('.scrollDetail').fadeOut('fast');
	$("#subjects img:eq(" + currentScrollPosition + ")").addClass('currentScrollItem').next('.scrollDetail').fadeIn('slow');
	//alert('the current scroll item is ' + currentScrollPosition);
}
$(document).ready(function() {
	
	// scrolling background image call				   	
	var timerclouds = setInterval(scrollClouds, 100);
	
	// show what's hot on delay
	//setTimeout(flashWhatshot, 5000);
	
	// open what's hot window
	$('#nav_hotPicks > a').click(function() {
		$('#hotPickEvents').animate({ 'top': '90px'}, 2000, 'swing');
		$('#nav_hotPicks').addClass('selected');
	});
	
	// close what's hot window
	$('#closeHotPicks').click(function() {
		$('#hotPickEvents').animate({ 'top': '-240px'}, 1000, 'swing');
		$('#nav_hotPicks').removeClass('selected');
	});
	
	// scrollable background
	$("#subjectsWrap").scrollable({ 
		speed : 2000, 
		mousewheel: false, 
		circular: false,
		onSeek: getCurrentScrollPosition
	}).autoscroll({ 
		autoplay: true, 
		interval: 10000 
	});
	
	// scrollable hot picks
	$("#hotPickEvents .mainBarScrollable").scrollable({ 
		speed : 1000, 
		mousewheel: false, 
		circular: false
	});
	
	// get current scroll position on load
	getCurrentScrollPosition();
	
	// go to first event in scrollable list on homepage
	$('#scrollToFirst').click(function() {
		$("#subjectsWrap").data("scrollable").begin(2000);
	});
	
	// go to first event in hot picks
	$('#hotPickEvents .icon-doubleArrowL').click(function() {
		$(this).parent('.inlineBarLeft').next('.mainBarScrollable').data("scrollable").begin(2000);
	})
	
	// go to last event in hot picks
	$('#hotPickEvents .icon-doubleArrowR').click(function() {
		var eventListSize = $(this).parent('.inlineBarRight').prev('.mainBarScrollable').data("scrollable").getSize();
		var lastEventIndex = eventListSize - 1;
		//alert('my list has ' + eventListSize + ' events');
		$(this).parent('.inlineBarRight').prev('.mainBarScrollable').data("scrollable").seekTo(lastEventIndex,2000);
	});
	
	// go to last event in scrollable list on homepage
	$('#scrollToLast').click(function() {
		var eventListSize = $("#subjectsWrap").data("scrollable").getSize();
		var lastEventIndex = eventListSize - 2;
		//alert('my list has ' + eventListSize + ' events');
		$("#subjectsWrap").data("scrollable").seekTo(lastEventIndex,2000);
	});
	
	// focus on scrollable 
	$("#subjectsWrap").data("scrollable").focus();
	
	// when it reaches the last item, scroll back to beginning
	$('#subjectsWrap').data("scrollable").onSeek(function(event, index) {
		var musicListSize = $('#subjectsWrap').data("scrollable").getSize();
		var musicLastEventIndex = musicListSize - 1;
		//var musicIndex = $('#music .scrollable').data("scrollable").getIndex();
		if( $('#subjectsWrap').data("scrollable").getIndex() == musicLastEventIndex ) {
			//alert('Music has reached the last event!');
			$('#subjectsWrap').data("scrollable").begin(2000);
		}
	});
	
	/* lightbox */
	$("a.lightbox").fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	300, 
		'overlayShow'	:	true,
		'overlayOpacity':	.5,
		'overlayColor' 	:	'#000',
		'titlePosition'	:	'inside',
		'transitionIn'	: 	'elastic',
		'transitionOut'	: 	'elastic'
	});
	
	// form validation - email signup
	$("#signupForm").validate({
		rules: {
			fields_email: "required"
		},
		errorPlacement: function(error, element) {
			 error.appendTo( element.parent("div") );
		},
		messages: {
			fields_email: "Please enter your email address."
		}
	});
	
	
}); // doc ready end

} // end splash page scripts
