SIV.addHandlers({	

	//showOverlay : function(success, data) {
		
	//	if(success){
	//		$('#sites-overlay').html(data.html);
	//	 	$('#sites-overlay').modal();
	//		$('#modalContainer').center();
	//		$("#modalContainer").css({ zIndex:"200000" });
	//	}
	//}
	showCalendar: function(success, data){
		
		if(success){
			$('#eventsCalContainer').html(data.html);
		}
		
	},
	
	signUp: function(success, data){
		
			if (success) {
				$.colorbox({
					width: "50%",
					inline: true,
					href: "#colorbox_page"
				});
			}
			else {			
				
					if (data.error == 'validating_email') {
					
						$.colorbox({
							
							width: "50%",
							html: "<p>We are sorry, but there seems to be a problem with the email address you have entered.</p><p>Please enter a valid email address, and try again.</p>"
						});
					
					}else if (data.error == 'email_already_in_database') {
					
						$.colorbox({
							width: "50%",
							html: "<p>We are sorry, but your email address is already registered with us.</p>"
						});
					
					}else if (data.error == 'sending_email') {
					
						$.colorbox({
							width: "50%",
							html: "<p>Error! Temporary problem sending email. Please try again later.</p><p>Apologises for any inconvenience.</p>"
						});
					
					}else if (data.error == 'database_error') {
					
						$.colorbox({
							width: "50%",
							html: "<p>Error! Temporary problem creating subscription. Please try again later.</p><p>Apologises for any inconvenience.</p>"
						});
					
					}else{
						
						$.colorbox({
							width: "50%",
							html: "<p>We are sorry, but an unknown error has occurred.</p>"
						});
						
					}
				
			}	
		
	}
});

$(function() {	

		$("input#searchstr").autocomplete({'minLength':3,'source':DataBridge.eventTitles,select: function(event, ob) { document.location.href='/events/' + ob.item['value']; return false; }
		});
		
	
		//$("#signUp").colorbox({width:"50%", inline:true, href:"#colorbox_page"});
		
		$('#signUp').click(function(ev){
			ev.preventDefault();			
			
			SIV.ajaxCall({
			url: '/ajax/signUp',
			form: $(this).findParent('form').attr('id'),
			handler: 'signUp'			
			});			
			
		});
		
		
		$('.close-splash').click(function(ev){
			ev.preventDefault();
			$('.arctics-banner').hide();
			$('.splash-overlay').fadeOut();
			
		});
		
		
		$("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($('#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');
		}

		
	//$('.social-bookmarks').bookmark({sites: ['google','facebook','digg','delicious','stumbleupon','reddit','myspace','yahoo'], title:$('#contentHeadline').html()});
	
	$('.parent-menu').click(function(ev){
		
		//console.log('hello');
		//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();
		$("#main-menu .active").removeClass('active');
	}
	
	function clearTopMenu(){
	
		$('#top-sub-menu .open').toggle();
		$('#top-sub-menu .open').removeClass('open');
		$("#top-menu  .active").removeClass('active');
	}
	
		
	$('#allVenues_title a').click(function(ev){
		ev.preventDefault();
		ev.target.blur();
		
		SIV.ajaxCall({
			url: '/ajax/sites/getOverlay',
			handler: 'showOverlay'
		});
		
	});
	
	$('.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;
	})

	
	if($('#xcontainer').length > 0){
		$('#eventSearch select').hide();
	}
	
	$('#xcontainer').click(function(){
		closeSplash();
		
	})
	$('#splash-continue-link').click(function(){
		closeSplash();
		return false;
	})
	$('#splash-promo-link').click(function(){
		closeSplash();
	})
 
 	$('#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;
	});
	
	$('#calHeader a').live('click',function(){
		if (!$(this).hasClass('disabled')) {
		
		
			$moYear = $(this).attr('href');
			$('#eventsCalContainer').html('<img src="/open/img/calendar-loader.gif" style="padding-top:30px;"/>');
			SIV.ajaxCall({
				url: '/ajax/calendar/getCal',
				handler: 'showCalendar',
				postData: {
					moYear: $moYear,
					venue: $('#calendarVenueSelect').val()
				}
			});
		}
		return false;
	})
	
	$('#calendarVenueSelect a').click(function(){
		if(!$(this).hasClass('active')){
			$moYear = $('#curCalendarMoYear').val();
			$('#eventsCalContainer').html('<img src="/open/img/calendar-loader.gif" style="padding-top:30px;"/>');
			venueId = $(this).attr('href');
			$('#calendarVenueSelect a').toggleClass('active');
			SIV.ajaxCall({
				url: '/ajax/calendar/getCal',
				handler: 'showCalendar',
				postData: {
					moYear: $moYear,
					venue: venueId
				}
			});
		}
		
		return false;
	})
	
	
});

function selectChanged(ev){
	if($(ev).attr('id').substring(7) != "")
	document.location.href="/events/" + $(ev).attr('id').substring(7)  + "/";
}

var css_browser_selector=function(){var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t)!=-1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js';h.className+=h.className?' '+c:c;

}



function closeSplash(){
	$('#modal-overlay').hide();
	$('#popup').hide();
	$('#eventSearch select').show();
}






