SIV.addHandlers({	

	showOverlay : function(success, data) {
		
		if(success){
			$('#sites-overlay').html(data.html);
		 	$('#sites-overlay').modal();
		}
	}
});



$(function() {

		$('#register-link').colorbox({
			width: "710px",
			inline: true,
			href: "#registerForm",
			overlayClose: false
		});
		
		$('#sivSiteSelect').change(function(){
			document.location.href = $(this).val();
		})
	
		
		$("a.feature-next").click(function(ev){
			 ev.preventDefault();
			 ev.target.blur();
    		 $("a.next-button").trigger('click');  
		});
		
		$("a.feature-back").click(function(ev){
			 ev.preventDefault();
			 ev.target.blur();
    		 $("a.back-button").trigger('click');  
		});
	
	if($('#head-text li').length > 1){
		
		var numFlashes = $('#head-text li').length;
		var flashItem = 1; 
		setInterval(
	        function()
	        {
				
				nextItem = flashItem + 1;
				
				
				if(nextItem > numFlashes) nextItem = 1;
				
				
	            $('#head-text li:nth-child(' + flashItem + ')').fadeOut();
				$('#head-text li:nth-child(' + nextItem + ')').fadeIn();
				flashItem = nextItem;
	        },
	        6000
	    );

	}
		
		
	$('.parent-menu').click(function(ev){
		ev.preventDefault();
		ev.target.blur();
		id = $(this).getId();
		if($(this).findParent('li').hasClass('active')){
			$(this).findParent('li').removeClass('active');
			
		}else{
			clearMenu();
			$(this).findParent('li').addClass('active');
		}
		
		$('#subMenu-' + id).slideToggle();

	});
	
	function clearMenu(){
	
		$('.active .submenu').slideToggle();
		$(".active").removeClass('active');
	}
	
		$('#allVenues_title a').click(function(ev){
		
		ev.target.blur();
		
		SIV.ajaxCall({
			url: '/ajax/sites/getOverlay',
			handler: 'showOverlay'
		});
		
	});	
	
	
	if($('#image-object-list li').length < 2){
		$('.image-object-selection').html('<br/>');
	}else{
		$('#image-object-current').html('1');
		$('#image-object-max').html($('#image-object-list li').length);
		$('#prev-select-image').addClass('disabled');
		$('#next-select-image').removeClass('disabled');
		$('#image-object-list li').hide();
		$('#image-object-list li:first').show();
	}
	
	$('.image-object-selection .prev').live('click',function(){
		if($(this).hasClass('disabled')) return false;
		
		id = $(this).getId();
		current = parseInt($('#' + id + '-object-current').html());
		$('#next-select-' + id).removeClass('disabled');
		next = current - 1;
		$('#' + id + '-object-list li:nth-child(' + current + ')').hide();
		$('#' + id + '-object-list li:nth-child(' + next + ')').show();
		
		$('#' + id + '-object-current').html(next);
		if(next == 1) $(this).addClass('disabled');
		return false;
		
	})
	
	$('.image-object-selection .next').live('click',function(){
		if($(this).hasClass('disabled')) return false;
		
		id = $(this).getId();
		current = parseInt($('#' + id + '-object-current').html());
		max =  parseInt($('#' + id + '-object-max').html());
		if(current == max) return false;
		$('#prev-select-' + id).removeClass('disabled');
		next = current + 1;
		$('#' + id + '-object-list li:nth-child(' + current + ')').hide();
		$('#' + id + '-object-list li:nth-child(' + next + ')').show();
		
		$('#' + id + '-object-current').html(next);
	
		if(next== max) $(this).addClass('disabled');
		return false;
	})
	
	$('#partners-scroll').jcarousel({
	    'wrap':'both',
		'auto':'3',
		'scroll':6,
		'visible':7
	});
	
	$('#hotel-input').datepicker({dateFormat:'dd/mm/yy',minDate: new Date() });
	$('#hotel-search').click(function(){
		dateVar = $('#hotel-input').val();
		dateArr = dateVar.split("/");
		dateArr[0] = dateArr[0] - 2;
		dateVar = dateArr[2]+"-"+dateArr[1]+"-"+dateArr[0];
		window.open('https://www.thebookingbutton.co.uk/property_groups/SheffieldAccom?start_date=' + dateVar); 
		return false;
	});
	
	$("#registerForm input[placeholder], #registerForm textarea[placeholder]").enablePlaceholder();


	
$('#xcontainer').click(function(){
		closeSplash();
		
	})
	$('#splash-continue-link').click(function(){
		closeSplash();
		return false;
	})
	$('#splash-promo-link').click(function(){
		closeSplash();
	})
	
	
	
})
function closeSplash(){
	$('#modal-overlay').hide();
	$('#popup').hide();
}

$.fn.hasAttr = function(name) {  
	var attr = $(this).attr(name);

  if (typeof attr !== 'undefined' && attr !== false){
  	return true
  }else{
  	return false;
  }
};



