jQuery(function(){
	
	jQuery('#fmThumb').submit(function(){
		var params = null;
		var options = {
			callBefore:function(){
				jQuery('#btn_submit').html(jQuery('<div></div>').attr('class','inline_loader'));
			},
			callAfterSuccess:function(data){
				jQuery('#btn_submit').html('<span style="float:right; color:#FFF;">Redirecting...</span>');
			},
			callAfterFailed:function(data){
				jQuery('#btn_submit').html('<button name="" type="submit" value="" class="submit" />');
			}
		}
		return Goingup.Form.Submit(this,params,options);	
	});
	
	jQuery('#mycarousel').jcarousel({
		scroll:5,
        buttonNextCallback:   mycarousel_buttonNextCallback,
        buttonPrevCallback:   mycarousel_buttonPrevCallback
    });
});

/**
 * This is the callback function which receives notification
 * about the state of the next button.
 */
function mycarousel_buttonNextCallback(carousel, button, enabled) {
	if (enabled){
		jQuery(button).show();
	}else{
		jQuery(button).hide();
	}
    
};

/**
 * This is the callback function which receives notification
 * about the state of the prev button.
 */
function mycarousel_buttonPrevCallback(carousel, button, enabled) {
    if (enabled){
		jQuery(button).show();
	}else{
		jQuery(button).hide();
	}
};

function mycarousel_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, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function mycarousel_itemLoadCallback(carousel, state)
{
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }

        if (i > mycarousel_itemList.length) {
            break;
        }

        carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i-1]));
    }
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<img src="' + item.url + '" width="150" height="100" alt="' + item.title + '" />';
};
