/*
	name			: ClassBehaviours, the javascript framework based on class-name parsing
	update			: 9.11.9
	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(){}

	// show or hide a node
	jQuery.classBehaviours.handlers.zoomOnPhoto = {
		// properties
		name: 'zoomOnPhoto',
		// methods
		start: function(node){
			// set the events for the container
			if(node.onmouseover==null){
				node.onmouseover = this.onover;
				node.onmouseout = this.onout;
			}
			// set the event for the thumbnail
			unzoomedNode = node.getElementsByTagName('IMG')[0];
			unzoomedNode.onmousemove = this.onmove;
		},
		// events
		onover: function(that){
			var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
			// show the zoomed photo
			hiddenNode = objNode.getElementsByTagName('DIV')[0];
			hiddenNode.style.display = 'block';
		},
		onout: function(that){
			var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
			// hide the zoomed photo
			hiddenNode = objNode.getElementsByTagName('DIV')[0];
			hiddenNode.style.display = 'none';
		},
		onmove: function(that){
			var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
			var zop = jQuery.classBehaviours.handlers.zoomOnPhoto;
			// get the mouse position
			mouseX = (typeof(event)!='undefined' && navigator.userAgent.indexOf('MSIE ')>-1) ? event.x : that.layerX ;
			mouseY = (typeof(event)!='undefined' && navigator.userAgent.indexOf('MSIE ')>-1) ? event.y : that.layerY ;
			// adjust the zoomed photo
			zoomedNode = objNode.parentNode.getElementsByTagName('IMG')[1];
			zoomedNode.style.top = Math.round(-1 * mouseY * (zoomedNode.offsetHeight-zoomedNode.parentNode.offsetHeight)/objNode.offsetHeight) + 'px';
			zoomedNode.style.left = Math.round(-1 * mouseX * (zoomedNode.offsetWidth-zoomedNode.parentNode.offsetWidth)/objNode.offsetWidth) + 'px';
		}
	}

	// add this addon to the jQuery object
	if(typeof(jQuery.fn)!='undefined'){
		// extend jQuery with this method
		jQuery.fn.zoomOnPhoto = function(){
			return this.each(
				function(){
					jQuery.classBehaviours.handlers.zoomOnPhoto.start(this);
				}
			);
		};
		// set the event handler for this jQuery method
		$(document).ready(
			function(){
				$(".zoomOnPhoto").zoomOnPhoto();
			}
		);
	}
