// <![CDATA[
/**
* We use the initCallback callback
* to assign functionality to the controls
*/

// Ride the carousel...
$(document).ready(function() {

// automatically generates numbers + controls for all gallerys on a page
	$('.jcarousel-skin-tango, .jcarousel-skin-threeCol, .jcarousel-skin-fourCol').each(function(){

	
			var output = '';
			var start = '<a href="#" id="'+this.id+'-prev">&nbsp;</a>';
			var end = '<a href="#" id="'+this.id+'-next">&nbsp;</a>';

			var s = $('#'+this.id+' li').size();
			var i = 1;
			while(i <= s){

				output = output + '<a class="num" href="#">0'+i+'</a>';
				i++;
			}
			if (i > 2){
				$('#'+this.id+' .externalControls div').append(start+output+end);
			}
		});
		


		
function firstcarousel_initCallback(carousel){

		$('#firstcarousel .jcarousel-control a.num').bind('click', function() {
			
			var t = $(this).closest('div');
			$(t).find('a.selected').removeClass('selected');
			$(this).addClass('selected');
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
			return false;
		});

		$('#firstcarousel .externalControls a.num:first').addClass('selected');

		$('#firstcarousel-next').click(function() {

			var last = $('#firstcarousel .externalControls a.num:last').attr('class');

			if (last != 'num selected'){
				var n = $('#firstcarousel .externalControls .selected').next('.num');
				$('#firstcarousel .selected').removeClass('selected');
				$(n).addClass('selected');
				carousel.next();
			} else {
				return false;
			}
				return false;
		});

		$('#firstcarousel-prev').click(function() {
			var first = $('#firstcarousel .externalControls a.num:first').attr('class');

			if (first != 'num selected'){
				var n = $('#firstcarousel .externalControls .selected').prev('.num');
				$('#firstcarousel .selected').removeClass('selected');
				$(n).addClass('selected');
				carousel.prev();
			} else {
				return false;
			}
				return false;

		});
};

function secondcarousel_initCallback(carousel) {

		$('#secondcarousel .jcarousel-control a.num').bind('click', function() {
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
			var t = $(this).closest('div');
			$(t).find('a.selected').removeClass('selected');
			$(this).addClass('selected');
			return false;
		});

		$('#secondcarousel .externalControls  a.num:first').addClass('selected');

		$('#secondcarousel-next').click(function() {

			var last = $('#secondcarousel .externalControls a.num:last').attr('class');

			if (last != 'num selected'){
				var n = $('#secondcarousel .externalControls .selected').next('.num');
				$('#secondcarousel .selected').removeClass('selected');
				$(n).addClass('selected');
				carousel.next();
			} else {
				return false;
			}
				return false;
		});

		$('#secondcarousel-prev').click(function() {
			var first = $('#secondcarousel .externalControls a.num:first').attr('class');

			if (first != 'num selected'){
				var n = $('#secondcarousel .externalControls .selected').prev('.num');
				$('#secondcarousel .selected').removeClass('selected');
				$(n).addClass('selected');
				carousel.prev();
			} else {
				return false;
			}
				return false;

		});
};

function thirdcarousel_initCallback(carousel) {

		$('#thirdcarousel .jcarousel-control a.num').bind('click', function() {
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
			var t = $(this).closest('div');
			$(t).find('a.selected').removeClass('selected');
			$(this).addClass('selected');
			return false;
		});

		$('#thirdcarousel .externalControls  a.num:first').addClass('selected');

		$('#thirdcarousel-next').click(function() {

			var last = $('#thirdcarousel .externalControls a.num:last').attr('class');

			if (last != 'num selected'){
				var n = $('#thirdcarousel .externalControls .selected').next('.num');
				$('#thirdcarousel .selected').removeClass('selected');
				$(n).addClass('selected');
				carousel.next();
			} else {
				return false;
			}
				return false;
		});

		$('#thirdcarousel-prev').click(function() {
			var first = $('#thirdcarousel .externalControls a.num:first').attr('class');

			if (first != 'num selected'){
				var n = $('#thirdcarousel .externalControls .selected').prev('.num');
				$('#thirdcarousel .selected').removeClass('selected');
				$(n).addClass('selected');
				carousel.prev();
			} else {
				return false;
			}
				return false;

		});
};

	function fourthcarousel_initCallback(carousel) {

		$('#fourthcarousel .jcarousel-control a.num').bind('click', function() {
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
			var t = $(this).closest('div');
			$(t).find('a.selected').removeClass('selected');
			$(this).addClass('selected');
			return false;
		});

		$('#fourthcarousel .externalControls  a.num:first').addClass('selected');

		$('#fourthcarousel-next').click(function() {

			var last = $('#fourthcarousel .externalControls a.num:last').attr('class');

			if (last != 'num selected'){
				var n = $('#fourthcarousel .externalControls .selected').next('.num');
				$('#fourthcarousel .selected').removeClass('selected');
				$(n).addClass('selected');
				carousel.next();
			} else {
				return false;
			}
				return false;
		});

		$('#fourthcarousel-prev').click(function() {
			var first = $('#fourthcarousel .externalControls a.num:first').attr('class');

			if (first != 'num selected'){
				var n = $('#fourthcarousel .externalControls .selected').prev('.num');
				$('#fourthcarousel .selected').removeClass('selected');
				$(n).addClass('selected');
				carousel.prev();
			} else {
				return false;
			}
				return false;

		});
};

function fifthcarousel_initCallback(carousel) {

		$('#fifthcarousel .jcarousel-control a.num').bind('click', function() {
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
			var t = $(this).closest('div');
			$(t).find('a.selected').removeClass('selected');
			$(this).addClass('selected');
			return false;
		});

		$('#fifthcarousel .externalControls  a.num:first').addClass('selected');

		$('#fifthcarousel-next').click(function() {

			var last = $('#fifthcarousel .externalControls a.num:last').attr('class');

			if (last != 'num selected'){
				var n = $('#fifthcarousel .externalControls .selected').next('.num');
				$('#fifthcarousel .selected').removeClass('selected');
				$(n).addClass('selected');
				carousel.next();
			} else {
				return false;
			}
				return false;
		});

		$('#fifthcarousel-prev').click(function() {
			var first = $('#fifthcarousel .externalControls a.num:first').attr('class');

			if (first != 'num selected'){
				var n = $('#fifthcarousel .externalControls .selected').prev('.num');
				$('#fifthcarousel .selected').removeClass('selected');
				$(n).addClass('selected');
				carousel.prev();
			} else {
				return false;
			}
				return false;

		});
};



		$("#firstcarousel").jcarousel({
				scroll: 1,
				initCallback: firstcarousel_initCallback,
				// This tells jCarousel NOT to autobuild prev/next buttons
				buttonNextHTML: null,
				buttonPrevHTML: null,
				animation: 0
		});

	$("#secondcarousel").jcarousel({
				scroll: 1,
				initCallback: secondcarousel_initCallback,
				// This tells jCarousel NOT to autobuild prev/next buttons
				buttonNextHTML: null,
				buttonPrevHTML: null,
				animation: 0
		});

	$("#thirdcarousel").jcarousel({
				scroll: 1,
				initCallback: thirdcarousel_initCallback,
				// This tells jCarousel NOT to autobuild prev/next buttons
				buttonNextHTML: null,
				buttonPrevHTML: null,
				animation: 0
		});

	$("#fourthcarousel").jcarousel({
				scroll: 1,
				initCallback: fourthcarousel_initCallback,
				// This tells jCarousel NOT to autobuild prev/next buttons
				buttonNextHTML: null,
				buttonPrevHTML: null,
				animation: 0
		});
		
		$("#fifthcarousel").jcarousel({
					scroll: 1,
					initCallback: fifthcarousel_initCallback,
					// This tells jCarousel NOT to autobuild prev/next buttons
					buttonNextHTML: null,
					buttonPrevHTML: null,
					animation: 0
			});

	$(".galCon a").hover(
			function () {
				$(this).append($("<span class=\"hoverState\"></span>"));
			}
			,
			function () {
					$(this).find("span:last").remove();
			}

	);

	$(".galConLg a").hover(
			function () {
				$(this).append($("<span class=\"hoverStateLg\"></span>"));
			}
			,
			function () {
					$(this).find("span:last").remove();
			}

	);



});
// ]]>
