function slider_initCallback(carousel) {
	$(".ct_prev").bind('click', function () {
		carousel.prev();
		return false;
	});

	$(".ct_next").bind('click', function () {
		carousel.next();
		return false;
	});
}

function nextButton(carousel,button,enabled) {
	if (enabled == 'disabled') {
		$('.ct_next').hide();
	} else {
		$('.ct_next').show();
		enabled ='enabled'
	}
}
function prevButton(carousel,button,enabled) {

}

$(document).ready(function() {

	// toggle play/pause on hover
	$('.slideshow ul li table td .ss_photo').hover(function() {
		if (slideShow == 'stop') {
		} else {
			$('.slideshow ul').cycle('pause');
		}
		$(this).children('.ss_share').show();
	}, function() {
		if (slideShow == 'stop') {
			// do nothing
		} else {
			$('.slideshow ul').cycle('resume');
		}
		$(this).children('.ss_share').hide();
	});

	function onAfter(curr,next,opts) {
		var image_count = '<span class="ss_count">' + (opts.currSlide + 1) + '</span>/'+ opts.slideCount;
		$('#image_count').html(image_count);
	}

	// signup form
	$('#emailAddress').focus(function() {
		if ($(this).val() == 'Sign up here for Opus news...') {
			$(this).val('');
		}
	});
	$('#emailAddress').blur(function() {
		if ($(this).val() == '') {
			$(this).val('Sign up here for Opus news...');
		}
	});

	// search form
	$('.bp_search input').focus(function() {
		if ($(this).val() == 'search ...') {
			$(this).val('');
		}
	});

	$('.bp_search input').blur(function() {
		if ($(this).val() == '') {
			$(this).val('search ...');
		}
	});

	// share this menu
	$('.sharethis').click(function() {
		if($(this).hasClass('sel')) {
			$(this).removeClass('sel');
			$('.sharethis_menu').hide();
		} else {
			$(this).addClass('sel');
			$('.sharethis_menu').show();
		}
		return false;
	});

	// hide/show the thumbs
	$('.icon_thumbs').click(function() {
		if($(this).hasClass('sel')) {
			hideThumbs(this);
		} else {
			showThumbs(this);
		}
		return false;
	});

	$('#emailAddress').keypress(function(e){
		if (e.which == 13) {
			onSubscribe();
		}
	});

	$('#search_words').keypress(function(e){
		if (e.which == 13) {
			$('#SearchForm').submit();
		}
	});
});

$(window).load(function() {
	// resize the span for the gallery thumbnails on hover

	$('.ct_thumb ul li').each(function(i) {
		var _width = $(this).children('a').children('img').width()-4;
		$(this).children('a').children('span').css({width:_width+'px'});
		$(this).children('a').children('img').css({width:_width+'px'});
		$(this).css({width:_width+'px'});
	});

	// Hack for weird bug on webkit
	if ($.browser.webkit) {
		$('a.next.notext').click();
	}

	// body click
	$('body').click(function() {
		$('.sharethis').removeClass('sel');
		$('.sharethis_menu').hide();
		$('.share_options').removeClass('sel');
		$('.share_options').hide();
	});
});

function showThumbs(_a) {
	$(_a).addClass('sel');
	$('.ct_mask').hide();
	$('.ct_list').show();
}

function hideThumbs(_a) {
	$(_a).removeClass('sel');
	$('.ct_mask').show();
	$('.ct_list').hide();
}

function launchThumbs() {
	$('.ct_loader').hide();
	$('.ct_mask').hide();
	$('.icon_thumbs').addClass('sel');
	$('.ct_list').css({'opacity':'1.0'});
}

var speed = 500;
var hoverColor = '#f17400';

function toggleLight() {
	$('body').attr('id', 'light');

	// header elements
	$('body').animate({backgroundColor: '#fff'}, speed);
	$('#header').animate({borderBottomColor: '#ddd'});
	$('#header .h_light').fadeTo(speed, 1.0);
	$('#header .h_dark').fadeTo(speed, 0.0);
	$('#header .logo_light').fadeTo(speed, 1.0);
	$('#header .logo_dark').fadeTo(speed, 0.0);
	$('#toggle .slider').removeClass('dark').addClass('light');
	$('.h_cities a').animate({color: '#C1C0C0'}, speed);
	$('#header .h_nav ul li a em').animate({color: '#000'}, speed);
	// content
	$('.na_name').animate({color: '#333'}, speed);
	$('.na_albums.divider').animate({borderTopColor: '#f2f2f2',borderBottomColor: '#f2f2f2'}, speed);
	$('.video_description').animate({color: '#000'}, speed);
	$('.na_albums ul li a').animate({color: '#C1C0C0'}, speed);
	$('.nav_options .no_one').animate({borderTopColor:'#f2f2f2'}, speed);
	$('.nav_options .no_two').animate({borderTopColor:'#f2f2f2'}, speed);
	$('.nav_options .no_three').animate({borderTopColor:'#f2f2f2'}, speed);
	$('.nav_options .no_four').animate({color:'#000',borderTopColor:'#f2f2f2'}, speed);
	$('.nav_options .no_two a em').animate({color:'#000'}, speed);
	$('.sharethis').animate({borderTopColor:'#fff',borderRightColor:'#fff',borderBottomColor:'#fff',borderLeftColor:'#fff', backgroundColor:'#9f9e9f'}, speed);
	$('.sharethis_menu').animate({borderTopColor:'#ddd',borderRightColor:'#ddd',borderBottomColor:'#ddd',borderLeftColor:'#ddd',backgroundColor:'#fff'}, speed);
	// footer elements
	$('#footer').animate({color: '#A6A6A6', borderTopColor: '#ddd'}, speed);
	$('#footer input').animate({color: '#fff', backgroundColor: '#A6A6A6'}, speed);
}

function toggleDark() {
	$('body').attr('id', 'dark');
	// header elements
	$('body').animate({backgroundColor:'#353334'}, speed);
	$('#header').animate({borderBottomColor: '#222'});
	$('#header .h_light').fadeTo(speed, 0.0);
	$('#header .h_dark').fadeTo(speed, 1.0);
	$('#header .logo_light').fadeTo(speed, 0.0);
	$('#header .logo_dark').fadeTo(speed, 1.0);
	$('#toggle .slider').removeClass('light').addClass('dark');
	$('.h_cities a').animate({color: '#666'}, speed);
	$('#header .h_nav ul li a em').animate({color: '#fff'}, speed);
	// content
	$('.na_name').animate({color: '#fff'}, speed);
	$('.na_albums.divider').animate({borderTopColor: '#000',borderBottomColor: '#000'}, speed);
	$('.video_description').animate({color: '#fff'}, speed);
	$('.na_albums ul li a').animate({color: '#999'}, speed);
	$('.na_albums ul li a.sel').animate({color: '#fff'}, speed);
	$('.nav_options .no_one').animate({borderTopColor:'#222'}, speed);
	$('.nav_options .no_two').animate({borderTopColor:'#222'}, speed);
	$('.nav_options .no_three').animate({borderTopColor:'#222'}, speed);
	$('.nav_options .no_four').animate({color:'#999',borderTopColor:'#222'}, speed);
	$('.nav_options .no_two a em').animate({color:'#fff'}, speed);
	$('.sharethis').animate({borderTopColor:'#000',borderRightColor:'#000',borderBottomColor:'#000',borderLeftColor:'#000',backgroundColor:'#353334'}, speed);
	$('.sharethis_menu').animate({borderTopColor:'#000',borderRightColor:'#000',borderBottomColor:'#000',borderLeftColor:'#000',backgroundColor:'#353334'}, speed);
	// footer elements
	$('#footer').animate({color: '#6c6c6c', borderTopColor: '#222'}, speed);
	$('#footer input').animate({color: '#484848', backgroundColor: '#000'}, speed);
}

// subscription form
function onSubscribe() {
	var email = $('#emailAddress').val();
	if (email != '') {
		$.ajax({
			url: '/contacts/subscribe', 
			data: $('#SubscribeForm').serialize(),
			type: 'POST',
			dataType: 'json',
			success: function(json) {
				var msg = $(json.message).find('li').html();
				$('.f_signup').html(msg);
			}
		});
	} else {
		$('#emailAddress').val('Enter your email address');
	}
	return false;
}


