/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */

var oHeight;
var oWidth;
var $marginTop; 
var $marginLeft;
 
function slideshow_initCallback(carousel){
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function doResize() {   
	var oHeight = jQuery('#overlay-ctr').height();
	
	$('#overlaybg').height($(document).height());
	$('#overlay').height($(document).height());
	var $marginTop = ((jQuery(window).height() - oHeight) / 2 + $(window).scrollTop() + 'px'); 
	
	if(jQuery(window).height() > oHeight){
		jQuery('#overlay-ctr').animate({'top': $marginTop}, 0);
    }
}

function closeOverlay(){
	jQuery('#overlay').fadeOut(500);
	jQuery('#overlaybg').fadeOut(500);
}

var isIE6 = ($.browser.msie && $.browser.version=="6.0");
var isDisabled;
var myWinWidth;
var myWinHeight;
 
 function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });

    jQuery('.jcarousel-control a').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;
    });

};

// Ride the carousel...


function rideTheCarousel() {

	jQuery(document).pngFix();
	setTimeout('doResize()', 1 );
    $('#overlaybg').css('opacity', '0.8');
	setTimeout('doResize()', 1 );
	$(window).resize(function() {
		setTimeout('doResize()', 1 );		
	});
	$(window).scroll(function() {
		setTimeout('doResize()', 1 );		
	});
	jQuery("#mapRef").click(function(){
		$('#overlay-ctr').empty();
		jQuery('#overlaybg').fadeIn(500);
		jQuery('#overlay').fadeIn(500);
		doResize();
		$('#overlay-ctr').load('/gmap.php .panel-946', function() {
			//jQuery('.overlaid').css('visibility', 'hidden');
			
			jQuery(".closeOverlay").click(closeOverlay);
		});
		return false;
	});
	jQuery("#termsLink").click(function(){
		$('#overlay-ctr').empty();
		jQuery('#overlaybg').fadeIn(500);
		jQuery('#overlay').fadeIn(500);
		doResize();
		$('#overlay-ctr').load('/terms.php .panel-946', function() {
			jQuery("#termsBox").jScrollPane({scrollbarWidth:10, scrollbarMargin:10});
			jQuery(".closeOverlay").click(closeOverlay);
		});
		return false;
	});

	jQuery("#privacyLink").click(function(){
		$('#overlay-ctr').empty();
		jQuery('#overlaybg').fadeIn(500);
		jQuery('#overlay').fadeIn(500);
		doResize();
		$('#overlay-ctr').load('/privacy.php .panel-946', function() {
			jQuery("#termsBox").jScrollPane({scrollbarWidth:10, scrollbarMargin:10});
			jQuery(".closeOverlay").click(closeOverlay);
		});
		return false;
	});
	
	jQuery("#menuScroller").jcarousel({
		scroll: 1
	});
	
    jQuery("#slideshow").jcarousel({
		auto: 2,
		scroll: 1,
		wrap: 'circular',
		initCallback: slideshow_initCallback
	});
	$("#venueInfo").jScrollPane({scrollbarWidth:10, scrollbarMargin:10});
    jQuery("#slideshow2").jcarousel({
		auto: 2,
		scroll: 1,
		wrap: 'circular',
		initCallback: slideshow_initCallback
	});	
	var mycarouselLength = jQuery("ul.jcarousel-list li").size();
	
	jQuery("#calendarBox").jScrollPane({scrollbarWidth:10, scrollbarMargin:10});

	jQuery("#menuTabs .tabMid input").click(function(){
		jQuery(this).addClass("selected");
		$(".tabbedList li").each(function() {
			jQuery(this).removeClass("active");	
			jQuery(this).addClass("inactive");
		});
		jQuery(this).closest("li").removeClass("inactive");
		jQuery(this).closest("li").addClass("active");
		//return false;
	});
	jQuery("a").each(function(i) {
		if(jQuery(this).attr('rel')) {
			jQuery(this).attr('target', '_blank');
		}
	});
};
