/**
 * 
 *
 */
jQuery.fn.infobar = function(params) {

		var options = {
			hideall:  true
		}
		op = jQuery.extend(options, params)


   return this.each(function(){
      	 if( !$(this).hasClass("ready") ){
           	 	
            $(this).addClass("ready");
//          $(this).children("a").wrap('<div class="imagewrapper"></div>');
	    $(this).attr("class", "imagewrapper");
	   

	    //$(this).children("img").wrap('<div class="imagewrapper"></div>');
          	
            //initializing variables
	    var $self  =  $(this);
            var $child  =  $self.children("img");
	   
	    var width  =  $self.width()+2;
	    var height =  $self.height()+2;
	    var offset =  $self.offset();
            var xpos   =  offset.left;  
	    var ypos   =  offset.top + height - 30;
	    var name   =  "infobox" + $self.children(":first").attr("id");
	    var text   =  $self.children(":first").attr("info");
	    

            //hide at beginning
            //if(op.hideall) {
            //    $(".imgInfo").hide();
            //}
	    
	    //append infobox 
	    var $box = $("<span></span>");
	    $box.attr("id", name);
	    $box.addClass("imgInfo");
	    $box.html("<p>ID: "+text+"</p>");
            // bind roll-over
	    //$box.bind("mouseenter", function(e){
	    //    $(this).show();
            // });
	    //$box.bind("mouseleave", function(e){
            //    $(this).hide();
            //});        
	    $(this).append( $box );

	    // set box position        
	    //var xpos   =  offset.left + 1;  
	    //var ypos   =  offset.top + height - $box.height();
	    //$box.css({ top: ypos, left: xpos });        
        

        
        // append remove links
        var $removeButton = $("<a></a>");
        //$removeButton.attr("href", "#?remove=" + $self.children(":first").attr("id") );

        if( lang=="en" )
	    $removeButton.attr("href", "javascript:CartQuery(Array('tem','id'),Array('lk_ajaxcartremove_e','" + $self.children(":first").attr("id") + "'),'basket');");
	//  $removeButton.attr("onClick", "CartQuery(Array('tem','id'),Array('lk_ajaxcartremove_e','" + $self.children(":first").attr("id") + "'),'basket'); return false;" );
        else
	    $removeButton.attr("href", "javascript:CartQuery(Array('tem','id'),Array('lk_ajaxcartremove_f','" + $self.children(":first").attr("id") + "'),'basket');");

        // $removeButton.click(function() { 
		//CartQuery(Array('tem','id'),Array('lk_ajaxcartremove_f','" + $self.children(":first").attr("id") + "'),'basket'); }
        //  $removeButton.attr("onClick", "CartQuery(Array('tem','id'),Array('lk_ajaxcartremove_f','" + $self.children(":first").attr("id") + "'),'basket'); return false;" );
	    


        $removeButton.addClass("imgboxRemoveButton");
        if( lang=="en" ){
            $removeButton.text("Remove");        	
        }
        else{
            $removeButton.text("Poista");
        }
        
        $(this).parent().append( $removeButton ) ;
	 

          // center image, call center.js
          $child.center({
              vertical: true,
              horizontal: true
          });

        
        
	    // set remove position        
	    //var xpos   =  offset.left+2;  
	    //var ypos   =  offset.top + height +2;
	    //$removeButton.css({ top: ypos, left: xpos });
        //<a href="#" style="display:inline-block; padding:90px 0 0 0; width:100%; text-align:right; color:#ccc;">Poista</a>

	   
	  //$self.hover(
          //function () {
          //	$box.show();
          //}, 
          //function () {
          //	$box.hide();
          //}
        //);



    } // conditional end   

	   
   });

};

