$(document).ready(function() {
	
	triggerAjax();
	
	$('#nextLink').bind('click', function(event){
		event.preventDefault();
		callAjaxSliderLoader('next');
	});
	
	$('#prevLink').bind('click', function(event){
		event.preventDefault();
		callAjaxSliderLoader('prev');
	});


	function callAjaxSliderLoader(link){
		var numRand = Math.floor(Math.random()*101);
		$.ajax({
			
//		    global: false,
		    type: "GET",
		    url: "?id=30&no_cache=1&eID=cfwb_mahe_institution&tx_cfwbmaheinstitution_pi1[nextUid]="+$('#nextUid').val()+"&tx_cfwbmaheinstitution_pi1[prevUid]="+$('#prevUid').val()+"&tx_cfwbmaheinstitution_pi1[linkNavSlider]="+link+"&cshash="+numRand,
		    contentType: "application/json; charset=utf-8",
		    dataType: "html",
//		    data: "{'id':'4'}",
		    async:true,
		    success: function(data){
				/*$('.contenu').hide(1000,function(){
					$('#musee_box').empty().html(data);
					$('.contenu').hide(0);
					$('.contenu').show(1000);
					
					$('#nextLink').bind('click', function(event){
						event.preventDefault();
						callAjaxSliderLoader('next');
					});
					
					$('#prevLink').bind('click', function(event){
						event.preventDefault();
						callAjaxSliderLoader('prev');
					});
				});*/
				$('.contenu').animate({width: 'toggle'},1000,function(){
					$('#musee_box').empty().html(data);
					/*$('.contenu').hide();
					$('.contenu').show(0);*/
					
					$('#nextLink').bind('click', function(event){
						event.preventDefault();
						callAjaxSliderLoader('next');
					});
					
					$('#prevLink').bind('click', function(event){
						event.preventDefault();
						callAjaxSliderLoader('prev');
					});
				});
				//$('.contenu').animate({marginLeft: parseInt($('.contenu').css('marginLeft'),10) == 0 ? $('.contenu').outerWidth() : 0},1000);
		    }
		});
		
	}	
	

	function triggerAjax(){
		setTimeout(function(){triggerAjax();},6000);
		$('#nextLink').trigger('click');
	}
	
	
//	function mahe_carousel_initCallback(carousel) {
//		$('#nextLink').trigger('click');
	    /*jQuery('.jcarousel-control a').bind('click', function() {
	        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
	        return false;
	    });

	    jQuery('.jcarousel-scroll select').bind('change', function() {
	        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
	        return false;
	    });*/

//	    $('#nextLink').bind('click', function() {
//	        carousel.next();
//	    	callAjaxSliderLoader('next');
//	        return false;
//	    });

//	    $('#prevLink').bind('click', function() {
//	        carousel.prev();
//	    	callAjaxSliderLoader('prev');
//	        return false;
//	    });
//	};
	
//    $('#mahe_carousel').jcarousel({
//      scroll: 1,
//      auto: 6,
//      visible: 1,
//      wrap: 'circular',
//      initCallback: mahe_carousel_initCallback(),
//      //itemLoadCallback: itemLoadCallbackFunction,
//      buttonNextHTML: null,
//      buttonPrevHTML: null
//    });
});


///*
// * jHeartbeat 0.3.0
// * (C)Alex Richards - http://www.ajtrichards.co.uk/
// */
// 
// $.jheartbeat = {
//
//    options: {
//		url: "heartbeat_default.asp",
//		delay: 10000,
//		div_id: "test_div"
//    },
//	
//	beatfunction:  function(){
//	
//	},
//	
//	timeoutobj:  {
//		id: -1
//	},
//
//    set: function(options, onbeatfunction) {
//		if (this.timeoutobj.id > -1) {
//			clearTimeout(this.timeoutobj);
//		}
//        if (options) {
//            $.extend(this.options, options);
//        }
//        if (onbeatfunction) {
//            this.beatfunction = onbeatfunction;
//        }
//
//		// Add the HeartBeatDIV to the page
//		$("body").append("<div id=\"" + this.options.div_id + "\" style=\"display: none;\"></div>");
//		this.timeoutobj.id = setTimeout("$.jheartbeat.beat();", this.options.delay);
//    },
//
//    beat: function() {
//		$.ajax({
//				url: this.options.url,
//				dataType: "html",
//				type: "GET",
//				error: function(e)   { 
//					$('#'+ $.jheartbeat.options.div_id).append("Error Requesting Data"); 
//				},
//				success: function(data){ 
//					$('#'+ $.jheartbeat.options.div_id).html(data); 
//				}
//			   });
//		this.timeoutobj.id = setTimeout("$.jheartbeat.beat();", this.options.delay);
//        this.beatfunction();
//    }
//};

