$.noConflict();
(function($) {
	
	

	$.fn.modalWindow = function(content, overlayId) {
	
			 var $t = this,
			content = $(content),
		 	overlayId = overlayId || "modal-overlay",
			overlayDiv = $("<div/>", {
				"id" : overlayId,
				html: content.html()
			});

		$t.click(function(e) {
			$("body").prepend(overlayDiv);
			var bgDiv = $("<div />", {
				"id" : "modal-bg"
			})
			.css({
				"height" : $("body").height() + "px",
				"width" : "100%"
			})
			.prependTo($("body")).fadeIn("500", function() {
				var topPos = ($(window).height()/2) - $("#"+overlayId).height()/2+$(window).scrollTop()-50,
					leftPos = (($(window).width() - $("#"+overlayId).width())/2);


				overlayDiv.css({
					"top" : topPos + "px",
					"left" : leftPos + "px"
				}).fadeIn("500");

			});

			return false;
		});

		$("#close-bttn, #modal-bg").live("click",function() {
			killOverlay();
		})

		function killOverlay() {
			$("#"+overlayId).fadeOut("500", function() {
				$("#modal-bg").fadeOut();
			});
		}

	}
	
	$(function() {
		$("#contact-overlay").css("display", "none");
		/*$(".news, #latest-news article").hover(*/
		$(".biscuits, #biscuits article").hover( /* This is a horrible cheat! */
			function() {
				var $t = $(this),
					$img = $t.find("img"),
					origSrc = $img.attr("src"),
					origSrcBits = origSrc.split("_"),
					popped = origSrcBits.pop(),
					newSrc = origSrcBits.join("_");
				
				$(this).find("img").attr("src", newSrc + "_on.png");
			},
			function() {
				var $t = $(this),
					$img = $t.find("img"),
					origSrc = $img.attr("src"),
					origSrcBits = origSrc.split("_"),
					popped = origSrcBits.pop(),
					newSrc = origSrcBits.join("_");
				$(this).find("img").attr("src", newSrc + "_off.png");
			}
		);

		$("header").hover(
			function() {
				$(this).css("cursor","pointer");
			}
		);
		$("header").click(function() {
			window.location = "index.php";
		})
		var browser=navigator.userAgent.toLowerCase();  
		var users_browser = ((browser.indexOf('iphone')!=-1));  
		if(!users_browser) {
			$("#contact-us-link, .call-link").modalWindow(document.getElementById("contact-overlay"));
		}

	})
	

})(jQuery)

