function change_calendar(precedence){
	var loader_img=base_url+'templates/images/ajax-loader.gif';
	
	$('.calendarLoader').fadeIn();
	$('.calendarPrevBtn').hide();		
	$('.calendarCurrContent').hide();
	$('.calendarNextBtn').hide();
	
	$.ajax({
		type: "POST",
		url: calendar_target_url,
		data: "precedence="+precedence,
		success: function(temp){
			var data=temp.split('|',7);
			$('#calendar_prev').html(data[0]).attr('onclick','change_calendar('+data[1]+');return false;').fadeIn();
			$('.calendarCurr h4').html(data[2]);
			$('.calendarDate').html(data[3]);
			$('#calendar_desc').html(data[4]);
			$('.calendarCurrContent').fadeIn(function(){
			$('.calendarLoader').fadeOut();	});
			$('#calendar_next').html(data[5]).attr('onclick','change_calendar('+data[6]+');return false;').fadeIn();
			if($('.calendarCurrContent h4').height() > 24){
			$('.calendarScroll').css('height', '101px');
			}
			else if($('.calendarCurrContent h4').height() < 25){
				$('.calendarScroll').css('height', '125px');
			}
			$('#calendarScroll').jScrollPane({
				verticalDragMinHeight: 5,
				verticalDragMaxHeight: 5,
			});
		}
	});
}

$(document).ready(function(){
	$('.overlay').css('opacity', 0.7);
	if($('a#signInBtn').length > 0){
		if($('#popupLogin').length > 0){
			$('#popupLogin').css('margin-top', -($('#popupLogin').height()/2));
			$('a#switchPopupBtn').click(function(){
				document.formregister.reset();
				$('#registerButton').show();
				$('#err_tr2').hide();
				$('#error_field2').html('');
				$('#popupLogin').slideUp('slow', function(){
					$('#popupRegister').slideDown('slow');
				})
			});
		}
		$('a#signInBtn').click(function(){
			document.formlogin.reset();
			$('#err_tr').hide();
			$('#error_field').html('');
			$('#overlay').fadeIn(150, function(){
				$('#popupLogin').slideDown('slow');
			});
		});
	}
	if($('a#registerBtn').length > 0){
		if($('#popupRegister').length > 0){
			$('#popupRegister').css('margin-top', -($('#popupRegister').height()/2));
		}
		$('a#registerBtn').click(function(){
			document.formregister.reset();
			$('#registerButton').show();
			$('#err_tr2').hide();
			$('#error_field2').html('');
			$('#overlay').fadeIn(150, function(){
				$('#popupRegister').slideDown('slow');
			});
		});
	}
	$('#overlay').click(function(){
		$('.popup').slideUp('normal', function(){
			$('#overlay').fadeOut('slow');
		});
	});
	$('.closeBtn').click(function(){
		$('.popup').slideUp('normal', function(){
			$('#overlay').fadeOut('slow');
		});
	});
	
	if($('.headAds').length > 0){
		$('.headAds').cycle();
	}
	if($('.adsItem').length > 0){
		$('.adsItem').cycle();
	}
	if($('#slider').length > 0){
    	$('#slider').movingBoxes({
			startPanel: 1,
			width: 960,
  			reducedSize: 1,
			panelWidth: 0.75,
	  		fixedHeight: true,
			wrap: true,
			buildNav: true,
			hashTags: false,
			navFormatter: function(){ return "&#9679;"; }
		});
	}
	if($('#sliderInside').length > 0){
    	$('#sliderInside').movingBoxes({
			startPanel: 1,
			width: 700,
  			reducedSize: 1,
			panelWidth: 1,
	  		fixedHeight: true,
			wrap: true,
			buildNav: true,
			hashTags: false,
			navFormatter: function(){ return "&#9679;"; }
		});
	}
	if($('#calendarScroll').length > 0){
		if($('.calendarCurrContent h4').height() > 24){
			$('.calendarScroll').css('height', '101px');
		}
		else if($('.calendarCurrContent h4').height() < 25){
			$('.calendarScroll').css('height', '125px');
		}
    	$('#calendarScroll').jScrollPane({
			verticalDragMinHeight: 5,
			verticalDragMaxHeight: 5,
		});
	}
	if($('#mapOfBali').length > 0){
		$(function() {
			$('.mapList a').lightBox({
				txtImage: 'Photo',
				imageLoading: 'http://dev.isysedge.com/hellobali/templates/images/lightbox-ico-loading.gif',
				imageBtnClose: 'http://dev.isysedge.com/hellobali/templates/images/lightbox-btn-close.gif',
				imageBtnPrev: 'http://dev.isysedge.com/hellobali/templates/images/lightbox-btn-prev.gif',
				imageBtnNext: 'http://dev.isysedge.com/hellobali/templates/images/lightbox-btn-next.gif'
				/*
				imageLoading:'images/lightbox-ico-loading.gif',
				imageBtnClose: 'images/lightbox-btn-close.gif',
				imageBtnPrev: 'images/lightbox-btn-prev.gif',
				imageBtnNext: 'images/lightbox-btn-next.gif
				*/
			});
		});
	}
	
	if($('#insideList').length > 0){
		$('.insideListItem').each(function(){
			$(this).find('.insideListDetails').animate({
				bottom: -($(this).find('.insideListDetails').height())
			});
			$(this).data('state', null);
			$(this).mouseenter(function(){
				if($(this).data('state') == null){
					$(this).find('.insideListDetails').stop().animate({bottom: '0'});
					$(this).data('state', 'active');
				}
			}).mouseleave(function(){
				if($(this).data('state') == 'active'){
					$(this).find('.insideListDetails').stop().delay(1000).animate({bottom: -($(this).find('.insideListDetails').height())});
					$(this).data('state', null);
				}
			})
		});
	}
	
	
});
