var bottlePlacement = function() {
    if ($(window).width() < 1350) {
        $(".b-bottle").hide();
    }
    else {

        $(".b-bottle").show();
    }
};

$(document).ready(function (e) {

	var cookie_value = jj.cookie('checkedAge');
	
	var current_location = window.location.href;
	
		if( (cookie_value == false || cookie_value == null) && window.location.href != 'http://www.stoneleigh.co.nz/agepage.php') {
			jj.cookie('back2page', window.location.href, { path: '/' });
			setTimeout(function(){
				window.location.href = 'http://www.stoneleigh.co.nz/agepage.php';
			}, 1);
		}
		else {
			$('.l-container').show();
		};

	$('#submitBut').bind('click',function(event){
		event.preventDefault();
		
		var c = countries;
		
		var month = $('input[name=month]').val();
		
		var year = $('input[name=year]').val();
		var country = $('select[name=country]').val();	
		var chosen_country = c[country];
		
		if( chosen_country == undefined) {
			alert('Please select a country');
			return false;
		}
		
		/* the minumum age you want to allow in */
		var min_age = parseInt(chosen_country.age);

		/* change "age_form" to whatever your form has for a name="..." */
		var yearNumber = parseInt(year);
		var monthNumber = parseInt(month) - 1;

		var theirDate = new Date((yearNumber + min_age), monthNumber);
		var today = new Date;

		if ( (today.getTime() - theirDate.getTime()) < 0) {
			alert("Unfortuntaly you are not old enough to legally visit this website.");
			return false;
		}
		
		
		if( isNaN(month) || month < 0 ||  month > 12) {
			alert('Please input a valid month and year.');
			return false;
		}
		
		if( isNaN(year) || year < 0 ||  year > 2011) {
			alert('Please input a valid month and year.');
			return false;
		}
		
		
		if( country.length > 0 ){
			var chosen_country = c[country];	
			
			
			var back2page = jj.cookie('back2page');		
			
			 if (back2page == null){
				window.location.href = 'http://www.stoneleigh.co.nz/';
			}
			else {
				if (document.agecheck.remember_me.checked == true){
					jj.cookie('checkedAge', true, { expires: 25, path: '/' });
					//console.log( document.agecheck );
					window.location.href = back2page;
				}
				else {
				
					jj.cookie('checkedAge', true, { path: '/' });
					//console.log( 'test' );
					window.location.href = back2page;
				}
			}
		}
		
	});
	
	bottlePlacement();
	
});

window.onresize = function() {
	bottlePlacement();
};
 
function MM_openBrWindow(theURL,winName,features) { 
    window.open(theURL,winName,features);
    return false;
}
