//**************************************************************
// jQZoom allows you to realize a small magnifier window,close
// to the image or images on your web page easily.
// Author Doc. Ing. Renzi Marco(www.mind-projects.it)
// Released on Dec 05 2007
// mail: renzi.mrc@gmail.com
// *** meiking edited it on Apr 24 2008 at www.bjcl.net.
// *** add some cool function, rework many place.
// *** if exist bugs, please tell me.
// *** mail: meiking@gmail.com
//**************************************************************
(function($){

	$.fn.jqueryzoom = function(options){

		var settings = {
			xzoom: 300,		//zoomed width default width
			yzoom: 300,		//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
		};

		if(options) {
			$.extend(settings, options);
		}

		var img_zoom = $(this).find("img");

		var top = getOffsetTop(img_zoom.get(0));
		var left = getOffsetLeft(img_zoom.get(0));

		var noalt ='';

		$(this).hover(function(){
			var img = new GetXYWH(img_zoom.get(0));

			var imageLeft = img.left;
			var imageRight = img_zoom.get(0).offsetRight;
			var imageTop =  img.top;
			var imageWidth = img.width;
			var imageHeight = img.height;
			
			var zoom_site_left = new GetXYWH($("#zoom_div_site").get(0));

			$(this).width(imageWidth);
			$(this).height(imageHeight);

			var bigimage = img_zoom.attr("lowalt");

			if($("div.zoomdiv").get().length == 0){
				$(this).after("<div class='zoomdiv'><img class='bigimg' src='"+bigimage+"'/></div>");
			}

			if($("#zoom_view").get().length == 0) {
				$(this).append("<div id='zoom_view'></div>");
				$(this).append("<div id='lim_top' class='use_filter'></div>");
				$(this).append("<div id='lim_left' class='use_filter'></div>");
				$(this).append("<div id='lim_right' class='use_filter'></div>");
				$(this).append("<div id='lim_bottom' class='use_filter'></div>");
			}

		    if(settings.position == "right"){
				leftpos = imageLeft + imageWidth + settings.offset;

		    }else{
				leftpos = imageLeft - settings.xzoom - settings.offset;
		    }
		    
			//leftpos = imageLeft;

//原位置，后一个为修改后位置
//			$("div.zoomdiv").css({"top": imageTop+95,"left": zoom_site_left.left+208,"width": 492,"height": 320});
			$("div.zoomdiv").css({"top": imageTop+95,"left": zoom_site_left.left+308,"width": 492,"height": 320});
//			$("div.zoomdiv").css({"top": imageTop+imageHeight+57,"left": zoom_site_left.left+2,"width": settings.xzoom,"height": settings.yzoom});
			$("div.zoomdiv").show();


			$(document.body).mousemove(function(e){

				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 = Math.round(bigwidth/imageWidth) ;

					var scaley = Math.round(bigheight/imageHeight);

				}

				mouse = new MouseEvent(e);


				scrolly = mouse.y - imageTop - ($("div.zoomdiv").height()*1/scaley)/2 ;
				$("div.zoomdiv").get(0).scrollTop = scrolly * scaley  ;

				$("#y").get(0).innerHTML = scrolly + " | " + scrolly * scaley;
				$("#imgy").get(0).innerHTML = imageTop + " | " + mouse.y;

				scrollx = mouse.x - imageLeft - ($("div.zoomdiv").width()*1/scalex)/2 ;
				$("div.zoomdiv").get(0).scrollLeft = scrollx * scalex ;

				$("#x").get(0).innerHTML = scrollx + " | " + scrollx * scalex;
				$("#imgx").get(0).innerHTML = imageLeft + " | " + mouse.x;

				$("#isie").get(0).innerHTML = ie;

				//					var view_width = imageWidth/scalex;
				//					var view_height = imageHeight/scaley;
				var view_width = 70;
				var view_height = 60;

				$("#zoom_view").css({"display":"block", "width":view_width, "height":view_height, "z-index":"99"});

				$("#lim_top").get(0).style.height = imageHeight;
				$("#lim_top").get(0).style.width = imageWidth;
				$("#lim_left").get(0).style.height = imageHeight;
				$("#lim_left").get(0).style.width = imageWidth;
				$("#lim_bottom").get(0).style.height = imageHeight;
				$("#lim_bottom").get(0).style.width = imageWidth;
				$("#lim_right").get(0).style.height = imageHeight;
				$("#lim_right").get(0).style.width = imageWidth;

				/* mouse top */
				if (mouse.y-view_height/2 <= imageTop) {
					$("#zoom_view").get(0).style.top = img_zoom.get(0).offsetTop+1;
					$("#lim_top").height(1);
					$("#lim_bottom").height(imageHeight-view_height)+1;
					if(ie)
					$("#lim_bottom").get(0).style.top	= imageTop+view_height;
					else
					$("#lim_bottom").get(0).style.top	= imageTop+view_height+1;
					$("#lim_left").get(0).style.top		= imageTop+1;
					$("#lim_right").get(0).style.top	= imageTop+1;
				}
				/* mouse buttom */
				else if(mouse.y+view_height/2 >= imageTop+imageHeight) {
					$("#zoom_view").get(0).style.top = img_zoom.get(0).offsetTop+imageHeight-view_height-1;
					$("#lim_top").height(imageHeight-view_height+1);
					$("#lim_bottom").height(1);
					$("#lim_bottom").get(0).style.top	= imageTop+imageHeight-1;
					$("#lim_left").get(0).style.top		= imageTop+imageHeight-(view_height)+1;
					$("#lim_right").get(0).style.top	= imageTop+imageHeight-(view_height)+1;
				}
				else {
					$("#zoom_view").get(0).style.top = mouse.y-view_height/2;
					$("#lim_top").height(mouse.y-imageTop-view_height/2+1);
					$("#lim_bottom").height(imageTop+imageHeight-mouse.y-view_height/2+1);
					if(ie) {
						$("#lim_bottom").get(0).style.top	= mouse.y+view_height/2;
					}else {
						$("#lim_bottom").get(0).style.top	= mouse.y+view_height/2+1;
					}
					$("#lim_left").get(0).style.top		= mouse.y-view_height/2+1;
					$("#lim_right").get(0).style.top	= mouse.y-view_height/2+1;
				}

				/* mouse right */
				if(mouse.x+view_width/2 >= imageLeft+imageWidth) {
					if(ie) {
						$("#zoom_view").get(0).style.left = img_zoom.get(0).offsetLeft+imageWidth-view_width;
						$("#lim_left").width(imageWidth-view_width);
						$("#lim_right").width(2);
						$("#lim_right").get(0).style.left = imageLeft+imageWidth-1;
					}
					else {
						$("#zoom_view").get(0).style.left = img_zoom.get(0).offsetLeft+imageWidth-view_width-3;
						$("#lim_left").width(imageWidth-view_width-1);
						$("#lim_right").width(1);
						$("#lim_right").get(0).style.left = imageLeft+imageWidth;
					}
				}
				/* mouse left */
				else if (mouse.x-view_width/2 <= img_zoom.get(0).offsetLeft) {
					$("#zoom_view").get(0).style.left = img_zoom.get(0).offsetLeft+1;
					$("#lim_left").width(1);

					if(ie) {
						$("#lim_right").width(imageWidth-view_width-3);
						$("#lim_right").get(0).style.left = imageLeft+view_width+3;
					}
					else {
						$("#lim_right").width(imageWidth-view_width);
						$("#lim_right").get(0).style.left = imageLeft+view_width;
					}
				}
				else {
					$("#zoom_view").get(0).style.left = mouse.x-view_width/2;
					$("#lim_left").width(mouse.x-imageLeft-view_width/2);
					if(ie) {
						$("#lim_right").width(imageWidth-(mouse.x-imageLeft+view_width/2));
						$("#lim_right").get(0).style.left = mouse.x+view_width/2;
					} else {
						$("#lim_right").width(imageWidth-(mouse.x-imageLeft+view_width/2));
						$("#lim_right").get(0).style.left = mouse.x+view_width/2;
					}
				}

				$("#lim_left").get(0).style.left = imageLeft;
				if(ie) {
					$("#lim_right").height(view_height-1);
					$("#lim_left").height(view_height-1);
				}
				else {
					$("#lim_right").height(view_height);
					$("#lim_left").height(view_height);
				}
				$("#lim_top").get(0).style.top = imageTop;
				$("#lim_top").get(0).style.left = imageLeft;
				$("#lim_bottom").get(0).style.left = imageLeft;

			});


		},function(){
			img_zoom.attr("alt",noalt);
			$("div.zoomdiv").hide();
			$(document.body).unbind("mousemove");
			$("div.zoomdiv").remove();
			$("#zoom_view").remove();
			$("#lim_top").remove();
			$("#lim_left").remove();
			$("#lim_right").remove();
			$("#lim_bottom").remove();
		});

	}


})(jQuery);

function MouseEvent(e) {
	this.x = e.pageX
	this.y = e.pageY
}

function getOffsetTop(obj) {
	var top = obj.offsetTop;
	while(1) {
		if(obj.offsetParent != null) {
			top+= obj.offsetParent.offsetTop;
			obj = obj.offsetParent;
		}
		else
		break;
	}
	return top;
}
function getOffsetLeft(obj) {
	var top = obj.offsetLeft;
	while(1) {
		if(obj.offsetParent != null) {
			top+= obj.offsetParent.offsetLeft;
			obj = obj.offsetParent;
		}
		else
		break;
	}
	return top;
}

var w3c=(document.getElementById)? true:false;
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
var ie5=(w3c && ie)? true : false;
var ns6=(w3c && (navigator.appName=="Netscape"))? true: false;
var op8=(navigator.userAgent.toLowerCase().indexOf("opera")==-1)? false:true;

function Obj(o){
	return document.getElementById(o)?document.getElementById(o):o;
}

function GetXYWH(o){
	var nLt=0;
	var nTp=0;
	var offsetParent = o;
	while (offsetParent!=null && offsetParent!=document.body) {
		nLt+=offsetParent.offsetLeft;
		nTp+=offsetParent.offsetTop;
		if(!ns6){
			parseInt(offsetParent.currentStyle.borderLeftWidth)>0 ? nLt+=parseInt(offsetParent.currentStyle.borderLeftWidth) : "";
			parseInt(offsetParent.currentStyle.borderTopWidth)>0 ? nTp+=parseInt(offsetParent.currentStyle.borderTopWidth) : "";
		}
		offsetParent=offsetParent.offsetParent;
		//alert(offsetParent.tagName);
	}
	this.left = nLt;
	this.top = nTp;
	this.width = o.offsetWidth;
	this.height = o.offsetHeight;
}


/**
 * HoverAccordion - jQuery plugin for intuitively opening accordions and menus
 * http://berndmatzner.de/jquery/hoveraccordion/
 * Copyright (c) 2007 Bernd Matzner
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Version: 0.4
 */
(function($){$.fn.hoverAccordion=function(options){options=jQuery.extend({speed:'fast',activateitem:'true',active:'active',header:'header',hover:'hover',opened:'opened',closed:'closed',keepheight:'true'},options);thislist=$(this);thislist.attr('hovering','false');var thisurl=window.location.href;function doHover(obj){if($(obj).html()==undefined)obj=this;if(thislist.attr('hovering')=='false'){var newelem=$(obj).parent().children('ul');var oldelem=$(obj).parent().parent().children('li').children('ul:visible');if(options.keepheight=='true'){thisheight=maxheight}else{thisheight=newelem.height()}if(!newelem.is(':visible')){thislist.attr('hovering','true');if(!oldelem.length>0){newelem.animate({height:thisheight},{duration:options.speed,easing:'linear'})}else{newelem.show()}oldelem.animate({height:'hide'},{step:function(n){newelem.height(Math.ceil(thisheight-n))},duration:options.speed,easing:'linear'});oldelem.parent().children('a').addClass(options.closed).removeClass(options.opened);newelem.parent().children('a').addClass(options.opened).removeClass(options.closed);resetHover=window.setTimeout("thislist.attr('hovering','false');",600)}}};function doNothing(){};var itemNo=0;var maxheight=0;$(this).children('li').each(function(){var thisitem=$(this);itemNo++;var thislink=thisitem.children('a');if(thislink.length>0){thislink.hover(function(){$(this).addClass(options.hover)},function(){$(this).removeClass(options.hover)});var thishref=thislink.attr('href');if(thishref=='#'){thislink.click(function(){thislist.attr('hovering','false');doHover(this);this.blur();return false})}else if(options.activateitem=='true'&&thisurl.indexOf(thishref)>0&&thisurl.length-thisurl.lastIndexOf(thishref)==thishref.length){thislink.parent().addClass(options.active)}}var thischild=thisitem.children('ul');if(thischild.length>0){if(maxheight<thischild.height())maxheight=thischild.height();thischild.children('li.'+options.active).parent().parent().children('a').addClass(options.header);try{thislink.hoverIntent({sensitivity:1,interval:80,over:doHover,timeout:600,out:doNothing})}catch(err){thislink.hover(function(){doHover(this)},function(){doNothing()})}if(options.activateitem=='true'){thischild.children('li').each(function(){var m=$(this).children('a').attr('href');if(m){if(thisurl.indexOf(m)>0&&thisurl.length-thisurl.lastIndexOf(m)==m.length){$(this).addClass(options.active).parent().parent().children('a').addClass(options.opened)}}})}else if(parseInt(options.activateitem)==itemNo){thisitem.addClass(options.active).children('a').addClass(options.opened)}}thischild.not($(this).parent().children('li.'+options.active).children('ul')).not(thischild.children('li.'+options.active).parent()).hide().parent().children('a').addClass(options.closed)})}})(jQuery);



jQuery.noConflict();
jQuery(document).ready(
function(){
	$('#item').hoverAccordion({
		activateitem: '1',
		speed: 'slow'
	});
	$('#item').children('li:first').addClass('firstitem');
	$('#item').children('li:last').addClass('lastitem');
	var overFlow2 = $("#category_li");
	$("#category_show").hover(
			function(){
				overFlow2.fadeIn();
			},
			function (){
				overFlow2.fadeOut();
			}
	);
			$("#category_li").hover(
			function(){
				overFlow2.fadeIn();
			},
			function(){
				overFlow2.fadeOut();
			}
	);
        jQuery("#zoom_div").jqueryzoom(
    {
        xzoom: 300, //zoomed width
        yzoom: 400,
        offset: 10,
        position: "right"
    }
    );
        $('#first_slice').show();
}
);