/*	name			: ClassBehaviours, the javascript framework based on class-name parsing	update			: 20081124	author			: Maurice van Creij	dependencies	: jquery.classbehaviours.js	info			: http://www.classbehaviours.com/

    This file is part of jQuery.classBehaviours.
    
    ClassBehaviours is a javascript framework based on class-name parsing.
    Copyright (C) 2008  Maurice van Creij

    ClassBehaviours is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ClassBehaviours is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ClassBehaviours. If not, see http://www.gnu.org/licenses/gpl.html.*/

	// create the jQuery object if it doesn't already exist
	if(typeof(jQuery)=='undefined') jQuery = function(){};
	
	// create the root classbehaviours object if it doesn't already exist
	if(typeof(jQuery.classBehaviours)=='undefined') jQuery.classBehaviours = function(){};
	
	// create the handlers child object if it doesn't already exist
	if(typeof(jQuery.classBehaviours.handlers)=='undefined') jQuery.classBehaviours.handlers = function(){}

	// Open print dialog
	jQuery.classBehaviours.handlers.openAsPrintable = {
		// properties
		name: 'openAsPrintable',
		// methods
		start: function(node){
			node.onclick = this.process;
		},
		process: function(that){
			var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
			// If there is a demo popup
			if(document.getElementById('tgtPopTitle')){
				// copy the title to the print popup title
				document.getElementById('tgtPopTitle').innerHTML = document.getElementById('content').getElementsByTagName('h1')[0].innerHTML;
				// copy the content tot the print popup content
				document.getElementById('tgtPopText').innerHTML = (document.getElementById('content').innerHTML.indexOf('</h1>')>-1) ? document.getElementById('content').innerHTML.split('</h1>')[1] : document.getElementById('content').innerHTML.split('</H1>')[1];
				// show the print popup
				jQuery.classBehaviours.handlers.openLayerPopUp.show(document.getElementById('popup0'));
				// open the print dialog
				setTimeout("window.print();",2048);
			}else{
				window.print();
			}
			// cancel the click
			return false;
		}
	}
			
	// add this addon to the jQuery object
	if(typeof(jQuery.fn)!='undefined'){
		// extend jQuery with this method
		jQuery.fn.openAsPrintable = function(){
			return this.each(
				function(){
					jQuery.classBehaviours.handlers.openAsPrintable.start(this);
				}
			);
		};
		// set the event handler for this jQuery method
		$(document).ready(
			function(){
				$(".openAsPrintable").openAsPrintable();
			}
		);
	}


