function wealth_buttonCallback(carousel, item, idx, state) {
    var str = $("#wealth .slider > li:eq(" + (idx - 1) + ") h3.hidden").text();
    $("#wealth h2 span").html(str);
};

function videos_initCallback(carousel) {    
    jQuery("#videos_next").bind("click", function() {
        carousel.next();
        return false;
    });

    jQuery("#videos_prev").bind("click", function() {
        carousel.prev();
        return false;
    });
    
};

function videos_buttonNextCallback(carousel, button, enabled) {
    jQuery("#videos_next").removeClass("enabled disabled");
    jQuery("#videos_next").addClass(enabled ? "enabled" : "disabled");
};

function videos_buttonPrevCallback(carousel, button, enabled) {
    jQuery("#videos_prev").removeClass("enabled disabled");
    jQuery("#videos_prev").addClass(enabled ? "enabled" : "disabled");
};

function featured_initCallback(carousel) {
    jQuery("#featured_box .controls li a").bind("click", function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        $("#featured_box .controls li").removeClass("active");
        $(this).parent().toggleClass("active");
        return false;
    });
    
    jQuery("#feat_next").bind("click", function() {
        carousel.next();
        return false;
    });

    jQuery("#feat_prev").bind("click", function() {
        carousel.prev();
        return false;
    });
    
};

function featured_itemFirstInCallback(carousel, item, idx, state) {
    $("#featured_box .controls li").removeClass("active");
    $("#featured_box .controls li:eq(" + (idx - 1) + ")").toggleClass("active");
};


function featured_buttonNextCallback(carousel, button, enabled) {
    jQuery("#feat_next").removeClass("enabled disabled");
    jQuery("#feat_next").addClass(enabled ? "enabled" : "disabled");
};

function featured_buttonPrevCallback(carousel, button, enabled) {
    jQuery("#feat_prev").removeClass("enabled disabled");
    jQuery("#feat_prev").addClass(enabled ? "enabled" : "disabled");
};

$(document).ready(function() {
   
	$("#index .slider").jcarousel({scroll: 1});
	$("#profiles .slider").jcarousel();
	$("#wealth .slider").jcarousel({
		itemFirstInCallback:   wealth_buttonCallback	
	});
	$("#contributors .slider").jcarousel();	
	$("#recommended .slider").jcarousel();
	
    jQuery("#videos .slider").jcarousel({
        scroll: 1,
        initCallback: videos_initCallback,
        buttonNextCallback:   videos_buttonNextCallback,
        buttonPrevCallback:   videos_buttonPrevCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
    
    jQuery("#featured_box .slider").jcarousel({
        scroll: 1,
        initCallback: featured_initCallback,
        buttonNextCallback:   featured_buttonNextCallback,
        buttonPrevCallback:   featured_buttonPrevCallback,
        itemFirstInCallback:  featured_itemFirstInCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });

    $("#map div.info a.close").click(function (e) {
      $(this).parent().hide();
      e.preventDefault();
    });

    $("#map .map a.info").click(function (e) {
      $("#map .map div.info").toggle();
      e.preventDefault();
    });

    $("#map .slider-control a.button").click(function (e) {
      $(this).toggleClass("active");
      $(this).next().toggle();
      e.preventDefault();
    });
    
    if($.ui) {
	    $(".custom-select select#sub_topic").selectmenu({
	    	width: 150,
			menuWidth: 200,
			positionOptions: {
						my: "left top",
						at: "left bottom",
						offset: "0 2"
					}
	
		});
		
		 $(".custom-select select#contributor").selectmenu({
	    	width: 150,
			menuWidth: 200,
			positionOptions: {
						my: "left top",
						at: "left bottom",
						offset: "0 2"
					}
	
		});
		
		 $(".custom-select select#date_range").selectmenu({
	    	width: 220,
			menuWidth: 220,
			positionOptions: {
						my: "left top",
						at: "left bottom",
						offset: "0 2"
					}
	
		});

                $(".custom-select select#month").selectmenu({
	    	width: 120,
			menuWidth: 120,
			positionOptions: {
						my: "left top",
						at: "left bottom",
						offset: "0 2"
					}

		});

		$(".custom-select select#event").selectmenu({
	    	width: 220,
			menuWidth: 240,
			positionOptions: {
						my: "left top",
						at: "left bottom",
						offset: "0 2"
					}

		});

		jQuery( "#slider-5" ).each(function() {
			// read initial values from markup and remove that
			var value = parseInt( $( this ).text(), 10 );
			$( this ).empty().slider({
				value: value,
				min: 0,
				max: 10,
				step: 1,
				create: function( event, ui ) {
						$( "a", this ).append("<span class=\"number\">" + value + "</span>");
					},
				slide: function( event, ui ) {
						$( "span", this ).text( ui.value );
					}
			});
		});
                jQuery( "#slider-6" ).each(function() {
			// read initial values from markup and remove that
			var value = parseInt( $( this ).text(), 10 );
			$( this ).empty().slider({
				value: value,
				min: 0,
				max: 10,
				step: 1,
				create: function( event, ui ) {
						$( "a", this ).append("<span class=\"number\">" + value + "</span>");
					},
				slide: function( event, ui ) {
						$( "span", this ).text( ui.value );
					}
			});
		});
                jQuery( "#slider-7" ).each(function() {
			// read initial values from markup and remove that
			var value = parseInt( $( this ).text(), 10 );
			$( this ).empty().slider({
				value: value,
				min: 0,
				max: 10,
				step: 1,
				create: function( event, ui ) {
						$( "a", this ).append("<span class=\"number\">" + value + "</span>");
					},
				slide: function( event, ui ) {
						$( "span", this ).text( ui.value );
					}
			});
		});
	}
        
        jQuery('#month, #event').change(function(){
            document.location = jQuery(this).val();
        });
        
        jQuery('body.events:not(.writeup) #tabs').tabs();
        jQuery('#view-speakers').click(function(){
            jQuery('body.events:not(.writeup) #tabs').tabs('select', 'panel_tab_speakers');
            return false;
        });
        
        jQuery('#tab_register_now a').click(function(){
            //document.location = jQuery(this).attr('data-href');
            window.open(jQuery(this).attr('data-href'), 'Registration');
        });
 });
