/*
 * jQuery UI Effects Scale
 *
 * Copyright (c) 2008 Aaron Eisenberger (aaronchi@gmail.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 * 
 * http://docs.jquery.com/UI/Effects/Scale
 *
 * Depends:
 * effects.core.js
 */
(function($) {

$.effects.puff = function(o) {

 return this.queue(function() {

 // Create element
 var el = $(this);
 
 // Set options
 var options = $.extend(true, {}, o.options);
 var mode = $.effects.setMode(el, o.options.mode || 'hide'); // Set Mode
 var percent = parseInt(o.options.percent) || 150; // Set default puff percent
 options.fade = true; // It's not a puff if it doesn't fade! :)
 var original = {height: el.height(), width: el.width()}; // Save original
 
 // Adjust
 var factor = percent / 100;
 el.from = (mode == 'hide') ? original : {height: original.height * factor, width: original.width * factor};
 
 // Animation
 options.from = el.from;
 options.percent = (mode == 'hide') ? percent : 100;
 options.mode = mode;
 
 // Animate
 el.effect('scale', options, o.duration, o.callback);
 el.dequeue();
 });
 
};

$.effects.scale = function(o) {
 
 return this.queue(function() {
 
 // Create element
 var el = $(this);

 // Set options
 var options = $.extend(true, {}, o.options);
 var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode
 var percent = parseInt(o.options.percent) || (parseInt(o.options.percent) == 0 ? 0 : (mode == 'hide' ? 0 : 100)); // Set default scaling percent
 var direction = o.options.direction || 'both'; // Set default axis
 var origin = o.options.origin; // The origin of the scaling
 if (mode != 'effect') { // Set default origin and restore for show/hide
 options.origin = origin || ['middle','center'];
 options.restore = true;
 }
 var original = {height: el.height(), width: el.width()}; // Save original
 el.from = o.options.from || (mode == 'show' ? {height: 0, width: 0} : original); // Default from state
 
 // Adjust
 var factor = { // Set scaling factor
 y: direction != 'horizontal' ? (percent / 100) : 1,
 x: direction != 'vertical' ? (percent / 100) : 1
 };
 el.to = {height: original.height * factor.y, width: original.width * factor.x}; // Set to state
 
 if (o.options.fade) { // Fade option to support puff
 if (mode == 'show') {el.from.opacity = 0; el.to.opacity = 1;};
 if (mode == 'hide') {el.from.opacity = 1; el.to.opacity = 0;};
 };
 
 // Animation
 options.from = el.from; options.to = el.to; options.mode = mode;
 
 // Animate
 el.effect('size', options, o.duration, o.callback);
 el.dequeue();
 });
 
};

$.effects.size = function(o) {

 return this.queue(function() {
 
 // Create element
 var el = $(this), props = ['position','top','left','width','height','overflow','opacity'];
 var props1 = ['position','top','left','overflow','opacity']; // Always restore
 var props2 = ['width','height','overflow']; // Copy for children
 var cProps = ['fontSize'];
 var vProps = ['borderTopWidth', 'borderBottomWidth', 'paddingTop', 'paddingBottom'];
 var hProps = ['borderLeftWidth', 'borderRightWidth', 'paddingLeft', 'paddingRight'];
 
 // Set options
 var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode
 var restore = o.options.restore || false; // Default restore
 var scale = o.options.scale || 'both'; // Default scale mode
 var origin = o.options.origin; // The origin of the sizing
 var original = {height: el.height(), width: el.width()}; // Save original
 el.from = o.options.from || original; // Default from state
 el.to = o.options.to || original; // Default to state
 // Adjust
 if (origin) { // Calculate baseline shifts
 var baseline = $.effects.getBaseline(origin, original);
 el.from.top = (original.height - el.from.height) * baseline.y;
 el.from.left = (original.width - el.from.width) * baseline.x;
 el.to.top = (original.height - el.to.height) * baseline.y;
 el.to.left = (original.width - el.to.width) * baseline.x;
 };
 var factor = { // Set scaling factor
 from: {y: el.from.height / original.height, x: el.from.width / original.width},
 to: {y: el.to.height / original.height, x: el.to.width / original.width}
 };
 if (scale == 'box' || scale == 'both') { // Scale the css box
 if (factor.from.y != factor.to.y) { // Vertical props scaling
 props = props.concat(vProps);
 el.from = $.effects.setTransition(el, vProps, factor.from.y, el.from);
 el.to = $.effects.setTransition(el, vProps, factor.to.y, el.to);
 };
 if (factor.from.x != factor.to.x) { // Horizontal props scaling
 props = props.concat(hProps);
 el.from = $.effects.setTransition(el, hProps, factor.from.x, el.from);
 el.to = $.effects.setTransition(el, hProps, factor.to.x, el.to);
 };
 };
 if (scale == 'content' || scale == 'both') { // Scale the content
 if (factor.from.y != factor.to.y) { // Vertical props scaling
 props = props.concat(cProps);
 el.from = $.effects.setTransition(el, cProps, factor.from.y, el.from);
 el.to = $.effects.setTransition(el, cProps, factor.to.y, el.to);
 };
 };
 $.effects.save(el, restore ? props : props1); el.show(); // Save & Show
 $.effects.createWrapper(el); // Create Wrapper
 el.css('overflow','hidden').css(el.from); // Shift
 
 // Animate
 if (scale == 'content' || scale == 'both') { // Scale the children
 vProps = vProps.concat(['marginTop','marginBottom']).concat(cProps); // Add margins/font-size
 hProps = hProps.concat(['marginLeft','marginRight']); // Add margins
 props2 = props.concat(vProps).concat(hProps); // Concat
 el.find("*[width]").each(function(){
 child = $(this);
 if (restore) $.effects.save(child, props2);
 var c_original = {height: child.height(), width: child.width()}; // Save original
 child.from = {height: c_original.height * factor.from.y, width: c_original.width * factor.from.x};
 child.to = {height: c_original.height * factor.to.y, width: c_original.width * factor.to.x};
 if (factor.from.y != factor.to.y) { // Vertical props scaling
 child.from = $.effects.setTransition(child, vProps, factor.from.y, child.from);
 child.to = $.effects.setTransition(child, vProps, factor.to.y, child.to);
 };
 if (factor.from.x != factor.to.x) { // Horizontal props scaling
 child.from = $.effects.setTransition(child, hProps, factor.from.x, child.from);
 child.to = $.effects.setTransition(child, hProps, factor.to.x, child.to);
 };
 child.css(child.from); // Shift children
 child.animate(child.to, o.duration, o.options.easing, function(){
 if (restore) $.effects.restore(child, props2); // Restore children
 }); // Animate children
 });
 };
 
 // Animate
 el.animate(el.to, { queue: false, duration: o.duration, easing: o.options.easing, complete: function() {
 if(mode == 'hide') el.hide(); // Hide
 $.effects.restore(el, restore ? props : props1); $.effects.removeWrapper(el); // Restore
 if(o.callback) o.callback.apply(this, arguments); // Callback
 el.dequeue();
 }}); 
 
 });

};

})(jQuery);

//**************************************************************
// jQZoom allows you to realize a small magnifier window,close
// to the image or images on your web page easily.
//
// jqZoom version 2.2
// Author Doc. Ing. Renzi Marco(www.mind-projects.it)
// First Release on Dec 05 2007
// i'm looking for a job,pick me up!!!
// mail: renzi.mrc@gmail.com
//**************************************************************

(function($){

 $.fn.jqueryzoom = function(options){

 var settings = {
 xzoom: 200, //zoomed width default width
 yzoom: 200, //zoomed div default width
 offset: 10, //zoomed div default offset
 position: "right" ,//zoomed div default position,offset position is to the right of the image
 lens:1, //zooming lens over the image,by default is 1;
 preload: 1, 
 anim_scale: 1

 };

 if(options) {
 $.extend(settings, options);
 }

 var noalt='';

 $(this).hover(function(){
 
 var imageLeft = $(this).offset().left; 
 var imageTop = $(this).offset().top;

 
 var imageWidth = $(this).children('img').get(0).offsetWidth;
 var imageHeight = $(this).children('img').get(0).offsetHeight;


 noalt= $(this).children("img").attr("alt");

 var bigimage = $(this).children("img").attr("jqimg");

 $(this).children("img").attr("alt",'');

 if($("div.zoomdiv").get().length == 0){

 $(this).after("<div class='zoomdiv'><img class='bigimg' src='"+bigimage+"'/></div>");


 $(this).append("<div class='jqZoomPup'>&nbsp;</div>");

 }


 if(settings.position == "right"){

 if(imageLeft + imageWidth + settings.offset + settings.xzoom > screen.width){

 leftpos = imageLeft - settings.offset - settings.xzoom;

 }else{

 leftpos = imageLeft + imageWidth + settings.offset;
 }
 }else{
 leftpos = imageLeft - settings.xzoom - settings.offset;
 if(leftpos < 0){

 eftpos = imageLeft + imageWidth + settings.offset;

 }

 }
 
 var imageLeft2 = $(this).position().left; 
 var imageTop2 = $(this).position().top;
 var leftpos2 = imageLeft2 + imageWidth + 10;
 var imageTop2 = imageTop2 + 10;
 $("div.zoomdiv").css({ top: imageTop2,left: leftpos2 });

 $("div.zoomdiv").width(settings.xzoom);

 $("div.zoomdiv").height(settings.yzoom);

 if(settings.anim_scale) {
 $("div.zoomdiv").show("scale", {}, 1000);
 } else {
 $("div.zoomdiv").show();
 }
 if(!settings.lens){
 $(this).css('cursor','crosshair');
 }

 $(document.body).mousemove(function(e){



 mouse = new MouseEvent(e);

 /*$("div.jqZoomPup").hide();*/


 var bigwidth = $(".bigimg").get(0).offsetWidth;

 var bigheight = $(".bigimg").get(0).offsetHeight;

 var scaley ='x';

 var scalex= 'y';


 if(isNaN(scalex)|isNaN(scaley)){

 var scalex = (bigwidth/imageWidth);

 var scaley = (bigheight/imageHeight);




 //$("div.jqZoomPup").width((settings.xzoom)/scalex );

// $("div.jqZoomPup").height((settings.yzoom)/scaley);

 if(settings.lens){
 $("div.jqZoomPup").css('visibility','visible');
 }

 }

 

 xpos = mouse.x - $("div.jqZoomPup").width()/2 - imageLeft;

 ypos = mouse.y - $("div.jqZoomPup").height()/2 - imageTop ;

 if(settings.lens){

 xpos = (mouse.x - $("div.jqZoomPup").width()/2 < imageLeft ) ? 0 : (mouse.x + $("div.jqZoomPup").width()/2 > imageWidth + imageLeft ) ? (imageWidth -$("div.jqZoomPup").width() -2) : xpos;

 ypos = (mouse.y - $("div.jqZoomPup").height()/2 < imageTop ) ? 0 : (mouse.y + $("div.jqZoomPup").height()/2 > imageHeight + imageTop ) ? (imageHeight - $("div.jqZoomPup").height() -2 ) : ypos;

 }


 if(settings.lens){

 $("div.jqZoomPup").css({ top: ypos,left: xpos });

 }



 scrolly = ypos;

 $("div.zoomdiv").get(0).scrollTop = scrolly * scaley;

 scrollx = xpos;

 $("div.zoomdiv").get(0).scrollLeft = (scrollx) * scalex ;


 });
 },function(){

 $(this).children("img").attr("alt",noalt);
 $(document.body).unbind("mousemove");
 if(settings.lens){
 $("div.jqZoomPup").remove();
 }
 $("div.zoomdiv").remove();
 $("div#fxWrapper").remove();
 });

 count = 0;

 if(settings.preload){

 $('body').append("<div style='display:none;' class='jqPreload"+count+"'>Loading...</div>");

 $(this).each(function(){

 var imagetopreload= $(this).children("img").attr("jqimg");

 var content = jQuery('div.jqPreload'+count+'').html();

 jQuery('div.jqPreload'+count+'').html(content+'<img src=\"'+imagetopreload+'\">');

 });

 }

 }

})(jQuery);

function MouseEvent(e) {
this.x = e.pageX;
this.y = e.pageY;


}

