//Methods and initializations global for every pagevar global = {		$ajax_loader : $('<p style="text-align:center;"><img src="/der_neuer_site/assets/images/ajax-loader.gif" width="32" height="32" /></p>'),	$dimmer : $('<div />', {'id':'dimmer'}), $overlay :  $('<div />', {'id':'overlay'}), $modal : $('<div />', {'id':'modal'}),	init : function(){				//So we can close modals with ESC		$('html, body').keyup(function(e){			if(e.keyCode === 27){				global.close_modals();			}		})					$('#sign-up-form').submit(function(){						$(this).ajaxSubmit({ 								dataType : 'json',								//show the loading message				beforeSubmit:  function(){									},								success: function(responseJSON, textStatus, jqXHR) { 					if(responseJSON.status === 'success'){						$('#priority-sign-up form').remove();						$('#priority-sign-up').prepend($('<div />', {}).load('ajax/get_signup_complete'));					}else {						$('#sign-up-message').show().html(responseJSON.message);					}								} 			}); 						return false;		});				$('#sign-in-form').submit(function(){						$(this).ajaxSubmit({ 				dataType :'json',								//show ajax loader...				beforeSubmit:  function(){									},								success: function(responseJSON, textStatus, jqXHR) { 									if(responseJSON.status === 'success'){						location.reload(true);					}else {						$('#sign-in-message').html(responseJSON.message);					}				} 			}); 						return false;		});				$('#feedback_form').submit(function(){			$(this).ajaxSubmit({ 				dataType :'json',								//show the loading message				beforeSubmit:  function(){					//pages.global.show_loading_dialog('Kirjaudutaan sisään');				},								success: function(responseJSON, textStatus, jqXHR) { 									if(responseJSON.status === 'success'){											var $close_link = $('<a />', {'href':''}).html('Sulje').click(function(e){							e.preventDefault();							global.close_modals();						})												$('#feedback form').hide();						$('#feedback_message').show().html(responseJSON.message).append('<br/><br/>').append($('<p />').append($close_link));					}else {						$('#feedback_message').show().html(responseJSON.message);					}				} 			}); 						return false;		});						$('#forgot-password-form').submit(function(){			$(this).ajaxSubmit({ 				dataType :'json',								//show the loading message				beforeSubmit:  function(){				},								success: function(responseJSON, textStatus, jqXHR) { 									if(responseJSON.status === 'success'){											var $close_link = $('<a />', {'href':''}).html('Sulje').click(function(e){							e.preventDefault();							global.close_modals();						})												$('#forgot-password form').hide();						$('#forgot-password_message').show().html(responseJSON.message).append('<br/><br/>').append($('<p />').append($close_link));					}else {						$('#forgot-password_message').show().html(responseJSON.message);					}				} 			}); 						return false;		});										$('#sign-in-email').focus(function(){					//Doenst match, probably because of some encoding issues			if ($(this).val() ==='sähköposti'){				$(this).val('');			}		});				$('#sign-in-password').focus(function(){			if ($(this).val() === 'salasana'){				$(this).val('');			}		});				$('.feedback-link').click(function(e){			e.preventDefault();			$('#feedback').show();		});					$('#show-sign-in-form, .log-in-link').click(function(e){			e.preventDefault();			$('body').toggleClass('show-sign-in-form');		});				$('#show-sign-up-form, .sign-up-link').click(function(e){			e.preventDefault();			$('#priority-sign-up').show();		});				$('#close-feedback-form, #close-signup-form, #close-forgot-password-form').click(function(e){			e.preventDefault();			global.close_modals();		});				$('.lost-password').click(function(e){			e.preventDefault();			$('#forgot-password').show();		})			},		init_age_verification : function(){			$("#age-verification-form input").focus(function(){			if($(this).hasClass('emptyme')){				$(this).val('');				$(this).removeClass('emptyme');			}		})			$('#age-verification-form').submit(function(){						var $day = $(this).find('#age_day');			var $month = $(this).find('#age_month');			var $year = $(this).find('#age_year');						if($day.val() === '' || $day.val() === 'PÄIVÄ' || $day.val() === 'PP'){				$day.val('PP');				return false;			}						if($month.val() === '' || $month.val() === 'KUUKAUSI' || $month.val() === 'KK'){				$month.val('KK');				return false;			}						if($year.val() === '' || $year.val() === 'VUOSI' || $year.val() === 'YYYY' ){				$year.val('YYYY');				return false;			}												$(this).ajaxSubmit({ 				dataType :'json',								success: function(responseJSON, textStatus, jqXHR) { 					if(responseJSON.status === 'success'){						location.reload(true);					}else {						window.location = 'http://www.hartwall.fi';					}				} 			}); 						return false;		});			},		close_modals : function(){		$('.modal').each(function(){			if($(this).attr('id') !== 'k18'){				$(this).hide();			}		})	},		open_modal : function(modal_page, t, w, h ){				global.$modal.dialog({				width: w, 				height: h, 				modal:true, 				resizable:false,				draggable: false,				title: t,				open : function(){					$.ajax({						"processData":false,						"dataType": 'html',						"type": "GET",						"url": "/modal/" + modal_page,						"beforeSend":function(request){							var dialog_height = ((global.$modal.dialog("option", "height") / 2) - 106);							global.$ajax_loader.css("padding-top", dialog_height);							global.$modal.html(global.$ajax_loader);						},						"success": function(response){							global.$modal.html(response);						}					});				}			});				}		/* 		show_message : function(msgJSON){				var icon = '';				var $message_dialog = '';				var timer;								switch(msgJSON.type){					case 'success': icon = 'ui-icon-circle-check'; break;					case 'error': icon = 'ui-icon-circle-close'; break;					case 'alert': icon = 'ui-icon-alert'; break;				}								if((msgJSON.title === "" || typeof(msgJSON.title)==='undefined') && msgJSON.type === "error"){					msgJSON.title = "Virhe!";				}								$message_dialog = 				$('<div />')				.append('<p><span class="ui-icon '+ icon +'" style="float:left; margin:0 7px 50px 0;"></span>'+ msgJSON.text +'</p>')				.dialog({					title : msgJSON.title,					modal: true,					buttons: {						Ok: function() {							$( this ).dialog( "close" );						}					},					open: function(){						if(msgJSON.type === 'success'){							timer = setTimeout(function(){								$message_dialog.dialog("widget").hide('highlight',{},1500, function(){									$message_dialog.dialog("close");								});							}, 2000);							}					},					beforeClose: function(){						clearTimeout(timer);					}				});			}	*/};//Page-specific methods and initializationsvar pages = {		beerplications : 	{			init: function(){				}		},		home : 	{		init : function(){				},				init_no_sale : function(){					$('.join').click(function(){				$('#priority-sign-up').show();			})					}	},		priority : 	{		init : function(){				},				init_saannot_ja_ehdot : function(){			$('html,body').animate({scrollTop: $("#content-2").offset().top}, 1000);		},				init_miten_se_toimii : function(){			$('html,body').animate({scrollTop: $("#content-2").offset().top}, 1000);		}		},		tuotetiedot :	{			init : function(){				}		},		videot: 	{			active_video : '',				init: function(){						pages.videot.active_video = $('#video_player').attr('src');			pages.videot.fade_thumbs();						$('a.video').hover(function(){				$(this).animate({opacity: 1}, 1000);			}, function(){				if($(this).attr('href') !== pages.videot.active_video){					$(this).animate({opacity: 0.6}, 500);				}			}).click(function(e){				e.preventDefault();				var url = $(this).attr('href');								pages.videot.active_video = url;				pages.videot.fade_thumbs();				$('#video_player').attr('src', url);			});		},				fade_thumbs : function(){			//Set the active video opacity to 1			$('a.video').filter(function(){					if($(this).attr('href') == pages.videot.active_video){					$(this).animate({opacity: 1}, 0);				}else {					$(this).animate({opacity: 0.6}, 0);				}			});		}	}};		
