$(document).ready(function() {	

//$('a[name=modal]').click(function(e) {

// e.preventDefault(); 

 //var id = $(this).attr('href'); 
 
 $('a[name=modal]').click(function(e) {
 e.preventDefault(); 

var id = $(this).attr('href'); 
//Get the A tag
		var id = '#dialog';
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		//$('#mask').css({'width':'100%','height':'1000px'});
		$('#mask').css({'width':'100%'});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css({'top': '20px'});
//		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
		$( ".printable" ).printElement();
});


		//Get the A tag
		var id = '#dialog';
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		//$('#mask').css({'width':'100%','height':'1000px'});
		$('#mask').css({'width':'100%'});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css({'top': '20px'});
//		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000);
		
$( ".printable" ).printElement();



	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});

/*
* Print Element Plugin 0.9
*
* Copyright (c) 2009 Erik Zaadi
*
* Inspired by PrintArea (http://plugins.jquery.com/project/PrintArea) and
* http://stackoverflow.com/questions/472951/how-do-i-print-an-iframe-from-javascript-in-safari-chrome
*
* $Id: jquery.printElement.js PENDING ID ErikZ $
*
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*/
(function($) {
    $.fn.printElement = function(options) { var mainOptions = $.extend({}, $.fn.printElement.defaults, options); $("[id^='printElement_']").remove(); return this.each(function() { var opts = $.meta ? $.extend({}, mainOptions, $this.data()) : mainOptions; _printElement($(this), opts); }); }; $.fn.printElement.defaults = { printMode: 'iframe', pageTitle: '', overrideElementCSS: [], printBodyOptions: { styleToAdd: 'padding:10px;margin:10px;', classNameToAdd: '' }, leaveOpen: false, iframeElementOptions: { styleToAdd: 'position:absolute;width:0px;height:0px;', classNameToAdd: ''} }; function _printElement(element, opts) {
        var $elementToPrint = $(element); var html = _getMarkup($elementToPrint, opts); var popupOrIframe = null; var documentToWriteTo = null; if (opts.printMode.toLowerCase() == 'popup') { popupOrIframe = window.open('', 'printElementWindow', 'width=650,height=440,scrollbars=yes'); documentToWriteTo = popup.document; }
        else { var printElementID = "printElement_" + (Math.random() * 99999).toString(); iframe = document.createElement('IFRAME'); $(iframe).attr({ style: opts.iframeElementOptions.styleToAdd, id: printElementID, className: opts.iframeElementOptions.classNameToAdd }); document.body.appendChild(iframe); documentToWriteTo = iframe.contentWindow.document; var iframe = document.frames ? document.frames[printElementID] : document.getElementById(printElementID); popupOrIframe = iframe.contentWindow || iframe; }
        documentToWriteTo.open(); documentToWriteTo.write(html); documentToWriteTo.close(); popupOrIframe.focus();
    }; function _getMarkup(element, opts) {
        var $elementToPrint = $(element); var html = new Array(); html.push('<html><head><title>' + opts.pageTitle + '</title>'); if (opts.overrideElementCSS && opts.overrideElementCSS.length > 0) { for (var x = 0; x < opts.overrideElementCSS.length; x++) { html.push('<link type="text/css" rel="stylesheet" href="' + opts.overrideElementCSS[x] + '" >'); } }
        else { $(document).find("link ").filter(function() { return $(this).attr("rel").toLowerCase() == "stylesheet"; }).each(function() { html.push('<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >'); }); }
        html.push('</head><body onload="printPage();" style="' + opts.printBodyOptions.styleToAdd + '" class="' + opts.printBodyOptions.classNameToAdd + '">'); html.push('<div class="' + $elementToPrint.attr("class") + '">' + $elementToPrint.html() + '</div>'); html.push('<script type="text/javascript">function printPage() { focus();print();' + (opts.leaveOpen ? '' : 'close();') + '}</script></body></html>'); return html.join('');
    };
})(jQuery);

/*
// Create a jquery plugin that prints the given element.
jQuery.fn.print = function(){
	// NOTE: We are trimming the jQuery collection down to the
	// first element in the collection.
	if (this.size() > 1){
		this.eq( 0 ).print();
		return;
	} else if (!this.size()){
		return;
	}
 
	// ASSERT: At this point, we know that the current jQuery
	// collection (as defined by THIS), contains only one
	// printable element.
 
	// Create a random name for the print frame.
	var strFrameName = ("printer-" + (new Date()).getTime());
 
	// Create an iFrame with the new name.
	var jFrame = $( "<iframe name='" + strFrameName + "'>" );
 
	// Hide the frame (sort of) and attach to the body.
	jFrame
		.css( "width", "1px" )
		.css( "height", "1px" )
		.css( "position", "absolute" )
		.css( "left", "-9999px" )
		.appendTo( $( "body:first" ) )
	;
 
	// Get a FRAMES reference to the new frame.
	var objFrame = window.frames[ strFrameName ];
 
	// Get a reference to the DOM in the new frame.
	var objDoc = objFrame.document;
 
	// Grab all the style tags and copy to the new
	// document so that we capture look and feel of
	// the current document.
 
	// Create a temp document DIV to hold the style tags.
	// This is the only way I could find to get the style
	// tags into IE.
	var jStyleDiv = $( "<div>" ).append(
		$( "style" ).clone()
		);
 
	// Write the HTML for the document. In this, we will
	// write out the HTML of the current element.
	objDoc.open();
	objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
	objDoc.write( "<html>" );
	objDoc.write( "<body>" );
	objDoc.write( "<head>" );
	objDoc.write( "<title>" );
	objDoc.write( document.title );
	objDoc.write( "</title>" );
	objDoc.write( jStyleDiv.html() );
	objDoc.write( "</head>" );
	objDoc.write( this.html() );
	objDoc.write( "</body>" );
	objDoc.write( "</html>" );
	objDoc.close();
 
	// Print the document.
	objFrame.focus();
	objFrame.print();
 
	// Have the frame remove itself in about a minute so that
	// we don't build up too many of these frames.
	setTimeout(
		function(){
			jFrame.remove();
		},
		(60 * 1000)
		);
}

// When the document is ready, initialize the link so
// that when it is clicked, the printable area of the
// page will print.
$(
function(){
  
// Hook up the print link.
 $( "a.doit" )
 .attr( "href", "javascript:void( 0 )" )
 .click(
 function(){
 // Print the DIV.
 $( ".printable" ).print();
  
 // Cancel click event.
 return( false );
 }
 )
 ;
  
 }
 );
*/
