$(document).ready(function() {

    // Populate the print friendly layer for articles
    $("#articleDtl-print").click(function() {

        var print = $("#lightbox-printDetail");

        // Empty the layer
        $("#lightbox-printDetail").children()
                .not("div.closeLightbox")
                .not("div#printDetail-copyright")
                .remove();

        // Insert content
        var contentMarker = $("#lightbox-printDetail").children("#printDetail-copyright");
		contentMarker.before($("#miraTrendArticle-title").children().clone());
        contentMarker.before($("#miraTrendArticle-copyArea").children().clone());		
		$(".lightbox-content h1").wrap('<div class="lightboxPrint-header clearfix"></div>');
		$(".lightbox-content h1").before('<img width="35" height="35" border="0" alt="Print this page" onclick="window.print(); return false;" src="/common/images/btn-print-off.gif" class="btn-printMe" />');
		$('.btn-printMe').bind("mouseover", function() {
			$(this).attr("src",$(this).attr("src").replace("-off","-on"));
		});
		$('.btn-printMe').bind("mouseout", function() {
			$(this).attr("src",$(this).attr("src").replace("-on","-off"));
		});
        
        // Remove non-print elements
		print.find(".btn-back, #miraTrendArticle-largeBanner ul, #miraTrendArticle-bannerImages, span.pressPhoto, #miraTrendArticle-copy img").remove();
    });
	
	// Populate the print friendly layer for Where to Buy
	$("#wtbFormat-print").click(function() {

        var print = $("#lightbox-printDetail");

        // Empty the layer
        $("#lightbox-printDetail").children()
                .not("div.closeLightbox")
                .not("div#printDetail-copyright")
                .remove();

        // Insert content
        var contentMarker = $("#lightbox-printDetail").children("#printDetail-copyright");
		contentMarker.before($("p.wtb-companyName").clone());
		$("#lightbox-printDetail p.wtb-companyName").replaceWith('<h1>' + $("#lightbox-printDetail p.wtb-companyName").text() + '</h1>');
        contentMarker.before($(".wtb-companyAddress").clone());
		contentMarker.before($(".wtb-callFirst").clone());
		$(".lightbox-content h1").wrap('<div class="lightboxPrint-header clearfix"></div>');
		$(".lightbox-content h1").before('<img width="35" height="35" border="0" alt="Print this page" onclick="window.print(); return false;" src="/common/images/btn-print-off.gif" class="btn-printMe" />');
		contentMarker.before($("#whereToBuy-multiMap").clone());
		$('.btn-printMe').bind("mouseover", function() {
			$(this).attr("src",$(this).attr("src").replace("-off","-on"));
		});
		$('.btn-printMe').bind("mouseout", function() {
			$(this).attr("src",$(this).attr("src").replace("-on","-off"));
		});
    });
	
	// Populate the print friendly layer for Water Systems
	$("#waterSystems-print").click(function() {

        var print = $("#lightbox-printDetail");

        // Empty the layer
        $("#lightbox-printDetail").children()
                .not("div.closeLightbox")
                .not("div#printDetail-copyright")
                .remove();

        // Insert content
        var contentMarker = $("#lightbox-printDetail").children("#printDetail-copyright");
		contentMarker.before($("#supportApprovals-header").children().clone());
        contentMarker.before($(".supportApproval-description, .supportApproval-description-last").clone());
		$(".lightbox-content h1").wrap('<div class="lightboxPrint-header clearfix"></div>');
		$(".lightbox-content h1").before('<img width="35" height="35" border="0" alt="Print this page" onclick="window.print(); return false;" src="/common/images/btn-print-off.gif" class="btn-printMe" />');
		$('.btn-printMe').bind("mouseover", function() {
			$(this).attr("src",$(this).attr("src").replace("-off","-on"));
		});
		$('.btn-printMe').bind("mouseout", function() {
			$(this).attr("src",$(this).attr("src").replace("-on","-off"));
		});
    });
	
	// Populate the print friendly layer for Customer Testimonials, Privacy, and Disclaimer
	$("#privacyDisclaimer-print").click(function() {

        var print = $("#lightbox-printDetail");

        // Empty the layer
        $("#lightbox-printDetail").children()
                .not("div.closeLightbox")
                .not("div#printDetail-copyright")
                .remove();

        // Insert content
        var contentMarker = $("#lightbox-printDetail").children("#printDetail-copyright");
		contentMarker.before($("#privacyDisclaimer-text").children().clone());
		$(".lightbox-content h1").wrap('<div class="lightboxPrint-header clearfix"></div>');
		$(".lightbox-content h1").before('<img width="35" height="35" border="0" alt="Print this page" onclick="window.print(); return false;" src="/common/images/btn-print-off.gif" class="btn-printMe" />');
		$('.btn-printMe').bind("mouseover", function() {
			$(this).attr("src",$(this).attr("src").replace("-off","-on"));
		});
		$('.btn-printMe').bind("mouseout", function() {
			$(this).attr("src",$(this).attr("src").replace("-on","-off"));
		});
    });
	
	//FAQ Print Scripts
    $("#lightbox-faqPrint .btn-send").click(function() {
		$('#lightbox-printDetail').queue(function() {
			$("#lightbox-faqPrint .btn-send").parents(".lightbox-content:first").hideLightbox();
			$(this).dequeue();
		})			
	    $('#lightbox-printDetail').queue(function() {
	        $('#lightbox-printDetail').showLightbox();
            $('link[rel*=style]').each(function(i) {
                if ($(this).attr('href').indexOf('print.css') > -1) $(this).attr('href', '/common/css/printLightbox.css');
            });
	        var print = $("#lightbox-printDetail");
	
	        // Empty the layer
	        $("#lightbox-printDetail").children()
	                .not("div.closeLightbox")
	                .not("div#printDetail-copyright")
	                .remove();
	
	        // Insert content
	        var contentMarker = $("#lightbox-printDetail").children("#printDetail-copyright");
	        contentMarker.before($("#questionAnswers-header").children().clone());
	        contentMarker.before($(".faq-category").clone());    
	        $(".lightbox-content h1").wrap('<div class="lightboxPrint-header clearfix"></div>');
	        $(".lightbox-content h1").before('<img width="35" height="35" border="0" alt="Print this page" onclick="window.print(); return false;" src="/common/images/btn-print-off.gif" class="btn-printMe" />');
	        $('.btn-printMe').bind("mouseover", function() {
	            $(this).attr("src",$(this).attr("src").replace("-off","-on"));
	        });
	        $('.btn-printMe').bind("mouseout", function() {
	            $(this).attr("src",$(this).attr("src").replace("-on","-off"));
	        });
	        // Remove non-print elements
	        print.find("ul, .btn-top").remove();
	        $(this).dequeue();
	    });
	    $('#lightbox-printDetail').queue(function() {
			var faqCount = $("#printFAQ-checkboxes").find("input[type=checkbox]").length;
			faqCount --;
			for(var b=0;b<faqCount;b++) {
				if($("#printFAQ-checkboxes input#categoryPrint" + b)[0].checked == true) {
					$(".lightbox-content .category" + b).css("display","block");
				}
			}
	        $(this).dequeue();
	    })
	});


	
	// Populate the print friendly layer for FAQs
	$("#faqs-print").click(function() {
		$('#lightbox-faqPrint').queue(function() {
	        $('#lightbox-faqPrint').showLightbox();
			$(this).dequeue();
		})
		
		$('#lightbox-faqPrint').queue(function() {
	        $("#printFAQ-checkboxes input#categoryAll").click(function() {
				var faqCount2 = $("#printFAQ-checkboxes").find("input[type=checkbox]").length;
				faqCount2 --;
				if ($(this)[0].checked == true) {
					for(var c=0;c<faqCount2;c++) {
						$("#printFAQ-checkboxes input#categoryPrint" + c)[0].checked = true;
					}
				} else {
					for(var d=0;d<faqCount2;d++) {
						$("#printFAQ-checkboxes input#categoryPrint" + d)[0].checked = false;
					}
				}
			})
			$(this).dequeue();
		})
		
    });
	
	
	// Populate the print friendly layer for Planning Tips and Glossary
	$("#faqFormat-print").click(function() {
        var print = $("#lightbox-printDetail");

        // Empty the layer
        $("#lightbox-printDetail").children()
                .not("div.closeLightbox")
                .not("div#printDetail-copyright")
                .remove();

        // Insert content
        var contentMarker = $("#lightbox-printDetail").children("#printDetail-copyright");
		contentMarker.before($("#questionAnswers-header").children().clone());
		contentMarker.before($("#answers").children().clone());	
		$(".lightbox-content h1").wrap('<div class="lightboxPrint-header clearfix"></div>');
		$(".lightbox-content h1").before('<img width="35" height="35" border="0" alt="Print this page" onclick="window.print(); return false;" src="/common/images/btn-print-off.gif" class="btn-printMe" />');
		$('.btn-printMe').bind("mouseover", function() {
			$(this).attr("src",$(this).attr("src").replace("-off","-on"));
		});
		$('.btn-printMe').bind("mouseout", function() {
			$(this).attr("src",$(this).attr("src").replace("-on","-off"));
		});
		// Remove non-print elements
		print.find("ul, .btn-top").remove();
    });

    // Populate the print friendly layer for service and repairs
        $("#faqFormat-print").click(function() {
            var print = $("#lightbox-printDetail");

            // Empty the layer
            $("#lightbox-printDetail").children()
                    .not("div.closeLightbox")
                    .not("div#printDetail-copyright")
                    .remove();

            // Insert content
            var contentMarker = $("#lightbox-printDetail").children("#printDetail-copyright");
            contentMarker.before($("#form-middleColumn").children().clone());
            $(".lightbox-content h1").wrap('<div class="lightboxPrint-header clearfix"></div>');
            $(".lightbox-content h1").before('<img width="35" height="35" border="0" alt="Print this page" onclick="window.print(); return false;" src="/common/images/btn-print-off.gif" class="btn-printMe" />');
            $('.btn-printMe').bind("mouseover", function() {
                $(this).attr("src",$(this).attr("src").replace("-off","-on"));
            });
            $('.btn-printMe').bind("mouseout", function() {
                $(this).attr("src",$(this).attr("src").replace("-on","-off"));
            });
            // Remove non-print elements
            print.find("#link,.btn-top").remove();
        });
    
});
