﻿// JavaScript Document
$(document).ready(function() { 
//imagebox code begin
	$('body').append('<div id="shadow" class="shadow"></div><div id="imagebox" class="modal"><div class="top"><div><div><a id="imageclose" class="close" href="javascript:void(0)"></a></div></div></div><div class="middle"><div id="image" class="photo"><img src="" alt=""><span class="tl"></span><span class="tr"></span><span class="br"></span><span class="bl"></span></div><a id="imagenext" href="javascript:void(0)"></a><a id="imageprev" href="javascript:void(0)"></a></div><div class="bottom"><div><div id="imagetext">&nbsp;</div></div></div></div>');
	$("#shadow").css({opacity: "0.7"});
	$("#image img").css({display:'none'});
	var last = $("a.imagebox").size()-1;
	$("a.imagebox").click(function(){
		var current = $(this);
		var index = $("a.imagebox").index(current);
		if(index == 0){
			$("#imageprev").hide();
		}
		if(index == last){
			$("#imagenext").hide();
		}
		if($(this).hasClass('one')){
			$("#imageprev").hide();
			$("#imagenext").hide();
		}
		var path = $(current).attr("href");
		var imagetext = $(current).attr("title");
		$("#imagenext").click(function(){
			$("#image img").fadeTo(100,0);
			var next = $("a.imagebox").eq(index+1).attr("href");
			imagetext = $("a.imagebox").eq(index+1).attr("title");
			$("#image img").attr({src: next});
			$("#imageprev").show();
			index = index+1;
			if(index == last){
				$("#imagenext").hide();
			}
			return false;
		});
		$("#imageprev").click(function(){
			$("#image img").fadeTo(100,0);
			var prev = $("a.imagebox").eq(index-1).attr("href");
			imagetext = $("a.imagebox").eq(index+1).attr("title");
			$("#image img").attr({src: prev});
			$("#imagenext").show();
			index = index-1;
			if(index == 0){
				$("#imageprev").hide();
			}
			return false;
		});
		$("#shadow").fadeIn(800);
		$("#imagebox").fadeIn(1000);
		$("#imagebox").css({top: $(document).scrollTop()+30+'px'});
		$("#image img").attr({src: path}).bind("load", function(){
			var img_w = $(this).width()+80;
			var img_h = $(this).height()+90;
			$("#imagebox").animate({width:img_w+"px", marginLeft: -1*img_w/2+"px"}, 300, function(){
				$("#imagebox").animate({height:img_h+"px"}, 300, function(){
					$("#image img").fadeTo(300,1);
					$('#imagetext').text(imagetext);
				});
			});
		});
		return false;
	});
	$("#shadow,#imageclose").click(function(){
		$("#image img").removeAttr('style').fadeOut(0).attr({src: ""});
		$("#imagetext").text(' ');
		$("#shadow").fadeOut(200);
		$("#imagebox").fadeOut(200).removeAttr('style');
		$("#imagenext").show(0);
		$("#imageprev").show(0);
	});
	//imegabox code end
});
