

SIV.addHandlers({	

	showOverlay : function(success, data) {
		
		if(success){
			$('#sites-overlay').html(data.html);
		 	$('#sites-overlay').modal();
		}
	},
	emailThis : function(success, data) {
		if(success){
			$('#emailThisForm')[0].reset();
			$('#emailThisForm input, #emailThisForm textarea').removeClass('error').removeClass('removeBg');
			$('#load-email').hide();
			$('#send-email-button').show();
			$.colorbox.close();
			
		
		}else{
			
			$('#load-email').hide();
			$('#send-email-button').show();
			$('#' + data.field).addClass('error').focus()
			$('#' + data.field).next().show();
		}
	}
});

$(function() {
	$('.print-page').click(function(ev){
		ev.preventDefault();
		var docprint=window.open("",""); 
		docprint.document.write('<html><head>'  + 
		'<link href="/devlink/shared/css/print.css" type="text/css" rel="stylesheet" />' + 
		'<link href="/devlink/pages/css/viewPage.css" type="text/css" rel="stylesheet" /></head>');
		docprint.document.write('<body>' + $('.newsItemContainer').html() + '</body></html>');
		docprint.document.close(); 
	});
	
	$('#mobileMenuButton').click(function(){
		$('#menuBar').toggle();
		return false;
	})
		$('#registration-link').click(function(ev){
		$('#modal-overlay').fadeIn();
		$('#register-box').fadeIn();
		
	})
	
	$('#register-box a').click(function(ev){
		$('#modal-overlay').fadeOut();
		$('#register-box').fadeOut();
	})
	if($('#feature_block img').length > 1){
	
		
		$('#feature_block').nivoSlider({ 
			  effect:'sliceDown', // Specify sets like: 'fold,fade,sliceDown'
		        slices:15, // For slice animations
		        boxCols: 8, // For box animations
		        boxRows: 4, // For box animations
		        animSpeed:700, // Slide transition speed
		        pauseTime:7000, // How long each slide will show
		        startSlide:0, // Set starting Slide (0 index)
		        directionNav:true, // Next & Prev navigation
		        directionNavHide:true, // Only show on hover
		        controlNav:false, // 1,2,3... navigation
		        controlNavThumbs:false, // Use thumbnails for Control Nav
		        controlNavThumbsFromRel:false, // Use image rel for thumbs
		        controlNavThumbsSearch: '.jpg', // Replace this with...
		        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
		        keyboardNav:true, // Use left & right arrows
		        pauseOnHover:false, // Stop animation while hovering
		        manualAdvance:false, // Force manual transitions
		        captionOpacity:0.8, // Universal caption opacity
		        prevText: '', // Prev directionNav text
		        nextText: ''

			 });
			
			//$('#feature_block').jqFancyTransitions({ width: 680, height: 330 });

			 
			 
	}
	
		
	$('.close-splash').click(function(ev){
		ev.preventDefault();
		$('.u2-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');  
		});
		
	//$('.social-bookmarks').bookmark({sites: ['google','facebook','digg','delicious','stumbleupon','reddit','myspace','yahoo'], title:$('#contentHeadline').html()});
	
	$('#social-share-container .print').click(function(){
		window.print();
		return false;
	})
	
	$('#social-share-container .email').colorbox({
			width: "710px",
			inline: true,
			href: "#emailThisForm",
			overlayClose: false
		});
	if(DataBridge.isMobile){
		$('#signupButton').colorbox({
			width: "97%",
			inline: true,
			href: "#signupForm",
			overlayClose: false
		});
	}else{
		$('#signupButton').colorbox({
			width: "710px",
			inline: true,
			href: "#signupForm",
			overlayClose: false
		});
	}	
	
		
		$("#registerForm input[placeholder], #registerForm textarea[placeholder], #emailThisForm input[placeholder], #emailThisForm textarea[placeholder]").enablePlaceholder();
	
	/*$('#menuBar li a.parent-menu').live('click',function(ev){		
			id = $(this).getId();
			$('.sub-menu').hide();
			$('#subMenu-' + id).show();
			return false;
	});*/
	
		
	function clearMenu(){
	
		$('.active .submenu').hide();
		$(".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').remove();
	}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-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;
	})

	$('#closeContinue').click(function(){
		closeSplash();
		return false;
	})
	$('#modal-overlay').click(function(){
		closeSplash();
	});
	
	
	$('#promoClick').click(function(){
		closeSplash();
	})
	$('#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;
	})
	
	$('#send-email').click(function(){
		$(this).parent('div').hide();
		$('#load-email').show();
		
		$('#emailThisForm .check').each(function(){
			if($(this).val() == $(this).attr('placeholder')){
				$(this).addClass('error').focus().next().show();
				$('#send-email-button').show();
				$('#load-email').hide();
				return false;
			}
			
			
			
		})
		
		//console.log('test');
		
		SIV.ajaxCall({
				url: '/ajax/social/emailThis',
				form: 'emailThisForm',
				postData:{
					'title': document.title 
				},
				handler: 'emailThis'
			});
		return false;
	})
	
	if(!DataBridge.isMobile){
		$('#partners-scroll').jcarousel({
		    'wrap':'both',
			'auto':'3',
			'scroll':6,
			'visible':7
		});
	}
	
	$('#sivSiteSelect').change(function(){
		document.location.href = $(this).val();
	})
	
	if(!DataBridge.isMobile){
		$('#olympicBar').meerkat({
			background: 'url(/open/img/olympicBarBg.png) repeat-x left bottom',
			height: '60px',
			width: '90%',
			position: 'bottom',
			animationIn: 'slide',
			animationSpeed: 500,
			close: '#olympicBarClose',
			dontShowAgain: '#olympicBarNever',
			onMeerkatShow:function(){
				$('#footer').css("margin-bottom","70px");
			}
		});

	}
	
	
	
})
function closeSplash(){
	$('#modal-overlay').hide();
	$('#popup').hide();
}
	

var javascript_countdown = function () {
	var time_left = 10; //number of seconds for countdown
	var output_element_id = 'javascript_countdown_time';
	var keep_counting = 1;
	var no_time_left_message = 'No time left for JavaScript countdown!';
	var timer;
	var stop = false;
 
	function countdown() {
		if(time_left < 2) {
			keep_counting = 0;
		}
 
		time_left = time_left - 1;
	}
 
	function add_leading_zero(n) {
		if(n.toString().length < 2) {
			return '0' + n;
		} else {
			return n;
		}
	}
 
	function format_output() {
		var hours, minutes, seconds;
		seconds = time_left % 60;
		minutes = Math.floor(time_left / 60) % 60;
		hours = Math.floor(time_left / 3600);
 
		return seconds;
	}
 
	function show_time_left() {
		$('#' + output_element_id).text(format_output())//time_left;
	}
 
	function no_time_left() {
		if(!stop){
			window.open('http://www.sivonline.com/','SIV Online') ;
			$.colorbox.close()
		}
		
	}
 
	return {
		count: function () {
			countdown();
			show_time_left();
		},
		timer: function () {
			javascript_countdown.count();
 
			if(keep_counting) {
				timer = setTimeout("javascript_countdown.timer();", 1000);
			} else {
				no_time_left();
			}
		},
		//Kristian Messer requested recalculation of time that is left
		setTimeLeft: function (t) {
			time_left = t;
			if(keep_counting == 0) {
				javascript_countdown.timer();
				
			}
		},
		init: function (t, element_id) {
			time_left = t;
			keep_counting = 1;
			output_element_id = element_id;
			javascript_countdown.timer();
			stop = false;
		},
		stop: function(){
			keep_counting = 0;
			stop = true;
			time_left = 0;
		}
	};
}();

function openSubMenu(id){
		
	$('.sub-menu').hide();
	$('#subMenu-' + id).show();
	return false;
}
 

