/*
 * Facebox (for jQuery)
 * version: 1.1 (03/01/2008)
 * @requires jQuery v1.2 or later
 * Examples at http://famspam.com/facebox/
 * Licensed under the MIT:
 * http://www.opensource.org/licenses/mit-license.php
 * Copyright 2007, 2008 Chris Wanstrath [ chris@ozmm.org ]
 */
(function($) {
 $.fbx = function(data, klass) {
 $.fbx.init()
 $.fbx.loading()
 $.isFunction(data) ? data.call($) : $.fbx.reveal(data, klass)
 }

 $.fbx.settings = {
 loading_image : '/s/fb/loading.gif',
 close_image : '/s/fb/closelabel.gif',
 image_types : [ 'png', 'jpg', 'jpeg', 'gif' ],
 fbx_html : '\
 <div id="fbx" style="display:none;"> \
 <div class="popup"> \
 <table> \
 <tbody> \
 <tr> \
 <td class="tl"/><td class="b"/><td class="tr"/> \
 </tr> \
 <tr> \
 <td class="b"/> \
 <td class="body"> \
 <div class="content"> \
 </div> \
 <div class="footer"> \
 <a href="#" class="close"> \
 <img src="'+this.close_image+'" title="close" class="close_image" /> \
 </a> \
 </div> \
 </td> \
 <td class="b"/> \
 </tr> \
 <tr> \
 <td class="bl"/><td class="b"/><td class="br"/> \
 </tr> \
 </tbody> \
 </table> \
 </div> \
 </div>'
 }

 $.fbx.loading = function() {
 if ($('#fbx .loading').length == 1) return true

 $('#fbx .content').empty()
 $('#fbx .body').children().hide().end().
 append('<div class="loading"><img src="'+$.fbx.settings.loading_image+'"/></div>')

 var pageScroll = $.fbx.getPageScroll()
 $('#fbx').css({
 top:	pageScroll[1] + ($.fbx.getPageHeight() / 10),
 left:	pageScroll[0]
 }).show()

 $(document).bind('keydown.fbx', function(e) {
 if (e.keyCode == 27) $.fbx.close()
 })
 }

 $.fbx.reveal = function(data, klass) {
 if (klass) $('#fbx .content').addClass(klass)
 $('#fbx .content').append(data)
 $('#fbx .loading').remove()
 $('#fbx .body').children().fadeIn('normal')
 }

 $.fbx.close = function() {
 $(document).trigger('close.fbx')
 return false
 }

 $(document).bind('close.fbx', function() {
 $(document).unbind('keydown.fbx')
 $('#fbx').fadeOut(function() {
 $('#fbx .content').removeClass().addClass('content')
 })
 })

 $.fn.fbx = function(settings) {
 $.fbx.init(settings)

 var image_types = $.fbx.settings.image_types.join('|')
 image_types = new RegExp('\.' + image_types + '$', 'i')

 function click_handler() {
 $.fbx.loading(true)

 // support for rel="fbx[.inline_popup]" syntax, to add a class
 var klass = this.rel.match(/pic\[\.(\w+)\]/)
 if (klass) klass = klass[1]

 // div
 if (this.href.match(/#/)) {
 var url = window.location.href.split('#')[0]
 var target = this.href.replace(url,'')
 $.fbx.reveal($(target).clone().show(), klass)

 // image
 } else if (this.href.match(image_types)) {
 var image = new Image()
 image.onload = function() {
 $.fbx.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
 }
 image.src = this.href

 // ajax
 } else {
 $.get(this.href, function(data) { $.fbx.reveal(data, klass) })
 }

 return false
 }

 this.click(click_handler)
 return this
 }

 $.fbx.init = function(settings) {
 if ($.fbx.settings.inited) {
 return true
 } else {
 $.fbx.settings.inited = true
 }

 if (settings) $.extend($.fbx.settings, settings)
 $('body').append($.fbx.settings.fbx_html)

 var preload = [ new Image(), new Image() ]
 preload[0].src = $.fbx.settings.close_image
 preload[1].src = $.fbx.settings.loading_image

 $('#fbx').find('.b:first, .bl, .br, .tl, .tr').each(function() {
 preload.push(new Image())
 preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
 })

 $('#fbx .close').click($.fbx.close)
 $('#fbx .close_image').attr('src', $.fbx.settings.close_image)
 }

 // getPageScroll() by quirksmode.com
 $.fbx.getPageScroll = function() {
 var xScroll, yScroll;
 if (self.pageYOffset) {
 yScroll = self.pageYOffset;
 xScroll = self.pageXOffset;
 } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
 yScroll = document.documentElement.scrollTop;
 xScroll = document.documentElement.scrollLeft;
 } else if (document.body) {// all other Explorers
 yScroll = document.body.scrollTop;
 xScroll = document.body.scrollLeft;
 }
 return new Array(xScroll,yScroll)
 }

 // adapter from getPageSize() by quirksmode.com
 $.fbx.getPageHeight = function() {
 var windowHeight
 if (self.innerHeight) {	// all except Explorer
 windowHeight = self.innerHeight;
 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
 windowHeight = document.documentElement.clientHeight;
 } else if (document.body) { // other Explorers
 windowHeight = document.body.clientHeight;
 }
 return windowHeight
 }
})(jQuery);

//
 jQuery(document).ready(function($) {
 $('a[rel*=pic]').fbx()
 })
