// Initialization, you can leave this here or move this somewhere else
/*$(function()
{
	$('ul.jd_menu').jdMenu({	onShow: loadMenu
								//onHideCheck: onHideCheckMenu,
								//onHide: onHideMenu, 
								//onClick: onClickMenu, 
								//onAnimate: onAnimate
								});
	$('ul.jd_menu_vertical').jdMenu({onShow: loadMenu, onHide: unloadMenu, offset: 1, onAnimate: onAnimate});
});*/

function onAnimate(show) 
{
	//$(this).fadeIn('slow').show();
	if (show) 
	{
		$(this)
			.css('visibility', 'hidden').show()
				.css('width', $(this).innerWidth())
			.hide().css('visibility', 'visible')
		.fadeIn('normal');
	} 
	else 
	{
		$(this).fadeOut('fast');
	}
}

var MENU_COUNTER = 1;
function loadMenu() 
{
	if (this.id == 'dynamicMenu') 
	{
		$('> ul > li', this).remove();

		var ul = $('<ul></ul>');
		var t = MENU_COUNTER + 10;
		for (; MENU_COUNTER < t; MENU_COUNTER++) 
		{
			$('> ul', this).append('<li>Item ' + MENU_COUNTER + '</li>');
		}
	}
}

function unloadMenu() 
{
	if (MENU_COUNTER >= 30) 
	{
		MENU_COUNTER = 1;
	}
}

// We're passed a UL
function onHideCheckMenu() 
{
	return !$(this).parent().is('.LOCKED');
}

// We're passed a LI
function onClickMenu() 
{
	$(this).toggleClass('LOCKED');
	return true;
}


/*
* Scroll Me! v0.01 - jQuery scroller
* Copyright (c) 2008 Dinesh Sailor
*
* dinesh(at)augustinfotech.com
*
*/
(function($) {
		  
	$.fn.dsScrollMe = function(settings){
		return this.each(function(i) {
								  
			$this = $(this);
			
			settings = jQuery.extend({
							/* amount of pixels that the content is scrolled */
							scrollStepSize : 95,
							/* Animation duration */
							scrollDuration : 500,
							
							/* Bind Exteral Control */
					        initCallback: null,

							/* Scroll buttons */
							scrollBtn : true,
							scrollUpBtn : null,
							scrollDownBtn : null
						}, settings);

			if (settings.initCallback != null)
				settings.initCallback(this, 'init');

			var uniqueId = $this.attr('class').replace(" ", '') + i;

			/* Let's build the control */
			$this.html((settings.scrollUpBtn == null ? '<div class="scroll-up scroll-up-' + uniqueId + '"></div>' : '') +
					   '<div class="scroll-pane scroll-pane-' + uniqueId + '">' +
					   		'<div class="scroll-body scroll-body-' + uniqueId + '">' + $this.html() + '</div>' +
					   '</div>' +
					   (settings.scrollDownBtn == null ? '<div class="scroll-down scroll-down-' + uniqueId + '"></div>' : ''));

			/* Find the scroll height */
			var maxScroll = $('.scroll-body-' + uniqueId).height() - $('.scroll-pane-' + uniqueId).height();
			var scrollPosition = parseInt($('.scroll-body-' + uniqueId).css('margin-top'));
			
			if(maxScroll < 0)
			{
				$(settings.scrollUpBtn == null ? '.scroll-up-' + uniqueId : settings.scrollUpBtn).css('visibility', 'hidden');
				$(settings.scrollDownBtn == null ? '.scroll-down-' + uniqueId : settings.scrollDownBtn).css('visibility', 'hidden');
			}
			
			/**
			 * Used to scroll the content upwards
			 * 
			 * @param {Integer} amount of pixels to scroll
			 */
			function scrollUp() {
				if(scrollPosition < 0) {
					scrollPosition += settings.scrollStepSize;
					$('.scroll-body-' + uniqueId).animate({marginTop: scrollPosition}, settings.scrollDuration );
				} else {
					clearInterval(scrollInterval);
				}
			}
			
			/**
			 * Used to scroll the content downwards
			 * 
			 * @param {Integer} amount of pixels to scroll
			 */
			function scrollDown() {
				if(Math.abs(scrollPosition) < maxScroll) {
					scrollPosition -= settings.scrollStepSize;
					$('.scroll-body-' + uniqueId).animate({marginTop: scrollPosition}, settings.scrollDuration );
				} else {
					clearInterval(scrollInterval);
				}
			}

			if(settings.scrollBtn)
			{
				/* Let bind the events */
				$(settings.scrollUpBtn == null ? '.scroll-up-' + uniqueId : settings.scrollUpBtn).hover(
										function() {
											scrollInterval = setInterval(scrollUp, settings.scrollDuration);
										},
										function() {
											clearInterval(scrollInterval);
										}
									);
				$(settings.scrollDownBtn == null ? '.scroll-down-' + uniqueId : settings.scrollDownBtn).hover(
										function() {
											scrollInterval = setInterval(scrollDown, settings.scrollDuration);
										},
										function() {
											clearInterval(scrollInterval);
										}
									);
			}
			else
			{
				$(settings.scrollUpBtn == null ? '.scroll-up-' + uniqueId : settings.scrollUpBtn).css('display', 'none');
				$(settings.scrollDownBtn == null ? '.scroll-down-' + uniqueId : settings.scrollDownBtn).css('display', 'none');
			}
		});
	};
	
	$.fn.dsScrollMe.extend = $.extend;
	
	$.fn.dsScrollMe.extend({
	
		/**
		 * Used to scroll the content upwards
		 * 
		 * @param {Integer} amount of pixels to scroll
		 */
		scroll: function (index) {
			alert('here' + index);
			return true;
		}
	});

})(jQuery);


/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function album_initCallback(carousel) {
    jQuery('.jcarousel-album-control-pages a').bind('click', function() {
		jQuery('.jcarousel-album-control-pages a').removeClass();
		jQuery(this).attr("class","active");
        carousel.scroll(carousel.options.scroll * (jQuery.jcarousel.intval(jQuery(this).text())-1) + 1);
        return false;
    });

    jQuery('#jcarousel-album-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#jcarousel-album-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 */
function album_itemLastInCallback(carousel, item, idx, state) {
	jQuery('.jcarousel-album-control-pages a').removeClass();
	jQuery('#jcarousel-album-control-page-'+Math.ceil(idx/3)).attr("class","active");
};

/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function photos_initCallback(carousel) {
    jQuery('.jcarousel-photos-control-pages a').bind('click', function() {
		jQuery('.jcarousel-photos-control-pages a').removeClass();
		jQuery(this).attr("class","active");
        carousel.scroll(carousel.options.scroll * (jQuery.jcarousel.intval(jQuery(this).text())-1) + 1);
        return false;
    });

    jQuery('#jcarousel-photos-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#jcarousel-photos-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 */
function photos_itemLastInCallback(carousel, item, idx, state) {
	jQuery('.jcarousel-photos-control-pages a').removeClass();
	jQuery('#jcarousel-photos-control-page-'+Math.ceil(idx/3)).attr("class","active");
};