var jsb = {
	init : function(page) {
		this.check(page);
		this.browserfilter(page);
		this.global.init();
		if(page=="omoss" || page=="kontakt") {
			jsb.schema.contactform();
			//jsb.fixes.height({ from : "#img_omoss_wrapper", to : "#maintop" } );
		}
		if(page=="omoss") {
			jsb.fixes.height({ from : "#img_omoss_wrapper", to : "#maintop" } );
		}
		/*if(page=="omoss") {
			jsb.global.effects.sequence(0);
		}*/
	},
	browserfilter : function(page) {
		if(BrowserDetect.browser == "Explorer") {
			if(BrowserDetect.version < 7)
				window.location="ie6.html";
		}	else if((BrowserDetect.OS == "Mac" && BrowserDetect.browser == "Firefox") || BrowserDetect.browser == "Safari") {
			$("#menu li a").css("top","0");
			$("#menu .active a").css("top","-3px");
		}
	},
	schema : {
		clear : function(id, newValue) {
			$(id).val((newValue ? newValue : ""));
		}, 
		contactform : function() {
			this.trixystuff({ id : "navn", txt : "ditt navn" });
			this.trixystuff({ id : "epost", txt :"din e-post" });
			this.trixystuff({ id : "melding", txt : "din melding" });
			$("#send_inn").click(function() {
				$(this).blur();
				if($("#navn").val()!="ditt navn" && $("#navn").val()!="" && 
					jsb.schema.isEmail($("#epost").val()) &&
					$("#melding").val()!="din melding" && $("#melding").val()!="") {
						jsb.ax("ajax/mail.php", {
							 name : encodeURIComponent($("#navn").val()),
							 email : encodeURIComponent($("#epost").val()),
							 message : encodeURIComponent($("#melding").val())
							}, function(r) {
							eval(r);
							if(response.success) {
								$("#msg").html("Takk for din henvendelse!").fadeIn("fast", function() {
									jsb.schema.clear("#navn", "ditt navn");
									jsb.schema.clear("#epost", "din e-post");
									jsb.schema.clear("#melding", "din melding");
									$(this).animate({opacity:1.0},3000, function() {
										$(this).fadeOut("fast", function() {
											$("#send_inn").attr("disabled",false);
										});
									});
								});
							} else {
								alert("En feil oppsto med skjemaet.<br><br>Vennligst send en mail til post@fotoringen.no i steden!");
							}
						});
					} else {
						$("#msg").html("Vennligst fyll ut alle feltene!").fadeIn("fast", function() {
							$(this).animate({opacity:1.0},3000, function() {
								$(this).fadeOut("fast", function() {
									$("#send_inn").attr("disabled",false);
								});
							});
						});
					}
			});
		},
		trixystuff : function(options) {
		 	$("#"+options.id).val(options.txt).focus(function() {
				if($(this).val()==options.txt) {
					$(this).val("");
				}
				$(this).blur(function() {
					if($(this).val()=="") {
						$(this).val(options.txt);
					}
				});
			});
			if(options.enter) {
				$("#"+options.id).keydown(function(event) {
					if(event.keyCode==13) {
						$(options.enter).submit();	
					}
				});
			}
		 },
		 isEmail : function(email) {
			return email.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)==null ? false : true;
		}
	},
	ax : function(s,d,callback) {
		$.post(s,d,function(r){
			callback(r);
		}, "script");
	},
	check : function(page) {
		$("#menu #"+page).attr("class","active");
	},
	global : {
		init : function() {
			this.effects.hover();
			this.effects.fader();
			this.footer.init();
			this.loginpad.init();
			this.emailImageLink();
		},
		emailImageLink : function() {
			$(".emailimage").click(function() {
				window.location="mailto:post@fotoringen.no";
			});
		},
		footer : {
			init : function() {
				$("#reeltime").unbind("click").click(function() {
					window.open("http://www.reeltime.no");
				});	
			}
		},
		loginpad : {
			init : function() {
			jsb.schema.trixystuff( { id : "brukernavn", txt : "brukernavn" } );
			jsb.schema.trixystuff({ id : "passord", txt : "passord", enter : "#login form" });
			$("#logg_inn").click(function() {
				$(this).blur();
				if($("#brukernavn").val()!="brukernavn" && $("#brukernavn").val()!="" && $("#passord").val()!="passord" && $("#passord").val()!="") {
					$("#login form").submit();
				} else {
					$("#brukernavn").focus();
				}
				return false;
			});
		 }
		},
		effects : {
			hover : function() {
				$(".knappf").hover(function() {
				$(this).attr("src",$(this).attr("src").replace(".jpg","_over.jpg"));
				},function() {
					$(this).attr("src",$(this).attr("src").replace("_over.jpg",".jpg"));
				});		
			},
			fader : function() {
				$('#fader').innerfade({ animationtype: 'fade', speed: 2000, timeout: 8000, type: 'random_start', containerheight: '1em' }).fadeIn("slow"); 
			},
			sequence : function(i) {
				if(i>=0) {
					$(".ansatt").eq(i).fadeIn("slow", function() {
						jsb.global.effects.sequence(i+1);
					});
				}
			}
		}
	},
	fixes : {
		height : function(options) {
			$(options.to).height($(options.from).height());
		}
	}
};
