/**
 * Homepage form carousel: We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a.bind').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

// HTML value for homepage carousel with infinite loop has to be defined here
var removed_from_carousel = [
  '<li class="callout-member"><h3 class="callout-h3">Member Search</h3><p class="callout-p"><a href="/index.html?search=member">Want to network with others in the events industry? Find event managers, attendees, planners, exhibitors and more on EIA.</a></p></li>',
  '<li class="callout-rsvp"><h3 class="callout-h3">Advance Networking</h3><p class="callout-p"><a class="youtube" href="http://www.youtube.com/v/_7eXnslRdW0&rel=0">Announce your participation at an upcoming event. Network with others ahead of time.</a></p></li>',
  '<li class="callout-search"><h3 class="callout-h3">Membership Benefits</h3><p class="callout-p"><a class="youtube" href="http://www.youtube.com/v/_7eXnslRdW0&amp;rel=0">Search our event listings. Save common searches. Sync to your desktop calendar. Share info with colleagues.</a></p></li>',
  '<li class="callout-cons"><h3 class="callout-h3">Need Help Planning Your Event?</h3><p class="callout-p"><a href="/concierge.html">EIA can provide assistance in facility and supplier selection, event management and marketing. Contact Us for details.</a></p></li>',
  '<li class="callout-video"><h3 class="callout-h3">Video Tutorials</h3><p class="callout-p"><a class="iframe" href="http://www.youtube.com/eiavids">Want to know how easy it is to use Events in America? Click here to see our video tutorials.</a></p></li>'
];
var mycarousel2_itemList = [
  '<li class="callout-supplier"><h3 class="callout-h3">Partner Benefits</h3><p class="callout-p"><a class="youtube" href="http://www.youtube.com/v/_7eXnslRdW0&rel=0">Serve the events industry? Create your preferred partner page and win sales through Events In America.</a></p></li>',
  '<li class="callout-hotel"><h3 class="callout-h3">Hotel Benefits</h3><p class="callout-p"><a class="youtube" href="http://www.youtube.com/v/_7eXnslRdW0&rel=0">Host conventions, meetings, events and trade shows at your hotel? Make sure your facility is listed on EIA to receive RFPs.</a></p></li>'
];
function mycarousel2_itemVisibleInCallback(carousel, item, i, state, evt)
{
    var idx = carousel.index(i, mycarousel2_itemList.length);
    carousel.add(i, mycarousel2_itemList[idx - 1]);
    jQuery("#mycarousel2 .youtube").colorbox({iframe:true, width:650, height:550});
	jQuery("#mycarousel2 .iframe").colorbox({width:"80%", height:"80%", iframe:true});
};

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

jQuery(document).ready(function() {
	
	// Superfish dropdown menu
    jQuery('ul.sf-menu').superfish({
      autoArrows: false,
      dropShadows: false
    });
    // put empty list in #mycarousel2, for validation purposes
    jQuery("#mycarousel2").html("<ul></ul>");
    jQuery("#mycarousel").jcarousel({
        scroll: 1,
        start: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
	
    jQuery("#mycarousel2").jcarousel({
    	auto: 5,
    	scroll: 1,
      	itemVisibleInCallback: {onBeforeAnimation: mycarousel2_itemVisibleInCallback},
      	itemVisibleOutCallback: {onAfterAnimation: mycarousel2_itemVisibleOutCallback},
    	buttonNextHTML: null,
    	buttonPrevHTML: null
    });
    
    jQuery("form.jqtransform").jqTransform();
    
    // This replaces the input values with defaults in the forms using onFocus and onBlur actions
    var formPrompts = {
      eventKeywords: 'event name, keyword, venue or contact',
      eventStartDate: 'starting date range (optional)',
      eventEndDate: 'ending date range (optional)',
      eventCity: 'city (optional)',
      supplierKeywords: 'company name or keywords',
      supplierCity: 'city',
      venueKeywords: 'facility name',
      venueSeating: 'estimated seating capacity',
      venueMeeting: 'estimated meeting rooms',
      venueSleeping: 'estimated sleeping rooms',
      venueRoomSize: 'largest meeting room size (sq ft)',
      memberKeywords: 'keywords or professional interests',
      memberKeywords2: 'member name or email address',
      memberName: 'member name',
      memberEmail: 'email address',
      memberCity: 'city',
      cvbKeywords: 'CVB name, Convention Center name, keyword or contact',
      cvbmeeting_space: 'estimated meeting space (sf)',
      cvblargest_ballroom: 'estimated ballroom space (sf)',
      cvbCity: 'city',
      event_plannerKeywords: 'company or individual name or keywords',
      event_plannerCity: 'city'
    }
    function resetFormPrompts() {
      jQuery('form input').each(function() {
        if(jQuery(this).attr('value') != formPrompts[jQuery(this).attr('id')]) {
          jQuery(this).attr('value', formPrompts[jQuery(this).attr('id')]);
        }
      });
    }
    resetFormPrompts();
    jQuery('form input').focus(function() {
      if(jQuery(this).attr('value') == formPrompts[jQuery(this).attr('id')]) {
        jQuery(this).attr('value', '');
      }
    });
    jQuery('form input').blur(function() {
      if(jQuery(this).attr('value') == '') {
        jQuery(this).attr('value', formPrompts[jQuery(this).attr('id')]);
      }
    });
    
    // This tells the jQuery validationEngine what forms to validate
    jQuery('#event-form-actual, #supplier-form-actual, #event-planner-form-actual, #venue-form-actual, #member-form-actual, #cvb-form-actual').validationEngine();
    
    // This initializes the jQuery datepicker
    jQuery('.datepicker').datepicker();
    
    //Examples of how to assign the ColorBox event to elements
	jQuery("a[rel='colorbox']").colorbox();
	jQuery(".colorbox").colorbox();
	jQuery(".youtube").colorbox({iframe:true, width:650, height:435});
	jQuery(".iframe").colorbox({width:"80%", height:"80%", iframe:true});
	jQuery(".login").colorbox({iframe:true, width:700, height: 325});
    
});
