(function($){

/* FUNCTION FOR CENTERING POPUP */

$.fn.centerInClient = function(options) {
    /// <summary>Centers the selected items in the browser window. Takes into account scroll position.
    /// Ideally the selected set should only match a single element.
    /// </summary>    
    /// <param name="fn" type="Function">Optional function called when centering is complete. Passed DOM element as parameter</param>    
    /// <param name="forceAbsolute" type="Boolean">if true forces the element to be removed from the document flow 
    ///  and attached to the body element to ensure proper absolute positioning. 
    /// Be aware that this may cause ID hierachy for CSS styles to be affected.
    /// </param>
    /// <returns type="jQuery" />
    var opt = { forceAbsolute: false,
                container: window,    // selector of element to center in
                completeHandler: null
              };
    $.extend(opt, options);
   
    return this.each(function(i) {
        var el = $(this);
        var jWin = $(opt.container);
        var isWin = opt.container == window;

        // force to the top of document to ENSURE that 
        // document absolute positioning is available
        if (opt.forceAbsolute) {
            if (isWin)
                el.remove().appendTo("body");
            else
                el.remove().appendTo(jWin.get(0));
        }

        // have to make absolute
        el.css("position", "absolute");

        // height is off a bit so fudge it
        var heightFudge = isWin ? 2.0 : 1.8;

        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

        el.css("left", x + jWin.scrollLeft());
        el.css("top", y + jWin.scrollTop());

        // if specified make callback and pass element
        if (opt.completeHandler)
            opt.completeHandler(this);
    });
}

/* POPUP PACKAGE LIGHTBOXES */

$('ul.nav li a.tb').click(function(e){
e.preventDefault();

var url = $(this).attr('href');
var tbheight = $(this).attr('tbheight');
var maskHeight = $(document).height();
var maskWidth = $(window).width();

if (! tbheight) tbheight=550;
if (url=='totalcost.html'){
	var tbcss = 'tcofj';
	var tbwidth=600; 
} else {
	var tbcss = '';
	var tbwidth=568;
}

$('body').append('<div id="fjp_overlay"></div>');
$('#fjp_overlay').css({'width':maskWidth,'height':maskHeight});
$('#fjp_overlay').fadeTo(500, .75);

	tbheight=562;
	$('body').append('<div id="fjp_lightbox"><div id="medialb" class="'+tbcss+'"><div class="top"><a href="#" class="close"><img src="images/close.png" alt="Close" border="0" /></a></div><div class="mid"><iframe src="'+url+'?sid='+Math.random()+'" width="'+tbwidth+'" height="'+tbheight+'" frameborder="0" style="width:'+tbwidth+'px;height:'+tbheight+'px;border:0px;margin:0px 0px 0px 5px;" scrolling="no" id="lghtbox'+Math.random()+'"></iframe></div><div class="bot"><!-- spacer --></div></div></div>');
/*
if (url=='media.html'){
	tbheight=562;
	$('body').append('<div id="fjp_lightbox"><div id="medialb"><div class="top"><!-- spacer --></div><div class="mid"><iframe src="'+url+'?sid='+Math.random()+'" width="'+tbwidth+'" height="'+tbheight+'" frameborder="0" style="width:'+tbwidth+'px;height:'+tbheight+'px;border:0px;margin:0px;" scrolling="no" id="lghtbox"></iframe></div><div class="bot"><!-- spacer --></div></div></div>');
} else {
	$('body').append('<div id="fjp_lightbox"><iframe src="'+url+'" width="'+tbwidth+'" height="'+tbheight+'" frameborder="0" style="width:'+tbwidth+'px;height:'+tbheight+'px;border:0px;" scrolling="no" id="lghtbox"></iframe></div>');
}
*/

var posTop = ( $(window).height() - $("#fjp_lightbox").height() ) / 2 + $(window).scrollTop();
$("#fjp_lightbox").centerInClient();

$('#fjp_overlay').fadeTo(500, 0.75, function(){
	$('#fjp_lightbox').css('display', 'block');

});

$('#fjp_lightbox a.close').click(function(e){
	e.preventDefault();
	$('#fjp_lightbox').fadeTo(100, 0, function(){
		$(this).remove();
		$('#fjp_overlay').fadeTo(250, 0, function(){
			$(this).remove();
		});
	});
});

});

})(window.jQuery);


function showvideo(f,t){

	$.fancybox({
			'padding'		: 0,
			'autoScale'		: true,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'		: t,
			'href'			: 'http://www.youtube.com/v/'+f+'?fs=1&hl=en_US',
			'type'			: 'swf',
			'swf'			: {
			 'wmode'		: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});
}

    function showgal(i) {
               $.fancybox([
			{
				'href'	: 'images/media/photo1-large.jpg',
				'title'	: 'The RENA Mach 5 Digital Color Printer'
			},
			{
				'href'	: 'images/media/photo2-large.jpg',
				'title'	: 'Super Close Up Video Of Memjet Printhead Technology'
			},
			{
				'href'	: 'images/media/photo3-large.jpg',
				'title'	: 'Close-Up Of The Print Nozzles Of The Memjet Printhead'
			},
			{
				'href'	: 'images/media/photo4-large.jpg',
				'title'	: 'A View Of The Exclusive Memjet Print Engine'
			},
			{
				'href'	: 'images/media/photo5-large.jpg',
				'title'	: '250 ML Ink Tanks For Longer Print Runs'
			},
			{
				'href'	: 'images/media/photo6-large.jpg',
				'title'	: 'The Extended Hopper Holds up to 500 No. 10 Envelopes'
			},
			{
				'href'	: 'images/media/photo7-large.jpg',
				'title'	: 'The RENA Mach 5 Shown With The TB-390 Conveyor'
			}
               ], {
                       'padding'                      : 0,
                       'transitionIn'         : 'elastic',
                       'transitionOut'        : 'fade',
                       'type'              : 'image',
                       'changeFade'        : 0,
			  'autoScale'		 : true,
			  'index'		: i
               });
        }

