/**
 * Fancybox for special pages
 * @author 		Jeroen Dijkstra
 * @company		Crowd Surfing
 */
$(document).ready(
	function()
	{
		$('a.fancybox').fancybox
		(
			{
				'overlayOpacity' 	: '0.7',
				'overlayColor'		: '#000'
			}
		);
	}
);

/**
 * Replace Button with images
 * @author 		Jeroen Dijkstra
 * @company		Crowd Surfing
 */
$(document).ready(
	function()
	{
		$('a.Button').each(
			function(index)
			{
				if (!$(this).hasClass('ShoppingBasketRemoveButton'))
				{
					$($(this)).addClass('ImageButton');
					$(this).html('<span class="InnerButton"><span>' + $(this).html() + '</span></span>');
					$('<span class="LeftButton"></span>').prependTo($(this));
					$('<span class="RightButton"></span>').appendTo($(this));
					$($(this)).removeClass('Button');
				}
			}
		);

		$('input.Button').each(
			function(index)
			{
				$('<a href="#" onclick="$(this).closest(\'form\').submit(); $(this).attr(\'disabled\', true); return false;" class="ImageButton"><span class="LeftButton"></span><span class="InnerButton">'+ $(this).attr('value') + '</span><span class="RightButton"></span></a>').appendTo($(this).parent());
				$($(this)).remove();
			}
		);
	}
);

/**
 * Show the delay notice when the
 * confirm button is clicked
 * @author 		Jeroen Dijkstra
 * @company		Crowd Surfing
 */
$(document).ready(
	function()
	{
		$('#DelayNotice').hide();
		$('form.ConfirmForm a.ImageButton').click(
			function()
			{
				$('#DelayNotice').fadeIn();
			}
		);
	}
);

/**
 * Remove unwanted keywords from news items
 * the Q&D way because IE doesnt support nth-child
 * @author 		Jeroen Dijkstra
 * @company 	Crowd Surfing
 */
$(document).ready(
	function()
	{
		$('table.newsitem tfoot tr:nth-child(odd) td').html('&nbsp;');
		$('table.newsitem thead tr:nth-child(even) td').html('&nbsp;');
	}
);

/**
 * Infinite scroll
 * 
 * @author 		Jeroen Dijkstra
 * @company 	Crowd Surfing
 */
$(document).ready
(
	function()
	{
		if ($('div.BreadCrumsBottom').length)
		{
			$('div#Column').infinitescroll
			(
				{
					navSelector: 	'div.BreadCrumsBottom',
					nextSelector:	'div.BreadCrumsBottom a:last',
					itemSelector:	'div.ArtCollectionContainer div.ArtCollectionBox',
					loadingImg:		'/Includes/Themes/DigitalArtwork/Images/ajax-loader.gif',
					loadingText:	'',
					donetext:		'',
					bufferPx:		50
				}
			);
		}
	}
);

/**
 * jCarousel - http://sorgalla.com/projects/jcarousel/
 * Configuration for jCarousel
 *
 * @author 		Jeroen Dijkstra
 * @company 	Crowd Surfing
*/
function carousel_initCallback(carousel) {
	var nextInterval, prevInterval;
	
	jQuery('.jcarousel-next').hover(
		function()
		{
			carousel.next();
			nextInterval = setInterval
			(
				function()
				{
					carousel.next();
				},
				1000
			)
	        return false;
		},
		function()
		{
			clearInterval(nextInterval);
		}
	);

	jQuery('.jcarousel-prev').hover(
		function()
		{
			carousel.prev();
			prevInterval = setInterval
			(
				function()
				{
					carousel.prev();
				},
				1000
			)
	        return false;
		},
		function()
		{
			clearInterval(prevInterval);
		}
	);
};

var carousel_itemList = [
	{url: 'Includes/Themes/DigitalArtwork/Images/Carrousel/Limited_Editions.png', title: 'Limited Edition'},
    {url: 'Includes/Themes/DigitalArtwork/Images/Carrousel/Galerie1Abstract.jpg', title: 'Abstract'},
    {url: 'Includes/Themes/DigitalArtwork/Images/Carrousel/Galerie2Natuur.jpg', title: 'Natuur'},
    {url: 'Includes/Themes/DigitalArtwork/Images/Carrousel/Galerie3Figuratief.jpg', title: 'Figuratef'},
    {url: 'Includes/Themes/DigitalArtwork/Images/Carrousel/Galerie4Fotografie.jpg', title: 'Fotografie'},
    {url: 'Includes/Themes/DigitalArtwork/Images/Carrousel/Galerie5Grafisch.jpg', title: 'Grafisch'},
    {url: 'Includes/Themes/DigitalArtwork/Images/Carrousel/Galerie6Industrieel.jpg', title: 'Industrieel'},
    {url: 'Includes/Themes/DigitalArtwork/Images/Carrousel/Galerie7Stedelijk.jpg', title: 'Stedelijk'}
];

function carousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, carousel_itemList.length);
    carousel.add(i, carousel_getItemHTML(carousel_itemList[idx - 1], idx));
};

function carousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function carousel_getItemHTML(item, idx)
{
	var url	= '';
	if (idx == 1)
	{
		url = "limited-editions";
	}
	if (idx == 2)
	{
		url	= "abstract";
	}
	if (idx == 3)
	{
		url = "natuur";
	}
	if (idx == 4)
	{
		url = "figuratief";
	}
	if (idx == 5)
	{
		url = "fotografie";
	}
	if (idx == 6)
	{
		url = "grafisch";
	}
	if (idx == 7)
	{
		url = "industrieel";
	}
	if (idx == 8)
	{
		url = "stedelijk";
	}

    return '<a href="/' + url + '"><img src="' + item.url + '" alt="' + item.title + '" /></a>';
};

