(function($){

	$.fn.picbox = function(params)
	{
    $("#thumblink").click(function() {
      $(".thumb_div").each(function(){
      
        if($(this).find("a.link_120").children("img.thumb_pic").size() > 0 ){
        }else{
        
          var picsrcid  = $(this).find("a.link_320").attr("id");
          var picsrc    = $(this).find("a.link_320").attr("href");
          var picsrc_150 = $(this).find("a.link_150").attr("href");
          var tp_title  = $(this).find("img.thumb_dummy").attr("title");
          var tp_alt    = $(this).find("img.thumb_dummy").attr("alt");
          var tp_style  = $(this).find("img.thumb_dummy").attr("style");
          var tp_width  = $(this).find("img.thumb_dummy").attr("width"); 
          var tp_height = $(this).find("img.thumb_dummy").attr("height"); 
          var tp_border = $(this).find("img.thumb_dummy").attr("border");       
          var base_img  ="<img class='thumb_pic' border='0' src='" +picsrc_150 + "' >";
                        
        
          $(this).find("img.thumb_dummy").remove();
          $(this).find("a.link_120").append(base_img);
          $(this).find("img").attr("title",tp_title);
          $(this).find("img").attr("alt",tp_alt);
          $(this).find("img").attr("width",tp_width); 
          $(this).find("img").attr("height",tp_height);  
          $(this).find("img").css({'width':'100px', 'height':'65px'}) ;      
        }    
      });     
       
      if ($("#thumb_container").hasClass("show_thumbs")) {       
        $("#thumb_container").removeClass("show_thumbs").stop();
        $("#thumb_container").slideUp();      
      } else {      
      		$("#thumb_container").addClass("show_thumbs").stop();
        	$("#thumb_container").slideDown();
      }
     });
       	  	
  	$(".thumb_div").each(function(){       
     var picid=$(this).find("a.link_320").attr("id");
  	 var piclink = $(this).find("a.link_320").attr("href");
  
     $(this).hover(
       function() {
         $("#img_320_first").stop(false, true).fadeOut('fast');
         if($("a#link_320").children("img#img_"+picid).size() > 0 ){
            $("img#img_"+picid).stop(true, true).fadeIn('fast');
         }else{
            $("a#link_320").append("<img id='img_" + picid + "' border='0' src='" +piclink + "' >");         
            $("#img_" + picid ).removeAttr("height");
            $("#img_" + picid ).removeAttr("width");
            $("#img_" + picid ).removeAttr("style");
            $("#img_" + picid ).css({'position':'absolute', 'display':'none'}) ;
            $("#img_" + picid ).stop(true, true).fadeIn('fast');
         }
       },
       function() {
          $("img#img_"+picid).stop(true, true).fadeOut('slow');
          $("#img_320_first").stop(false, true).fadeIn('slow');          
       } 
     ); 
    });
    
  }
})(jQuery);
